sgl

changeset 15:a16b34ac3f2a

bah
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 17 May 2011 11:21:09 +0300
parents 5b8fb89fe63f
children 01a576351090 ee7b3a898b6b
files configure src/wsys_cocoa.m
diffstat 2 files changed, 61 insertions(+), 12 deletions(-) [+]
line diff
     1.1 --- a/configure	Mon May 16 23:09:53 2011 +0300
     1.2 +++ b/configure	Tue May 17 11:21:09 2011 +0300
     1.3 @@ -74,7 +74,7 @@
     1.4  		fi
     1.5  	fi
     1.6  
     1.7 -	name=`echo $m | sort | sed 's/src\/wsys_//' | sed 's/\.c\|\.m//'`
     1.8 +	name=`echo $m | sort | sed 's/src\/wsys_//' | sed 's/\.c//' | sed 's/\.m//'`
     1.9  	`which echo` -n "-> trying module $name (needs: $dep) ... "
    1.10  
    1.11  	if try_link "$dep"; then
     2.1 --- a/src/wsys_cocoa.m	Mon May 16 23:09:53 2011 +0300
     2.2 +++ b/src/wsys_cocoa.m	Tue May 17 11:21:09 2011 +0300
     2.3 @@ -6,12 +6,14 @@
     2.4  
     2.5  #import <Cocoa/Cocoa.h>
     2.6  #include "sgl.h"
     2.7 +#include "wsys.h"
     2.8  
     2.9  @interface OpenGLView : NSOpenGLView
    2.10  {
    2.11 +	int foo;
    2.12  }
    2.13  
    2.14 -//-(id) initWithFrame: (NSRect) frameRect;
    2.15 +/*-(id) initWithFrame: (NSRect) frameRect;*/
    2.16  
    2.17  -(void) drawRect: (NSRect) rect;
    2.18  -(void) reshape;
    2.19 @@ -32,8 +34,11 @@
    2.20  
    2.21  struct window {
    2.22  	int wid;
    2.23 +	int width, height;
    2.24  	NSWindow *win;
    2.25  	OpenGLView *view;
    2.26 +	NSOpenGLContext *ctx;
    2.27 +	int needs_redisplay;
    2.28  	struct window *next;
    2.29  };
    2.30  
    2.31 @@ -89,7 +94,7 @@
    2.32  
    2.33  void sgl_register_cocoa(void)
    2.34  {
    2.35 -	sgl_register_cocoa(&ws);
    2.36 +	sgl_register_module(&ws);
    2.37  }
    2.38  
    2.39  
    2.40 @@ -105,9 +110,16 @@
    2.41  
    2.42  -(void) reshape
    2.43  {
    2.44 -	sgl_reshape_callback_t func = sgl_get_callback(SGL_RESHAPE);
    2.45 -	if(func) {
    2.46 -		func(x, y);
    2.47 +	NSSize sz;
    2.48 +	sgl_reshape_callback_t func;
    2.49 +
    2.50 +	sz = [self bounds].size;
    2.51 +
    2.52 +	if((func = sgl_get_callback(SGL_RESHAPE)) && (sz.width != active_win->width ||
    2.53 +				sz.height != active_win->height)) {
    2.54 +		active_win->width = sz.width;
    2.55 +		active_win->height = sz.height;
    2.56 +		func(sz.width, sz.height);
    2.57  	}
    2.58  }
    2.59  
    2.60 @@ -120,6 +132,7 @@
    2.61  static int init(void)
    2.62  {
    2.63  	app = [NSApplication sharedApplication];
    2.64 +	return 0;
    2.65  }
    2.66  
    2.67  static void shutdown(void)
    2.68 @@ -151,7 +164,7 @@
    2.69  {
    2.70  	NSWindow *nswin;
    2.71  	NSRect rect;
    2.72 -	NSView *view;
    2.73 +	OpenGLView *view;
    2.74  	unsigned int style;
    2.75  	struct window *win;
    2.76  	static int next_id = 1;
    2.77 @@ -176,10 +189,15 @@
    2.78  
    2.79  	win->win = nswin;
    2.80  	win->view = view;
    2.81 +	win->ctx = [view openGLContext];
    2.82  	win->wid = next_id++;
    2.83 +	win->needs_redisplay = 1;
    2.84  	win->next = winlist;
    2.85  	winlist = win;
    2.86  
    2.87 +	if(!active_win) {
    2.88 +		activate_window(win);
    2.89 +	}
    2.90  	return win->wid;
    2.91  }
    2.92  
    2.93 @@ -215,6 +233,8 @@
    2.94  /* window management */
    2.95  static int set_active(int wid)
    2.96  {
    2.97 +	struct window *win = find_window(wid);
    2.98 +	return activate_window(win);
    2.99  }
   2.100  
   2.101  static struct window *find_window(int wid)
   2.102 @@ -222,7 +242,7 @@
   2.103  	struct window *win = winlist;
   2.104  
   2.105  	while(win) {
   2.106 -		if(win->win == id) {
   2.107 +		if(win->wid == wid) {
   2.108  			return win;
   2.109  		}
   2.110  		win = win->next;
   2.111 @@ -247,16 +267,17 @@
   2.112  	nsstr = [[NSString alloc] initWithCString: str encoding: NSASCIIStringEncoding];
   2.113  	[active_win->win setTitle: nsstr];
   2.114  	[nsstr release];
   2.115 +	return 0;
   2.116  }
   2.117  
   2.118  static void redisplay(void)
   2.119  {
   2.120 -	[active_win->view setNeedsRedisplay: YES];
   2.121 +	active_win->needs_redisplay = 1;
   2.122  }
   2.123  
   2.124  static void swap_buffers(void)
   2.125  {
   2.126 -	[active_win->flushBuffer];
   2.127 +	[active_win->ctx flushBuffer];
   2.128  }
   2.129  
   2.130  
   2.131 @@ -274,11 +295,26 @@
   2.132  static int process_events(void)
   2.133  {
   2.134  	NSAutoreleasePool *pool;
   2.135 -	int state;
   2.136  	sgl_idle_callback_t idle;
   2.137 +	sgl_display_callback_t disp;
   2.138 +	struct window *win;
   2.139 +	int res = 0;
   2.140  
   2.141  	pool = [[NSAutoreleasePool alloc] init];
   2.142  
   2.143 +	idle = sgl_get_callback(SGL_IDLE);
   2.144 +	disp = sgl_get_callback(SGL_DISPLAY);
   2.145 +
   2.146 +	win = winlist;
   2.147 +	while(win) {
   2.148 +		if(win->needs_redisplay && disp) {
   2.149 +			activate_window(win);
   2.150 +			disp();
   2.151 +			win->needs_redisplay = 0;
   2.152 +		}
   2.153 +		win = win->next;
   2.154 +	}
   2.155 +
   2.156  	for(;;) {
   2.157  		NSEvent *ev = [app nextEventMatchingMask: NSAnyEventMask
   2.158  			untilDate: [NSDate distantPast] inMode: NSDefaultRunLoopMode dequeue: YES];
   2.159 @@ -286,8 +322,15 @@
   2.160  			break;
   2.161  		}
   2.162  
   2.163 -		handle_event(ev);
   2.164 +		res = handle_event(ev);
   2.165  	}
   2.166 +
   2.167 +	if(idle) {
   2.168 +		idle();
   2.169 +	}
   2.170 +
   2.171 +	[pool drain];
   2.172 +	return 0;
   2.173  }
   2.174  
   2.175  static int handle_event(NSEvent *ev)
   2.176 @@ -295,7 +338,13 @@
   2.177  	switch([ev type]) {
   2.178  	case NSKeyDown:
   2.179  	case NSKeyUp:
   2.180 +		printf("key pressed\n");
   2.181 +		break;
   2.182  
   2.183 +	default:
   2.184 +		break;
   2.185 +	}
   2.186 +	return 0;
   2.187  }
   2.188  
   2.189  #endif	/* USE_WSYS_MODULE_COCOA */