From 5ed42a138650efc5016e84d9a28a0a1a7cf20183 Mon Sep 17 00:00:00 2001 From: martin-s Date: Thu, 21 Jul 2011 21:07:32 +0000 Subject: [PATCH] Add:Core:Initial work for graphics_cocoa git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@4658 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/CMakeLists.txt | 1 + navit/navit/graphics/cocoa/CMakeLists.txt | 1 + navit/navit/graphics/cocoa/cocoa_if.h | 23 +++++++ navit/navit/graphics/cocoa/cocoa_if.m | 27 ++++++++ navit/navit/graphics/cocoa/graphics_cocoa.c | 103 ++++++++++++++++++++++++++++ navit/navit/graphics/cocoa/nick.h | 17 +++++ navit/navit/graphics/cocoa/nick.m | 43 ++++++++++++ 7 files changed, 215 insertions(+) create mode 100644 navit/navit/graphics/cocoa/CMakeLists.txt create mode 100644 navit/navit/graphics/cocoa/cocoa_if.h create mode 100644 navit/navit/graphics/cocoa/cocoa_if.m create mode 100644 navit/navit/graphics/cocoa/graphics_cocoa.c create mode 100644 navit/navit/graphics/cocoa/nick.h create mode 100644 navit/navit/graphics/cocoa/nick.m diff --git a/navit/CMakeLists.txt b/navit/CMakeLists.txt index 9f12448..cdbb581 100644 --- a/navit/CMakeLists.txt +++ b/navit/CMakeLists.txt @@ -317,6 +317,7 @@ add_plugin(support/espeak "Default" FALSE) add_module(vehicle/android "Default" FALSE) add_module(vehicle/iphone "Default" FALSE) add_module(vehicle/wince "Default" FALSE) +add_module(graphics/cocoa "Default" FALSE "-lcocoa" ) # other features add_feature(USE_PLUGINS "default" TRUE) diff --git a/navit/navit/graphics/cocoa/CMakeLists.txt b/navit/navit/graphics/cocoa/CMakeLists.txt new file mode 100644 index 0000000..61a8ea3 --- /dev/null +++ b/navit/navit/graphics/cocoa/CMakeLists.txt @@ -0,0 +1 @@ +module_add_library(graphics_cocoa graphics_cocoa.c cocoa_if.m cocoa_if.h nick.m nick.h) diff --git a/navit/navit/graphics/cocoa/cocoa_if.h b/navit/navit/graphics/cocoa/cocoa_if.h new file mode 100644 index 0000000..a5f5fb6 --- /dev/null +++ b/navit/navit/graphics/cocoa/cocoa_if.h @@ -0,0 +1,23 @@ +// +// HelloWorldAppDelegate.h +// HelloWorld +// +// Created by Nick Geoghegan on 21/07/2011. +// Copyright 2011 __MyCompanyName__. All rights reserved. +// + +#ifdef __OBJC__ + + +#import + +@interface HelloWorldAppDelegate : NSObject { + NSWindow *window; +} + +@property (assign) IBOutlet NSWindow *window; + +@end + +int coca_if_main(void); +#endif diff --git a/navit/navit/graphics/cocoa/cocoa_if.m b/navit/navit/graphics/cocoa/cocoa_if.m new file mode 100644 index 0000000..71078d7 --- /dev/null +++ b/navit/navit/graphics/cocoa/cocoa_if.m @@ -0,0 +1,27 @@ +// +// HelloWorldAppDelegate.m +// HelloWorld +// +// Created by Nick Geoghegan on 21/07/2011. +// Copyright 2011 __MyCompanyName__. All rights reserved. +// + +#import "cocoa_if.h" + +@implementation HelloWorldAppDelegate + +@synthesize window; + +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { + // Insert code here to initialize your application +} + +@end + +int cocoa_if_main(void) +{ + int argc=1; + char *argv[]={"navit",NULL}; + return NSApplicationMain(argc, (const char **) argv); +} + diff --git a/navit/navit/graphics/cocoa/graphics_cocoa.c b/navit/navit/graphics/cocoa/graphics_cocoa.c new file mode 100644 index 0000000..0d7b17b --- /dev/null +++ b/navit/navit/graphics/cocoa/graphics_cocoa.c @@ -0,0 +1,103 @@ +#include "config.h" +#include "debug.h" +#include "plugin.h" +#include "point.h" +#include "window.h" +#include "graphics.h" +#include "event.h" +#include + +struct graphics_priv { + struct window win; +}; + +static void * +get_data(struct graphics_priv *this, const char *type) +{ + dbg(0,"enter\n"); + if (strcmp(type,"window")) + return NULL; + return &this->win; +} + + +static struct graphics_methods graphics_methods = { + NULL, /* graphics_destroy, */ + NULL, /* draw_mode, */ + NULL, /* draw_lines, */ + NULL, /* draw_polygon, */ + NULL, /* draw_rectangle, */ + NULL, /* draw_circle, */ + NULL, /* draw_text, */ + NULL, /* draw_image, */ + NULL, /* draw_image_warp, */ + NULL, /* draw_restore, */ + NULL, /* draw_drag, */ + NULL, /* font_new, */ + NULL, /* gc_new, */ + NULL, /* background_gc, */ + NULL, /* overlay_new, */ + NULL, /* image_new, */ + get_data, + NULL, /* image_free, */ + NULL, /* get_text_bbox, */ + NULL, /* overlay_disable, */ + NULL, /* overlay_resize, */ + NULL, /* set_attr, */ +}; + + + +struct graphics_priv * +graphics_cocoa_new(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl) +{ + *meth=graphics_methods; + dbg(0,"enter\n"); + if(!event_request_system("cocoa","graphics_cocoa")) + return NULL; + return g_new0(struct graphics_priv, 1); +} + +static void +event_cocoa_main_loop_run(void) +{ + dbg(0,"enter\n"); + cocoa_if_main(); +} + +static void * +event_cocoa_add_timeout(void) +{ + dbg(0,"enter\n"); + return NULL; +} + +static struct event_methods event_cocoa_methods = { + event_cocoa_main_loop_run, + NULL, /* event_cocoa_main_loop_quit, */ + NULL, /* event_cocoa_add_watch, */ + NULL, /* event_cocoa_remove_watch, */ + event_cocoa_add_timeout, + NULL, /* event_cocoa_remove_timeout, */ + NULL, /* event_cocoa_add_idle, */ + NULL, /* event_cocoa_remove_idle, */ + NULL, /* event_cocoa_call_callback, */ +}; + + +static struct event_priv * +event_cocoa_new(struct event_methods *meth) +{ + dbg(0,"enter\n"); + *meth=event_cocoa_methods; + return NULL; +} + + +void +plugin_init(void) +{ + dbg(0,"enter\n"); + plugin_register_graphics_type("cocoa", graphics_cocoa_new); + plugin_register_event_type("cocoa", event_cocoa_new); +} diff --git a/navit/navit/graphics/cocoa/nick.h b/navit/navit/graphics/cocoa/nick.h new file mode 100644 index 0000000..de3037f --- /dev/null +++ b/navit/navit/graphics/cocoa/nick.h @@ -0,0 +1,17 @@ +// +// nick.h +// HelloWorld +// +// Created by Nick Geoghegan on 21/07/2011. +// Copyright 2011 __MyCompanyName__. All rights reserved. +// + +#import + + +@interface nick : NSView +{ + +} + +@end diff --git a/navit/navit/graphics/cocoa/nick.m b/navit/navit/graphics/cocoa/nick.m new file mode 100644 index 0000000..78afb66 --- /dev/null +++ b/navit/navit/graphics/cocoa/nick.m @@ -0,0 +1,43 @@ +// +// nick.m +// HelloWorld +// +// Created by Nick Geoghegan on 21/07/2011. +// Copyright 2011 __MyCompanyName__. All rights reserved. +// + +#import "nick.h" + + +@implementation nick + +- (id)initWithFrame:(NSRect)frame { + self = [super initWithFrame:frame]; + if (self) { + // Initialization code here. + } + return self; +} + +- (void)drawRect:(NSRect)dirtyRect { + // Drawing code here. + NSString* hws = @"Hello Navit!"; + NSPoint p; + NSMutableDictionary* attribs; + NSColor* c; + NSFont* fnt; + + p = NSMakePoint( 10, 100 ); + + attribs = [[[NSMutableDictionary alloc] init] autorelease]; + + c = [NSColor redColor]; + fnt = [NSFont fontWithName:@"Times Roman" size:48]; + + [attribs setObject:c forKey:NSForegroundColorAttributeName]; + [attribs setObject:fnt forKey:NSFontAttributeName]; + + [hws drawAtPoint:p withAttributes:attribs]; +} + +@end -- 2.7.4