Index: linux/ui_pgui.c
===================================================================
RCS file: /cvsroot/waba/waba/vm/linux/ui_pgui.c,v
retrieving revision 1.11
diff -r1.11 ui_pgui.c
29,52d28
< g_error sucess = {ERRT_NONE,NULL};
< 
< g_error mkerror(unsigned char type, char *msg) {
<   g_error e = {type,msg};
<   return e;
< }
< 
< g_error prerror(g_error e) {
<   if (e.type == ERRT_NONE) return sucess;
<   if (!e.msg) e.msg = "?";
<   printf("*** ERROR (");
<   switch (e.type) {
<   case ERRT_MEMORY: printf("MEMORY"); break;
<   case ERRT_IO: printf("IO"); break;
<   case ERRT_NETWORK: printf("NETWORK"); break;
<   case ERRT_BADPARAM: printf("BADPARAM"); break;
<   case ERRT_HANDLE: printf("HANDLE"); break;
<   case ERRT_INTERNAL: printf("INTERNAL"); break;
<   default: printf("?");
<   }
<   printf(") : %s\n",e.msg);
<   return e;
< }
< 
55,140d30
< int evtDrawMainWindow( struct pgEvent *evt ) {
< /* handling of the repaint event */
< 
<   DPUTS( "EVT: repaint ???" );
< 
<   return 0;
< 
< }
< 
< int evtMouse( struct pgEvent *evt ) {
< /* handling of the mouse events */
<   int x, y;
<   struct ui_Event ui_event;
<   int quit;
< 
<   ui_event.x = evt->e.pntr.x;
<   ui_event.y = evt->e.pntr.y;
<   ui_event.code = 0;
< 
<   switch( evt->type ) {
<   case PG_WE_PNTR_DOWN:
<     ui_event.type = penDownEvent;
<     break;
<   case PG_WE_PNTR_UP:
<     ui_event.type = penUpEvent;
<     break;
<   case PG_WE_PNTR_MOVE:
<     ui_event.type = penMoveEvent;
<     break;
<   default:
<     ui_event.type = penDownEvent;
<     break;
<   }
< 
<   quit = handleMainWinEvent( &ui_event );
< 
<   return TRUE;
< 
< }
< 
< int evtChar( struct pgEvent *evt ) {
< /* handling of the key character event */
< 
<   struct ui_Event ui_event;
< 
<   ui_event.code = evt->e.kbd.key;
<   ui_event.type = keyDownEvent;
< 
<   handleMainWinEvent (&ui_event);
< 
<   return TRUE;
< }
< 
< int evtKeyDown( struct pgEvent *evt ) {
< /* handling of the key down event */
< 
<   int retValue = TRUE;
< 
<   switch (evt->e.kbd.key)
<     {
<     case PGKEY_HOME:
<     case PGKEY_END:
<     case PGKEY_LEFT:
<     case PGKEY_RIGHT:
< 	retValue = evtChar (evt);
< 	break;
<     default:
< 	break;
<     }
< 
<   return TRUE;
< }
< 
< int evtKeyUp( struct pgEvent *evt ) {
< /* handling of the key up event */
< 
<   struct ui_Event ui_event;
< 
<   ui_event.code = evt->e.kbd.key;
<   ui_event.type = keyUpEvent;
< 
<   handleMainWinEvent (&ui_event);
< 
<   return TRUE;
< }
< 
146c36,37
<   pgcontext *gc;
---
>   pghandle backBuffer;   /* Draw to the backbuffer also for automatic redraw */
>   ui_GraphicsContextType *gct;
152,156c43,45
<   argv = malloc( 2 * sizeof( char *));
<   argv[0] = malloc( sizeof( char ) * ( strlen( "waba_x86" ) + 1 ));
<   strcpy( argv[0], "waba_x86" );
<   argv[1] = malloc( sizeof( char ) * ( strlen( "none" ) + 1 ));
<   strcpy( argv[1], "none" );
---
>   argv = malloc(2 * sizeof( char *));
>   argv[0] = "waba";
>   argv[1] = NULL;
165,180c54,55
<   /* Grab the focus on the MainWindow, because Canvas widgets don't */
<   /* normally get keyboard input */
<   pgFocus (MainWindow);
< 
<   gc = xmalloc( sizeof( pgcontext ));
<   *gc = pgNewCanvasContext( PGDEFAULT, PGFX_IMMEDIATE );
< 
<   /* TODO: set the main window size */
< 
<   /*********** connect the events : */
< 
<   /* - for repainting */
<   pgBind( PGDEFAULT, PG_WE_BUILD, &evtDrawMainWindow, NULL );
< 
<   /* - for the mouse down */
<   pgBind( PGDEFAULT, PG_WE_PNTR_DOWN, &evtMouse, NULL );
---
>   /* Make a backbuffer bitmap */
>   backBuffer = pgCreateBitmap(hwr_width,hwr_height);
182,195c57,71
<   /* - for the mouse up */
<   pgBind( PGDEFAULT, PG_WE_PNTR_UP, &evtMouse, NULL );
< 
<   /* - for the mouse down */
<   pgBind( PGDEFAULT, PG_WE_PNTR_MOVE, &evtMouse, NULL );
< 
<   /* - for a key press */
<   pgBind( PGDEFAULT, PG_WE_KBD_CHAR, &evtChar, NULL );
<   pgBind( PGDEFAULT, PG_WE_KBD_KEYDOWN, &evtKeyDown, NULL );
< 
<   /* - for a key release */
<   pgBind( PGDEFAULT, PG_WE_KBD_KEYUP, &evtKeyUp, NULL );
< 
<   return gc;
---
>   /* In persistent mode, draw the backbuffer and set the clipping rectangle 
>    */
>   pgWriteCmd(MainWindow,PGCANVAS_GROP,6,PG_GROP_BITMAP,
> 	     0,0,hwr_width,hwr_height,backBuffer);
>   pgWriteCmd(MainWindow,PGCANVAS_GROP,5,PG_GROP_SETCLIP,
> 	     0,0,hwr_width,hwr_height);   /* Clipped to the Waba size */
>   /* Always set the clipping rectangle (doing incremental or full redraws) */
>   pgWriteCmd(MainWindow,PGCANVAS_GROPFLAGS,1,PG_GROPF_UNIVERSAL);
> 
>   /* Make a structure to stick the contexts in */
>   gct = xmalloc( sizeof( ui_GraphicsContextType ));
> 
>   /* Create contexts for teh canvas itself and the back-buffer */
>   gct->gc = pgNewCanvasContext( MainWindow, PGFX_IMMEDIATE );
>   gct->bgc = pgNewBitmapContext( backBuffer );
196a73
>   return gct;
200,229d76
<   // TODO:
< }
< 
< void hwr_clear() {
< }
< 
< void hwr_update() {
< }
< 
< void hwr_pixel(int x,int y,devcolort c) {
< }
< 
< void hwr_slab(int x,int y,int l,devcolort c) {
< }
< 
< void hwr_bar(int x,int y,int l,devcolort c) {
< }
< 
< 
< void hwr_rect(int x,int y,int w,int h,devcolort c) {
<   if (w<=0) return;
<   if (h<=0) return;
< }
< 
< 
< void hwr_frame(int x,int y,int w,int h,devcolort c) {
<   hwr_slab(x,y,w,c);
<   hwr_slab(x,y+h-1,w,c);
<   hwr_bar(x,y+1,h-2,c);
<   hwr_bar(x+w-1,y+1,h-2,c);
234,237d80
< 
< 
< /*****************************************************************************/
< 
247a91,141
>   struct pgEvent evt;
>   
>   /* Retrieve the next PicoGUI event. The only widgets that could be sending
>    * us an event are the canvas and the application panel. The app panel will
>    * send a PG_WE_CLOSE event when we're closed, everything from the canvas
>    * (almost) should go to the Waba app.
>    */
>   
>   while (1) {
>     evt = *pgGetEvent();
> 
>     /* These will not always be applicable, but filling
>      * them in now shouldn't hurt. 
>      */
>     ui_event->x = evt.e.pntr.x;
>     ui_event->y = evt.e.pntr.y;
>     ui_event->code = evt.e.kbd.key;
> 
>     switch (evt.type) {
>       
>     case PG_WE_PNTR_DOWN:
>       /* Focus the canvas widget.
>        * (we don't know whether the app will need keyboard input or not)
>        */
>       pgFocus(evt.from);
>       ui_event->type = penDownEvent;
>       return;
>     case PG_WE_PNTR_UP:
>       ui_event->type = penUpEvent;
>       return;
>     case PG_WE_PNTR_MOVE:
>       ui_event->type = penMoveEvent;
>       return;
>     case PG_WE_KBD_CHAR:
>       ui_event->type = keyDownEvent;
>       return;
>     case PG_WE_KBD_KEYUP:
>       ui_event->type = keyUpEvent;
>       return;
>     case PG_WE_KBD_KEYDOWN:
>       /* Send keydowns for events not covered by char */
>       if (evt.e.kbd.key > 255) {
> 	ui_event->type = keyDownEvent;
> 	return;
>       }
>       break;
> 
>     default:
>       pgDispatchEvent(&evt);
>     }
>   }
254,257c148,153
< /* run the main loop */
< 
<   pgEventLoop();
< 
---
>   struct ui_Event evt;
>   
>   /* run the main loop */
>   do {
>     ui_GetEvent(&evt);
>   } while (!handleMainWinEvent(&evt));
332c228,229
< 			    WOBJ_FontSize( font ) - 2,   /* - 2 seem to best match the look of Palm */
---
> 			    /* - 2 seem to best match the look of Palm */
> 			    WOBJ_FontSize( font ) - 2,
334,339c231,232
< 			        ? PG_FSTYLE_FLUSH | PG_FSTYLE_BOLD : PG_FSTYLE_FLUSH | PG_FSTYLE_DEFAULT );
< 
< 	if( *aFont == 0 ) {
< 
< 	  // bad => create a default font
< 	  *aFont = pgNewFont( DEFAULT_FONT, DEFAULT_FONT_SIZE, PG_FSTYLE_FLUSH | PG_FSTYLE_DEFAULT );
---
> 			    ? PG_FSTYLE_FLUSH | PG_FSTYLE_BOLD : 
> 			    PG_FSTYLE_FLUSH | PG_FSTYLE_DEFAULT );
341d233
< 	}
353d244
< 
393c284
<   WOBJ_FontMetricsDescent(fontMetrics) = 10;
---
>   WOBJ_FontMetricsDescent(fontMetrics) = 3;
463c354,355
<     pgSetLgop( *theGC, PG_LGOP_OR );
---
>     pgSetLgop( theGC->gc, PG_LGOP_OR );
>     pgSetLgop( theGC->bgc, PG_LGOP_OR );
467c359,360
<     pgSetLgop( *theGC, PG_LGOP_AND );
---
>     pgSetLgop( theGC->gc, PG_LGOP_AND );
>     pgSetLgop( theGC->bgc, PG_LGOP_AND );
471c364,365
<     pgSetLgop( *theGC, PG_LGOP_INVERT_XOR );
---
>     pgSetLgop( theGC->gc, PG_LGOP_INVERT_XOR );
>     pgSetLgop( theGC->bgc, PG_LGOP_INVERT_XOR );
475c369,370
<     pgSetLgop( *theGC, PG_LGOP_NONE );
---
>     pgSetLgop( theGC->gc, PG_LGOP_NONE );
>     pgSetLgop( theGC->bgc, PG_LGOP_NONE );
480,481d374
<   DPUTS( "??? setTheDrawFunction not implemented" );
< 
485,488c378,379
< /* set the clip to the given rectangle */
< 
<   DPUTS( "??? ui_ClipTo not implemented" );
< 
---
>   pgSetClip(theGC->bgc,rect.x,rect.y,rect.width,rect.height);
>   pgSetClip(theGC->gc,rect.x,rect.y,rect.width,rect.height);
497c388
<     theColor = 0x10000 * red + 0x100 * green + blue;
---
>     theColor = (red<<16) | (green<<8) | blue;
500,501c391,392
<     pgSetColor( *theGC, theColor );
< 
---
>     pgSetColor( theGC->gc, theColor );
>     pgSetColor( theGC->bgc, theColor );
507,508c398,399
<   pgPixel( *theGC, x, y );
< 
---
>   pgPixel( theGC->gc, x, y );
>   pgPixel( theGC->bgc, x, y );
515,516c406,407
<     pgLine( *theGC, x1, y1, x2, y2 );
< 
---
>   pgLine( theGC->gc, x1, y1, x2, y2 );
>   pgLine( theGC->bgc, x1, y1, x2, y2 );
520,527c411,427
< /* draw theText with theFont at x,y on gc */
< /* don't need to use drawingPixmap */
< 
<     DPUTS ("ui_DrawText: see if we need to use enter/leave Context" );
<     DPUTS ("ui_DrawText: need to re-activate font selection" );
<     pgSetFont( *theGC, *theFont );
<     pgText( *theGC, x, y, pgNewString( theText ));
< 
---
>   pghandle text;
>   
>   /* draw theText with theFont at x,y on gc */
>   /* don't need to use drawingPixmap */
> 
>   pgEnterContext();
>   text = pgNewString(theText);
>   pgSetFont( theGC->bgc, *theFont );
>   pgText( theGC->bgc, x, y, text);
>   pgContextUpdate(theGC->bgc);
>   pgSetFont( theGC->gc, *theFont );
>   pgText( theGC->gc, x, y,text);
>   pgContextUpdate(theGC->gc);
> 
>   /* Make it render now so we can ditch the text handle */
>   pgUpdate();
>   pgLeaveContext();
534,535c434,435
<   pgRect( *theGC, x, y, w, h );
< 
---
>   pgRect( theGC->gc, x, y, w, h );
>   pgRect( theGC->bgc, x, y, w, h );
577,578c477,484
<   /* force PicoGUI to repaint */
<   pgContextUpdate( *theGC );
---
>   /* NOTE: Right now we're drawing simultaneously to both the display and a
>    * backbuffer, like in the Scribble Pad app. This seems a little messy.
>    * Alternative methods may be:
>    *
>    * - use only immediate mode, tell the Waba app to redraw
>    * - Add something in PicoGUI to automatically render to multiple contexts
>    * - Copy to the backbuffer in this function
>    */
579a486,488
>   /* force PicoGUI to repaint */
>   pgContextUpdate( theGC->gc );
>   pgContextUpdate( theGC->bgc );
Index: linux/ui_pgui.h
===================================================================
RCS file: /cvsroot/waba/waba/vm/linux/ui_pgui.h,v
retrieving revision 1.3
diff -r1.3 ui_pgui.h
122c122,124
< #define ui_GraphicsContextType pgcontext
---
> typedef struct {
>   pgcontext gc,bgc;        /* Canvas context and backbuffer context */
> } ui_GraphicsContextType;
