changes, protected by a disabled compile-time flag, to use cairo-based

API for drawing instead of now-deprecated gdk ones.  Unfortunately
nothing actually draws and I'm putting the debugging off until I have
some time.
This commit is contained in:
Andy2 2011-01-14 18:15:33 -08:00
parent 13ef8dd098
commit c9fec737e5
3 changed files with 182 additions and 70 deletions

View file

@ -37,6 +37,7 @@ ifdef CURSES_SMALL_SCREEN
DO_CURSES += -DCURSES_SMALL_SCREEN DO_CURSES += -DCURSES_SMALL_SCREEN
endif endif
DO_GTK = -DPLATFORM_GTK DO_GTK = -DPLATFORM_GTK
# DO_GTK += -DUSE_CAIRO
# uncomment for standalone build # uncomment for standalone build
# STANDALONE = -DXWFEATURE_STANDALONE_ONLY # STANDALONE = -DXWFEATURE_STANDALONE_ONLY
@ -178,8 +179,8 @@ endif
ifneq (,$(findstring DPLATFORM_GTK,$(DEFINES))) ifneq (,$(findstring DPLATFORM_GTK,$(DEFINES)))
LIBS += `pkg-config --libs gtk+-2.0` LIBS += `pkg-config --libs gtk+-2.0`
CFLAGS += `pkg-config --cflags gtk+-2.0` \ CFLAGS += `pkg-config --cflags gtk+-2.0`
-DGDK_DISABLE_DEPRECATED # CFLAGS += -DGDK_DISABLE_DEPRECATED
POINTER_SUPPORT = -DPOINTER_SUPPORT POINTER_SUPPORT = -DPOINTER_SUPPORT
endif endif

View file

@ -22,8 +22,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#undef GDK_DISABLE_DEPRECATED
#include <gdk/gdkdrawable.h> #include <gdk/gdkdrawable.h>
#include "gtkmain.h" #include "gtkmain.h"
@ -64,31 +62,75 @@ gtkInsetRect( XP_Rect* r, short i )
#define GTKMIN_W_HT 12 #define GTKMIN_W_HT 12
#ifdef USE_CAIRO
# define XP_UNUSED_CAIRO(var) UNUSED__ ## var __attribute__((unused))
#else
# define XP_UNUSED_CAIRO(var) var
#endif
static void
draw_rectangle( const GtkDrawCtx* dctx,
GdkDrawable* XP_UNUSED_CAIRO(drawable),
GdkGC* XP_UNUSED_CAIRO(gc),
gboolean fill, gint left, gint top, gint width,
gint height )
{
#ifdef USE_CAIRO
cairo_rectangle( dctx->cr, left, top, width, height );
cairo_stroke_preserve( dctx->cr );
cairo_set_source_rgb( dctx->cr, 1, 1, 1 );
/* if ( fill ) { */
cairo_fill( dctx->cr );
/* } else { */
cairo_stroke( dctx->cr );
/* } */
fill = fill;
#else
dctx = dctx;
gdk_draw_rectangle( drawable, gc, fill, left, top, width, height );
#endif
}
static void static void
gtkFillRect( GtkDrawCtx* dctx, const XP_Rect* rect, const GdkColor* color ) gtkFillRect( GtkDrawCtx* dctx, const XP_Rect* rect, const GdkColor* color )
{ {
#ifdef USE_CAIRO
color = color;
//gdk_cairo_set_source_color( dctx->cr, color );
#else
gdk_gc_set_foreground( dctx->drawGC, color ); gdk_gc_set_foreground( dctx->drawGC, color );
gdk_draw_rectangle( DRAW_WHAT(dctx), dctx->drawGC, #endif
TRUE, draw_rectangle( dctx, DRAW_WHAT(dctx), dctx->drawGC, TRUE,
rect->left, rect->top, rect->width, rect->left, rect->top, rect->width,
rect->height ); rect->height );
}
static void
set_color_cairo( const GtkDrawCtx* dctx, unsigned short red,
unsigned short green, unsigned short blue )
{
GdkColor color = { red, green, blue };
color = color;
dctx = dctx;
//gdk_cairo_set_source_color( dctx->cr, &color );
} }
static void static void
gtkEraseRect( const GtkDrawCtx* dctx, const XP_Rect* rect ) gtkEraseRect( const GtkDrawCtx* dctx, const XP_Rect* rect )
{ {
gdk_draw_rectangle( DRAW_WHAT(dctx), set_color_cairo( dctx, 0xFFFF, 0xFFFF, 0xFFFF );
dctx->drawing_area->style->white_gc, draw_rectangle( dctx, DRAW_WHAT(dctx),
TRUE, rect->left, rect->top, dctx->drawing_area->style->white_gc,
rect->width, rect->height ); TRUE, rect->left, rect->top,
rect->width, rect->height );
} /* gtkEraseRect */ } /* gtkEraseRect */
static void static void
frameRect( GtkDrawCtx* dctx, const XP_Rect* rect ) frameRect( GtkDrawCtx* dctx, const XP_Rect* rect )
{ {
gdk_draw_rectangle( DRAW_WHAT(dctx), draw_rectangle( dctx, DRAW_WHAT(dctx), dctx->drawGC,
dctx->drawGC, FALSE, rect->left, rect->top, FALSE, rect->left, rect->top,
rect->width, rect->height ); rect->width, rect->height );
} /* frameRect */ } /* frameRect */
#ifdef DRAW_WITH_PRIMITIVES #ifdef DRAW_WITH_PRIMITIVES
@ -225,9 +267,14 @@ draw_string_at( GtkDrawCtx* dctx, PangoLayout* layout,
} }
} }
#ifdef USE_CAIRO
frground = frground;
bkgrnd = bkgrnd;
#else
gdk_draw_layout_with_colors( DRAW_WHAT(dctx), dctx->drawGC, gdk_draw_layout_with_colors( DRAW_WHAT(dctx), dctx->drawGC,
xx, yy, layout, xx, yy, layout,
frground, bkgrnd ); frground, bkgrnd );
#endif
} /* draw_string_at */ } /* draw_string_at */
static void static void
@ -248,8 +295,8 @@ drawBitmapFromLBS( GtkDrawCtx* dctx, const XP_Bitmap bm, const XP_Rect* rect )
pm = gdk_pixmap_new( DRAW_WHAT(dctx), nCols, nRows, -1 ); pm = gdk_pixmap_new( DRAW_WHAT(dctx), nCols, nRows, -1 );
gdk_draw_rectangle( pm, dctx->drawing_area->style->white_gc, TRUE, draw_rectangle( dctx, pm, dctx->drawing_area->style->white_gc, TRUE,
0, 0, nCols, nRows ); 0, 0, nCols, nRows );
x = 0; x = 0;
y = 0; y = 0;
@ -259,7 +306,10 @@ drawBitmapFromLBS( GtkDrawCtx* dctx, const XP_Bitmap bm, const XP_Rect* rect )
for ( i = 0; i < 8; ++i ) { for ( i = 0; i < 8; ++i ) {
XP_Bool draw = ((byte & 0x80) != 0); XP_Bool draw = ((byte & 0x80) != 0);
if ( draw ) { if ( draw ) {
#ifdef USE_CAIRO
#else
gdk_draw_point( pm, dctx->drawing_area->style->black_gc, x, y ); gdk_draw_point( pm, dctx->drawing_area->style->black_gc, x, y );
#endif
} }
byte <<= 1; byte <<= 1;
if ( ++x == nCols ) { if ( ++x == nCols ) {
@ -273,6 +323,9 @@ drawBitmapFromLBS( GtkDrawCtx* dctx, const XP_Bitmap bm, const XP_Rect* rect )
XP_ASSERT( nBytes == -1 ); /* else we're out of sync */ XP_ASSERT( nBytes == -1 ); /* else we're out of sync */
#ifdef USE_CAIRO
rect = rect;
#else
gdk_draw_drawable( DRAW_WHAT(dctx), gdk_draw_drawable( DRAW_WHAT(dctx),
dctx->drawGC, dctx->drawGC,
(GdkDrawable*)pm, 0, 0, (GdkDrawable*)pm, 0, 0,
@ -280,7 +333,7 @@ drawBitmapFromLBS( GtkDrawCtx* dctx, const XP_Bitmap bm, const XP_Rect* rect )
rect->top+2, rect->top+2,
lbs->nCols, lbs->nCols,
lbs->nRows ); lbs->nRows );
#endif
g_object_unref( pm ); g_object_unref( pm );
} /* drawBitmapFromLBS */ } /* drawBitmapFromLBS */
@ -299,10 +352,10 @@ gtk_draw_destroyCtxt( DrawCtx* p_dctx )
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx; GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
GtkAllocation* alloc = &dctx->drawing_area->allocation; GtkAllocation* alloc = &dctx->drawing_area->allocation;
gdk_draw_rectangle( DRAW_WHAT(dctx), draw_rectangle( dctx, DRAW_WHAT(dctx),
dctx->drawing_area->style->white_gc, dctx->drawing_area->style->white_gc,
TRUE, TRUE,
0, 0, alloc->width, alloc->height ); 0, 0, alloc->width, alloc->height );
g_list_foreach( dctx->fontsPerSize, freer, NULL ); g_list_foreach( dctx->fontsPerSize, freer, NULL );
g_list_free( dctx->fontsPerSize ); g_list_free( dctx->fontsPerSize );
@ -328,7 +381,11 @@ gtk_draw_boardBegin( DrawCtx* p_dctx, const XP_Rect* rect,
dctx->cellWidth = width; dctx->cellWidth = width;
dctx->cellHeight = height; dctx->cellHeight = height;
#ifdef USE_CAIRO
//gdk_cairo_set_source_color( dctx->cr, &dctx->black );
#else
gdk_gc_set_foreground( dctx->drawGC, &dctx->black ); gdk_gc_set_foreground( dctx->drawGC, &dctx->black );
#endif
gdkrect = *(GdkRectangle*)rect; gdkrect = *(GdkRectangle*)rect;
++gdkrect.width; ++gdkrect.width;
@ -364,6 +421,9 @@ gtk_draw_vertScrollBoard( DrawCtx* p_dctx, XP_Rect* rect,
ysrc = ydest + dist; ysrc = ydest + dist;
} }
#ifdef USE_CAIRO
dctx = dctx;
#else
gdk_draw_drawable( DRAW_WHAT(dctx), gdk_draw_drawable( DRAW_WHAT(dctx),
dctx->drawGC, dctx->drawGC,
DRAW_WHAT(dctx), DRAW_WHAT(dctx),
@ -373,7 +433,7 @@ gtk_draw_vertScrollBoard( DrawCtx* p_dctx, XP_Rect* rect,
ydest, ydest,
rect->width, rect->width,
rect->height - dist ); rect->height - dist );
#endif
if ( !down ) { if ( !down ) {
rect->top += rect->height - dist; rect->top += rect->height - dist;
} }
@ -391,33 +451,37 @@ drawHintBorders( GtkDrawCtx* dctx, const XP_Rect* rect, HintAtts hintAtts)
XP_Rect lrect = *rect; XP_Rect lrect = *rect;
gtkInsetRect( &lrect, 1 ); gtkInsetRect( &lrect, 1 );
#ifdef USE_CAIRO
//gdk_cairo_set_source_color( dctx->cr, &dctx->black );
#else
gdk_gc_set_foreground( dctx->drawGC, &dctx->black ); gdk_gc_set_foreground( dctx->drawGC, &dctx->black );
#endif
if ( (hintAtts & HINT_BORDER_LEFT) != 0 ) { if ( (hintAtts & HINT_BORDER_LEFT) != 0 ) {
gdk_draw_rectangle( DRAW_WHAT(dctx), draw_rectangle( dctx, DRAW_WHAT(dctx),
dctx->drawGC, dctx->drawGC,
FALSE, lrect.left, lrect.top, FALSE, lrect.left, lrect.top,
0, lrect.height); 0, lrect.height);
} }
if ( (hintAtts & HINT_BORDER_TOP) != 0 ) { if ( (hintAtts & HINT_BORDER_TOP) != 0 ) {
gdk_draw_rectangle( DRAW_WHAT(dctx), draw_rectangle( dctx, DRAW_WHAT(dctx),
dctx->drawGC, dctx->drawGC,
FALSE, lrect.left, lrect.top, FALSE, lrect.left, lrect.top,
lrect.width, 0/*rectInset.height*/); lrect.width, 0/*rectInset.height*/);
} }
if ( (hintAtts & HINT_BORDER_RIGHT) != 0 ) { if ( (hintAtts & HINT_BORDER_RIGHT) != 0 ) {
gdk_draw_rectangle( DRAW_WHAT(dctx), draw_rectangle( dctx, DRAW_WHAT(dctx),
dctx->drawGC, dctx->drawGC,
FALSE, lrect.left+lrect.width, FALSE, lrect.left+lrect.width,
lrect.top, lrect.top,
0, lrect.height); 0, lrect.height);
} }
if ( (hintAtts & HINT_BORDER_BOTTOM) != 0 ) { if ( (hintAtts & HINT_BORDER_BOTTOM) != 0 ) {
gdk_draw_rectangle( DRAW_WHAT(dctx), draw_rectangle( dctx, DRAW_WHAT(dctx),
dctx->drawGC, dctx->drawGC,
FALSE, lrect.left, FALSE, lrect.left,
lrect.top+lrect.height, lrect.top+lrect.height,
lrect.width, 0 ); lrect.width, 0 );
} }
} }
} }
@ -462,12 +526,16 @@ gtk_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* letter,
gtkInsetRect( &rectInset, 1 ); gtkInsetRect( &rectInset, 1 );
if ( showGrid ) { if ( showGrid ) {
#ifdef USE_CAIRO
//gdk_cairo_set_source_color( dctx->cr, &dctx->black );
#else
gdk_gc_set_foreground( dctx->drawGC, &dctx->black ); gdk_gc_set_foreground( dctx->drawGC, &dctx->black );
gdk_draw_rectangle( DRAW_WHAT(dctx), #endif
dctx->drawGC, draw_rectangle( dctx, DRAW_WHAT(dctx),
FALSE, dctx->drawGC,
rect->left, rect->top, rect->width, FALSE,
rect->height ); rect->left, rect->top, rect->width,
rect->height );
} }
/* We draw just an empty, potentially colored, square IFF there's nothing /* We draw just an empty, potentially colored, square IFF there's nothing
@ -483,10 +551,14 @@ gtk_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* letter,
foreground = NULL; foreground = NULL;
} }
if ( !!foreground ) { if ( !!foreground ) {
#ifdef USE_CAIRO
//gdk_cairo_set_source_color( dctx->cr, foreground );
#else
gdk_gc_set_foreground( dctx->drawGC, foreground ); gdk_gc_set_foreground( dctx->drawGC, foreground );
gdk_draw_rectangle( DRAW_WHAT(dctx), dctx->drawGC, TRUE, #endif
rectInset.left, rectInset.top, draw_rectangle( dctx, DRAW_WHAT(dctx), dctx->drawGC, TRUE,
rectInset.width+1, rectInset.height+1 ); rectInset.left, rectInset.top,
rectInset.width+1, rectInset.height+1 );
} }
} }
if ( (flags & CELL_ISSTAR) != 0 ) { if ( (flags & CELL_ISSTAR) != 0 ) {
@ -499,13 +571,21 @@ gtk_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* letter,
XP_Bool isBlank = (flags & CELL_ISBLANK) != 0; XP_Bool isBlank = (flags & CELL_ISBLANK) != 0;
GdkColor* foreground; GdkColor* foreground;
if ( cursor ) { if ( cursor ) {
#ifdef USE_CAIRO
//gdk_cairo_set_source_color( dctx->cr, cursor );
#else
gdk_gc_set_foreground( dctx->drawGC, cursor ); gdk_gc_set_foreground( dctx->drawGC, cursor );
#endif
} else if ( !highlight ) { } else if ( !highlight ) {
#ifdef USE_CAIRO
//gdk_cairo_set_source_color( dctx->cr, &dctx->tileBack );
#else
gdk_gc_set_foreground( dctx->drawGC, &dctx->tileBack ); gdk_gc_set_foreground( dctx->drawGC, &dctx->tileBack );
#endif
} }
gdk_draw_rectangle( DRAW_WHAT(dctx), dctx->drawGC, TRUE, draw_rectangle( dctx, DRAW_WHAT(dctx), dctx->drawGC, TRUE,
rectInset.left, rectInset.top, rectInset.left, rectInset.top,
rectInset.width+1, rectInset.height+1 ); rectInset.width+1, rectInset.height+1 );
if ( isBlank && 0 == strcmp("_",letter ) ) { if ( isBlank && 0 == strcmp("_",letter ) ) {
letter = "?"; letter = "?";
@ -517,6 +597,8 @@ gtk_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* letter,
XP_GTK_JUST_CENTER, foreground, cursor ); XP_GTK_JUST_CENTER, foreground, cursor );
if ( isBlank ) { if ( isBlank ) {
#ifdef USE_CAIRO
#else
gdk_draw_arc( DRAW_WHAT(dctx), dctx->drawGC, gdk_draw_arc( DRAW_WHAT(dctx), dctx->drawGC,
0, /* filled */ 0, /* filled */
rect->left, /* x */ rect->left, /* x */
@ -524,6 +606,7 @@ gtk_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* letter,
rect->width,/*width, */ rect->width,/*width, */
rect->height,/*width, */ rect->height,/*width, */
0, 360*64 ); 0, 360*64 );
#endif
} }
} }
@ -547,7 +630,7 @@ gtk_draw_invertCell( DrawCtx* XP_UNUSED(p_dctx),
/* gdk_gc_set_function( dctx->drawGC, GDK_INVERT ); */ /* gdk_gc_set_function( dctx->drawGC, GDK_INVERT ); */
/* gdk_gc_set_clip_rectangle( dctx->drawGC, (GdkRectangle*)rect ); */ /* gdk_gc_set_clip_rectangle( dctx->drawGC, (GdkRectangle*)rect ); */
/* gdk_draw_rectangle( DRAW_WHAT(dctx), dctx->drawGC, */ /* draw_rectangle( DRAW_WHAT(dctx), dctx->drawGC, */
/* TRUE, rect->left, rect->top, */ /* TRUE, rect->left, rect->top, */
/* rect->width, rect->height ); */ /* rect->width, rect->height ); */
@ -617,19 +700,23 @@ gtkDrawTileImpl( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* textP,
} }
/* frame the tile */ /* frame the tile */
#ifdef USE_CAIRO
//gdk_cairo_set_source_color( dctx->cr, &dctx->black );
#else
gdk_gc_set_foreground( dctx->drawGC, &dctx->black ); gdk_gc_set_foreground( dctx->drawGC, &dctx->black );
gdk_draw_rectangle( DRAW_WHAT(dctx), #endif
dctx->drawGC, draw_rectangle( dctx, DRAW_WHAT(dctx),
FALSE, dctx->drawGC,
insetR.left, insetR.top, insetR.width, FALSE,
insetR.height ); insetR.left, insetR.top, insetR.width,
insetR.height );
if ( (flags & CELL_HIGHLIGHT) != 0 ) { if ( (flags & CELL_HIGHLIGHT) != 0 ) {
gtkInsetRect( &insetR, 1 ); gtkInsetRect( &insetR, 1 );
gdk_draw_rectangle( DRAW_WHAT(dctx), draw_rectangle( dctx, DRAW_WHAT(dctx),
dctx->drawGC, dctx->drawGC,
FALSE, insetR.left, insetR.top, FALSE, insetR.left, insetR.top,
insetR.width, insetR.height); insetR.width, insetR.height);
} }
} }
} /* gtkDrawTileImpl */ } /* gtkDrawTileImpl */
@ -693,11 +780,15 @@ gtk_draw_drawTrayDivider( DrawCtx* p_dctx, const XP_Rect* rect,
--r.height; --r.height;
} }
#ifdef USE_CAIRO
//gdk_cairo_set_source_color( dctx->cr, &dctx->black );
#else
gdk_gc_set_foreground( dctx->drawGC, &dctx->black ); gdk_gc_set_foreground( dctx->drawGC, &dctx->black );
gdk_draw_rectangle( DRAW_WHAT(dctx), #endif
dctx->drawGC, draw_rectangle( dctx, DRAW_WHAT(dctx),
!selected, dctx->drawGC,
r.left, r.top, r.width, r.height); !selected,
r.left, r.top, r.width, r.height);
} /* gtk_draw_drawTrayDivider */ } /* gtk_draw_drawTrayDivider */
@ -940,7 +1031,11 @@ gtk_draw_score_drawPlayer( DrawCtx* p_dctx, const XP_Rect* rInner,
gtkFillRect( dctx, rOuter, cursor ); gtkFillRect( dctx, rOuter, cursor );
} }
#ifdef USE_CAIRO
//gdk_cairo_set_source_color( dctx->cr, &dctx->playerColors[playerNum] );
#else
gdk_gc_set_foreground( dctx->drawGC, &dctx->playerColors[playerNum] ); gdk_gc_set_foreground( dctx->drawGC, &dctx->playerColors[playerNum] );
#endif
if ( dsi->selected ) { if ( dsi->selected ) {
XP_Rect selRect = *rOuter; XP_Rect selRect = *rOuter;
@ -960,9 +1055,9 @@ gtk_draw_score_drawPlayer( DrawCtx* p_dctx, const XP_Rect* rInner,
} }
} }
gdk_draw_rectangle( DRAW_WHAT(dctx), dctx->drawGC, draw_rectangle( dctx, DRAW_WHAT(dctx), dctx->drawGC,
TRUE, selRect.left, selRect.top, TRUE, selRect.left, selRect.top,
selRect.width, selRect.height ); selRect.width, selRect.height );
if ( hasCursor ) { if ( hasCursor ) {
gtkFillRect( dctx, rInner, cursor ); gtkFillRect( dctx, rInner, cursor );
} }
@ -1099,8 +1194,11 @@ gtk_draw_drawMiniWindow( DrawCtx* p_dctx, const XP_UCHAR* text,
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx; GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
XP_Rect localR = *rect; XP_Rect localR = *rect;
#ifdef USE_CAIRO
//gdk_cairo_set_source_color( dctx->cr, &dctx->black );
#else
gdk_gc_set_foreground( dctx->drawGC, &dctx->black ); gdk_gc_set_foreground( dctx->drawGC, &dctx->black );
/* gdk_gc_set_clip_rectangle( dctx->drawGC, (GdkRectangle*)&localR ); */ #endif
/* play some skanky games to get the shadow drawn under and to the /* play some skanky games to get the shadow drawn under and to the
right... */ right... */
@ -1227,7 +1325,16 @@ gtkDrawCtxtMake( GtkWidget* drawing_area, GtkAppGlobals* globals )
} else { } else {
window = GTK_WIDGET(drawing_area)->window; window = GTK_WIDGET(drawing_area)->window;
} }
window = GTK_WIDGET(drawing_area)->window;
#ifdef USE_CAIRO
dctx->cr = gdk_cairo_create( window );
XP_LOGF( "dctx->cr=%p", dctx->cr );
cairo_set_line_width( dctx->cr, 1.0 );
cairo_set_line_cap( dctx->cr, CAIRO_LINE_CAP_SQUARE );
cairo_set_source_rgb( dctx->cr, 0, 0, 0 );
#else
dctx->drawGC = gdk_gc_new( window ); dctx->drawGC = gdk_gc_new( window );
#endif
} }
map = gdk_colormap_get_system(); map = gdk_colormap_get_system();

View file

@ -47,7 +47,11 @@ typedef struct GtkDrawCtx {
GtkWidget* drawing_area; GtkWidget* drawing_area;
struct GtkAppGlobals* globals; struct GtkAppGlobals* globals;
#ifdef USE_CAIRO
cairo_t* cr;
#else
GdkGC* drawGC; GdkGC* drawGC;
#endif
GdkColor black; GdkColor black;
GdkColor white; GdkColor white;