Update of /cvsroot/roadmap/roadmap/src/iphone In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv8277/iphone Modified Files: Makefile roadmap_canvas.m roadmap_iphonecanvas.h roadmap_iphonemain.h roadmap_iphonemessagebox.h roadmap_main.m roadmap_messagebox.m Log Message: support for chorded (multitouch) rotation and drag, on the iphone. also support for bezier lines in iphone drawing routines. (all from morten bek.) Index: roadmap_iphonemessagebox.h =================================================================== RCS file: /cvsroot/roadmap/roadmap/src/iphone/roadmap_iphonemessagebox.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** roadmap_iphonemessagebox.h 4 May 2008 16:49:21 -0000 1.1 --- roadmap_iphonemessagebox.h 4 Nov 2008 14:56:23 -0000 1.2 *************** *** 32,35 **** } -(void)showWithTitle: (const char *) title text: (const char *) text modal: (int) modal; ! -(void)alertSheet:(UIAlertSheet*)sheet buttonClicked:(int)button; @end --- 32,35 ---- } -(void)showWithTitle: (const char *) title text: (const char *) text modal: (int) modal; ! -(void)alertSheet:(UIActionSheet*)sheet buttonClicked:(int)button; @end Index: roadmap_canvas.m =================================================================== RCS file: /cvsroot/roadmap/roadmap/src/iphone/roadmap_canvas.m,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** roadmap_canvas.m 7 Oct 2008 00:42:21 -0000 1.3 --- roadmap_canvas.m 4 Nov 2008 14:56:23 -0000 1.4 *************** *** 5,8 **** --- 5,9 ---- * Copyright 2002 Pascal F. Martin * Copyright 2008 Morten Bek Ditlevsen + * Copyright 2008 Avi Romano * * This file is part of RoadMap. *************** *** 33,37 **** #import <Foundation/Foundation.h> #import <GraphicsServices/GraphicsServices.h> ! #import <UIKit/CDStructures.h> #include "roadmap.h" --- 34,38 ---- #import <Foundation/Foundation.h> #import <GraphicsServices/GraphicsServices.h> ! #import <UIKit/UITouch.h> #include "roadmap.h" *************** *** 39,46 **** --- 40,50 ---- #include "roadmap_gui.h" + #include "roadmap_path.h" #include "roadmap_canvas.h" #include "roadmap_iphonecanvas.h" #include "colors.h" + #define FONT_INC_FACTOR 1.3 //Trying to compensate the high PPI of iPhone screen + #define FONT_DEFAULT_SIZE 12 extern int CGFontGetAscent(CGFontRef font); extern int CGFontGetDescent(CGFontRef font); *************** *** 50,53 **** --- 54,58 ---- extern CGFontRef CGFontCreateWithFontName (CFStringRef name); + struct RoadMapColor { float r; *************** *** 67,80 **** }; static struct roadmap_canvas_pen *RoadMapPenList = NULL; ! static RoadMapCanvasView *RoadMapDrawingArea; static CGContextRef RoadMapGc; - static LKLayer *mainLayer; static int CanvasWidth, CanvasHeight; static RoadMapPen CurrentPen; /* The canvas callbacks: all callbacks are initialized to do-nothing * functions, so that we don't care checking if one has been setup. --- 72,90 ---- }; + #define ROADMAP_CANVAS_LAYER_COUNT 2 + #define BEZIER_SMOOTH_VALUE 0.5 static struct roadmap_canvas_pen *RoadMapPenList = NULL; ! RoadMapCanvasView *RoadMapDrawingArea; static CGContextRef RoadMapGc; static int CanvasWidth, CanvasHeight; static RoadMapPen CurrentPen; + static CGPoint ChordingPoints[MAX_CHORDING_POINTS]; //Number of chording fingers. We actually use max of 2 + static CGPoint touch1point, touch2point; + static UITouch *touch1, *touch2; + /* The canvas callbacks: all callbacks are initialized to do-nothing * functions, so that we don't care checking if one has been setup. *************** *** 107,111 **** while (points < end) { cgpoints->x = points->x; ! cgpoints->y = CanvasHeight - points->y; cgpoints += 1; points += 1; --- 117,121 ---- while (points < end) { cgpoints->x = points->x; ! cgpoints->y = points->y; cgpoints += 1; points += 1; *************** *** 120,124 **** while (points < end) { rects->origin.x = points->x; ! rects->origin.y = CanvasHeight - points->y; rects->size.width = 1.0; rects->size.height = 1.0; --- 130,134 ---- while (points < end) { rects->origin.x = points->x; ! rects->origin.y = points->y; rects->size.width = 1.0; rects->size.height = 1.0; *************** *** 128,136 **** } void roadmap_canvas_get_text_extents (const char *text, int size, int *width, int *ascent, int *descent, int *can_tilt) { ! float size_f = (size * 1.0f); UniChar buf[2048]; CGGlyph glyphs[2048]; --- 138,168 ---- } + void set_fast_draw (int fast_draw) { + if (fast_draw) { + CGContextSetAllowsAntialiasing (RoadMapGc, NO); + CGContextSetInterpolationQuality (RoadMapGc, kCGInterpolationNone); + CGContextSetLineCap(RoadMapGc, kCGLineCapButt); + CGContextSetLineJoin(RoadMapGc, kCGLineJoinMiter); + } + } + + void end_fast_draw (int fast_draw) { + if (fast_draw) { + CGContextSetAllowsAntialiasing (RoadMapGc, YES); + CGContextSetInterpolationQuality (RoadMapGc, kCGInterpolationDefault); + CGContextSetLineCap(RoadMapGc, kCGLineCapRound); + CGContextSetLineJoin(RoadMapGc, kCGLineJoinRound); + } + } + void roadmap_canvas_get_text_extents (const char *text, int size, int *width, int *ascent, int *descent, int *can_tilt) { ! if (size == -1) ! { ! size = FONT_DEFAULT_SIZE; ! } ! float size_f = (size * 1.0); UniChar buf[2048]; CGGlyph glyphs[2048]; *************** *** 144,154 **** CFIndex length = CFStringGetLength(string); if (length >= 2048) return; CFStringGetCharacters (string, CFRangeMake(0, length), buf); CGFontGetGlyphsForUnichars(font, buf, glyphs, length); CGContextSetTextDrawingMode (RoadMapGc, kCGTextInvisible); ! CGContextSetTextPosition(RoadMapGc, 0,0); CGContextShowGlyphs(RoadMapGc, glyphs, length); point = CGContextGetTextPosition(RoadMapGc); --- 176,190 ---- CFIndex length = CFStringGetLength(string); if (length >= 2048) + { + CFRelease (string); return; + } CFStringGetCharacters (string, CFRangeMake(0, length), buf); + CFRelease (string); CGFontGetGlyphsForUnichars(font, buf, glyphs, length); CGContextSetTextDrawingMode (RoadMapGc, kCGTextInvisible); ! CGContextSetTextMatrix(RoadMapGc, CGAffineTransformIdentity); CGContextShowGlyphs(RoadMapGc, glyphs, length); point = CGContextGetTextPosition(RoadMapGc); *************** *** 222,230 **** if (*color == '#') { ! int ir, ig, ib; ! sscanf(color, "#%2x%2x%2x", &ir, &ig, &ib); r = ir/255.0; g = ig/255.0; b = ib/255.0; } else { /* Do binary search on color table */ --- 258,272 ---- if (*color == '#') { ! int ir, ig, ib, ia; ! int count; ! count = sscanf(color, "#%2x%2x%2x%2x", &ir, &ig, &ib, &ia); r = ir/255.0; g = ig/255.0; b = ib/255.0; + + if (count == 4) + { + a = ia/255.0; + } } else { /* Do binary search on color table */ *************** *** 250,255 **** CurrentPen->stroke.g = g; CurrentPen->stroke.b = b; ! CurrentPen->stroke.a = a; } --- 292,298 ---- CurrentPen->stroke.g = g; CurrentPen->stroke.b = b; ! CurrentPen->stroke.a = a; + roadmap_canvas_select_pen(CurrentPen); } *************** *** 263,266 **** --- 306,314 ---- void roadmap_canvas_set_thickness (int thickness) { + if (thickness < 0) { + //printf ("Warning: thickness %d changed to 0\n",thickness); + thickness = 0; + } + CurrentPen->lineWidth = thickness * 1.0; } *************** *** 290,296 **** void roadmap_canvas_erase (void) { /* 'erase' means fill the canvas with the foreground color */ ! CGContextFillRect(RoadMapGc, [RoadMapDrawingArea frame]); } void roadmap_canvas_draw_string (RoadMapGuiPoint *position, int corner, --- 338,351 ---- void roadmap_canvas_erase (void) { /* 'erase' means fill the canvas with the foreground color */ ! CGContextFillRect(RoadMapGc, [RoadMapDrawingArea bounds]); ! } ! ! void roadmap_canvas_erase_area (const RoadMapGuiRect *rect) ! { ! CGRect imageRect = CGRectMake(rect->minx * 1.0f, rect->miny * 1.0f, (rect->maxx - rect->minx) * 1.0f, (rect->maxy - rect->miny) * 1.0f); ! CGContextFillRect(RoadMapGc, imageRect); } + void roadmap_canvas_draw_string (RoadMapGuiPoint *position, int corner, *************** *** 301,307 **** --- 356,364 ---- int text_ascent; int text_descent; + int text_height; RoadMapGuiPoint start[1]; roadmap_canvas_get_text_extents (text, size, &text_width, &text_ascent, &text_descent, NULL); + text_height = text_ascent + text_descent; start->x = position->x; start->y = position->y; *************** *** 325,331 **** { CGAffineTransform trans; ! float angle_f = (angle * -1.0f) * M_PI / 180.0f; float x = center->x * 1.0f; ! float y = CanvasHeight - center->y * 1.0f; float size_f = (size * 1.0f); UniChar buf[2048]; --- 382,388 ---- { CGAffineTransform trans; ! float angle_f = (angle - 180.0f) * M_PI / 180.0f; float x = center->x * 1.0f; ! float y = center->y * 1.0f; float size_f = (size * 1.0f); UniChar buf[2048]; *************** *** 345,348 **** --- 402,406 ---- trans = CGAffineTransformMakeRotation(angle_f); + trans = CGAffineTransformScale (trans, -1.0, 1.0); CGContextSetTextMatrix(RoadMapGc, trans); *************** *** 366,383 **** void roadmap_canvas_draw_multiple_lines (int count, int *lines, RoadMapGuiPoint *points, int fast_draw) { int i; int count_of_points; CGPoint cgpoints[1024]; for (i = 0; i < count; ++i) { count_of_points = *lines; while (count_of_points > 1024) { roadmap_canvas_convert_points (cgpoints, points, 1024); CGContextBeginPath(RoadMapGc); ! CGContextAddLines(RoadMapGc, cgpoints, 1024); CGContextStrokePath(RoadMapGc); points += 1023; --- 424,548 ---- + static void roadmap_calc_bezier_controlpoints + (CGPoint *points, float *c1x, float *c1y, float *c2x, float *c2y) + { + float smooth = BEZIER_SMOOTH_VALUE; + short x0 = points[0].x; + short y0 = points[0].y; + short x1 = points[1].x; + short y1 = points[1].y; + short x2 = points[2].x; + short y2 = points[2].y; + + float angle; + + float xc1 = (x0 + x1) / 2.0; + float yc1 = (y0 + y1) / 2.0; + float xc2 = (x1 + x2) / 2.0; + float yc2 = (y1 + y2) / 2.0; + + float len1 = sqrt((x1-x0) * (x1-x0) + (y1-y0) * (y1-y0)); + float len2 = sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1)); + float dot = (x1 - x0) * (x2 - x1) + (y1 - y0) * (y2 - y1); + + angle = acos ( dot / (len1 * len2) ); + if (dot < 0) + { + if (angle > 0) + angle += M_PI; + else + angle -= M_PI; + } + + /* If the angle is less than a bit more than 90 degrees + _or_ if two of the points coincide - return the + mid point as control points (to cause a sharp + corner) */ + if ((angle > 1.4 || angle < -1.4) || + (len1 < 0.0001 && len1 > -0.001) || + (len2 < 0.0001 && len2 > -0.001)) + { + *c1x = x1; + *c1y = y1; + + *c2x = x1; + *c2y = y1; + return; + } + + float k = len1 / (len1 + len2); + + float xm = xc1 + (xc2 - xc1) * k; + float ym = yc1 + (yc2 - yc1) * k; + + *c1x = (xc1 - xm) * smooth + x1; + *c1y = (yc1 - ym) * smooth + y1; + + *c2x = (xc2 - xm) * smooth + x1; + *c2y = (yc2 - ym) * smooth + y1; + } + + static void roadmap_draw_bezier_path(CGPoint *p, int count) + { + int i = 0; + float c1x, c1y, c2x, c2y, p1x, p1y, p2x, p2y; + CGContextBeginPath(RoadMapGc); + CGContextMoveToPoint(RoadMapGc, p[0].x, p[0].y); + c1x = (p[1].x - p[0].x) / 2.0 + p[0].x; + c1y = (p[1].y - p[0].y) / 2.0 + p[0].y; + roadmap_calc_bezier_controlpoints(&(p[0]), &p1x, &p1y, &p2x, &p2y); + c2x = p1x; c2y = p1y; + CGContextAddCurveToPoint(RoadMapGc, c1x, c1y, c2x, c2y, p[i+1].x, p[i+1].y); + i = 0; + for (i = 1; i + 3 <= count; i++) + { + c1x = p2x; c1y = p2y; + roadmap_calc_bezier_controlpoints(&(p[i]), &p1x, &p1y, &p2x, &p2y); + c2x = p1x; c2y = p1y; + CGContextAddCurveToPoint(RoadMapGc, c1x, c1y, c2x, c2y, p[i+1].x, p[i+1].y); + } + if (count > 2) + { + c1x = p2x; c1y = p2y; + + c2x = (p[i + 1].x - p[i].x) / 2.0 + p[i].x; + c2y = (p[i + 1].y - p[i].y) / 2.0 + p[i].y; + CGContextAddCurveToPoint(RoadMapGc, c1x, c1y, c2x, c2y, p[i+1].x, p[i+1].y); + } + CGContextStrokePath(RoadMapGc); + } + /* + Known graphic artifacts of the following function: + When drawing bezier lines - every 1024th point will + have a sharp corner. + Lines that are moving out of the screen will suddenly + change from being drawn with one control point to + two... To fix this, an extra line segment outside the + screen must always be included in the line paths to + be drawn. + */ void roadmap_canvas_draw_multiple_lines (int count, int *lines, RoadMapGuiPoint *points, int fast_draw) { int i; + int bezier = !fast_draw; int count_of_points; CGPoint cgpoints[1024]; + set_fast_draw (fast_draw); for (i = 0; i < count; ++i) { count_of_points = *lines; + if (count_of_points < 2) + continue; + while (count_of_points > 1024) { roadmap_canvas_convert_points (cgpoints, points, 1024); CGContextBeginPath(RoadMapGc); ! if (bezier) ! roadmap_draw_bezier_path(cgpoints, 1024); ! else ! CGContextAddLines(RoadMapGc, cgpoints, 1024); ! CGContextStrokePath(RoadMapGc); points += 1023; *************** *** 386,406 **** roadmap_canvas_convert_points (cgpoints, points, count_of_points); - CGContextBeginPath(RoadMapGc); ! CGContextAddLines(RoadMapGc, cgpoints, count_of_points); ! CGContextStrokePath(RoadMapGc); points += count_of_points; lines += 1; } } void roadmap_canvas_draw_multiple_polygons (int count, int *polygons, RoadMapGuiPoint *points, int filled, int fast_draw) { int i; int count_of_points; CGPoint cgpoints[1024]; ! for (i = 0; i < count; ++i) { count_of_points = *polygons; --- 551,580 ---- roadmap_canvas_convert_points (cgpoints, points, count_of_points); CGContextBeginPath(RoadMapGc); ! if (bezier) ! roadmap_draw_bezier_path(cgpoints, count_of_points); ! else ! CGContextAddLines(RoadMapGc, cgpoints, count_of_points); + CGContextStrokePath(RoadMapGc); points += count_of_points; lines += 1; } + + end_fast_draw (fast_draw); } + void roadmap_canvas_draw_multiple_polygons (int count, int *polygons, RoadMapGuiPoint *points, int filled, int fast_draw) { + int i; int count_of_points; CGPoint cgpoints[1024]; ! ! set_fast_draw (fast_draw); ! ! for (i = 0; i < count; ++i) { count_of_points = *polygons; *************** *** 432,435 **** --- 606,611 ---- polygons += 1; } + + end_fast_draw (fast_draw); } *************** *** 440,448 **** int i; for (i = 0; i < count; ++i) { int r = radius[i]; ! CGRect circle = CGRectMake(centers[i].x-r, (CanvasHeight - centers[i].y)-r, r*2, r*2); CGContextAddEllipseInRect(RoadMapGc, circle); if (filled) --- 616,626 ---- int i; + set_fast_draw (fast_draw); + for (i = 0; i < count; ++i) { int r = radius[i]; ! CGRect circle = CGRectMake(centers[i].x-r, (centers[i].y)-r, r*2, r*2); CGContextAddEllipseInRect(RoadMapGc, circle); if (filled) *************** *** 452,455 **** --- 630,635 ---- } + + end_fast_draw (fast_draw); } *************** *** 526,534 **** { CGImageRef image = CGBitmapContextCreateImage (RoadMapGc); ! // save image CGImageRelease(image); } } @implementation RoadMapCanvasView --- 706,821 ---- { CGImageRef image = CGBitmapContextCreateImage (RoadMapGc); ! // TODO: save image CGImageRelease(image); } } + int roadmap_canvas_image_width (const RoadMapImage image) + { + UIImage *img = (UIImage*)image; + if (img) + return img.size.width; + else + return 0; + } + + int roadmap_canvas_image_height (const RoadMapImage image) + { + UIImage *img = (UIImage*)image; + if (img) + return img.size.height; + else + return 0; + } + + static char *roadmap_canvas_image_path (const char *name) { + unsigned int i; + + if (name == NULL) + return NULL; + + const char *image_file = roadmap_path_search_icon (name); + if (image_file == NULL) + return NULL; + + for (i = 0; i < strlen(image_file); i++) + { + if (strncmp (image_file + i, "resources", 9) == 0) + { + return (char *)(image_file + i); + } + } + return NULL; + } + + RoadMapImage roadmap_canvas_load_image ( const char* path, const char* file_name) + { + char *imagePath; + NSString *nsImagePath; + imagePath = roadmap_canvas_image_path (file_name); + + if (imagePath) + { + nsImagePath = [[NSString alloc] initWithUTF8String:imagePath]; + UIImage *image = [UIImage imageNamed: nsImagePath]; + return (RoadMapImage)image; + } + return NULL; + } + + void roadmap_canvas_draw_image (RoadMapImage image, RoadMapGuiPoint *pos, + int opacity, int mode) + { + UIImage *img = (UIImage*)image; + CGPoint point; + point.x = pos->x; + point.y = pos->y; + //NSLog (@"draw image with opacity: %i at %f %f", opacity, point.x, point.y); + if (img) + { + UIGraphicsPushContext(RoadMapGc); + [img drawAtPoint:point blendMode:kCGBlendModeNormal alpha:1.0f]; + UIGraphicsPopContext(); + } + } + + void roadmap_canvas_copy_image (RoadMapImage dst_image, + const RoadMapGuiPoint *pos, + const RoadMapGuiRect *rect, + RoadMapImage src_image, int mode) + { + } + + void roadmap_canvas_draw_image_text (RoadMapImage image, + const RoadMapGuiPoint *position, + int size, const char *text) + { + } + + void roadmap_canvas_layer_select(int layer) + { + /* remove me */ + } + + void roadmap_canvas_get_chording_pt (RoadMapGuiPoint points[MAX_CHORDING_POINTS]) + { + points[0].x = ChordingPoints[0].x; + points[0].y = ChordingPoints[0].y; + + points[1].x = ChordingPoints[1].x; + points[1].y = ChordingPoints[1].y; + + points[2].x = ChordingPoints[2].x; + points[2].y = ChordingPoints[2].y; + } + + int roadmap_canvas_is_chording() + { + return (ChordingPoints[0].x > -1); + } + + + + @implementation RoadMapCanvasView *************** *** 539,543 **** --- 826,835 ---- self = [super initWithFrame: rect]; + + touch1 = nil; + touch2 = nil; + RoadMapDrawingArea = self; + self.multipleTouchEnabled = TRUE; CGColorSpaceRef imageColorSpace = CGColorSpaceCreateDeviceRGB(); *************** *** 545,557 **** CGColorSpaceRelease(imageColorSpace); ! CGFontRef font = CGFontCreateWithFontName((CFStringRef)@"arialuni") ; CGContextSetFont(RoadMapGc, font); CGContextSetTextDrawingMode (RoadMapGc, kCGTextFill); CGContextSetLineCap(RoadMapGc, kCGLineCapRound); - mainLayer = [[LKLayer layer] retain]; - [mainLayer setFrame: rect]; - - [self._layer addSublayer: mainLayer]; (*RoadMapCanvasConfigure) (); --- 837,845 ---- CGColorSpaceRelease(imageColorSpace); ! CGFontRef font = CGFontCreateWithFontName((CFStringRef)@"ArialUnicodeMS") ; CGContextSetFont(RoadMapGc, font); CGContextSetTextDrawingMode (RoadMapGc, kCGTextFill); CGContextSetLineCap(RoadMapGc, kCGLineCapRound); (*RoadMapCanvasConfigure) (); *************** *** 566,602 **** so if we're lucky no copy is actually made! */ CGImageRef ref = CGBitmapContextCreateImage(RoadMapGc); ! [mainLayer setContents: (id)ref]; CGImageRelease(ref); } } ! - (void)mouseDown: (GSEvent*)event { ! printf("mouseDown\n"); ! CGPoint location = GSEventGetLocationInWindow(event); ! RoadMapGuiPoint point; ! point.x = location.x; ! point.y = location.y; ! (*RoadMapCanvasMouseButtonPressed) (1, &point); } ! - (void) mouseUp:(GSEvent*)event { ! printf("mouseUp\n"); ! CGPoint location = GSEventGetLocationInWindow(event); ! RoadMapGuiPoint point; ! point.x = location.x; ! point.y = location.y; ! (*RoadMapCanvasMouseButtonReleased) (1, &point); } ! - (void) mouseDragged:(GSEvent*)event { ! printf("mouseMoved\n"); ! CGPoint location = GSEventGetLocationInWindow(event); ! RoadMapGuiPoint point; ! point.x = location.x; ! point.y = location.y; ! (*RoadMapCanvasMouseMoved) (0, &point); } --- 854,947 ---- so if we're lucky no copy is actually made! */ CGImageRef ref = CGBitmapContextCreateImage(RoadMapGc); ! CGContextDrawImage(UIGraphicsGetCurrentContext(), rect, ref); CGImageRelease(ref); } } ! - (void)touchesBegan: (NSSet *) touches withEvent: (UIEvent*)event { ! UITouch *touch = [touches anyObject]; ! CGPoint location = [touch locationInView: touch.view]; ! RoadMapGuiPoint point; ! point.x = location.x; ! point.y = location.y; ! for (UITouch *touch in touches) { ! location = [touch locationInView: touch.view]; ! if (touch1 == nil) ! { ! touch1 = touch; ! touch1point = location; ! } ! else if (touch2 == nil) ! { ! touch2 = touch; ! touch2point = location; ! } ! } ! if (touch1 != nil && touch2 != nil) { ! ChordingPoints[0] = touch1point; ! ChordingPoints[1] = touch2point; ! } else { ! ChordingPoints[0].x = -1; ! } ! ChordingPoints[2].x = -1; ! ! (*RoadMapCanvasMouseButtonPressed) (1, &point); } ! - (void)touchesEnded: (NSSet *) touches withEvent: (UIEvent*)event { ! UITouch *touch = [touches anyObject]; ! CGPoint location = [touch locationInView: touch.view]; ! RoadMapGuiPoint point; ! point.x = location.x; ! point.y = location.y; ! for (UITouch *touch in touches) { ! if (touch == touch1) ! touch1 = nil; ! else if (touch == touch2) ! touch2 = nil; ! } ! ! if (touch1 != nil && touch2 != nil) { ! NSLog(@"chording !"); ! ! ChordingPoints[0] = touch1point; ! ChordingPoints[1] = touch2point; ! ! ChordingPoints[2].x = -1; ! } else { ! ChordingPoints[0].x = -1; ! } ! ! (*RoadMapCanvasMouseButtonReleased) (1, &point); } ! - (void)touchesMoved: (NSSet *) touches withEvent: (UIEvent*)event { ! UITouch *touch = [touches anyObject]; ! CGPoint location = [touch locationInView: touch.view]; ! RoadMapGuiPoint point; ! point.x = location.x; ! point.y = location.y; ! for (UITouch *touch in touches) { ! location = [touch locationInView: touch.view]; ! if (touch1 == touch) ! touch1point = location; ! else if (touch2 == touch) ! touch2point = location; ! } ! ! if (touch1 != nil && touch2 != nil) { ! ! ChordingPoints[0] = touch1point; ! ChordingPoints[1] = touch2point; ! ! ChordingPoints[2].x = -1; ! } else { ! ChordingPoints[0].x = -1; ! } ! ! (*RoadMapCanvasMouseMoved) (0, &point); } Index: roadmap_iphonecanvas.h =================================================================== RCS file: /cvsroot/roadmap/roadmap/src/iphone/roadmap_iphonecanvas.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** roadmap_iphonecanvas.h 20 Jun 2008 13:09:19 -0000 1.2 --- roadmap_iphonecanvas.h 4 Nov 2008 14:56:23 -0000 1.3 *************** *** 33,37 **** #import <UIKit/UIKit.h> - #import <UIKit/UIButtonBar.h> @interface RoadMapCanvasView : UIView { --- 33,36 ---- Index: Makefile =================================================================== RCS file: /cvsroot/roadmap/roadmap/src/iphone/Makefile,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Makefile 28 Jun 2008 16:49:28 -0000 1.3 --- Makefile 4 Nov 2008 14:56:23 -0000 1.4 *************** *** 8,16 **** ROADMAP_BUNDLE=RoadMap.app ROADGPS_BUNDLE=RoadGps.app ! LIBS += ! LDFLAGS += -L/home/ditlemor/usr/local/lib -lobjc -ObjC \ ! -framework CoreFoundation -framework Foundation \ ! -framework UIKit -framework LayerKit -framework CoreGraphics \ ! -framework GraphicsServices # --- iPhone sources & targets ----------------------------------- --- 8,22 ---- ROADMAP_BUNDLE=RoadMap.app ROADGPS_BUNDLE=RoadGps.app ! LIBS += -lobjc -lstdc++.6 ! LDFLAGS += -fobjc-abi-version=2 \ ! -L/home/ditlemor/dat/sys/usr/lib \ ! -F/home/ditlemor/dat/sys/System/Library/Frameworks \ ! -framework CoreFoundation -framework CoreGraphics \ ! -framework Foundation \ ! -framework UIKit -bind_at_load \ ! # -framework GraphicsServices ! # -F/System/Library/Frameworks \ ! # ! CFLAGS += -fobjc-abi-version=2 # --- iPhone sources & targets ----------------------------------- Index: roadmap_messagebox.m =================================================================== RCS file: /cvsroot/roadmap/roadmap/src/iphone/roadmap_messagebox.m,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** roadmap_messagebox.m 4 May 2008 16:49:21 -0000 1.1 --- roadmap_messagebox.m 4 Nov 2008 14:56:23 -0000 1.2 *************** *** 27,31 **** */ ! #import <UIKit/UIAlertSheet.h> #include "roadmap.h" --- 27,31 ---- */ ! #import <UIKit/UIAlert.h> #include "roadmap.h" *************** *** 42,55 **** -(void)showWithTitle: (const char *) title text: (const char *) text modal: (int) modal { ! UIAlertSheet * zSheet; NSString *nstitle = [[NSString alloc] initWithUTF8String: title]; NSString *nstext = [[NSString alloc] initWithUTF8String: text]; ! NSArray *buttons = [NSArray arrayWithObjects:@"OK", nil]; ! zSheet = [[UIAlertSheet alloc] initWithTitle:nstitle buttons:buttons defaultButtonIndex:1 delegate:self context:self]; ! [zSheet setBodyText: nstext]; ! [zSheet setRunsModal: true]; //I'm a big fan of running sheet modally ! [zSheet popupAlertAnimated:YES]; //Displays //Pauses here until user taps the sheet closed [zSheet autorelease]; --- 42,54 ---- -(void)showWithTitle: (const char *) title text: (const char *) text modal: (int) modal { ! UIAlertView * zSheet; NSString *nstitle = [[NSString alloc] initWithUTF8String: title]; NSString *nstext = [[NSString alloc] initWithUTF8String: text]; ! zSheet = [[UIAlertView alloc] initWithTitle:nstitle message: nstext delegate:self cancelButtonTitle: @"OK" otherButtonTitles: nil]; ! // [zSheet setRunsModal: true]; //I'm a big fan of running sheet modally ! // [zSheet popupAlertAnimated:YES]; //Displays //Pauses here until user taps the sheet closed + [zSheet show]; [zSheet autorelease]; *************** *** 58,64 **** } ! -(void)alertSheet:(UIAlertSheet*)sheet buttonClicked:(int)button { ! [sheet dismiss]; } @end --- 57,63 ---- } ! -(void)alertView:(UIAlertView*)sheet clickedButtonAtIndex:(NSInteger)button { ! // [sheet dismiss]; } @end *************** *** 86,87 **** --- 85,90 ---- return roadmap_messagebox_show (title, message, 1); } + + void roadmap_messagebox_die (const char *title, const char *message) { + (void)roadmap_messagebox_show (title, message, 1); + } Index: roadmap_main.m =================================================================== RCS file: /cvsroot/roadmap/roadmap/src/iphone/roadmap_main.m,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** roadmap_main.m 12 Jul 2008 09:24:15 -0000 1.3 --- roadmap_main.m 4 Nov 2008 14:56:23 -0000 1.4 *************** *** 62,66 **** static RoadMapApp *TheApp; ! static int RoadMapMainToolbarAdded = 0; static int sArgc; static char ** sArgv; --- 62,66 ---- static RoadMapApp *TheApp; ! static int RoadMapMainTabBarAdded = 0; static int sArgc; static char ** sArgv; *************** *** 87,101 **** static RoadMapKeyInput RoadMapMainInput = NULL; - static UIWindow *RoadMapMainWindow = NULL; static UIView *RoadMapMainBox = NULL; static RoadMapCanvasView *RoadMapCanvasBox = NULL; //static UIView *RoadMapMainMenuBar = NULL; ! static UIButtonBar *RoadMapMainToolbar = NULL; //static UIView *RoadMapMainStatus = NULL; ! static NSArray *RoadMapMainToolbarArray = NULL; static int buttonCount = 0; ! static RoadMapCallback RoadMapMainToolbarCallbacks[6]; static char *roadmap_main_toolbar_icon (const char *icon) { unsigned int i; --- 87,113 ---- static RoadMapKeyInput RoadMapMainInput = NULL; static UIView *RoadMapMainBox = NULL; static RoadMapCanvasView *RoadMapCanvasBox = NULL; //static UIView *RoadMapMainMenuBar = NULL; ! UIToolbar *RoadMapMainTabBar = NULL; //static UIView *RoadMapMainStatus = NULL; ! static NSArray *RoadMapMainTabBarArray = NULL; static int buttonCount = 0; ! static RoadMapCallback RoadMapMainTabBarCallbacks[6]; + void roadmap_main_send_email(const char *subject, const char *contents, + const char *att_path, const char *att_name) + { + char text[4096]; + if (att_path) + snprintf(text, 4096, "mailto:?subject=%s&body=%s&attachment=%s/%s", subject, contents, att_path, att_name); + else + snprintf(text, 4096, "mailto:?subject=%s&body=%s", subject, contents); + CFStringRef string = CFStringCreateWithCString(NULL, text, kCFStringEncodingUTF8); + CFStringRef urlString = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, string, NULL, NULL, kCFStringEncodingUTF8); + [TheApp openURL: [NSURL URLWithString: (NSString *)urlString]]; + } + static char *roadmap_main_toolbar_icon (const char *icon) { unsigned int i; *************** *** 111,115 **** --- 123,129 ---- { if (strncmp (icon_file + i, "resources", 9) == 0) + { return (char *)(icon_file + i); + } } return NULL; *************** *** 217,222 **** void roadmap_main_add_toolbar (const char *orientation) { NSLog (@"roadmap_main_add_toolbar orientation: %s\n", orientation); ! RoadMapMainToolbarAdded = 1; ! RoadMapMainToolbarArray = [[NSArray array] init]; } --- 231,236 ---- void roadmap_main_add_toolbar (const char *orientation) { NSLog (@"roadmap_main_add_toolbar orientation: %s\n", orientation); ! RoadMapMainTabBarAdded = 1; ! RoadMapMainTabBarArray = [[NSArray array] init]; } *************** *** 228,232 **** NSString *nsicon, *nslabel; ! NSLog (@"roadmap_main_add_tool label: %s icon: %s tip: %s\n", label, icon, tip); if (buttonCount >= 5) { --- 242,246 ---- NSString *nsicon, *nslabel; ! // NSLog (@"roadmap_main_add_tool label: %s icon: %s tip: %s\n", label, icon, tip); if (buttonCount >= 5) { *************** *** 234,260 **** return; } - buttonCount++; ! NSArray *tmp = RoadMapMainToolbarArray; nslabel = [[NSString alloc] initWithUTF8String:icon]; iconstr = roadmap_main_toolbar_icon(icon); if (iconstr) nsicon = [[NSString alloc] initWithUTF8String:iconstr]; else ! nsicon = @""; ! RoadMapMainToolbarCallbacks[buttonCount] = callback; ! NSDictionary *dict = [ NSDictionary dictionaryWithObjectsAndKeys: ! @"buttonBarItemTapped:", kUIButtonBarButtonAction, ! nsicon, kUIButtonBarButtonInfo, ! @"imagedown.png", kUIButtonBarButtonSelectedInfo, ! [ NSNumber numberWithInt: buttonCount], kUIButtonBarButtonTag, ! TheApp, kUIButtonBarButtonTarget, ! nslabel, kUIButtonBarButtonTitle, ! //@"", kUIButtonBarButtonTitle, ! @"0", kUIButtonBarButtonType, ! nil ! ]; ! RoadMapMainToolbarArray = [tmp arrayByAddingObject: dict]; } --- 248,273 ---- return; } ! NSArray *tmp = RoadMapMainTabBarArray; nslabel = [[NSString alloc] initWithUTF8String:icon]; iconstr = roadmap_main_toolbar_icon(icon); + UIImage *image = NULL; if (iconstr) + { nsicon = [[NSString alloc] initWithUTF8String:iconstr]; + image = [UIImage imageNamed: nsicon]; + } + + UIBarButtonItem *item = [UIBarButtonItem alloc]; + if (image == NULL) + [item initWithTitle: nslabel style: UIBarButtonItemStylePlain target: TheApp action: @selector(buttonPressed:)]; else ! [item initWithImage: image style: UIBarButtonItemStylePlain target: TheApp action: @selector(buttonPressed:)]; ! item.tag = buttonCount; ! item.width = 64.0f; ! RoadMapMainTabBarCallbacks[buttonCount] = callback; ! RoadMapMainTabBarArray = [tmp arrayByAddingObject: item]; ! buttonCount++; } *************** *** 281,288 **** void roadmap_main_add_canvas (void) { ! struct CGRect rect = [UIHardware fullScreenApplicationContentRect]; rect.origin.x = 0.0f; ! rect.origin.y = 0.0f; ! if (RoadMapMainToolbarAdded) rect.size.height = 480.0f - 49.0f - 20.0f; else --- 294,302 ---- void roadmap_main_add_canvas (void) { ! //struct CGRect rect = [UIHardware fullScreenApplicationContentRect]; ! struct CGRect rect = [RoadMapMainBox frame]; rect.origin.x = 0.0f; ! rect.origin.y = 20.0f; ! if (RoadMapMainTabBarAdded) rect.size.height = 480.0f - 49.0f - 20.0f; else *************** *** 302,309 **** configured, we use this to add the finalized toolbar to the main view */ ! if (RoadMapMainToolbarAdded) { ! RoadMapMainToolbar = [TheApp createButtonBar]; ! [RoadMapMainBox addSubview: RoadMapMainToolbar]; } } --- 316,323 ---- configured, we use this to add the finalized toolbar to the main view */ ! if (RoadMapMainTabBarAdded) { ! RoadMapMainTabBar = [TheApp createButtonBar]; ! [RoadMapMainBox addSubview: RoadMapMainTabBar]; } } *************** *** 343,352 **** int roadmap_main_flush (void) { ! if ([[NSNotificationCenter defaultCenter] isEmpty]) return 0; return 1; // NSLog (@"roadmap_main_flush\n"); /* while (gtk_events_pending ()) { --- 357,385 ---- int roadmap_main_flush (void) { ! /* if ([[NSNotificationCenter defaultCenter] isEmpty]) return 0; + + NSLog (@"notificationcenter has notifications\n"); return 1; + */ + // NSLog (@"roadmap_main_flush\n"); + //[[NSRunLoop currentRunLoop] run]; + + double resolution = 0.0001; + + + + NSDate* next = [NSDate dateWithTimeIntervalSinceNow:resolution]; + + [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode + + beforeDate:next]; + + + + /* while (gtk_events_pending ()) { *************** *** 361,365 **** int roadmap_main_flush_synchronous (int deadline) { ! NSLog (@"roadmap_main_flush_synchronous\n"); long start_time, duration; --- 394,398 ---- int roadmap_main_flush_synchronous (int deadline) { ! // NSLog (@"roadmap_main_flush_synchronous\n"); long start_time, duration; *************** *** 389,397 **** void roadmap_main_exit (void) { ! static int exit_done; if (!exit_done++) { roadmap_start_exit (); ! } } --- 422,432 ---- void roadmap_main_exit (void) { ! /* static int exit_done; if (!exit_done++) { roadmap_start_exit (); ! */ ! // YYYY [TheApp terminate]; ! exit(0); } *************** *** 399,402 **** --- 434,438 ---- int i; int j = 0; + int returnCode; sArgc = argc; sArgv = (char **)malloc(argc * (sizeof (char*))); *************** *** 417,469 **** roadmap_option (sArgc, sArgv, 0, NULL); NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; ! return UIApplicationMain(sArgc, sArgv, [RoadMapApp class]); [pool release]; ! return 0; } @implementation RoadMapApp ! - (UIButtonBar *)createButtonBar { ! UIButtonBar *buttonBar; ! buttonBar = [ [ UIButtonBar alloc ] ! initInView: RoadMapMainBox ! withFrame: CGRectMake(0.0f, 480.0f - 49.0f - 20.0f, 320.0f, 49.0f) ! withItemList: RoadMapMainToolbarArray ]; ! [buttonBar setDelegate:self]; ! [buttonBar setBarStyle:0]; ! [buttonBar setButtonBarTrackingMode: 1]; ! ! int buttons[5] = { 1, 2, 3, 4, 5}; ! [buttonBar registerButtonGroup:0 withButtons:buttons withCount: buttonCount]; ! [buttonBar showButtonGroup: 0 withDuration: 0.0f]; ! int tag; ! for(tag = 1; tag <= buttonCount; tag++) { ! [ [ buttonBar viewWithTag:tag ] ! setFrame:CGRectMake(2.0f + ((tag - 1) * 64.0f), 1.0f, 64.0f, 48.0f) ! ]; ! } return buttonBar; } ! - (void)buttonBarItemTapped:(id) sender { int button = [ sender tag ]; ! printf("buttonclicked: %i\n", button); ! (RoadMapMainToolbarCallbacks[button] ) (); } -(void) newWithTitle: (const char *)title andWidth: (int) width andHeight: (int) height { ! if (RoadMapMainWindow == NULL) { ! struct CGRect rect = [UIHardware fullScreenApplicationContentRect]; ! rect.origin.x = rect.origin.y = 0.0f; ! RoadMapMainWindow = [[UIWindow alloc] initWithContentRect: rect]; ! RoadMapMainBox = [[UIView alloc] initWithFrame: rect]; ! [RoadMapMainWindow orderFront: self]; ! [RoadMapMainWindow makeKey: self]; ! [RoadMapMainWindow _setHidden: NO]; ! [RoadMapMainWindow setContentView: RoadMapMainBox]; ! } if (RoadMapMainTitle != NULL) { --- 453,491 ---- roadmap_option (sArgc, sArgv, 0, NULL); NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; ! returnCode = UIApplicationMain(sArgc, sArgv, @"RoadMapApp", @"RoadMapApp"); [pool release]; ! return returnCode; } @implementation RoadMapApp + @synthesize window, view; ! -(RoadMapApp *) init ! { ! self = [super init]; ! return self; ! } ! - (UIToolbar *) createButtonBar { ! UIToolbar *buttonBar; ! buttonBar = [ [ UIToolbar alloc ] ! initWithFrame: CGRectMake(0.0f, 480.0f - 49.0f, 320.0f, 49.0f)]; + buttonBar.items = RoadMapMainTabBarArray; return buttonBar; } ! - (void)buttonPressed: (id) sender { int button = [ sender tag ]; ! (RoadMapMainTabBarCallbacks[button] ) (); } -(void) newWithTitle: (const char *)title andWidth: (int) width andHeight: (int) height { ! self.window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; ! self.view = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; ! [self.window addSubview: self.view]; ! [self.window makeKeyAndVisible]; ! RoadMapMainBox = self.view; if (RoadMapMainTitle != NULL) { *************** *** 584,588 **** } ! - (void) applicationDidFinishLaunching: (id) unused { TheApp = self; --- 606,610 ---- } ! - (void) applicationDidFinishLaunching: (UIApplication *) application { TheApp = self; *************** *** 594,599 **** roadmap_start (sArgc, sArgv); ! ! [self reportAppLaunchFinished]; } --- 616,621 ---- roadmap_start (sArgc, sArgv); ! ! //YYY [self reportAppLaunchFinished]; } *************** *** 601,605 **** { // [self terminate]; ! printf("go to sleep\n"); } --- 623,627 ---- { // [self terminate]; ! // printf("go to sleep\n"); } *************** *** 612,617 **** - (void)applicationWillTerminate { ! roadmap_main_exit(); ! [TheApp release]; } --- 634,643 ---- - (void)applicationWillTerminate { ! static int exit_done; ! ! if (!exit_done++) { ! roadmap_start_exit (); ! } ! [self release]; } Index: roadmap_iphonemain.h =================================================================== RCS file: /cvsroot/roadmap/roadmap/src/iphone/roadmap_iphonemain.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** roadmap_iphonemain.h 20 Jun 2008 13:09:19 -0000 1.2 --- roadmap_iphonemain.h 4 Nov 2008 14:56:23 -0000 1.3 *************** *** 34,42 **** #import <CoreFoundation/CoreFoundation.h> #import <Foundation/Foundation.h> - #import <UIKit/CDStructures.h> #import <UIKit/UIWindow.h> - #import <UIKit/UIView-Hierarchy.h> - #import <UIKit/UIView-Geometry.h> - #import <UIKit/UIHardware.h> #import <UIKit/UIKit.h> #import <UIKit/UIApplication.h> --- 34,38 ---- *************** *** 44,55 **** #import <UIKit/UIImage.h> #import <UIKit/UITextView.h> ! #import <UIKit/UIButtonBarTextButton.h> ! #import <UIKit/UIPushButton.h> ! #import <UIKit/UIView-Geometry.h> ! @interface RoadMapApp : UIApplication { } ! -(void)buttonBarItemTapped:(id) sender; ! -(UIButtonBar *)createButtonBar; -(void) newWithTitle: (const char *)title andWidth: (int) width andHeight: (int) height; -(void) ioCallback: (id) notify; --- 40,56 ---- #import <UIKit/UIImage.h> #import <UIKit/UITextView.h> ! #import <UIKit/UITabBar.h> ! @interface RoadMapApp : UIApplication <UITabBarDelegate> { ! UIWindow *window; ! UIView *view; } ! ! @property (nonatomic, retain) UIWindow *window; ! @property (nonatomic, retain) UIView *view; ! ! //-(void)buttonBarItemTapped:(id) sender; ! //-(void)buttonPressed; ! -(UITabBar *)createButtonBar; -(void) newWithTitle: (const char *)title andWidth: (int) width andHeight: (int) height; -(void) ioCallback: (id) notify; |