1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
|
/* interface.c - GFingerPoken Graphics Routines (some)
* Copyright 1999-2000 Martin Hock
*
* This file is part of Gfingerpoken.
*
* Gfingerpoken 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 3 of the License, or
* (at your option) any later version.
*
* Gfingerpoken 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, see <http://www.gnu.org/licenses/>.
*/
#include "gfp.h"
#include "common.h"
#include "graphics.h"
/* Drawing routines - GTK specific */
void borderdraw() {
int xcounter, pmloc, ycounter=0;
arrinused[arrhistptr]=0; arroutused[arrhistptr]=0;
for (; ycounter < gridy+2; ycounter++) {
for (xcounter = 0; xcounter < gridx+2; xcounter++) {
pmloc = 0;
if (ycounter == 0) pmloc = 1;
if (ycounter == gridy+1) pmloc = 2;
if (xcounter == 0) pmloc += 3;
if (xcounter == gridx+1) pmloc += 6;
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
borderpix, (pmloc-1)*pixwidth, 0, xcounter*pixwidth, ycounter*pixheight,
pixwidth, pixheight);
if (xcounter == 0 && ycounter != 0 && ycounter != gridy+1) xcounter += gridx; /* Kludge City */
}
}
}
void borderrefresh() {
gdk_draw_pixmap(leveldraw->window, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
levelpixmap, pixwidth, 0, pixwidth, 0, pixwidth*gridx, pixheight); /* Top */
gdk_draw_pixmap(leveldraw->window, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
levelpixmap, 0, pixheight, 0, pixheight, pixwidth, pixheight*gridy); /* Left */
gdk_draw_pixmap(leveldraw->window, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
levelpixmap, pixwidth, (gridy+1)*pixheight, pixwidth, (gridy+1)*pixheight,
pixwidth*gridx, pixheight); /* Bottom */
gdk_draw_pixmap(leveldraw->window, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
levelpixmap, pixwidth*(gridx+1), pixheight, pixwidth*(gridx+1), pixheight,
pixwidth, pixheight*gridy); /* Right */
}
void histdraw(unsigned int item, unsigned char drawmarble, GdkPixmap *ptarrowpix[], GdkBitmap *ptarrowmask[]) { /* Draw a history item */
if (checked) return;
if (arrinused[item]) {
gdk_gc_set_clip_mask(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)], marblemask);
switch (arrindir[item]) { /* First, the in arrows/ballhalves */
case DUp: /* As long as I have to do special cases, may as well do the arrows too */
if (drawmarble) {
gdk_gc_set_clip_origin(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
arrinx[item]*pixwidth, pixheight*(gridy+1)-pixheight/2);
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
marblepix, item*2*skipsize*pixwidth, pixheight/2,
arrinx[item]*pixwidth, pixheight*(gridy+1), pixwidth, pixheight/2);
}
gdk_gc_set_clip_origin(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
arrinx[item]*pixwidth, pixheight*(gridy+1));
gdk_gc_set_clip_mask(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)], ptarrowmask[DUp]);
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
ptarrowpix[DUp], 0, 0, arrinx[item]*pixwidth,
pixheight*(gridy+1), pixwidth, pixheight/2);
break;
case DDown:
gdk_gc_set_clip_origin(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
arrinx[item]*pixwidth, pixheight/2);
if (drawmarble)
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
marblepix, item*2*skipsize*pixwidth, 0, arrinx[item]*pixwidth,
pixheight/2, pixwidth, pixheight/2);
gdk_gc_set_clip_mask(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)], ptarrowmask[DDown]);
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
ptarrowpix[DDown], 0, 0, arrinx[item]*pixwidth,
pixheight/2, pixwidth, pixheight/2);
break;
case DLeft:
if (drawmarble) {
gdk_gc_set_clip_origin(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
pixwidth*(gridx+1)-pixwidth/2, arriny[item]*pixheight);
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
marblepix, item*2*skipsize*pixwidth+pixwidth/2, 0,
pixwidth*(gridx+1), arriny[item]*pixheight, pixwidth/2, pixheight);
}
gdk_gc_set_clip_origin(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
pixwidth*(gridx+1), arriny[item]*pixheight);
gdk_gc_set_clip_mask(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)], ptarrowmask[DLeft]);
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
ptarrowpix[DLeft], 0, 0, pixwidth*(gridx+1),
arriny[item]*pixheight, pixwidth/2, pixheight);
break;
case DRight:
gdk_gc_set_clip_origin(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
pixwidth/2, arriny[item]*pixheight);
if (drawmarble)
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
marblepix, item*2*skipsize*pixwidth, 0,
pixwidth/2, arriny[item]*pixheight, pixwidth/2, pixheight);
gdk_gc_set_clip_mask(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)], ptarrowmask[DRight]);
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
ptarrowpix[DRight], 0, 0, pixwidth/2,
arriny[item]*pixheight, pixwidth/2, pixheight);
break;
}
}
if (arroutused[item]) {
gdk_gc_set_clip_mask(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)], marblemask);
switch (arroutdir[item]) { /* Slightly modified in arrow routines */
case DUp:
gdk_gc_set_clip_origin(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
arroutx[item]*pixwidth, 0);
if (drawmarble)
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
marblepix, item*2*skipsize*pixwidth, 0, arroutx[item]*pixwidth,
0, pixwidth, pixheight/2);
gdk_gc_set_clip_mask(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)], ptarrowmask[DUp]);
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
ptarrowpix[DUp], 0, 0, arroutx[item]*pixwidth,
0, pixwidth, pixheight/2);
break;
case DDown:
if (drawmarble) {
gdk_gc_set_clip_origin(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
arroutx[item]*pixwidth, pixheight*(gridy+1));
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
marblepix, item*2*skipsize*pixwidth, pixheight/2,
arroutx[item]*pixwidth, pixheight*(gridy+1)+pixheight/2, pixwidth, pixheight/2);
}
gdk_gc_set_clip_origin(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
arroutx[item]*pixwidth, pixheight*(gridy+1)+pixheight/2);
gdk_gc_set_clip_mask(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)], ptarrowmask[DDown]);
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
ptarrowpix[DDown], 0, 0, arroutx[item]*pixwidth,
pixheight*(gridy+1)+pixheight/2, pixwidth, pixheight/2);
break;
case DLeft:
gdk_gc_set_clip_origin(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
0, arrouty[item]*pixheight);
if (drawmarble)
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
marblepix, item*2*skipsize*pixwidth, 0,
0, arrouty[item]*pixheight, pixwidth/2, pixheight);
gdk_gc_set_clip_mask(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)], ptarrowmask[DLeft]);
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
ptarrowpix[DLeft], 0, 0, 0,
arrouty[item]*pixheight, pixwidth/2, pixheight);
break;
case DRight:
if (drawmarble) {
gdk_gc_set_clip_origin(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
pixwidth*(gridx+1), arrouty[item]*pixheight);
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
marblepix, item*2*skipsize*pixwidth+pixwidth/2, 0,
pixwidth*(gridx+1)+pixwidth/2, arrouty[item]*pixheight, pixwidth/2, pixheight);
}
gdk_gc_set_clip_origin(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
pixwidth*(gridx+1)+pixwidth/2, arrouty[item]*pixheight);
gdk_gc_set_clip_mask(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)], ptarrowmask[DRight]);
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
ptarrowpix[DRight], 0, 0, pixwidth*(gridx+1)+pixwidth/2,
arrouty[item]*pixheight, pixwidth/2, pixheight);
break;
}
}
gdk_gc_set_clip_mask(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)], NULL);
}
void bardraw() { /* This is ONLY used to create a new toolbar, which is frequent */
int interiorcounter, vref = 0, objcounter = 0;
gint colordepth;
if (toolpixmap) {
gdk_pixmap_unref(toolpixmap);
toolpixmap = NULL;
}
if (!bufsize) {
gdk_window_clear(tooldraw->window);
gtk_widget_show(mainbarbut[ICheck]);
return;
}
gtk_widget_hide(mainbarbut[ICheck]);
colordepth = gdk_window_get_visual(tooldraw->window)->depth;
toolpixmap = gdk_pixmap_new(tooldraw->window, pixwidth, pixheight*bufsize, colordepth);
gtk_drawing_area_size(GTK_DRAWING_AREA(tooldraw), pixwidth, pixheight*bufsize);
for (; objcounter < DrNum; objcounter++)
for (interiorcounter = dragbuf[objcounter]; interiorcounter > 0; interiorcounter--)
gdk_draw_pixmap(toolpixmap, tooldraw->style->fg_gc[GTK_WIDGET_STATE(tooldraw)],
tilepic[drtoobj(objcounter)], 0, 0, 0, vref++*pixheight,
pixwidth, pixheight);
gdk_window_clear(tooldraw->window);
gdk_draw_pixmap(tooldraw->window, tooldraw->style->fg_gc[GTK_WIDGET_STATE(tooldraw)],
toolpixmap, 0, 0, 0, 0, pixwidth, pixheight*bufsize);
/* And now for a horrible refresh hack that works OK */
GTK_WIDGET_UNSET_FLAGS(GTK_SCROLLED_WINDOW(toolscroll)->vscrollbar, GTK_VISIBLE);
gtk_widget_show(GTK_SCROLLED_WINDOW(toolscroll)->vscrollbar);
}
void fullgriddraw() { /* This is ONLY used to create a new grid */
int ycounter=0, xcounter, pmloc;
gint colordepth;
if (levelpixmap) gdk_pixmap_unref(levelpixmap);
colordepth = gdk_window_get_visual(tooldraw->window)->depth;
levelpixmap = gdk_pixmap_new(mainwin->window, pixwidth*(gridx+2), pixheight*(gridy+2), colordepth);
gtk_drawing_area_size(GTK_DRAWING_AREA(leveldraw), pixwidth*(gridx+2), pixheight*(gridy+2));
for (; ycounter < gridy+2; ycounter++) {
for (xcounter = 0; xcounter < gridx+2; xcounter++) {
pmloc = 0;
if (ycounter == 0) pmloc = 1;
if (ycounter == gridy+1) pmloc = 2;
if (xcounter == 0) pmloc += 3;
if (xcounter == gridx+1) pmloc += 6;
if (pmloc)
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
borderpix, (pmloc-1)*pixwidth, 0, xcounter*pixwidth, ycounter*pixheight,
pixwidth, pixheight);
else
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
tilepic[grid[(xcounter-1)+(ycounter-1)*gridx]], 0, 0, xcounter*pixwidth,
ycounter*pixheight, pixwidth, pixheight);
}
}
gdk_draw_pixmap(leveldraw->window, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
levelpixmap, 0, 0, 0, 0, pixwidth*(gridx+2), pixheight*(gridy+2));
vdeltabuf = gdk_pixmap_new(leveldraw->window, pixwidth, pixheight+frameskip, colordepth);
hdeltabuf = gdk_pixmap_new(leveldraw->window, pixwidth+frameskip, pixheight, colordepth);
}
void drawtile(int x, int y) {
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
tilepic[grid[x+y*gridx]], 0, 0,
(x+1)*pixwidth, (y+1)*pixheight, pixwidth, pixheight);
if (markgrid[x+y*gridx]) {
gdk_gc_set_clip_mask(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)], markmask[markgrid[x+y*gridx]-1]);
gdk_gc_set_clip_origin(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
(x+1)*pixwidth, (y+1)*pixheight);
gdk_draw_pixmap(levelpixmap, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
markpix[markgrid[x+y*gridx]-1], 0, 0,
(x+1)*pixwidth, (y+1)*pixheight, pixwidth, pixheight);
gdk_gc_set_clip_mask(leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)], NULL);
}
gdk_draw_pixmap(leveldraw->window, leveldraw->style->fg_gc[GTK_WIDGET_STATE(leveldraw)],
levelpixmap, (x+1)*pixwidth, (y+1)*pixheight, (x+1)*pixwidth,
(y+1)*pixheight, pixwidth, pixheight);
}
void resizelevel() {
toolscroll->allocation.width = 0;
toolscroll->allocation.height = 0;
levelscroll->allocation.width = 0;
levelscroll->allocation.height = 0;
gtk_widget_set_usize(toolscroll, pixwidth +
GTK_SCROLLED_WINDOW(toolscroll)->vscrollbar->allocation.width+7,
levelscroll->allocation.height);
gtk_widget_set_usize(levelscroll, pixwidth*(gridx+2) +
GTK_SCROLLED_WINDOW(levelscroll)->vscrollbar->allocation.width+7,
pixheight*(gridy+2) +
GTK_SCROLLED_WINDOW(levelscroll)->hscrollbar->allocation.height+7);
}
|