2007-01-06 18:46:02 +01:00
|
|
|
/* -*- mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE"; -*- */
|
2003-11-01 06:35:29 +01:00
|
|
|
/*
|
2008-03-09 00:16:21 +01:00
|
|
|
* Copyright 1997-2008 by Eric House (xwords@eehouse.org). All rights
|
|
|
|
* reserved.
|
2003-11-01 06:35:29 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
#ifdef PLATFORM_GTK
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
#include <gdk/gdkdrawable.h>
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
#include "gtkmain.h"
|
|
|
|
#include "draw.h"
|
|
|
|
#include "board.h"
|
|
|
|
#include "linuxmain.h"
|
|
|
|
|
2005-05-30 02:03:58 +02:00
|
|
|
typedef enum {
|
|
|
|
XP_GTK_JUST_NONE
|
|
|
|
,XP_GTK_JUST_CENTER
|
|
|
|
,XP_GTK_JUST_TOPLEFT
|
|
|
|
,XP_GTK_JUST_BOTTOMRIGHT
|
|
|
|
} XP_GTK_JUST;
|
|
|
|
|
2007-10-23 05:08:47 +02:00
|
|
|
typedef struct FontPerSize {
|
|
|
|
unsigned int ht;
|
|
|
|
PangoFontDescription* fontdesc;
|
|
|
|
PangoLayout* layout;
|
|
|
|
} FontPerSize;
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
/* static GdkGC* newGCForColor( GdkWindow* window, XP_Color* newC ); */
|
|
|
|
static void
|
2008-07-28 07:03:37 +02:00
|
|
|
gtkInsetRect( XP_Rect* r, short i )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
r->top += i;
|
|
|
|
r->left += i;
|
|
|
|
i *= 2;
|
|
|
|
|
|
|
|
r->width -= i;
|
|
|
|
r->height -= i;
|
2008-07-28 07:03:37 +02:00
|
|
|
} /* gtkInsetRect */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
#if 0
|
|
|
|
#define DRAW_WHAT(dc) ((dc)->globals->pixmap)
|
|
|
|
#else
|
|
|
|
#define DRAW_WHAT(dc) ((dc)->drawing_area->window)
|
|
|
|
#endif
|
|
|
|
|
2007-11-14 06:57:12 +01:00
|
|
|
#define GTKMIN_W_HT 12
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-07-28 07:03:37 +02:00
|
|
|
static void
|
2008-10-24 11:07:30 +02:00
|
|
|
gtkFillRect( GtkDrawCtx* dctx, const XP_Rect* rect, const GdkColor* color )
|
2008-07-28 07:03:37 +02:00
|
|
|
{
|
|
|
|
gdk_gc_set_foreground( dctx->drawGC, color );
|
|
|
|
gdk_draw_rectangle( DRAW_WHAT(dctx), dctx->drawGC,
|
|
|
|
TRUE,
|
|
|
|
rect->left, rect->top, rect->width,
|
|
|
|
rect->height );
|
|
|
|
}
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
static void
|
2008-03-25 13:47:05 +01:00
|
|
|
gtkEraseRect( GtkDrawCtx* dctx, const XP_Rect* rect )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
gdk_draw_rectangle( DRAW_WHAT(dctx),
|
2005-05-29 22:32:48 +02:00
|
|
|
dctx->drawing_area->style->white_gc,
|
|
|
|
TRUE, rect->left, rect->top,
|
|
|
|
rect->width, rect->height );
|
2008-03-25 13:47:05 +01:00
|
|
|
} /* gtkEraseRect */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
static void
|
2008-03-09 00:16:21 +01:00
|
|
|
frameRect( GtkDrawCtx* dctx, const XP_Rect* rect )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
gdk_draw_rectangle( DRAW_WHAT(dctx),
|
|
|
|
dctx->drawGC, FALSE, rect->left, rect->top,
|
|
|
|
rect->width, rect->height );
|
|
|
|
} /* frameRect */
|
|
|
|
|
|
|
|
#ifdef DRAW_WITH_PRIMITIVES
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_prim_draw_setClip( DrawCtx* p_dctx, XP_Rect* newClip, XP_Rect* oldClip)
|
|
|
|
{
|
|
|
|
} /* gtk_prim_draw_setClip */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_prim_draw_frameRect( DrawCtx* p_dctx, XP_Rect* rect )
|
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
|
|
|
frameRect( dctx, rect );
|
|
|
|
} /* gtk_prim_draw_frameRect */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_prim_draw_invertRect( DrawCtx* p_dctx, XP_Rect* rect )
|
|
|
|
{
|
|
|
|
/* not sure you can do this on GTK!! */
|
|
|
|
} /* gtk_prim_draw_invertRect */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_prim_draw_clearRect( DrawCtx* p_dctx, XP_Rect* rect )
|
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
2008-03-25 13:47:05 +01:00
|
|
|
gtkEraseRect( dctx, rect );
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* gtk_prim_draw_clearRect */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_prim_draw_drawString( DrawCtx* p_dctx, XP_UCHAR* str,
|
|
|
|
XP_U16 x, XP_U16 y )
|
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
|
|
|
XP_U16 fontHeight = 10; /* FIX ME */
|
|
|
|
gdk_draw_string( DRAW_WHAT(dctx), dctx->gdkFont, dctx->drawGC,
|
|
|
|
x, y + fontHeight, str );
|
|
|
|
} /* gtk_prim_draw_drawString */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_prim_draw_drawBitmap( DrawCtx* p_dctx, XP_Bitmap bm,
|
|
|
|
XP_U16 x, XP_U16 y )
|
|
|
|
{
|
|
|
|
} /* gtk_prim_draw_drawBitmap */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_prim_draw_measureText( DrawCtx* p_dctx, XP_UCHAR* str,
|
2005-05-29 22:32:48 +02:00
|
|
|
XP_U16* widthP, XP_U16* heightP )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
|
|
|
gint len = strlen(str);
|
|
|
|
gint width = gdk_text_measure( dctx->gdkFont, str, len );
|
|
|
|
|
|
|
|
*widthP = width;
|
|
|
|
*heightP = 12; /* ??? :-) */
|
|
|
|
} /* gtk_prim_draw_measureText */
|
|
|
|
|
|
|
|
#endif /* DRAW_WITH_PRIMITIVES */
|
|
|
|
|
2007-10-23 05:08:47 +02:00
|
|
|
static gint
|
|
|
|
compForHt( gconstpointer a,
|
|
|
|
gconstpointer b )
|
|
|
|
{
|
|
|
|
FontPerSize* fps1 = (FontPerSize*)a;
|
|
|
|
FontPerSize* fps2 = (FontPerSize*)b;
|
|
|
|
return fps1->ht - fps2->ht;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PangoLayout*
|
|
|
|
layout_for_ht( GtkDrawCtx* dctx, XP_U16 ht )
|
|
|
|
{
|
2007-10-24 14:46:15 +02:00
|
|
|
PangoLayout* layout = NULL;
|
2007-10-23 05:08:47 +02:00
|
|
|
|
|
|
|
/* Try to find a cached layout. Otherwise create a new one. */
|
|
|
|
FontPerSize fps = { .ht = ht };
|
|
|
|
GList* gl = g_list_find_custom( dctx->fontsPerSize, &fps,
|
|
|
|
compForHt );
|
|
|
|
if ( NULL != gl ) {
|
2007-10-24 14:46:15 +02:00
|
|
|
layout = ((FontPerSize*)gl->data)->layout;
|
2007-10-23 05:08:47 +02:00
|
|
|
}
|
|
|
|
|
2007-10-24 14:46:15 +02:00
|
|
|
if ( NULL == layout ) {
|
2007-10-23 05:08:47 +02:00
|
|
|
FontPerSize* fps = g_malloc( sizeof(*fps) );
|
|
|
|
dctx->fontsPerSize = g_list_insert( dctx->fontsPerSize,
|
|
|
|
fps, 0 );
|
|
|
|
|
|
|
|
char font[32];
|
2008-03-25 13:47:05 +01:00
|
|
|
snprintf( font, sizeof(font), "helvetica normal %dpx", ht );
|
2007-10-23 05:08:47 +02:00
|
|
|
|
2007-10-24 14:46:15 +02:00
|
|
|
layout = pango_layout_new( dctx->pangoContext );
|
2007-10-23 05:08:47 +02:00
|
|
|
fps->fontdesc = pango_font_description_from_string( font );
|
2007-10-24 14:46:15 +02:00
|
|
|
pango_layout_set_font_description( layout, fps->fontdesc );
|
|
|
|
fps->layout = layout;
|
2007-10-23 05:08:47 +02:00
|
|
|
|
|
|
|
/* This only happens first time??? */
|
2007-10-24 14:46:15 +02:00
|
|
|
pango_layout_set_alignment( layout, PANGO_ALIGN_CENTER );
|
2007-10-23 05:08:47 +02:00
|
|
|
fps->ht = ht;
|
|
|
|
}
|
|
|
|
|
2007-10-24 14:46:15 +02:00
|
|
|
return layout;
|
|
|
|
} /* layout_for_ht */
|
2007-10-23 05:08:47 +02:00
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
static void
|
2008-10-24 11:07:30 +02:00
|
|
|
draw_string_at( GtkDrawCtx* dctx, PangoLayout* layout,
|
|
|
|
const char* str, XP_U16 fontHt,
|
2005-05-30 02:03:58 +02:00
|
|
|
const XP_Rect* where, XP_GTK_JUST just,
|
2005-05-29 22:32:48 +02:00
|
|
|
const GdkColor* frground, const GdkColor* bkgrnd )
|
|
|
|
{
|
2008-03-25 13:47:05 +01:00
|
|
|
gint xx = where->left;
|
|
|
|
gint yy = where->top;
|
2005-05-30 02:03:58 +02:00
|
|
|
|
2008-10-24 11:07:30 +02:00
|
|
|
if ( !layout ) {
|
|
|
|
layout = layout_for_ht( dctx, fontHt );
|
|
|
|
}
|
2007-10-23 05:08:47 +02:00
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
pango_layout_set_text( layout, str, strlen(str) );
|
2005-05-30 02:03:58 +02:00
|
|
|
|
|
|
|
if ( just != XP_GTK_JUST_NONE ) {
|
|
|
|
int width, height;
|
|
|
|
pango_layout_get_pixel_size( layout, &width, &height );
|
|
|
|
|
|
|
|
switch( just ) {
|
|
|
|
case XP_GTK_JUST_CENTER:
|
2008-03-25 13:47:05 +01:00
|
|
|
xx += (where->width - width) / 2;
|
|
|
|
yy += (where->height - height) / 2;
|
2005-05-30 02:03:58 +02:00
|
|
|
break;
|
|
|
|
case XP_GTK_JUST_BOTTOMRIGHT:
|
2008-03-25 13:47:05 +01:00
|
|
|
xx += where->width - width;
|
|
|
|
yy += where->height - height;
|
2005-05-30 02:03:58 +02:00
|
|
|
break;
|
|
|
|
case XP_GTK_JUST_TOPLEFT:
|
|
|
|
default:
|
|
|
|
/* nothing to do?? */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
gdk_draw_layout_with_colors( DRAW_WHAT(dctx), dctx->drawGC,
|
2008-03-25 13:47:05 +01:00
|
|
|
xx, yy, layout,
|
2005-05-29 22:32:48 +02:00
|
|
|
frground, bkgrnd );
|
2005-05-30 02:03:58 +02:00
|
|
|
} /* draw_string_at */
|
2005-05-29 22:32:48 +02:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
static void
|
2009-01-13 14:02:17 +01:00
|
|
|
drawBitmapFromLBS( GtkDrawCtx* dctx, const XP_Bitmap bm, const XP_Rect* rect )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GdkPixmap* pm;
|
|
|
|
LinuxBMStruct* lbs = (LinuxBMStruct*)bm;
|
|
|
|
gint x, y;
|
|
|
|
XP_U8* bp;
|
|
|
|
XP_U16 i;
|
|
|
|
XP_S16 nBytes;
|
|
|
|
XP_U16 nCols, nRows;
|
|
|
|
|
|
|
|
nCols = lbs->nCols;
|
|
|
|
nRows = lbs->nRows;
|
|
|
|
bp = (XP_U8*)(lbs + 1); /* point to the bitmap data */
|
|
|
|
nBytes = lbs->nBytes;
|
|
|
|
|
|
|
|
pm = gdk_pixmap_new( DRAW_WHAT(dctx), nCols, nRows, -1 );
|
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
gdk_draw_rectangle( pm, dctx->drawing_area->style->white_gc, TRUE,
|
2003-11-01 06:35:29 +01:00
|
|
|
0, 0, nCols, nRows );
|
|
|
|
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
|
|
|
|
while ( nBytes-- ) {
|
|
|
|
XP_U8 byte = *bp++;
|
|
|
|
for ( i = 0; i < 8; ++i ) {
|
|
|
|
XP_Bool draw = ((byte & 0x80) != 0);
|
|
|
|
if ( draw ) {
|
2005-05-29 22:32:48 +02:00
|
|
|
gdk_draw_point( pm, dctx->drawing_area->style->black_gc, x, y );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
byte <<= 1;
|
|
|
|
if ( ++x == nCols ) {
|
|
|
|
x = 0;
|
|
|
|
if ( ++y == nRows ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XP_ASSERT( nBytes == -1 ); /* else we're out of sync */
|
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
gdk_draw_drawable( DRAW_WHAT(dctx),
|
|
|
|
dctx->drawGC,
|
|
|
|
(GdkDrawable*)pm, 0, 0,
|
|
|
|
rect->left+2,
|
|
|
|
rect->top+2,
|
|
|
|
lbs->nCols,
|
|
|
|
lbs->nRows );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
g_object_unref( pm );
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* drawBitmapFromLBS */
|
|
|
|
|
2007-10-23 05:08:47 +02:00
|
|
|
static void
|
|
|
|
freer( gpointer data, gpointer XP_UNUSED(user_data) )
|
|
|
|
{
|
|
|
|
FontPerSize* fps = (FontPerSize*)data;
|
|
|
|
pango_font_description_free( fps->fontdesc );
|
|
|
|
g_object_unref( fps->layout );
|
|
|
|
g_free( fps );
|
|
|
|
}
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
static void
|
|
|
|
gtk_draw_destroyCtxt( DrawCtx* p_dctx )
|
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
2005-05-29 22:32:48 +02:00
|
|
|
GtkAllocation* alloc = &dctx->drawing_area->allocation;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
gdk_draw_rectangle( DRAW_WHAT(dctx),
|
2005-05-29 22:32:48 +02:00
|
|
|
dctx->drawing_area->style->white_gc,
|
2003-11-01 06:35:29 +01:00
|
|
|
TRUE,
|
|
|
|
0, 0, alloc->width, alloc->height );
|
|
|
|
|
2007-10-23 05:08:47 +02:00
|
|
|
g_list_foreach( dctx->fontsPerSize, freer, NULL );
|
|
|
|
g_list_free( dctx->fontsPerSize );
|
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
g_object_unref( dctx->pangoContext );
|
|
|
|
|
|
|
|
} /* gtk_draw_destroyCtxt */
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-09-05 14:11:37 +02:00
|
|
|
static void
|
|
|
|
gtk_draw_dictChanged( DrawCtx* XP_UNUSED(p_dctx),
|
|
|
|
const DictionaryCtxt* XP_UNUSED(dict) )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-02-13 14:54:52 +01:00
|
|
|
static XP_Bool
|
2008-09-05 14:11:37 +02:00
|
|
|
gtk_draw_boardBegin( DrawCtx* p_dctx, const XP_Rect* rect,
|
|
|
|
DrawFocusState XP_UNUSED(dfs) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GdkRectangle gdkrect;
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
|
|
|
|
|
|
|
gdk_gc_set_foreground( dctx->drawGC, &dctx->black );
|
|
|
|
|
|
|
|
gdkrect = *(GdkRectangle*)rect;
|
|
|
|
++gdkrect.width;
|
|
|
|
++gdkrect.height;
|
2005-05-29 22:32:48 +02:00
|
|
|
/* gdk_gc_set_clip_rectangle( dctx->drawGC, &gdkrect ); */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2004-02-13 14:54:52 +01:00
|
|
|
return XP_TRUE;
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* draw_finish */
|
|
|
|
|
2007-01-06 18:46:02 +01:00
|
|
|
static void
|
2007-01-19 09:20:58 +01:00
|
|
|
gtk_draw_objFinished( DrawCtx* XP_UNUSED(p_dctx),
|
|
|
|
BoardObjectType XP_UNUSED(typ),
|
|
|
|
const XP_Rect* XP_UNUSED(rect),
|
|
|
|
DrawFocusState XP_UNUSED(dfs) )
|
2007-01-06 18:46:02 +01:00
|
|
|
{
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* draw_finished */
|
|
|
|
|
2007-01-21 23:59:29 +01:00
|
|
|
|
|
|
|
static XP_Bool
|
2008-04-12 18:50:46 +02:00
|
|
|
gtk_draw_vertScrollBoard( DrawCtx* p_dctx, XP_Rect* rect,
|
|
|
|
XP_S16 dist, DrawFocusState XP_UNUSED(dfs) )
|
2007-01-21 23:59:29 +01:00
|
|
|
{
|
|
|
|
/* Turn this on to mimic what palm does, but need to figure out some gtk
|
|
|
|
analog to copybits for it to actually work. */
|
2008-04-12 18:50:46 +02:00
|
|
|
#if 1
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
|
|
|
XP_Bool down = dist <= 0;
|
|
|
|
gint ysrc, ydest;
|
|
|
|
|
|
|
|
if ( down ) {
|
|
|
|
ysrc = rect->top;
|
|
|
|
dist = -dist; /* make it positive */
|
|
|
|
ydest = ysrc + dist;
|
2007-01-21 23:59:29 +01:00
|
|
|
} else {
|
2008-04-12 18:50:46 +02:00
|
|
|
ydest = rect->top;
|
|
|
|
ysrc = ydest + dist;
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_draw_drawable( DRAW_WHAT(dctx),
|
|
|
|
dctx->drawGC,
|
|
|
|
DRAW_WHAT(dctx),
|
|
|
|
rect->left,
|
|
|
|
ysrc,
|
|
|
|
rect->left,
|
|
|
|
ydest,
|
|
|
|
rect->width,
|
|
|
|
rect->height - dist );
|
|
|
|
|
|
|
|
if ( !down ) {
|
2007-01-21 23:59:29 +01:00
|
|
|
rect->top += rect->height - dist;
|
|
|
|
}
|
|
|
|
rect->height = dist;
|
|
|
|
#endif
|
|
|
|
return XP_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-15 03:44:39 +02:00
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
drawHintBorders( GtkDrawCtx* dctx, const XP_Rect* rect, HintAtts hintAtts)
|
2004-06-15 03:44:39 +02:00
|
|
|
{
|
2004-11-14 17:27:51 +01:00
|
|
|
if ( hintAtts != HINT_BORDER_NONE && hintAtts != HINT_BORDER_CENTER ) {
|
|
|
|
XP_Rect lrect = *rect;
|
2008-07-28 07:03:37 +02:00
|
|
|
gtkInsetRect( &lrect, 1 );
|
2004-06-15 03:44:39 +02:00
|
|
|
|
2004-11-14 17:27:51 +01:00
|
|
|
gdk_gc_set_foreground( dctx->drawGC, &dctx->black );
|
|
|
|
|
|
|
|
if ( (hintAtts & HINT_BORDER_LEFT) != 0 ) {
|
|
|
|
gdk_draw_rectangle( DRAW_WHAT(dctx),
|
|
|
|
dctx->drawGC,
|
|
|
|
FALSE, lrect.left, lrect.top,
|
|
|
|
0, lrect.height);
|
|
|
|
}
|
|
|
|
if ( (hintAtts & HINT_BORDER_TOP) != 0 ) {
|
|
|
|
gdk_draw_rectangle( DRAW_WHAT(dctx),
|
|
|
|
dctx->drawGC,
|
|
|
|
FALSE, lrect.left, lrect.top,
|
|
|
|
lrect.width, 0/*rectInset.height*/);
|
|
|
|
}
|
|
|
|
if ( (hintAtts & HINT_BORDER_RIGHT) != 0 ) {
|
|
|
|
gdk_draw_rectangle( DRAW_WHAT(dctx),
|
|
|
|
dctx->drawGC,
|
|
|
|
FALSE, lrect.left+lrect.width,
|
|
|
|
lrect.top,
|
|
|
|
0, lrect.height);
|
|
|
|
}
|
|
|
|
if ( (hintAtts & HINT_BORDER_BOTTOM) != 0 ) {
|
|
|
|
gdk_draw_rectangle( DRAW_WHAT(dctx),
|
|
|
|
dctx->drawGC,
|
|
|
|
FALSE, lrect.left,
|
|
|
|
lrect.top+lrect.height,
|
|
|
|
lrect.width, 0 );
|
|
|
|
}
|
2004-06-15 03:44:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
static XP_Bool
|
2006-04-01 23:01:20 +02:00
|
|
|
gtk_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* letter,
|
2009-01-13 14:02:17 +01:00
|
|
|
const XP_Bitmaps* bitmaps, Tile XP_UNUSED(tile),
|
|
|
|
XP_S16 owner, XWBonusType bonus, HintAtts hintAtts,
|
|
|
|
CellFlags flags )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
|
|
|
XP_Rect rectInset = *rect;
|
|
|
|
XP_Bool showGrid = dctx->globals->gridOn;
|
2007-10-24 14:46:15 +02:00
|
|
|
XP_Bool highlight = (flags & CELL_HIGHLIGHT) != 0;
|
2008-07-17 07:03:01 +02:00
|
|
|
GdkColor* cursor =
|
|
|
|
((flags & CELL_ISCURSOR) != 0) ? &dctx->cursor : NULL;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-03-25 13:47:05 +01:00
|
|
|
gtkEraseRect( dctx, rect );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-07-28 07:03:37 +02:00
|
|
|
gtkInsetRect( &rectInset, 1 );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
if ( showGrid ) {
|
2008-07-17 07:03:01 +02:00
|
|
|
gdk_gc_set_foreground( dctx->drawGC, &dctx->black );
|
2003-11-01 06:35:29 +01:00
|
|
|
gdk_draw_rectangle( DRAW_WHAT(dctx),
|
|
|
|
dctx->drawGC,
|
|
|
|
FALSE,
|
|
|
|
rect->left, rect->top, rect->width,
|
|
|
|
rect->height );
|
|
|
|
}
|
|
|
|
|
2008-03-09 00:16:21 +01:00
|
|
|
/* We draw just an empty, potentially colored, square IFF there's nothing
|
|
|
|
in the cell or if CELL_DRAGSRC is set */
|
2008-03-14 10:36:42 +01:00
|
|
|
if ( (flags & (CELL_DRAGSRC|CELL_ISEMPTY)) != 0 ) {
|
2008-07-17 07:03:01 +02:00
|
|
|
if ( !!cursor || bonus != BONUS_NONE ) {
|
|
|
|
GdkColor* foreground;
|
|
|
|
if ( !!cursor ) {
|
|
|
|
foreground = cursor;
|
|
|
|
} else if ( bonus != BONUS_NONE ) {
|
|
|
|
foreground = &dctx->bonusColors[bonus-1];
|
|
|
|
} else {
|
|
|
|
foreground = NULL;
|
|
|
|
}
|
|
|
|
if ( !!foreground ) {
|
|
|
|
gdk_gc_set_foreground( dctx->drawGC, foreground );
|
|
|
|
gdk_draw_rectangle( DRAW_WHAT(dctx), dctx->drawGC, TRUE,
|
|
|
|
rectInset.left, rectInset.top,
|
|
|
|
rectInset.width+1, rectInset.height+1 );
|
|
|
|
}
|
2008-03-09 00:16:21 +01:00
|
|
|
}
|
|
|
|
if ( (flags & CELL_ISSTAR) != 0 ) {
|
2008-10-24 11:07:30 +02:00
|
|
|
draw_string_at( dctx, NULL, "*", rect->height, rect,
|
|
|
|
XP_GTK_JUST_CENTER, &dctx->black, NULL );
|
2008-03-09 00:16:21 +01:00
|
|
|
}
|
2009-01-13 14:02:17 +01:00
|
|
|
} else if ( !!bitmaps ) {
|
|
|
|
drawBitmapFromLBS( dctx, bitmaps->bmps[0], rect );
|
2008-03-09 00:16:21 +01:00
|
|
|
} else if ( !!letter ) {
|
2008-07-28 07:03:37 +02:00
|
|
|
GdkColor* foreground;
|
2008-07-17 07:03:01 +02:00
|
|
|
if ( cursor ) {
|
|
|
|
gdk_gc_set_foreground( dctx->drawGC, cursor );
|
|
|
|
} else if ( !highlight ) {
|
2008-03-09 00:16:21 +01:00
|
|
|
gdk_gc_set_foreground( dctx->drawGC, &dctx->tileBack );
|
|
|
|
}
|
|
|
|
gdk_draw_rectangle( DRAW_WHAT(dctx), dctx->drawGC, TRUE,
|
|
|
|
rectInset.left, rectInset.top,
|
|
|
|
rectInset.width+1, rectInset.height+1 );
|
2005-05-29 22:32:48 +02:00
|
|
|
|
2008-07-28 07:03:37 +02:00
|
|
|
foreground = highlight? &dctx->white : &dctx->playerColors[owner];
|
2008-10-24 11:07:30 +02:00
|
|
|
draw_string_at( dctx, NULL, letter, rectInset.height-2, &rectInset,
|
2008-07-28 07:03:37 +02:00
|
|
|
XP_GTK_JUST_CENTER, foreground, cursor );
|
2008-03-09 00:16:21 +01:00
|
|
|
|
|
|
|
if ( (flags & CELL_ISBLANK) != 0 ) {
|
|
|
|
gdk_draw_arc( DRAW_WHAT(dctx), dctx->drawGC,
|
|
|
|
0, /* filled */
|
|
|
|
rect->left, /* x */
|
|
|
|
rect->top, /* y */
|
|
|
|
rect->width,/*width, */
|
|
|
|
rect->height,/*width, */
|
|
|
|
0, 360*64 );
|
2005-05-29 23:17:23 +02:00
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
2004-11-14 17:27:51 +01:00
|
|
|
drawHintBorders( dctx, rect, hintAtts );
|
2004-06-15 03:44:39 +02:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
return XP_TRUE;
|
|
|
|
} /* gtk_draw_drawCell */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
gtk_draw_invertCell( DrawCtx* XP_UNUSED(p_dctx),
|
|
|
|
const XP_Rect* XP_UNUSED(rect) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
/* GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx; */
|
|
|
|
/* (void)gtk_draw_drawMiniWindow( p_dctx, "f", rect); */
|
|
|
|
|
|
|
|
/* GdkGCValues values; */
|
|
|
|
|
|
|
|
/* gdk_gc_get_values( dctx->drawGC, &values ); */
|
|
|
|
|
|
|
|
/* gdk_gc_set_function( dctx->drawGC, GDK_INVERT ); */
|
|
|
|
|
|
|
|
/* gdk_gc_set_clip_rectangle( dctx->drawGC, (GdkRectangle*)rect ); */
|
|
|
|
/* gdk_draw_rectangle( DRAW_WHAT(dctx), dctx->drawGC, */
|
|
|
|
/* TRUE, rect->left, rect->top, */
|
|
|
|
/* rect->width, rect->height ); */
|
|
|
|
|
|
|
|
/* gdk_gc_set_function( dctx->drawGC, values.function ); */
|
|
|
|
} /* gtk_draw_invertCell */
|
|
|
|
|
2004-06-15 03:44:39 +02:00
|
|
|
static XP_Bool
|
2008-03-11 12:48:53 +01:00
|
|
|
gtk_draw_trayBegin( DrawCtx* p_dctx, const XP_Rect* XP_UNUSED(rect),
|
|
|
|
XP_U16 owner, DrawFocusState dfs )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
2005-05-29 22:32:48 +02:00
|
|
|
dctx->trayOwner = owner;
|
2007-01-06 18:46:02 +01:00
|
|
|
dctx->topFocus = dfs == DFS_TOP;
|
2004-06-15 03:44:39 +02:00
|
|
|
return XP_TRUE;
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* gtk_draw_trayBegin */
|
|
|
|
|
|
|
|
static void
|
2008-03-09 00:16:21 +01:00
|
|
|
gtkDrawTileImpl( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* textP,
|
2009-01-13 14:02:17 +01:00
|
|
|
const XP_Bitmaps* bitmaps, XP_U16 val, CellFlags flags,
|
2008-03-09 00:16:21 +01:00
|
|
|
XP_Bool clearBack )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2006-02-18 07:39:40 +01:00
|
|
|
XP_UCHAR numbuf[3];
|
2003-11-01 06:35:29 +01:00
|
|
|
gint len;
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
|
|
|
XP_Rect insetR = *rect;
|
2008-07-17 07:03:01 +02:00
|
|
|
XP_Bool isCursor = (flags & CELL_ISCURSOR) != 0;
|
2008-12-29 04:09:35 +01:00
|
|
|
XP_Bool valHidden = (flags & CELL_VALHIDDEN) != 0;
|
|
|
|
XP_Bool notEmpty = (flags & CELL_ISEMPTY) == 0;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-03-09 00:16:21 +01:00
|
|
|
if ( clearBack ) {
|
2008-03-25 13:47:05 +01:00
|
|
|
gtkEraseRect( dctx, &insetR );
|
2008-03-09 00:16:21 +01:00
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-12-29 04:09:35 +01:00
|
|
|
if ( isCursor || notEmpty ) {
|
2005-05-29 22:32:48 +02:00
|
|
|
GdkColor* foreground = &dctx->playerColors[dctx->trayOwner];
|
2005-05-30 02:03:58 +02:00
|
|
|
XP_Rect formatRect = insetR;
|
2005-05-29 22:32:48 +02:00
|
|
|
|
2008-07-28 07:03:37 +02:00
|
|
|
gtkInsetRect( &insetR, 1 );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-03-09 00:16:21 +01:00
|
|
|
if ( clearBack ) {
|
2008-12-29 04:09:35 +01:00
|
|
|
gtkFillRect( dctx, &insetR,
|
|
|
|
isCursor ? &dctx->cursor : &dctx->tileBack );
|
2008-03-09 00:16:21 +01:00
|
|
|
}
|
|
|
|
|
2008-12-29 04:09:35 +01:00
|
|
|
formatRect.left += 3;
|
|
|
|
formatRect.width -= 6;
|
2005-05-30 02:03:58 +02:00
|
|
|
|
2008-12-29 04:09:35 +01:00
|
|
|
if ( notEmpty ) {
|
2009-01-13 14:02:17 +01:00
|
|
|
if ( !!bitmaps ) {
|
|
|
|
drawBitmapFromLBS( dctx, bitmaps->bmps[1], &insetR );
|
|
|
|
} else if ( !!textP ) {
|
2008-07-17 07:03:01 +02:00
|
|
|
if ( *textP != LETTER_NONE ) { /* blank */
|
2008-10-24 11:07:30 +02:00
|
|
|
draw_string_at( dctx, NULL, textP, formatRect.height>>1,
|
2008-07-17 07:03:01 +02:00
|
|
|
&formatRect, XP_GTK_JUST_TOPLEFT,
|
|
|
|
foreground, NULL );
|
2005-05-29 22:32:48 +02:00
|
|
|
|
2008-07-17 07:03:01 +02:00
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
2008-12-29 04:09:35 +01:00
|
|
|
if ( !valHidden ) {
|
|
|
|
sprintf( numbuf, "%d", val );
|
|
|
|
len = strlen( numbuf );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-12-29 04:09:35 +01:00
|
|
|
draw_string_at( dctx, NULL, numbuf, formatRect.height>>2,
|
|
|
|
&formatRect, XP_GTK_JUST_BOTTOMRIGHT,
|
|
|
|
foreground, NULL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* frame the tile */
|
|
|
|
gdk_gc_set_foreground( dctx->drawGC, &dctx->black );
|
|
|
|
gdk_draw_rectangle( DRAW_WHAT(dctx),
|
|
|
|
dctx->drawGC,
|
|
|
|
FALSE,
|
|
|
|
insetR.left, insetR.top, insetR.width,
|
|
|
|
insetR.height );
|
|
|
|
|
|
|
|
if ( (flags & CELL_HIGHLIGHT) != 0 ) {
|
|
|
|
gtkInsetRect( &insetR, 1 );
|
2003-11-01 06:35:29 +01:00
|
|
|
gdk_draw_rectangle( DRAW_WHAT(dctx),
|
|
|
|
dctx->drawGC,
|
2008-12-29 04:09:35 +01:00
|
|
|
FALSE, insetR.left, insetR.top,
|
|
|
|
insetR.width, insetR.height);
|
2008-07-17 07:03:01 +02:00
|
|
|
}
|
2007-01-06 18:46:02 +01:00
|
|
|
}
|
2008-06-08 01:03:47 +02:00
|
|
|
} /* gtkDrawTileImpl */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-03-09 00:16:21 +01:00
|
|
|
static void
|
|
|
|
gtk_draw_drawTile( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* textP,
|
2009-01-13 14:02:17 +01:00
|
|
|
const XP_Bitmaps* bitmaps, XP_U16 val, CellFlags flags )
|
2008-03-09 00:16:21 +01:00
|
|
|
{
|
2009-01-13 14:02:17 +01:00
|
|
|
gtkDrawTileImpl( p_dctx, rect, textP, bitmaps, val, flags, XP_TRUE );
|
2008-03-09 00:16:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef POINTER_SUPPORT
|
|
|
|
static void
|
|
|
|
gtk_draw_drawTileMidDrag( DrawCtx* p_dctx, const XP_Rect* rect,
|
2009-01-13 14:02:17 +01:00
|
|
|
const XP_UCHAR* textP, const XP_Bitmaps* bitmaps,
|
2008-12-29 04:09:35 +01:00
|
|
|
XP_U16 val, XP_U16 owner, CellFlags flags )
|
2008-03-09 00:16:21 +01:00
|
|
|
{
|
2008-03-11 12:48:53 +01:00
|
|
|
gtk_draw_trayBegin( p_dctx, rect, owner, DFS_NONE );
|
2009-01-13 14:02:17 +01:00
|
|
|
gtkDrawTileImpl( p_dctx, rect, textP, bitmaps, val,
|
|
|
|
flags | CELL_HIGHLIGHT, XP_FALSE );
|
2008-03-09 00:16:21 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
static void
|
2006-11-12 15:51:47 +01:00
|
|
|
gtk_draw_drawTileBack( DrawCtx* p_dctx, const XP_Rect* rect,
|
2007-01-06 18:46:02 +01:00
|
|
|
CellFlags flags )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
2008-07-17 07:03:01 +02:00
|
|
|
XP_Bool hasCursor = (flags & CELL_ISCURSOR) != 0;
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_Rect r = *rect;
|
|
|
|
|
2008-07-28 07:03:37 +02:00
|
|
|
gtkInsetRect( &r, 1 );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-07-28 07:03:37 +02:00
|
|
|
gtkFillRect( dctx, &r, &dctx->playerColors[dctx->trayOwner] );
|
2005-05-29 23:17:23 +02:00
|
|
|
|
2008-07-28 07:03:37 +02:00
|
|
|
gtkInsetRect( &r, 1 );
|
|
|
|
gtkFillRect( dctx, &r, hasCursor? &dctx->cursor : &dctx->tileBack );
|
2005-05-29 23:17:23 +02:00
|
|
|
|
2008-10-24 11:07:30 +02:00
|
|
|
draw_string_at( dctx, NULL, "?", r.height,
|
2005-05-30 02:03:58 +02:00
|
|
|
&r, XP_GTK_JUST_CENTER,
|
2005-05-29 23:17:23 +02:00
|
|
|
&dctx->playerColors[dctx->trayOwner], NULL );
|
2007-01-06 18:46:02 +01:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* gtk_draw_drawTileBack */
|
|
|
|
|
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
gtk_draw_drawTrayDivider( DrawCtx* p_dctx, const XP_Rect* rect,
|
2008-07-17 07:03:01 +02:00
|
|
|
CellFlags flags )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
|
|
|
XP_Rect r = *rect;
|
2008-07-17 07:03:01 +02:00
|
|
|
XP_Bool selected = 0 != (flags & CELL_HIGHLIGHT);
|
|
|
|
XP_Bool isCursor = 0 != (flags & CELL_ISCURSOR);
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-03-25 13:47:05 +01:00
|
|
|
gtkEraseRect( dctx, &r );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-07-28 07:03:37 +02:00
|
|
|
gtkFillRect( dctx, &r, isCursor? &dctx->cursor:&dctx->white );
|
2008-07-17 07:03:01 +02:00
|
|
|
|
|
|
|
r.left += 2;
|
|
|
|
r.width -= 4;
|
2003-11-01 06:35:29 +01:00
|
|
|
if ( selected ) {
|
2008-03-09 00:16:21 +01:00
|
|
|
--r.height;
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
gdk_gc_set_foreground( dctx->drawGC, &dctx->black );
|
|
|
|
gdk_draw_rectangle( DRAW_WHAT(dctx),
|
|
|
|
dctx->drawGC,
|
|
|
|
!selected,
|
|
|
|
r.left, r.top, r.width, r.height);
|
|
|
|
|
|
|
|
} /* gtk_draw_drawTrayDivider */
|
|
|
|
|
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
gtk_draw_clearRect( DrawCtx* p_dctx, const XP_Rect* rectP )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
|
|
|
XP_Rect rect = *rectP;
|
|
|
|
|
|
|
|
++rect.width;
|
|
|
|
++rect.top;
|
|
|
|
|
2008-03-25 13:47:05 +01:00
|
|
|
gtkEraseRect( dctx, &rect );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
} /* gtk_draw_clearRect */
|
|
|
|
|
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
gtk_draw_drawBoardArrow( DrawCtx* p_dctx, const XP_Rect* rectP,
|
2006-08-16 15:44:44 +02:00
|
|
|
XWBonusType XP_UNUSED(cursorBonus), XP_Bool vertical,
|
2006-11-12 15:51:47 +01:00
|
|
|
HintAtts hintAtts, CellFlags XP_UNUSED(flags) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
2005-05-29 22:32:48 +02:00
|
|
|
const char* curs = vertical? "|":"-";
|
|
|
|
|
2007-10-24 14:46:15 +02:00
|
|
|
/* font needs to be small enough that "|" doesn't overwrite cell below */
|
2008-10-24 11:07:30 +02:00
|
|
|
draw_string_at( dctx, NULL, curs, (rectP->height*2)/3,
|
2005-05-30 02:03:58 +02:00
|
|
|
rectP, XP_GTK_JUST_CENTER,
|
2005-05-29 22:32:48 +02:00
|
|
|
&dctx->black, NULL );
|
2004-11-14 17:27:51 +01:00
|
|
|
drawHintBorders( dctx, rectP, hintAtts );
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* gtk_draw_drawBoardCursor */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
gtk_draw_scoreBegin( DrawCtx* p_dctx, const XP_Rect* rect,
|
|
|
|
XP_U16 XP_UNUSED(numPlayers),
|
2007-01-06 18:46:02 +01:00
|
|
|
DrawFocusState dfs )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
/* gdk_gc_set_clip_rectangle( dctx->drawGC, (GdkRectangle*)rect ); */
|
2008-03-25 13:47:05 +01:00
|
|
|
gtkEraseRect( dctx, rect );
|
2007-01-06 18:46:02 +01:00
|
|
|
dctx->topFocus = dfs == DFS_TOP;
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* gtk_draw_scoreBegin */
|
|
|
|
|
2008-03-25 13:47:05 +01:00
|
|
|
static PangoLayout*
|
|
|
|
getLayoutToFitRect( GtkDrawCtx* dctx, const char* str, const XP_Rect* rect )
|
|
|
|
{
|
|
|
|
PangoLayout* layout;
|
|
|
|
float ratio, ratioH;
|
|
|
|
int width, height;
|
|
|
|
XP_U16 len = strlen(str);
|
|
|
|
|
|
|
|
/* First measure it using any font at all */
|
|
|
|
layout = layout_for_ht( dctx, 24 );
|
|
|
|
pango_layout_set_text( layout, str, len );
|
|
|
|
pango_layout_get_pixel_size( layout, &width, &height );
|
|
|
|
|
|
|
|
/* Figure the ratio of is to should-be. The smaller of these is the one
|
|
|
|
we must use. */
|
|
|
|
ratio = (float)rect->width / (float)width;
|
|
|
|
ratioH = (float)rect->height / (float)height;
|
|
|
|
if ( ratioH < ratio ) {
|
|
|
|
ratio = ratioH;
|
|
|
|
}
|
|
|
|
height = 24.0 * ratio;
|
|
|
|
|
|
|
|
layout = layout_for_ht( dctx, height );
|
|
|
|
pango_layout_set_text( layout, str, len );
|
|
|
|
return layout;
|
|
|
|
} /* getLayoutToFitRect */
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
static void
|
2008-03-25 13:47:05 +01:00
|
|
|
gtkDrawDrawRemText( DrawCtx* p_dctx, const XP_Rect* rect, XP_S16 nTilesLeft,
|
2008-10-24 11:07:30 +02:00
|
|
|
XP_U16* widthP, XP_U16* heightP, XP_Bool focussed )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
|
|
|
char buf[10];
|
2008-10-24 11:07:30 +02:00
|
|
|
PangoLayout* layout;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-03-25 13:47:05 +01:00
|
|
|
snprintf( buf, sizeof(buf), "rem:%d", nTilesLeft );
|
2008-10-24 11:07:30 +02:00
|
|
|
layout = getLayoutToFitRect( dctx, buf, rect );
|
2008-03-25 13:47:05 +01:00
|
|
|
|
|
|
|
if ( !!widthP ) {
|
2005-05-29 22:32:48 +02:00
|
|
|
int width, height;
|
2006-05-11 05:02:11 +02:00
|
|
|
pango_layout_get_pixel_size( layout, &width, &height );
|
2008-03-25 13:47:05 +01:00
|
|
|
if ( width > rect->width ) {
|
|
|
|
width = rect->width;
|
|
|
|
}
|
|
|
|
if ( height > rect->height ) {
|
|
|
|
height = rect->height;
|
2005-05-29 22:32:48 +02:00
|
|
|
}
|
|
|
|
*widthP = width;
|
|
|
|
*heightP = height;
|
2008-03-25 13:47:05 +01:00
|
|
|
} else {
|
2008-10-24 11:07:30 +02:00
|
|
|
const GdkColor* cursor = NULL;
|
|
|
|
if ( focussed ) {
|
|
|
|
cursor = &dctx->cursor;
|
|
|
|
gtkFillRect( dctx, rect, cursor );
|
|
|
|
}
|
|
|
|
draw_string_at( dctx, layout, buf, rect->height,
|
2008-03-25 13:47:05 +01:00
|
|
|
rect, XP_GTK_JUST_TOPLEFT,
|
2008-10-24 11:07:30 +02:00
|
|
|
&dctx->black, cursor );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
} /* gtkDrawDrawRemText */
|
|
|
|
|
|
|
|
static void
|
2008-10-24 11:07:30 +02:00
|
|
|
gtk_draw_measureRemText( DrawCtx* p_dctx, const XP_Rect* rect, XP_S16 nTilesLeft,
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_U16* width, XP_U16* height )
|
|
|
|
{
|
2008-10-24 11:07:30 +02:00
|
|
|
if ( nTilesLeft <= 0 ) {
|
|
|
|
*width = *height = 0;
|
|
|
|
} else {
|
|
|
|
gtkDrawDrawRemText( p_dctx, rect, nTilesLeft, width, height, XP_FALSE );
|
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* gtk_draw_measureRemText */
|
|
|
|
|
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
gtk_draw_drawRemText( DrawCtx* p_dctx, const XP_Rect* rInner,
|
2008-10-24 11:07:30 +02:00
|
|
|
const XP_Rect* XP_UNUSED(rOuter), XP_S16 nTilesLeft,
|
|
|
|
XP_Bool focussed )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2008-10-24 11:07:30 +02:00
|
|
|
gtkDrawDrawRemText( p_dctx, rInner, nTilesLeft, NULL, NULL, focussed );
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* gtk_draw_drawRemText */
|
|
|
|
|
|
|
|
static void
|
2008-03-25 13:47:05 +01:00
|
|
|
formatScoreText( char* buf, XP_U16 bufLen, const DrawScoreInfo* dsi )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2008-02-02 16:17:53 +01:00
|
|
|
XP_S16 score = dsi->totalScore;
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_U16 nTilesLeft = dsi->nTilesLeft;
|
|
|
|
XP_Bool isTurn = dsi->isTurn;
|
2008-03-25 13:47:05 +01:00
|
|
|
int used;
|
2003-11-01 06:35:29 +01:00
|
|
|
char* borders = "";
|
2008-03-25 13:47:05 +01:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
if ( isTurn ) {
|
2005-05-29 22:32:48 +02:00
|
|
|
borders = "*";
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
2008-03-25 13:47:05 +01:00
|
|
|
used = snprintf( buf, bufLen, "%s%.3d", borders, score );
|
2007-11-25 16:12:22 +01:00
|
|
|
if ( (nTilesLeft < MAX_TRAY_TILES) && (nTilesLeft > 0) ) {
|
2005-05-29 22:32:48 +02:00
|
|
|
char nbuf[10];
|
|
|
|
sprintf( nbuf, ":%d", nTilesLeft );
|
|
|
|
(void)strcat( buf, nbuf );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
2008-03-25 13:47:05 +01:00
|
|
|
snprintf( buf+used, bufLen-used, "%s", borders );
|
|
|
|
} /* formatScoreText */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
static void
|
2008-03-25 13:47:05 +01:00
|
|
|
gtk_draw_measureScoreText( DrawCtx* p_dctx, const XP_Rect* bounds,
|
2006-02-18 07:39:40 +01:00
|
|
|
const DrawScoreInfo* dsi,
|
2008-03-25 13:47:05 +01:00
|
|
|
XP_U16* widthP, XP_U16* heightP )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
|
|
|
char buf[20];
|
2008-03-25 13:47:05 +01:00
|
|
|
PangoLayout* layout;
|
|
|
|
int height, width;
|
|
|
|
|
|
|
|
formatScoreText( buf, sizeof(buf), dsi );
|
|
|
|
layout = getLayoutToFitRect( dctx, buf, bounds );
|
|
|
|
pango_layout_get_pixel_size( layout, &width, &height );
|
|
|
|
|
|
|
|
*widthP = width;
|
|
|
|
*heightP = height;
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* gtk_draw_measureScoreText */
|
|
|
|
|
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
gtk_draw_score_drawPlayer( DrawCtx* p_dctx, const XP_Rect* rInner,
|
|
|
|
const XP_Rect* rOuter, const DrawScoreInfo* dsi )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
|
|
|
char scoreBuf[20];
|
2008-07-17 07:03:01 +02:00
|
|
|
XP_Bool hasCursor = (dsi->flags & CELL_ISCURSOR) != 0;
|
|
|
|
GdkColor* cursor = NULL;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-03-25 13:47:05 +01:00
|
|
|
formatScoreText( scoreBuf, sizeof(scoreBuf), dsi );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-07-17 07:03:01 +02:00
|
|
|
if ( hasCursor ) {
|
|
|
|
cursor = &dctx->cursor;
|
2008-07-28 07:03:37 +02:00
|
|
|
gtkFillRect( dctx, rOuter, cursor );
|
2008-07-17 07:03:01 +02:00
|
|
|
}
|
|
|
|
|
2005-03-15 04:27:24 +01:00
|
|
|
gdk_gc_set_foreground( dctx->drawGC, &dctx->playerColors[dsi->playerNum] );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
if ( dsi->selected ) {
|
2008-07-28 07:03:37 +02:00
|
|
|
XP_Rect selRect = *rOuter;
|
|
|
|
XP_S16 diff = selRect.width - rInner->width;
|
|
|
|
if ( diff > 0 ) {
|
|
|
|
selRect.width -= diff>>1;
|
|
|
|
selRect.left += diff>>2;
|
|
|
|
}
|
2005-05-29 22:32:48 +02:00
|
|
|
gdk_draw_rectangle( DRAW_WHAT(dctx), dctx->drawGC,
|
2008-07-28 07:03:37 +02:00
|
|
|
TRUE, selRect.left, selRect.top,
|
|
|
|
selRect.width, selRect.height );
|
2008-03-25 13:47:05 +01:00
|
|
|
gtkEraseRect( dctx, rInner );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
2008-10-24 11:07:30 +02:00
|
|
|
draw_string_at( dctx, NULL, scoreBuf, rInner->height - 1,
|
2005-05-30 02:03:58 +02:00
|
|
|
rInner, XP_GTK_JUST_CENTER,
|
2008-07-17 07:03:01 +02:00
|
|
|
&dctx->playerColors[dsi->playerNum], cursor );
|
2007-01-06 18:46:02 +01:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* gtk_draw_score_drawPlayer */
|
|
|
|
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
gtk_draw_score_pendingScore( DrawCtx* p_dctx, const XP_Rect* rect,
|
2006-11-12 15:51:47 +01:00
|
|
|
XP_S16 score, XP_U16 XP_UNUSED(playerNum),
|
2007-01-06 18:46:02 +01:00
|
|
|
CellFlags flags )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
|
|
|
char buf[5];
|
2007-10-23 05:08:47 +02:00
|
|
|
XP_U16 ht;
|
2003-11-01 06:35:29 +01:00
|
|
|
XP_Rect localR;
|
2008-07-17 07:03:01 +02:00
|
|
|
GdkColor* cursor = ((flags & CELL_ISCURSOR) != 0)
|
|
|
|
? &dctx->cursor : NULL;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
if ( score >= 0 ) {
|
2007-10-23 05:08:47 +02:00
|
|
|
sprintf( buf, "%.3d", score );
|
2003-11-01 06:35:29 +01:00
|
|
|
} else {
|
2007-10-23 05:08:47 +02:00
|
|
|
strcpy( buf, "???" );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
/* gdk_gc_set_clip_rectangle( dctx->drawGC, (GdkRectangle*)rect ); */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
localR = *rect;
|
2008-07-28 07:03:37 +02:00
|
|
|
gtkInsetRect( &localR, 1 );
|
|
|
|
|
|
|
|
if ( !!cursor ) {
|
|
|
|
gtkFillRect( dctx, &localR, cursor );
|
|
|
|
} else {
|
|
|
|
gtkEraseRect( dctx, &localR );
|
|
|
|
}
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2007-10-23 05:08:47 +02:00
|
|
|
ht = localR.height >> 2;
|
2008-10-24 11:07:30 +02:00
|
|
|
draw_string_at( dctx, NULL, "Pts:", ht,
|
2006-02-18 07:39:40 +01:00
|
|
|
&localR, XP_GTK_JUST_TOPLEFT,
|
2008-07-17 07:03:01 +02:00
|
|
|
&dctx->black, cursor );
|
2008-10-24 11:07:30 +02:00
|
|
|
draw_string_at( dctx, NULL, buf, ht,
|
2006-02-18 07:39:40 +01:00
|
|
|
&localR, XP_GTK_JUST_BOTTOMRIGHT,
|
2008-07-17 07:03:01 +02:00
|
|
|
&dctx->black, cursor );
|
2007-01-06 18:46:02 +01:00
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* gtk_draw_score_pendingScore */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtkFormatTimerText( XP_UCHAR* buf, XP_S16 secondsLeft )
|
|
|
|
{
|
|
|
|
XP_U16 minutes, seconds;
|
|
|
|
|
|
|
|
if ( secondsLeft < 0 ) {
|
2005-05-30 02:03:58 +02:00
|
|
|
*buf++ = '-';
|
|
|
|
secondsLeft *= -1;
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
minutes = secondsLeft / 60;
|
|
|
|
seconds = secondsLeft % 60;
|
|
|
|
sprintf( buf, "% 1d:%02d", minutes, seconds );
|
|
|
|
} /* gtkFormatTimerText */
|
|
|
|
|
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
gtk_draw_drawTimer( DrawCtx* p_dctx, const XP_Rect* rInner,
|
2006-08-16 15:44:44 +02:00
|
|
|
const XP_Rect* XP_UNUSED(rOuter),
|
|
|
|
XP_U16 XP_UNUSED(player), XP_S16 secondsLeft )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
|
|
|
XP_UCHAR buf[10];
|
|
|
|
|
|
|
|
gtkFormatTimerText( buf, secondsLeft );
|
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
/* gdk_gc_set_clip_rectangle( dctx->drawGC, (GdkRectangle*)rInner ); */
|
2008-03-25 13:47:05 +01:00
|
|
|
gtkEraseRect( dctx, rInner );
|
2008-10-24 11:07:30 +02:00
|
|
|
draw_string_at( dctx, NULL, buf, rInner->height-1,
|
2005-05-30 02:03:58 +02:00
|
|
|
rInner, XP_GTK_JUST_CENTER,
|
|
|
|
&dctx->black, NULL );
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* gtk_draw_drawTimer */
|
|
|
|
|
|
|
|
#define MINI_LINE_HT 12
|
|
|
|
#define MINI_V_PADDING 6
|
|
|
|
#define MINI_H_PADDING 8
|
|
|
|
|
2007-02-03 18:54:20 +01:00
|
|
|
static const XP_UCHAR*
|
2006-08-16 15:44:44 +02:00
|
|
|
gtk_draw_getMiniWText( DrawCtx* XP_UNUSED(p_dctx), XWMiniTextType textHint )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
/* GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx; */
|
2006-02-18 07:39:40 +01:00
|
|
|
XP_UCHAR* str;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
switch( textHint ) {
|
|
|
|
case BONUS_DOUBLE_LETTER:
|
|
|
|
str = "Double letter"; break;
|
|
|
|
case BONUS_DOUBLE_WORD:
|
|
|
|
str = "Double word"; break;
|
|
|
|
case BONUS_TRIPLE_LETTER:
|
|
|
|
str = "Triple letter"; break;
|
|
|
|
case BONUS_TRIPLE_WORD:
|
|
|
|
str = "Triple word"; break;
|
|
|
|
case INTRADE_MW_TEXT:
|
|
|
|
str = "Trading tiles;\nclick D when done"; break;
|
|
|
|
default:
|
|
|
|
XP_ASSERT( XP_FALSE );
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
} /* gtk_draw_getMiniWText */
|
|
|
|
|
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
gtk_draw_measureMiniWText( DrawCtx* p_dctx, const XP_UCHAR* str,
|
2005-05-29 22:32:48 +02:00
|
|
|
XP_U16* widthP, XP_U16* heightP )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
2005-05-29 22:32:48 +02:00
|
|
|
int height, width;
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2007-10-23 05:08:47 +02:00
|
|
|
PangoLayout* layout = layout_for_ht( dctx, GTKMIN_W_HT );
|
|
|
|
pango_layout_set_text( layout, str, strlen(str) );
|
|
|
|
pango_layout_get_pixel_size( layout, &width, &height );
|
2003-11-01 06:35:29 +01:00
|
|
|
*heightP = height;
|
2005-05-29 22:32:48 +02:00
|
|
|
*widthP = width + 6;
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* gtk_draw_measureMiniWText */
|
|
|
|
|
|
|
|
static void
|
2006-02-18 07:39:40 +01:00
|
|
|
gtk_draw_drawMiniWindow( DrawCtx* p_dctx, const XP_UCHAR* text,
|
2006-08-16 15:44:44 +02:00
|
|
|
const XP_Rect* rect, void** XP_UNUSED(closureP) )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
|
|
|
XP_Rect localR = *rect;
|
|
|
|
|
|
|
|
gdk_gc_set_foreground( dctx->drawGC, &dctx->black );
|
2005-05-29 22:32:48 +02:00
|
|
|
/* gdk_gc_set_clip_rectangle( dctx->drawGC, (GdkRectangle*)&localR ); */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
/* play some skanky games to get the shadow drawn under and to the
|
|
|
|
right... */
|
2008-03-25 13:47:05 +01:00
|
|
|
gtkEraseRect( dctx, &localR );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2008-07-28 07:03:37 +02:00
|
|
|
gtkInsetRect( &localR, 1 );
|
2003-11-01 06:35:29 +01:00
|
|
|
--localR.width;
|
|
|
|
--localR.height;
|
|
|
|
frameRect( dctx, &localR );
|
|
|
|
|
|
|
|
--localR.top;
|
|
|
|
--localR.left;
|
2008-03-25 13:47:05 +01:00
|
|
|
gtkEraseRect( dctx, &localR );
|
2003-11-01 06:35:29 +01:00
|
|
|
frameRect( dctx, &localR );
|
|
|
|
|
2008-10-24 11:07:30 +02:00
|
|
|
draw_string_at( dctx, NULL, text, GTKMIN_W_HT,
|
2005-05-30 02:03:58 +02:00
|
|
|
&localR, XP_GTK_JUST_CENTER,
|
2005-05-29 22:32:48 +02:00
|
|
|
&dctx->black, NULL );
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* gtk_draw_drawMiniWindow */
|
|
|
|
|
|
|
|
#define SET_GDK_COLOR( c, r, g, b ) { \
|
|
|
|
c.red = (r); \
|
|
|
|
c.green = (g); \
|
|
|
|
c.blue = (b); \
|
|
|
|
}
|
|
|
|
static void
|
2006-08-16 15:44:44 +02:00
|
|
|
draw_doNothing( DrawCtx* XP_UNUSED(dctx), ... )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
|
|
|
} /* draw_doNothing */
|
|
|
|
|
|
|
|
static void
|
|
|
|
allocAndSet( GdkColormap* map, GdkColor* color, unsigned short red,
|
2005-05-29 22:32:48 +02:00
|
|
|
unsigned short green, unsigned short blue )
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
gboolean success;
|
|
|
|
|
|
|
|
color->red = red;
|
|
|
|
color->green = green;
|
|
|
|
color->blue = blue;
|
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
success = gdk_colormap_alloc_color( map,
|
|
|
|
color,
|
|
|
|
TRUE, /* writeable */
|
|
|
|
TRUE ); /* best-match */
|
|
|
|
XP_ASSERT( success );
|
2003-11-01 06:35:29 +01:00
|
|
|
} /* allocAndSet */
|
|
|
|
|
|
|
|
DrawCtx*
|
2005-05-29 22:32:48 +02:00
|
|
|
gtkDrawCtxtMake( GtkWidget* drawing_area, GtkAppGlobals* globals )
|
2003-11-01 06:35:29 +01:00
|
|
|
{
|
2007-10-23 05:08:47 +02:00
|
|
|
GtkDrawCtx* dctx = g_malloc0( sizeof(GtkDrawCtx) );
|
2005-05-29 22:32:48 +02:00
|
|
|
GdkColormap* map;
|
|
|
|
|
2003-11-01 06:35:29 +01:00
|
|
|
short i;
|
|
|
|
|
|
|
|
dctx->vtable = g_malloc( sizeof(*(((GtkDrawCtx*)dctx)->vtable)) );
|
|
|
|
|
|
|
|
for ( i = 0; i < sizeof(*dctx->vtable)/4; ++i ) {
|
|
|
|
((void**)(dctx->vtable))[i] = draw_doNothing;
|
|
|
|
}
|
|
|
|
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_clearRect, gtk );
|
|
|
|
|
|
|
|
#ifdef DRAW_WITH_PRIMITIVES
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_setClip, gtk_prim );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_frameRect, gtk_prim );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_invertRect, gtk_prim );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawString, gtk_prim );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawBitmap, gtk_prim );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_measureText, gtk_prim );
|
|
|
|
|
|
|
|
InitDrawDefaults( dctx->vtable );
|
|
|
|
#else
|
|
|
|
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_boardBegin, gtk );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawCell, gtk );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_invertCell, gtk );
|
2006-11-05 17:54:18 +01:00
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_objFinished, gtk );
|
2007-01-21 23:59:29 +01:00
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_vertScrollBoard, gtk );
|
2003-11-01 06:35:29 +01:00
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_trayBegin, gtk );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawTile, gtk );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawTileBack, gtk );
|
2008-03-09 00:16:21 +01:00
|
|
|
#ifdef POINTER_SUPPORT
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawTileMidDrag, gtk );
|
|
|
|
#endif
|
2003-11-01 06:35:29 +01:00
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawTrayDivider, gtk );
|
|
|
|
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawBoardArrow, gtk );
|
|
|
|
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_scoreBegin, gtk );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_measureRemText, gtk );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawRemText, gtk );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_measureScoreText, gtk );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_score_drawPlayer, gtk );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_score_pendingScore, gtk );
|
|
|
|
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawTimer, gtk );
|
|
|
|
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_getMiniWText, gtk );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_measureMiniWText, gtk );
|
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_drawMiniWindow, gtk );
|
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_destroyCtxt, gtk );
|
2008-09-05 14:11:37 +02:00
|
|
|
SET_VTABLE_ENTRY( dctx->vtable, draw_dictChanged, gtk );
|
2003-11-01 06:35:29 +01:00
|
|
|
#endif
|
|
|
|
|
2007-10-23 05:08:47 +02:00
|
|
|
dctx->pangoContext = gtk_widget_get_pango_context( drawing_area );
|
2005-05-29 22:32:48 +02:00
|
|
|
dctx->drawing_area = drawing_area;
|
2003-11-01 06:35:29 +01:00
|
|
|
dctx->globals = globals;
|
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
map = gdk_colormap_get_system();
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
allocAndSet( map, &dctx->black, 0x0000, 0x0000, 0x0000 );
|
|
|
|
allocAndSet( map, &dctx->white, 0xFFFF, 0xFFFF, 0xFFFF );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
{
|
|
|
|
GdkWindow *window = NULL;
|
|
|
|
if ( GTK_WIDGET_FLAGS(GTK_WIDGET(drawing_area)) & GTK_NO_WINDOW ) {
|
|
|
|
/* XXX I'm not sure about this function because I never used it.
|
|
|
|
* (the name seems to indicate what you want though).
|
|
|
|
*/
|
|
|
|
window = gtk_widget_get_parent_window( GTK_WIDGET(drawing_area) );
|
|
|
|
} else {
|
|
|
|
window = GTK_WIDGET(drawing_area)->window;
|
|
|
|
}
|
|
|
|
dctx->drawGC = gdk_gc_new( window );
|
2003-11-01 06:35:29 +01:00
|
|
|
}
|
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
map = gdk_colormap_get_system();
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
allocAndSet( map, &dctx->black, 0x0000, 0x0000, 0x0000 );
|
|
|
|
allocAndSet( map, &dctx->white, 0xFFFF, 0xFFFF, 0xFFFF );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
allocAndSet( map, &dctx->bonusColors[0], 0xFFFF, 0xAFFF, 0xAFFF );
|
|
|
|
allocAndSet( map, &dctx->bonusColors[1], 0xAFFF, 0xFFFF, 0xAFFF );
|
|
|
|
allocAndSet( map, &dctx->bonusColors[2], 0xAFFF, 0xAFFF, 0xFFFF );
|
|
|
|
allocAndSet( map, &dctx->bonusColors[3], 0xFFFF, 0xAFFF, 0xFFFF );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
allocAndSet( map, &dctx->playerColors[0], 0x0000, 0x0000, 0xAFFF );
|
|
|
|
allocAndSet( map, &dctx->playerColors[1], 0xAFFF, 0x0000, 0x0000 );
|
|
|
|
allocAndSet( map, &dctx->playerColors[2], 0x0000, 0xAFFF, 0x0000 );
|
|
|
|
allocAndSet( map, &dctx->playerColors[3], 0xAFFF, 0x0000, 0xAFFF );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
2005-05-29 22:32:48 +02:00
|
|
|
allocAndSet( map, &dctx->tileBack, 0xFFFF, 0xFFFF, 0x9999 );
|
2008-11-22 17:37:58 +01:00
|
|
|
allocAndSet( map, &dctx->cursor, 253<<8, 12<<8, 222<<8 );
|
2005-05-29 22:32:48 +02:00
|
|
|
allocAndSet( map, &dctx->red, 0xFFFF, 0x0000, 0x0000 );
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
return (DrawCtx*)dctx;
|
2005-05-29 22:32:48 +02:00
|
|
|
} /* gtkDrawCtxtMake */
|
2003-11-01 06:35:29 +01:00
|
|
|
|
|
|
|
#endif /* PLATFORM_GTK */
|
|
|
|
|