SwitchWindow (int main)
{
currBoard = (main ? &mainOptions[W_BOARD] : &dualOptions[3]);
- csBoardWindow = DRAWABLE(currBoard);
+// CsBoardWindow = DRAWABLE(currBoard);
}
+
+static void
+NewCanvas (Option *graph)
+{
+ cairo_t *cr;
+ int w = graph->max, h = graph->value;
+ if(graph->choice) cairo_surface_destroy((cairo_surface_t *) graph->choice);
+ graph->choice = (char**) cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
+ // paint white, to prevent weirdness when people maximize window and drag pieces over space next to board
+ cr = cairo_create ((cairo_surface_t *) graph->choice);
+ cairo_rectangle (cr, 0, 0, w, h);
+ cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);
+ cairo_fill(cr);
+ cairo_destroy (cr);
+ graph->min &= ~REPLACE;
+}
+
+static cairo_surface_t *
+CsBoardWindow (Option *opt)
+{ // test before every draw event if we need to resize the canvas
+ if(opt->min & REPLACE) NewCanvas(opt);
+ return DRAWABLE(opt);
+}
+
+
void
SelectPieces(VariantClass v)
{
cairo_t *cr;
/* get a cairo_t */
- cr = cairo_create (csBoardWindow);
+ cr = cairo_create (CsBoardWindow(currBoard));
cairo_move_to (cr, x, y);
cairo_line_to(cr, xTo, yTo );
void DrawSeekBackground( int left, int top, int right, int bottom )
{
- cairo_t *cr = cairo_create (csBoardWindow);
+ cairo_t *cr = cairo_create (CsBoardWindow(currBoard));
cairo_rectangle (cr, left, top, right-left, bottom-top);
void DrawSeekText(char *buf, int x, int y)
{
- cairo_t *cr = cairo_create (csBoardWindow);
+ cairo_t *cr = cairo_create (CsBoardWindow(currBoard));
cairo_select_font_face (cr, "Sans",
CAIRO_FONT_SLANT_NORMAL,
void DrawSeekDot(int x, int y, int colorNr)
{
- cairo_t *cr = cairo_create (csBoardWindow);
+ cairo_t *cr = cairo_create (CsBoardWindow(currBoard));
int square = colorNr & 0x80;
colorNr &= 0x7F;
void
InitDrawingHandle (Option *opt)
{
- csBoardWindow = DRAWABLE(opt);
+// CsBoardWindow = DRAWABLE(opt);
+ currBoard = opt;
}
void
cairo_t *cr;
/* get a cairo_t */
- cr = cairo_create (csBoardWindow);
+ cr = cairo_create (CsBoardWindow(currBoard));
cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
SetPen(cr, lineGap, "#000000", 0);
case 2: col = appData.premoveHighlightColor; break;
default: col = "#808080"; break; // cannot happen
}
- cr = cairo_create(csBoardWindow);
+ cr = cairo_create(CsBoardWindow(currBoard));
cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
cairo_rectangle(cr, x+odd/2., y+odd/2., squareSize+lineGap, squareSize+lineGap);
SetPen(cr, lineGap, col, 0);
int w, h;
if(!opt) return;
- cr = cairo_create(DRAWABLE(opt));
+ cr = cairo_create(CsBoardWindow(opt));
cairo_rectangle (cr, 0, 0, opt->max, opt->value);
cairo_set_source_rgba(cr, 0.5, 0.5, 0.5, 1.0);
cairo_fill(cr); // paint background in case logo does not exist
void
DrawDot (int marker, int x, int y, int r)
{ // used for atomic captures; no need to draw on backup
- DoDrawDot(csBoardWindow, marker, x, y, r);
+ DoDrawDot(CsBoardWindow(currBoard), marker, x, y, r);
GraphExpose(currBoard, x-r, y-r, 2*r, 2*r);
}
cairo_text_extents_t te;
cairo_t *cr;
- cr = cairo_create (csBoardWindow);
+ cr = cairo_create (CsBoardWindow(currBoard));
cairo_select_font_face (cr, "Sans",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD);
// piece, background, coordinate/count, marker dot
if (piece == EmptySquare) {
- BlankSquare(csBoardWindow, x, y, square_color, piece, 1);
+ BlankSquare(CsBoardWindow(currBoard), x, y, square_color, piece, 1);
} else {
- pngDrawPiece(csBoardWindow, piece, square_color, x, y);
- if(appData.inscriptions[0]) InscribeKanji(csBoardWindow, piece, x, y);
+ pngDrawPiece(CsBoardWindow(currBoard), piece, square_color, x, y);
+ if(appData.inscriptions[0]) InscribeKanji(CsBoardWindow(currBoard), piece, x, y);
}
if(align) { // square carries inscription (coord or piece count)
}
if(marker) { // print fat marker dot, if requested
- DoDrawDot(csBoardWindow, marker, x + squareSize/4, y+squareSize/4, squareSize/2);
+ DoDrawDot(CsBoardWindow(currBoard), marker, x + squareSize/4, y+squareSize/4, squareSize/2);
}
}
{
if(c_animBufs[anr]) cairo_surface_destroy (c_animBufs[anr]);
if(c_animBufs[anr+2]) cairo_surface_destroy (c_animBufs[anr+2]);
- c_animBufs[anr+4] = csBoardWindow;
+ c_animBufs[anr+4] = CsBoardWindow(currBoard);
c_animBufs[anr+2] = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, squareSize, squareSize);
c_animBufs[anr] = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, squareSize, squareSize);
}
int srcX, int srcY, int width, int height, int destX, int destY)
{
cairo_t *cr;
- c_animBufs[anr+4] = csBoardWindow;
+ c_animBufs[anr+4] = CsBoardWindow(currBoard);
cr = cairo_create (c_animBufs[anr+destBuf]);
cairo_set_source_surface (cr, c_animBufs[anr+srcBuf], destX - srcX, destY - srcY);
cairo_rectangle (cr, destX, destY, width, height);
cairo_fill (cr);
cairo_destroy (cr);
- if(c_animBufs[anr+destBuf] == csBoardWindow) // suspect that GTK needs this!
+ if(c_animBufs[anr+destBuf] == CsBoardWindow(currBoard)) // suspect that GTK needs this!
GraphExpose(currBoard, destX, destY, width, height);
}
void
DrawPolygon (Pnt arrow[], int nr)
{
- DoDrawPolygon(csBoardWindow, arrow, nr);
+ DoDrawPolygon(CsBoardWindow(currBoard), arrow, nr);
// if(!dual) DoDrawPolygon(csBoardBackup, arrow, nr);
}
static int curX, curY;
if(penType != PEN_NONE) {
- cairo_t *cr = cairo_create(DRAWABLE(disp));
+ cairo_t *cr = cairo_create(CsBoardWindow(disp));
cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
cairo_move_to (cr, curX, curY);
cairo_line_to (cr, x,y);
{
cairo_t *cr;
- cr = cairo_create (DRAWABLE(disp));
+ cr = cairo_create (CsBoardWindow(disp));
cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
cairo_rectangle (cr, left, top, right-left, bottom-top);
switch(side)
{
// the magic constants 8 and 5 should really be derived from the font size somehow
cairo_text_extents_t extents;
- cairo_t *cr = cairo_create(DRAWABLE(disp));
+ cairo_t *cr = cairo_create(CsBoardWindow(disp));
/* GTK-TODO this has to go into the font-selection */
cairo_select_font_face (cr, "Sans",
#endif
static void
+ExposeDraw (Option *graph, GdkEventExpose *eevent)
+{
+ int w = eevent->area.width;
+ cairo_t *cr;
+ if(eevent->area.x + w > graph->max) w--; // cut off fudge pixel
+ cr = gdk_cairo_create(((GtkWidget *) (graph->handle))->window);
+ cairo_set_source_surface(cr, (cairo_surface_t *) graph->choice, 0, 0);
+//cairo_set_source_rgb(cr, 1, 0, 0);
+ cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
+ cairo_rectangle(cr, eevent->area.x, eevent->area.y, w, eevent->area.height);
+ cairo_fill(cr);
+ cairo_destroy(cr);
+}
+
+static void
GraphEventProc(GtkWidget *widget, GdkEvent *event, gpointer gdata)
{ // handle expose and mouse events on Graph widget
int w, h;
GdkEventMotion *mevent = (GdkEventMotion *) event;
GdkEventScroll *sevent = (GdkEventScroll *) event;
GtkAllocation a;
- cairo_t *cr;
// if (!XtIsRealized(widget)) return;
// to give drawing routines opportunity to use it before first expose event
// (which are only processed when main gets to the event loop, so after all init!)
// so only change when size is no longer good
- cairo_t *cr;
- if(graph->choice) cairo_surface_destroy((cairo_surface_t *) graph->choice);
- graph->choice = (char**) cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
- // paint white, to prevent weirdness when people maximize window and drag pieces over space next to board
- cr = cairo_create ((cairo_surface_t *) graph->choice);
- cairo_rectangle (cr, 0, 0, w, h);
- cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);
- cairo_fill(cr);
- cairo_destroy (cr);
+// NewCanvas(graph);
+ graph->min |= REPLACE; // defer making new canvas
break;
}
- w = eevent->area.width;
- if(eevent->area.x + w > graph->max) w--; // cut off fudge pixel
- cr = gdk_cairo_create(((GtkWidget *) (graph->handle))->window);
- cairo_set_source_surface(cr, (cairo_surface_t *) graph->choice, 0, 0);
-//cairo_set_source_rgb(cr, 1, 0, 0);
- cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
- cairo_rectangle(cr, eevent->area.x, eevent->area.y, w, eevent->area.height);
- cairo_fill(cr);
- cairo_destroy(cr);
+ ExposeDraw(graph, eevent);
default:
return;
case GDK_SCROLL:
GdkEventExpose e;
if(!opt->handle) return;
e.area.x = x; e.area.y = y; e.area.width = w; e.area.height = h; e.count = -1; e.type = GDK_EXPOSE; // count = -1: kludge to suppress sizing
- GraphEventProc(opt->handle, (GdkEvent *) &e, (gpointer) opt); // fake expose event
+ ExposeDraw(opt, &e); // fake expose event
}
void GenericCallback(GtkWidget *widget, gpointer gdata)
label = frame;
}
gtk_widget_set_size_request(label, option[i].max ? option[i].max : -1, -1);
- if(option[i].target || dlgNr != ErrorDlg && option[i].name && !strchr(option[i].name, '\n')) { // allow user to specify event handler for button presses
+ if(option[i].target || dlgNr != ErrorDlg && option[i].name) { // allow user to specify event handler for button presses
button = gtk_event_box_new();
gtk_container_add(GTK_CONTAINER(button), label);
label = button;