00001
00002
00003
00004
00005
00006 #include "lcconfig.h"
00007 #include <stdio.h>
00008 #include <stdlib.h>
00009 #include <sys/types.h>
00010 #include "lcstring.h"
00011 #ifdef LC_X11
00012 #include <X11/Xlib.h>
00013 #include <X11/Xatom.h>
00014 #include <X11/Xutil.h>
00015 #include "xpicedit.h"
00016 #elif defined (SVGALIB)
00017 #include <vga.h>
00018 #include <vgagl.h>
00019 #include <vgamouse.h>
00020 #endif
00021
00022 #define LIBDIR DEFAULT_LIBDIR
00023
00024 #ifdef __EMX__
00025 #include <X11/Xlibint.h>
00026 #define chown(x,y,z)
00027 #ifdef LIBDIR
00028 #undef LIBDIR
00029 #endif
00030 char LIBDIR[256];
00031 #define OS2_DEFAULT_LIBDIR "/XFree86/lib/X11/lincity"
00032 #endif
00033
00034 #define COLOUR_PAL_FILE "/colour.pal"
00035 #define FONTFILE "/opening/iso8859-1-8x8.raw"
00036
00037 #define WINSTARTX 240
00038 #define WINSTARTY ((14*16)-1)
00039 #define SWINSTARTX 56
00040 #define SWINSTARTY 260
00041 #define MAXIMAGESIZE 4
00042
00043 #define SIZEBUTTONX1x1 540
00044 #define SIZEBUTTONY1x1 260
00045 #define SIZEBUTTONX2x2 540
00046 #define SIZEBUTTONY2x2 276
00047 #define SIZEBUTTONX3x3 540
00048 #define SIZEBUTTONY3x3 292
00049 #define SIZEBUTTONX4x4 540
00050 #define SIZEBUTTONY4x4 308
00051 #define SIZEBUTTONSIZEX 32
00052 #define SIZEBUTTONSIZEY 16
00053
00054 #define FOCUSWINX 40
00055 #define FOCUSWINY 360
00056
00057 #define FOCUSWINSIZE 56
00058
00059 #define ZOOMBUTX 540
00060 #define ZOOMBUTY 390
00061 #define ZOOMBUTSIZEX 40
00062 #define ZOOMBUTSIZEY 16
00063
00064 #define HALFBUTX 540
00065 #define HALFBUTY 370
00066 #define HALFBUTSIZEX 40
00067 #define HALFBUTSIZEY 16
00068
00069 #define NORMBUTX 540
00070 #define NORMBUTY 350
00071 #define NORMBUTSIZEX 40
00072 #define NORMBUTSIZEY 16
00073
00074 #define DOTBUTX 150
00075 #define DOTBUTY 350
00076 #define DOTBUTSIZEX 40
00077 #define DOTBUTSIZEY 16
00078
00079 #define HFILBUTX 150
00080 #define HFILBUTY 370
00081 #define HFILBUTSIZEX 40
00082 #define HFILBUTSIZEY 16
00083
00084 #define VFILBUTX 150
00085 #define VFILBUTY 390
00086 #define VFILBUTSIZEX 40
00087 #define VFILBUTSIZEY 16
00088
00089 #define red(x) (32 + x)
00090 #define green(x) (64 + x)
00091 #define yellow(x) (96 + x)
00092 #define blue(x) (128 + x)
00093 #define magenta(x) (160 + x)
00094 #define cyan(x) (192 + x)
00095 #define white(x) (224 + x)
00096
00097 #define FOCUSWINCOLOUR green(30)
00098 #define UNFOCUSWINCOLOUR magenta(20)
00099 #define XFOCUSWINCOLOUR red(15)
00100
00101 unsigned char mouse_pointer[] =
00102 {
00103 255, 255, 255, 255, 1, 1, 1, 1,
00104 255, 1, 1, 1, 255, 255, 1, 1,
00105 255, 1, 255, 255, 255, 1, 255, 1,
00106 255, 1, 255, 1, 1, 255, 1, 1,
00107 1, 255, 255, 1, 1, 1, 255, 1,
00108 1, 255, 1, 255, 1, 1, 1, 1,
00109 1, 1, 255, 1, 255, 1, 1, 1,
00110 1, 1, 1, 1, 1, 1, 1};
00111
00112 unsigned char under_mouse_pointer[8 * 8], last16[16];
00113 unsigned char image[16 * MAXIMAGESIZE][16 * MAXIMAGESIZE];
00114 char imagefile[100];
00115
00116 int colour = 0, mx, my, mox, moy, zoom_flag = 1, hfill_flag = 0, vfill_flag = 0;
00117 int imagesize, newimagesize, focus, focusx, focusy;
00118 int old_focusx = 0, old_focusy = 0, stopflag, lc_mouse_type;
00119
00120 void do_buttons (int, int);
00121 void draw_dot (void);
00122 void draw_hfill (void);
00123 void draw_vfill (void);
00124 void full_zoom (void);
00125 void half_zoom (void);
00126 void norm_zoom (void);
00127 void do_error (char *);
00128 void choose_colour (int, int);
00129 void fill_colour (int, int);
00130 void hfill (int, int);
00131 void vfill (int, int);
00132 void fill_colourzoom (int, int);
00133 void fill_colour1 (int, int);
00134 void fill_colour2 (int, int);
00135 void fill_colour3 (int, int);
00136 void fill_colour4 (int, int);
00137 void setcustompalette (void);
00138 void initfont (void);
00139 void save_image (void);
00140 void load_image (void);
00141 void setup (void);
00142 void draw_focus (void);
00143 void draw_swin (void);
00144 void draw_big_image (void);
00145 void draw_big_imagezoom (void);
00146 void draw_big_image1 (void);
00147 void draw_big_image2 (void);
00148 void draw_big_image3 (void);
00149 void draw_big_image4 (void);
00150 void change_imagesize (int);
00151 void change_focus (int, int);
00152 void hide_mouse (void);
00153 void reshow_mouse (void);
00154
00155 #ifdef LC_X11
00156
00157 void Fgl_hline (int, int, int, int);
00158 void Fgl_line (int, int, int, int, int);
00159 void Fgl_setpixel (int, int, int);
00160 int Fgl_getpixel (int, int);
00161 void Fgl_write (int, int, char *);
00162 void Fgl_fillbox (int, int, int, int, int);
00163 void Fgl_putbox (int, int, int, int, unsigned char *);
00164 void Fgl_getbox (int, int, int, int, unsigned char *);
00165
00166 #else
00167
00168 void lincityrc ();
00169
00170 #define Fgl_setpixel(a,b,c) gl_setpixel(a,b,c)
00171 #define Fgl_getpixel(a,b) gl_getpixel(a,b)
00172 #define Fgl_hline(a,b,c,d) gl_hline(a,b,c,d)
00173 #define Fgl_line(a,b,c,d,e) gl_line(a,b,c,d,e)
00174 #define Fgl_write(a,b,c) gl_write(a,b,c)
00175 #define Fgl_fillbox(a,b,c,d,e) gl_fillbox(a,b,c,d,e)
00176 #define Fgl_putbox(a,b,c,d,e) gl_putbox(a,b,c,d,e)
00177 #define Fgl_getbox(a,b,c,d,e) gl_getbox(a,b,c,d,e)
00178
00179 #endif
00180
00181 #ifdef LC_X11
00182
00183 int winX, winY, mouse_button;
00184 unsigned int winW, winH;
00185 disp display;
00186
00187 char *bg_color = NULL;
00188 char pixmap[(640 + BORDERX * 2) * (480 + BORDERY * 2)];
00189 char myfont[256 * 8];
00190 int verbose = FALSE;
00191 int text_bg = 0;
00192 int text_fg = 255;
00193 int borderx, bordery;
00194 long unsigned int colour_table[256];
00195
00196 void parse_args (int, char **, char **);
00197 void Create_Window (char *);
00198 void HandleError (char *, int);
00199 void HandleEvent (XEvent *);
00200 void refresh_screen (int, int, int, int);
00201 void my_x_putchar (int, int, int);
00202
00203 #endif
00204 int
00205 main (int argc, char *argv[])
00206 {
00207 int x, y, c, m, ox, oy;
00208 #ifdef LC_X11
00209 XEvent xev;
00210 char *geometry = NULL;
00211 #endif
00212 c = 0;
00213 stopflag = 0;
00214 newimagesize = 1;
00215
00216 #ifdef __EMX__
00217 strcpy(LIBDIR, __XOS2RedirRoot(OS2_DEFAULT_LIBDIR));
00218 #endif
00219
00220 #ifdef LC_X11
00221 borderx = BORDERX;
00222 bordery = BORDERY;
00223 parse_args (argc, argv, &geometry);
00224 printf ("Got past parse args\n");
00225 Create_Window (geometry);
00226 XSync (display.dpy, FALSE);
00227
00228 while (XPending (display.dpy) == 0);
00229 XNextEvent (display.dpy, &xev);
00230 HandleEvent (&xev);
00231
00232 printf ("Got past create window\n");
00233 #else
00234 lincityrc ();
00235 vga_init ();
00236 vga_setmode (G640x480x256);
00237 gl_setcontextvga (G640x480x256);
00238 #endif
00239
00240 setcustompalette ();
00241 initfont ();
00242 if (argc < 2)
00243 strcpy (imagefile, "imagefile.default");
00244 else
00245 {
00246 strcpy (imagefile, argv[1]);
00247 load_image ();
00248 }
00249 #ifndef LC_X11
00250 m = mouse_init ("/dev/mouse", lc_mouse_type, MOUSE_DEFAULTSAMPLERATE);
00251 mouse_setxrange (0, 640 - 1);
00252 mouse_setyrange (0, 480 - 1);
00253 mouse_setwrap (MOUSE_NOWRAP);
00254 #endif
00255 setup ();
00256 #ifdef LC_X11
00257 XSync (display.dpy, FALSE);
00258 #endif
00259 printf ("Got past setup\n");
00260 if (newimagesize != imagesize)
00261 change_imagesize (newimagesize);
00262 change_focus (0, 0);
00263 printf ("Got to do loop\n");
00264 do
00265 {
00266 #ifdef LC_X11
00267 if (XPending (display.dpy))
00268 {
00269 XNextEvent (display.dpy, &xev);
00270 HandleEvent (&xev);
00271 }
00272 if (mouse_button != 0)
00273 do_buttons (0, 0);
00274 #else
00275 c = vga_getkey ();
00276 mouse_waitforupdate ();
00277 mx = mouse_getx ();
00278 my = mouse_gety ();
00279 if (mx != mox || my != moy)
00280 {
00281 Fgl_putbox (mox, moy, 8, 8, under_mouse_pointer);
00282 Fgl_getbox (mx, my, 8, 8, under_mouse_pointer);
00283 Fgl_putbox (mx, my, 8, 8, mouse_pointer);
00284 mox = mx;
00285 moy = my;
00286 }
00287 do_buttons (mx, my);
00288 #endif
00289 }
00290 while (c == 0 && stopflag == 0);
00291 printf ("Normal exit\n");
00292 #ifndef LC_X11
00293 mouse_close ();
00294 vga_setmode (TEXT);
00295 printf ("c=%d mouse %d\n", c, m);
00296 #endif
00297 save_image ();
00298 exit (0);
00299 }
00300
00301 void
00302 do_error (char *s)
00303 {
00304 #ifdef LC_X11
00305 HandleError (s, FATAL);
00306 #else
00307 vga_setmode (TEXT);
00308 printf ("%s\n", s);
00309 exit (1);
00310 #endif
00311 }
00312
00313 void
00314 do_buttons (int x, int y)
00315 {
00316 int b, left = 0, right = 0;
00317 #ifdef LC_X11
00318 int dummy_int;
00319 Window dummy_win;
00320 if (mouse_button == Button1)
00321 left = 1;
00322 else if (mouse_button == Button3)
00323 right = 1;
00324 XQueryPointer (display.dpy, display.win, &dummy_win, &dummy_win
00325 ,&dummy_int, &dummy_int, &x, &y, (unsigned int *) &dummy_int);
00326 x -= borderx;
00327 y -= bordery;
00328 #else
00329 b = mouse_getbutton ();
00330 left = b & MOUSE_LEFTBUTTON;
00331 right = b & MOUSE_RIGHTBUTTON;
00332 #endif
00333 if (right != 0 && x < 560)
00334 choose_colour (x, y);
00335 if (left != 0)
00336 {
00337 if (y < 16 * 14 - 2)
00338 choose_colour (x, y);
00339 else if (x < WINSTARTX + 256 && x >= WINSTARTX
00340 && y < WINSTARTY + 256 && y > WINSTARTY)
00341 fill_colour (x, y);
00342 else if (x > SIZEBUTTONX1x1
00343 && x < SIZEBUTTONX1x1 + SIZEBUTTONSIZEX
00344 && y > SIZEBUTTONY1x1
00345 && y < SIZEBUTTONY1x1 + SIZEBUTTONSIZEY
00346 && imagesize != 1)
00347 change_imagesize (1);
00348 else if (x > SIZEBUTTONX2x2
00349 && x < SIZEBUTTONX2x2 + SIZEBUTTONSIZEX
00350 && y > SIZEBUTTONY2x2
00351 && y < SIZEBUTTONY2x2 + SIZEBUTTONSIZEY
00352 && imagesize != 2)
00353 change_imagesize (2);
00354 else if (x > SIZEBUTTONX3x3
00355 && x < SIZEBUTTONX3x3 + SIZEBUTTONSIZEX
00356 && y > SIZEBUTTONY3x3
00357 && y < SIZEBUTTONY3x3 + SIZEBUTTONSIZEY
00358 && imagesize != 3)
00359 change_imagesize (3);
00360 else if (x > SIZEBUTTONX4x4
00361 && x < SIZEBUTTONX4x4 + SIZEBUTTONSIZEX
00362 && y > SIZEBUTTONY4x4
00363 && y < SIZEBUTTONY4x4 + SIZEBUTTONSIZEY
00364 && imagesize != 4)
00365 change_imagesize (4);
00366 else if (x > FOCUSWINX && x < FOCUSWINX + FOCUSWINSIZE
00367 && y > FOCUSWINY && FOCUSWINY + FOCUSWINSIZE
00368 && zoom_flag == 1)
00369 change_focus ((x - FOCUSWINX) / (FOCUSWINSIZE / 4)
00370 ,(y - FOCUSWINY) / (FOCUSWINSIZE / 4));
00371 else if (x > ZOOMBUTX && x < ZOOMBUTX + ZOOMBUTSIZEX
00372 && y > ZOOMBUTY && y < ZOOMBUTY + ZOOMBUTSIZEY)
00373 full_zoom ();
00374 else if (x > HALFBUTX && x < HALFBUTX + HALFBUTSIZEX
00375 && y > HALFBUTY && y < HALFBUTY + HALFBUTSIZEY)
00376 half_zoom ();
00377 else if (x > NORMBUTX && x < NORMBUTX + NORMBUTSIZEX
00378 && y > NORMBUTY && y < NORMBUTY + NORMBUTSIZEY)
00379 norm_zoom ();
00380 else if (x > DOTBUTX && x < DOTBUTX + DOTBUTSIZEX
00381 && y > DOTBUTY && y < DOTBUTY + DOTBUTSIZEY)
00382 draw_dot ();
00383 else if (x > HFILBUTX && x < HFILBUTX + HFILBUTSIZEX
00384 && y > HFILBUTY && y < HFILBUTY + HFILBUTSIZEY)
00385 draw_hfill ();
00386 else if (x > VFILBUTX && x < VFILBUTX + VFILBUTSIZEX
00387 && y > VFILBUTY && y < VFILBUTY + VFILBUTSIZEY)
00388 draw_vfill ();
00389 }
00390 }
00391
00392 void
00393 draw_dot (void)
00394 {
00395 Fgl_write (DOTBUTX - 10, DOTBUTY + 3, ">");
00396 Fgl_write (HFILBUTX - 10, HFILBUTY + 3, " ");
00397 Fgl_write (VFILBUTX - 10, VFILBUTY + 3, " ");
00398 hfill_flag = 0;
00399 vfill_flag = 0;
00400 }
00401
00402 void
00403 draw_hfill (void)
00404 {
00405 Fgl_write (DOTBUTX - 10, DOTBUTY + 3, " ");
00406 Fgl_write (HFILBUTX - 10, HFILBUTY + 3, ">");
00407 Fgl_write (VFILBUTX - 10, VFILBUTY + 3, " ");
00408 hfill_flag = 1;
00409 vfill_flag = 0;
00410 }
00411
00412 void
00413 draw_vfill (void)
00414 {
00415 Fgl_write (DOTBUTX - 10, DOTBUTY + 3, " ");
00416 Fgl_write (HFILBUTX - 10, HFILBUTY + 3, " ");
00417 Fgl_write (VFILBUTX - 10, VFILBUTY + 3, ">");
00418 vfill_flag = 1;
00419 hfill_flag = 0;
00420 }
00421
00422
00423 void
00424 full_zoom (void)
00425 {
00426 int y;
00427 if (zoom_flag == 0)
00428 return;
00429 Fgl_write (ZOOMBUTX - 10, ZOOMBUTY + 3, ">");
00430 Fgl_write (HALFBUTX - 10, HALFBUTY + 3, " ");
00431 Fgl_write (NORMBUTX - 10, NORMBUTY + 3, " ");
00432 if (imagesize == 3)
00433 {
00434 Fgl_fillbox (WINSTARTX - 1, WINSTARTY - 1
00435 ,258, 258, 0);
00436 Fgl_hline (WINSTARTX - 1, WINSTARTY - 1
00437 ,WINSTARTX + 240, 255);
00438 Fgl_hline (WINSTARTX - 1, WINSTARTY + 240
00439 ,WINSTARTX + 240, 255);
00440 Fgl_line (WINSTARTX - 1, WINSTARTY - 1, WINSTARTX - 1
00441 ,WINSTARTY + 240, 255);
00442 Fgl_line (WINSTARTX + 240, WINSTARTY - 1, WINSTARTX + 240
00443 ,WINSTARTY + 240, 255);
00444 }
00445 zoom_flag = 0;
00446 old_focusx = focusx;
00447 old_focusy = focusy;
00448 change_focus (0, 0);
00449
00450 draw_big_image ();
00451 }
00452
00453 void
00454 half_zoom (void)
00455 {
00456 int y;
00457 if (zoom_flag == 2 || imagesize < 2)
00458 return;
00459 zoom_flag = 2;
00460 Fgl_write (ZOOMBUTX - 10, ZOOMBUTY + 3, " ");
00461 Fgl_write (HALFBUTX - 10, HALFBUTY + 3, ">");
00462 Fgl_write (NORMBUTX - 10, NORMBUTY + 3, " ");
00463 if (zoom_flag != 0)
00464 {
00465 old_focusx = focusx;
00466 old_focusy = focusy;
00467 }
00468 if (focusx >= (imagesize - 1))
00469 focusx = imagesize - 2;
00470 if (focusy >= (imagesize - 1))
00471 focusy = imagesize - 2;
00472 change_focus (focusx, focusy);
00473 draw_big_image ();
00474 }
00475
00476
00477 void
00478 norm_zoom (void)
00479 {
00480 int y;
00481 if (zoom_flag == 1)
00482 return;
00483 Fgl_write (ZOOMBUTX - 10, ZOOMBUTY + 3, " ");
00484 Fgl_write (HALFBUTX - 10, HALFBUTY + 3, " ");
00485 Fgl_write (NORMBUTX - 10, NORMBUTY + 3, ">");
00486 Fgl_hline (WINSTARTX, WINSTARTY - 1, WINSTARTX + 256, 255);
00487 Fgl_hline (WINSTARTX, WINSTARTY + 256, WINSTARTX + 256, 255);
00488 Fgl_line (WINSTARTX - 1, WINSTARTY, WINSTARTX - 1, WINSTARTY + 256, 255);
00489 Fgl_line (WINSTARTX + 256, WINSTARTY
00490 ,WINSTARTX + 256, WINSTARTY + 256, 255);
00491 for (y = 0; y < 16; y++)
00492 {
00493 Fgl_hline (WINSTARTX, WINSTARTY + y * 16 + 15
00494 ,WINSTARTX + 255, 253);
00495 Fgl_line (WINSTARTX + y * 16 + 15, WINSTARTY, WINSTARTX + y * 16 + 15
00496 ,WINSTARTY + 255, 253);
00497 }
00498 zoom_flag = 1;
00499 change_focus (old_focusx, old_focusy);
00500 draw_big_image ();
00501 }
00502
00503 void
00504 choose_colour (int x, int y)
00505 {
00506 char s[100];
00507 int q, newcolour;
00508 newcolour = Fgl_getpixel (x - 1, y - 1);
00509 if (newcolour == colour)
00510 return;
00511 colour = newcolour;
00512 for (q = 15; q > 0; q--)
00513 last16[q] = last16[q - 1];
00514 last16[0] = colour;
00515 for (q = 0; q < 16; q++)
00516 {
00517 Fgl_fillbox (600, 14 * 16 + q * 16, 39, 15, (int) last16[q]);
00518 sprintf (s, "%d", (int) last16[q]);
00519 Fgl_write (600 + 3, 14 * 16 + q * 16 + 3, s);
00520 }
00521 }
00522
00523 void
00524 fill_colour (int x, int y)
00525 {
00526 if (hfill_flag != 0)
00527 hfill (x, y);
00528 else if (vfill_flag != 0)
00529 vfill (x, y);
00530 else if (zoom_flag == 1)
00531 fill_colourzoom (x, y);
00532 else if (zoom_flag == 2)
00533 fill_colour2 (x, y);
00534 else if (imagesize == 1)
00535 fill_colour1 (x, y);
00536 else if (imagesize == 2)
00537 fill_colour2 (x, y);
00538 else if (imagesize == 3)
00539 fill_colour3 (x, y);
00540 else if (imagesize == 4)
00541 fill_colour4 (x, y);
00542 }
00543
00544 void
00545 hfill (int x, int y)
00546 {
00547 int xx = 0, col, d;
00548 if (zoom_flag == 1)
00549 d = 16;
00550 else if (zoom_flag == 2)
00551 d = 8;
00552 else if (imagesize == 1)
00553 d = 16;
00554 else if (imagesize == 2)
00555 d = 8;
00556 else if (imagesize == 3)
00557 d = 5;
00558 else if (imagesize == 4)
00559 d = 4;
00560 col = image[((x - WINSTARTX) / d) + (focusx * 16)]
00561 [((y - (WINSTARTY)) / d) + (focusy * 16)];
00562
00563 while (((x - WINSTARTX) / d) + (focusx * 16) + xx < 16 * MAXIMAGESIZE
00564 && (image[((x - WINSTARTX) / d) + (focusx * 16) + xx]
00565 [((y - (WINSTARTY)) / d) + (focusy * 16)] == col))
00566 {
00567 image[((x - WINSTARTX) / d) + (focusx * 16) + xx]
00568 [((y - (WINSTARTY)) / d) + (focusy * 16)] = colour;
00569 xx++;
00570 }
00571 xx = -1;
00572 while (((x - WINSTARTX) / d) + (focusx * 16) + xx >= 0
00573 && (image[((x - WINSTARTX) / d) + (focusx * 16) + xx]
00574 [((y - (WINSTARTY)) / d) + (focusy * 16)] == col))
00575 {
00576 image[((x - WINSTARTX) / d) + (focusx * 16) + xx]
00577 [((y - (WINSTARTY)) / d) + (focusy * 16)] = colour;
00578 xx--;
00579 }
00580 Fgl_putbox (mox, moy, 8, 8, under_mouse_pointer);
00581 draw_swin ();
00582 draw_big_image ();
00583 Fgl_getbox (mx, my, 8, 8, under_mouse_pointer);
00584 Fgl_putbox (mx, my, 8, 8, mouse_pointer);
00585 }
00586
00587 void
00588 vfill (int x, int y)
00589 {
00590 int yy = 0, col, d;
00591 if (zoom_flag == 1)
00592 d = 16;
00593 else if (zoom_flag == 2)
00594 d = 8;
00595 else if (imagesize == 1)
00596 d = 16;
00597 else if (imagesize == 2)
00598 d = 8;
00599 else if (imagesize == 3)
00600 d = 5;
00601 else if (imagesize == 4)
00602 d = 4;
00603 col = image[((x - WINSTARTX) / d) + (focusx * 16)]
00604 [((y - (WINSTARTY)) / d) + (focusy * 16)];
00605
00606 while (((y - WINSTARTY) / d) + (focusy * 16) + yy < 16 * MAXIMAGESIZE
00607 && (image[((x - WINSTARTX) / d) + (focusx * 16)]
00608 [((y - (WINSTARTY)) / d) + (focusy * 16) + yy] == col))
00609 {
00610 image[((x - WINSTARTX) / d) + (focusx * 16)]
00611 [((y - (WINSTARTY)) / d) + (focusy * 16) + yy] = colour;
00612 yy++;
00613 }
00614 yy = -1;
00615 while (((y - WINSTARTY) / d) + (focusy * 16) + yy >= 0
00616 && (image[((x - WINSTARTX) / d) + (focusx * 16)]
00617 [((y - (WINSTARTY)) / d) + (focusy * 16) + yy] == col))
00618 {
00619 image[((x - WINSTARTX) / d) + (focusx * 16)]
00620 [((y - (WINSTARTY)) / d) + (focusy * 16) + yy] = colour;
00621 yy--;
00622 }
00623 Fgl_putbox (mox, moy, 8, 8, under_mouse_pointer);
00624 draw_swin ();
00625 draw_big_image ();
00626 Fgl_getbox (mx, my, 8, 8, under_mouse_pointer);
00627 Fgl_putbox (mx, my, 8, 8, mouse_pointer);
00628 }
00629
00630
00631 void
00632 fill_colourzoom (int x, int y)
00633 {
00634 int xx, yy;
00635 xx = (x - WINSTARTX) / 16;
00636 xx = WINSTARTX + (xx * 16);
00637 yy = (y - WINSTARTY) / 16;
00638 yy = WINSTARTY + (yy * 16);
00639 Fgl_putbox (mox, moy, 8, 8, under_mouse_pointer);
00640 Fgl_fillbox (xx, yy, 15, 15, colour);
00641 Fgl_getbox (mx, my, 8, 8, under_mouse_pointer);
00642 Fgl_putbox (mx, my, 8, 8, mouse_pointer);
00643
00644 Fgl_setpixel (((SWINSTARTX + 8) - imagesize * 8) + ((x - WINSTARTX) / 16)
00645 + (focusx * 16)
00646 ,((SWINSTARTY + 8) - imagesize * 8) + ((y - (WINSTARTY)) / 16) + (focusy * 16)
00647 ,colour);
00648 image[((x - WINSTARTX) / 16) + (focusx * 16)]
00649 [((y - (WINSTARTY)) / 16) + (focusy * 16)] = colour;
00650 }
00651
00652 void
00653 fill_colour1 (int x, int y)
00654 {
00655 int xx, yy;
00656 xx = (x - WINSTARTX) / 16;
00657 xx = WINSTARTX + (xx * 16);
00658 yy = (y - WINSTARTY) / 16;
00659 yy = WINSTARTY + (yy * 16);
00660 Fgl_putbox (mox, moy, 8, 8, under_mouse_pointer);
00661 Fgl_fillbox (xx, yy, 16, 16, colour);
00662 Fgl_getbox (mx, my, 8, 8, under_mouse_pointer);
00663 Fgl_putbox (mx, my, 8, 8, mouse_pointer);
00664
00665 Fgl_setpixel ((SWINSTARTX) + ((x - WINSTARTX) / 16)
00666 + (focusx * 16)
00667 ,(SWINSTARTY) + ((y - (WINSTARTY)) / 16) + (focusy * 16)
00668 ,colour);
00669 image[((x - WINSTARTX) / 16) + (focusx * 16)]
00670 [((y - (WINSTARTY)) / 16) + (focusy * 16)] = colour;
00671 }
00672
00673 void
00674 fill_colour2 (int x, int y)
00675 {
00676 int xx, yy;
00677 xx = (x - WINSTARTX) / 8;
00678 xx = WINSTARTX + (xx * 8);
00679 yy = (y - WINSTARTY) / 8;
00680 yy = WINSTARTY + (yy * 8);
00681 Fgl_putbox (mox, moy, 8, 8, under_mouse_pointer);
00682 Fgl_fillbox (xx, yy, 8, 8, colour);
00683 Fgl_getbox (mx, my, 8, 8, under_mouse_pointer);
00684 Fgl_putbox (mx, my, 8, 8, mouse_pointer);
00685
00686
00687 image[((x - WINSTARTX) / 8) + (focusx * 16)]
00688 [((y - (WINSTARTY)) / 8) + (focusy * 16)] = colour;
00689 draw_swin ();
00690 }
00691
00692 void
00693 fill_colour3 (int x, int y)
00694 {
00695 int xx, yy;
00696 xx = (x - WINSTARTX) / 5;
00697 if (xx > 47)
00698 return;
00699 xx = WINSTARTX + (xx * 5);
00700 yy = (y - WINSTARTY) / 5;
00701 if (yy > 47)
00702 return;
00703 yy = WINSTARTY + (yy * 5);
00704 Fgl_putbox (mox, moy, 8, 8, under_mouse_pointer);
00705 Fgl_fillbox (xx, yy, 5, 5, colour);
00706 Fgl_getbox (mx, my, 8, 8, under_mouse_pointer);
00707 Fgl_putbox (mx, my, 8, 8, mouse_pointer);
00708
00709 Fgl_setpixel ((SWINSTARTX - 16) + ((x - WINSTARTX) / 5)
00710 + (focusx * 5)
00711 ,(SWINSTARTY - 16) + ((y - (WINSTARTY)) / 5) + (focusy * 5)
00712 ,colour);
00713 image[((x - WINSTARTX) / 5) + (focusx * 5)]
00714 [((y - (WINSTARTY)) / 5) + (focusy * 5)] = colour;
00715 }
00716
00717 void
00718 fill_colour4 (int x, int y)
00719 {
00720 int xx, yy;
00721 xx = (x - WINSTARTX) / 4;
00722 xx = WINSTARTX + (xx * 4);
00723 yy = (y - WINSTARTY) / 4;
00724 yy = WINSTARTY + (yy * 4);
00725 Fgl_putbox (mox, moy, 8, 8, under_mouse_pointer);
00726 Fgl_fillbox (xx, yy, 4, 4, colour);
00727 Fgl_getbox (mx, my, 8, 8, under_mouse_pointer);
00728 Fgl_putbox (mx, my, 8, 8, mouse_pointer);
00729
00730 Fgl_setpixel ((SWINSTARTX - 24) + ((x - WINSTARTX) / 4)
00731 + (focusx * 4)
00732 ,(SWINSTARTY - 24) + ((y - (WINSTARTY)) / 4) + (focusy * 4)
00733 ,colour);
00734 image[((x - WINSTARTX) / 4) + (focusx * 4)]
00735 [((y - (WINSTARTY)) / 4) + (focusy * 4)] = colour;
00736 }
00737
00738 #ifdef LC_X11
00739 void
00740 setcustompalette (void)
00741 {
00742 char s[100], cpf[100];
00743 int i, n, r, g, b, me = 0, flag[256];
00744 long unsigned int plane_masks[3];
00745 FILE *inf;
00746 XColor pal[256];
00747 printf ("In setcustompalette\n");
00748 display.cmap = XDefaultColormap (display.dpy, display.screen);
00749 if (XAllocColorCells (display.dpy, display.cmap, 0
00750 ,plane_masks, 0, colour_table, 256) == 0)
00751 {
00752 me = (*DefaultVisual (display.dpy, display.screen)).map_entries;
00753 printf ("DefaultVisual id=%d bp-rgb=%d map-entries=%d\n"
00754 ,(*DefaultVisual (display.dpy, display.screen)).visualid
00755 ,(*DefaultVisual (display.dpy, display.screen)).bits_per_rgb
00756 ,(*DefaultVisual (display.dpy, display.screen)).map_entries);
00757 display.cmap = XCreateColormap (display.dpy, display.win
00758 ,DefaultVisual (display.dpy, display.screen)
00759
00760 ,AllocNone);
00761 if (me == 256 && XAllocColorCells (display.dpy, display.cmap, 0
00762 ,plane_masks, 0, colour_table, 256) != 0)
00763 printf ("Allocated 256 cells\n");
00764 else
00765 for (i = 0; i < 256; i++)
00766 colour_table[i] = i;
00767 }
00768 if (!display.cmap)
00769 HandleError ("No default colour map", FATAL);
00770 printf ("Got past create colourmap\n");
00771
00772 for (i = 0; i < 256; i++)
00773 flag[i] = 0;
00774 strcpy (cpf, LIBDIR);
00775 strcat (cpf, COLOUR_PAL_FILE);
00776 if ((inf = fopen (cpf, "r")) == 0)
00777 HandleError ("Can't find the colour pallet file", FATAL);
00778
00779 while (feof (inf) == 0)
00780 {
00781 fgets (s, 99, inf);
00782 if (sscanf (s, "%d %d %d %d", &n, &r, &g, &b) == 4)
00783 {
00784 pal[n].red = r << 10;
00785 pal[n].green = g << 10;
00786 pal[n].blue = b << 10;
00787 pal[n].flags = DoRed | DoGreen | DoBlue;
00788 if (me == 256)
00789 pal[n].pixel = colour_table[n];
00790 else
00791 {
00792 if (XAllocColor (display.dpy
00793 ,display.cmap, &(pal[n])) == 0)
00794 HandleError ("alloc colour failed"
00795 ,FATAL);
00796 colour_table[n] = pal[n].pixel;
00797 XSetForeground (display.dpy
00798 ,display.pixcolour_gc[n]
00799 ,colour_table[n]);
00800 }
00801 flag[n] = 1;
00802 }
00803 }
00804 fclose (inf);
00805 for (i = 0; i < 256; i++)
00806 if (flag[i] == 0)
00807 {
00808 printf ("Colour %d not loaded\n", i);
00809 do_error ("Can't continue");
00810 }
00811 if (me == 256)
00812 XStoreColors (display.dpy, display.cmap, pal, 256);
00813 XSetWindowColormap (display.dpy, display.win, display.cmap);
00814 }
00815
00816 #else
00817 void
00818 setcustompalette (void)
00819 {
00820 char s[100], cpf[100];
00821 int i, n, r, g, b, flag[256];
00822 FILE *inf;
00823 Palette pal;
00824 for (i = 0; i < 256; i++)
00825 flag[i] = 0;
00826 strcpy (cpf, LIBDIR);
00827 strcat (cpf, COLOUR_PAL_FILE);
00828 if ((inf = fopen (cpf, "r")) == 0)
00829 do_error ("Can't find the colour pallet file :(");
00830
00831 while (feof (inf) == 0)
00832 {
00833 fgets (s, 99, inf);
00834 if (sscanf (s, "%d %d %d %d", &n, &r, &g, &b) == 4)
00835 {
00836 pal.color[n].red = r;
00837 pal.color[n].green = g;
00838 pal.color[n].blue = b;
00839 flag[n] = 1;
00840 }
00841 }
00842 fclose (inf);
00843 for (i = 0; i < 256; i++)
00844 if (flag[i] == 0)
00845 {
00846 printf ("Colour %d not loaded\n", i);
00847 do_error ("Can't continue");
00848 }
00849 gl_setpalette (&pal);
00850 }
00851 #endif
00852
00853
00854 void
00855 initfont ()
00856 {
00857 #ifdef LC_X11
00858 char cpf[100];
00859 int i;
00860 FILE *finf;
00861 strcpy (cpf, LIBDIR);
00862 strcat (cpf, FONTFILE);
00863 if ((finf = fopen (cpf, "r")) == 0)
00864 HandleError ("Can't open the font file", FATAL);
00865 for (i = 0; i < 256 * 8; i++)
00866 myfont[i] = fgetc (finf);
00867 fclose (finf);
00868 #else
00869 void *font;
00870 font = malloc (256 * 8 * 8 * BYTESPERPIXEL);
00871 gl_expandfont (8, 8, white (24), gl_font8x8, font);
00872 gl_setfont (8, 8, font);
00873 #endif
00874 }
00875
00876
00877 void
00878 save_image (void)
00879 {
00880 int x, y;
00881 FILE *outf;
00882 if ((outf = fopen (imagefile, "wb")) == NULL)
00883 {
00884 printf ("Can't write image file %s \n", imagefile);
00885 return;
00886 }
00887 for (y = 0; y < 16 * imagesize; y++)
00888 for (x = 0; x < 16 * imagesize; x++)
00889 putc (image[x][y], outf);
00890 fclose (outf);
00891 }
00892
00893 void
00894 load_image (void)
00895 {
00896 int x, y, l;
00897 FILE *inf;
00898 if ((inf = fopen (imagefile, "rb")) == NULL)
00899 return;
00900 fseek (inf, 0L, SEEK_END);
00901 l = ftell (inf);
00902 fseek (inf, 0L, SEEK_SET);
00903 if (l == 256)
00904 newimagesize = 1;
00905 else if (l == 1024)
00906 newimagesize = 2;
00907 else if (l == 2304)
00908 newimagesize = 3;
00909 else if (l == 4096)
00910 newimagesize = 4;
00911 else
00912 {
00913 printf ("Can't load file %s, maybe wrong size %d\n"
00914 ,imagefile, l);
00915 exit (1);
00916 }
00917 for (y = 0; y < 16 * newimagesize; y++)
00918 for (x = 0; x < 16 * newimagesize; x++)
00919 image[x][y] = fgetc (inf);
00920 fclose (inf);
00921 }
00922
00923
00924
00925
00926 void
00927 setup (void)
00928 {
00929 char s[50];
00930 short x, y;
00931 Fgl_hline (WINSTARTX, WINSTARTY - 1, WINSTARTX + 256, 255);
00932 Fgl_hline (WINSTARTX, WINSTARTY + 256, WINSTARTX + 256, 255);
00933 Fgl_line (WINSTARTX - 1, WINSTARTY, WINSTARTX - 1, WINSTARTY + 256, 255);
00934 Fgl_line (WINSTARTX + 256, WINSTARTY, WINSTARTX + 256, WINSTARTY + 256, 255);
00935 for (y = 0; y < 16; y++)
00936 {
00937 Fgl_hline (WINSTARTX, WINSTARTY + y * 16 + 15, WINSTARTX + 255, 253);
00938 Fgl_line (WINSTARTX + y * 16 + 15, WINSTARTY, WINSTARTX + y * 16 + 15
00939 ,WINSTARTY + 255, 253);
00940 for (x = 0; x < 16; x++)
00941 {
00942 Fgl_fillbox (x * 40, y * 14, 38, 12, y * 16 + x);
00943 sprintf (s, "%d", y * 16 + x);
00944 Fgl_write (x * 40, y * 14, s);
00945 }
00946 }
00947 change_imagesize (1);
00948 Fgl_fillbox (SIZEBUTTONX1x1, SIZEBUTTONY1x1, SIZEBUTTONSIZEX - 1
00949 ,SIZEBUTTONSIZEY - 1, 240);
00950 Fgl_write (SIZEBUTTONX1x1 + 3, SIZEBUTTONY1x1 + 3, "1x1");
00951 Fgl_fillbox (SIZEBUTTONX2x2, SIZEBUTTONY2x2, SIZEBUTTONSIZEX - 1
00952 ,SIZEBUTTONSIZEY - 1, 240);
00953 Fgl_write (SIZEBUTTONX2x2 + 3, SIZEBUTTONY2x2 + 3, "2x2");
00954 Fgl_fillbox (SIZEBUTTONX3x3, SIZEBUTTONY3x3, SIZEBUTTONSIZEX - 1
00955 ,SIZEBUTTONSIZEY - 1, 240);
00956 Fgl_write (SIZEBUTTONX3x3 + 3, SIZEBUTTONY3x3 + 3, "3x3");
00957 Fgl_fillbox (SIZEBUTTONX4x4, SIZEBUTTONY4x4, SIZEBUTTONSIZEX - 1
00958 ,SIZEBUTTONSIZEY - 1, 240);
00959 Fgl_write (SIZEBUTTONX4x4 + 3, SIZEBUTTONY4x4 + 3, "4x4");
00960
00961 Fgl_fillbox (FOCUSWINX - 1, FOCUSWINY - 1, FOCUSWINSIZE + 1, FOCUSWINSIZE + 1, 240);
00962 draw_focus ();
00963
00964 Fgl_fillbox (ZOOMBUTX, ZOOMBUTY, ZOOMBUTSIZEX, ZOOMBUTSIZEY, 240);
00965 Fgl_write (ZOOMBUTX + 3, ZOOMBUTY + 3, "ZOOM");
00966
00967 Fgl_fillbox (HALFBUTX, HALFBUTY, HALFBUTSIZEX, HALFBUTSIZEY, 240);
00968 Fgl_write (HALFBUTX + 3, HALFBUTY + 3, "HALF");
00969
00970 Fgl_fillbox (NORMBUTX, NORMBUTY, NORMBUTSIZEX, NORMBUTSIZEY, 240);
00971 Fgl_write (NORMBUTX + 3, NORMBUTY + 3, "NORM");
00972
00973 Fgl_fillbox (DOTBUTX, DOTBUTY, DOTBUTSIZEX, DOTBUTSIZEY, 240);
00974 Fgl_write (DOTBUTX + 3, DOTBUTY + 3, "DOT");
00975
00976 Fgl_fillbox (HFILBUTX, HFILBUTY, HFILBUTSIZEX, HFILBUTSIZEY, 240);
00977 Fgl_write (HFILBUTX + 3, HFILBUTY + 3, "HFIL");
00978
00979 Fgl_fillbox (VFILBUTX, VFILBUTY, VFILBUTSIZEX, VFILBUTSIZEY, 240);
00980 Fgl_write (VFILBUTX + 3, VFILBUTY + 3, "VFIL");
00981 Fgl_write (0, 480 - 9, imagefile);
00982 Fgl_write (0, 423, " q - to save and quit...");
00983 Fgl_write (0, 433, " - (then move the mouse)");
00984 Fgl_write (0, 448, "^C - to quit without saving");
00985 }
00986
00987 void
00988 draw_focus (void)
00989 {
00990 int x, y;
00991 hide_mouse ();
00992 for (y = 0; y < 4; y++)
00993 for (x = 0; x < 4; x++)
00994 {
00995 if (x == focusx && y == focusy)
00996 Fgl_fillbox (FOCUSWINX + (FOCUSWINSIZE / 4) * focusx
00997 ,FOCUSWINY + (FOCUSWINSIZE / 4) * focusy
00998 ,(FOCUSWINSIZE / 4) - 1
00999 ,(FOCUSWINSIZE / 4) - 1, FOCUSWINCOLOUR);
01000 else if (zoom_flag == 2)
01001 {
01002 if ((x == focusx + 1 && y == focusy)
01003 || (x == focusx && y == focusy + 1)
01004 || (x == focusx + 1 && y == focusy + 1))
01005 Fgl_fillbox (FOCUSWINX + (FOCUSWINSIZE / 4) * x
01006 ,FOCUSWINY + (FOCUSWINSIZE / 4) * y
01007 ,(FOCUSWINSIZE / 4) - 1
01008 ,(FOCUSWINSIZE / 4) - 1, FOCUSWINCOLOUR);
01009 }
01010 else if (x < imagesize && y < imagesize)
01011 Fgl_fillbox (FOCUSWINX + (FOCUSWINSIZE / 4) * x
01012 ,FOCUSWINY + (FOCUSWINSIZE / 4) * y
01013 ,(FOCUSWINSIZE / 4) - 1
01014 ,(FOCUSWINSIZE / 4) - 1, UNFOCUSWINCOLOUR);
01015 else
01016 Fgl_fillbox (FOCUSWINX + (FOCUSWINSIZE / 4) * x
01017 ,FOCUSWINY + (FOCUSWINSIZE / 4) * y
01018 ,(FOCUSWINSIZE / 4) - 1
01019 ,(FOCUSWINSIZE / 4) - 1, XFOCUSWINCOLOUR);
01020 }
01021 reshow_mouse ();
01022 }
01023
01024 void
01025 draw_swin (void)
01026 {
01027 int x, y;
01028 Fgl_fillbox ((SWINSTARTX + 7) - 4 * 8, (SWINSTARTY + 7) - 4 * 8
01029 ,16 * 4 + 2, 16 * 4 + 2, 0);
01030 Fgl_hline ((SWINSTARTX + 7) - imagesize * 8, (SWINSTARTY + 7) - imagesize * 8
01031 ,((SWINSTARTX + 8) - imagesize * 8) + 16 * imagesize, 235);
01032 Fgl_hline ((SWINSTARTX + 7) - imagesize * 8
01033 ,((SWINSTARTY + 8) - imagesize * 8) + 16 * imagesize
01034 ,((SWINSTARTX + 8) - imagesize * 8) + 16 * imagesize, 235);
01035 Fgl_line ((SWINSTARTX + 7) - imagesize * 8, (SWINSTARTY + 7) - imagesize * 8
01036 ,(SWINSTARTX + 7) - imagesize * 8
01037 ,((SWINSTARTY + 8) - imagesize * 8) + 16 * imagesize, 235);
01038 Fgl_line (((SWINSTARTX + 8) - imagesize * 8) + 16 * imagesize
01039 ,(SWINSTARTY + 7) - imagesize * 8
01040 ,((SWINSTARTX + 8) - imagesize * 8) + 16 * imagesize
01041 ,((SWINSTARTY + 8) - imagesize * 8) + 16 * imagesize, 235);
01042 for (y = 0; y < 16 * imagesize; y++)
01043 for (x = 0; x < 16 * imagesize; x++)
01044 Fgl_setpixel (((SWINSTARTX + 8) - imagesize * 8) + x
01045 ,((SWINSTARTY + 8) - imagesize * 8) + y, image[x][y]);
01046 }
01047
01048 void
01049 draw_big_image (void)
01050 {
01051 if (zoom_flag == 1)
01052 draw_big_imagezoom ();
01053 else if (zoom_flag == 2)
01054 draw_big_image2 ();
01055 else if (imagesize == 1)
01056 draw_big_image1 ();
01057 else if (imagesize == 2)
01058 draw_big_image2 ();
01059 else if (imagesize == 3)
01060 draw_big_image3 ();
01061 else if (imagesize == 4)
01062 draw_big_image4 ();
01063 }
01064
01065 void
01066 draw_big_imagezoom (void)
01067 {
01068 int x, y;
01069 for (y = 0; y < 16; y++)
01070 for (x = 0; x < 16; x++)
01071 Fgl_fillbox (WINSTARTX + x * 16, (WINSTARTY) + y * 16, 15, 15
01072 ,image[x + focusx * 16][y + focusy * 16]);
01073 }
01074
01075 void
01076 draw_big_image1 (void)
01077 {
01078 int x, y;
01079 for (y = 0; y < 16; y++)
01080 for (x = 0; x < 16; x++)
01081 Fgl_fillbox (WINSTARTX + x * 16, (WINSTARTY) + y * 16, 16, 16
01082 ,image[x + focusx * 16][y + focusy * 16]);
01083 }
01084
01085 void
01086 draw_big_image2 (void)
01087 {
01088 int x, y;
01089 for (y = 0; y < 32; y++)
01090 for (x = 0; x < 32; x++)
01091 Fgl_fillbox (WINSTARTX + x * 8, (WINSTARTY) + y * 8, 8, 8
01092 ,image[x + focusx * 16][y + focusy * 16]);
01093 }
01094
01095 void
01096 draw_big_image3 (void)
01097 {
01098 int x, y;
01099 for (y = 0; y < 48; y++)
01100 for (x = 0; x < 48; x++)
01101 Fgl_fillbox (WINSTARTX + x * 5, (WINSTARTY) + y * 5, 5, 5
01102 ,image[x + focusx * 5][y + focusy * 5]);
01103 }
01104
01105 void
01106 draw_big_image4 (void)
01107 {
01108 int x, y;
01109 for (y = 0; y < 64; y++)
01110 for (x = 0; x < 64; x++)
01111 Fgl_fillbox (WINSTARTX + x * 4, (WINSTARTY) + y * 4, 4, 4
01112 ,image[x + focusx * 4][y + focusy * 4]);
01113 }
01114
01115 void
01116 change_imagesize (int n)
01117 {
01118 char s[50];
01119 imagesize = n;
01120 focus = 0;
01121 focusx = 0;
01122 focusy = 0;
01123 draw_swin ();
01124 draw_focus ();
01125 sprintf (s, "Image size %dx%d", n, n);
01126 Fgl_write (0, 480 - 20, s);
01127
01128 }
01129
01130 void
01131 change_focus (int x, int y)
01132 {
01133 if (x >= imagesize || y >= imagesize)
01134 return;
01135 focusx = x;
01136 focusy = y;
01137 draw_focus ();
01138 draw_big_image ();
01139 }
01140
01141 void
01142 hide_mouse (void)
01143 {
01144 Fgl_putbox (mox, moy, 8, 8, under_mouse_pointer);
01145 }
01146
01147 void
01148 reshow_mouse (void)
01149 {
01150 Fgl_getbox (mx, my, 8, 8, under_mouse_pointer);
01151 Fgl_putbox (mx, my, 8, 8, mouse_pointer);
01152 }
01153
01154
01155 #ifdef LC_X11
01156
01157 void
01158 parse_args (int argc, char **argv, char **geometry)
01159 {
01160
01161 int option;
01162 extern int optind;
01163 extern char *optarg;
01164
01165 int bits;
01166
01167
01168
01169 while ((option = getopt (argc, argv, "vbg:")) != EOF)
01170 {
01171 switch (option)
01172 {
01173 case 'v':
01174 verbose = TRUE;
01175 break;
01176 case 'g':
01177 *geometry = optarg;
01178 break;
01179 case 'b':
01180 borderx = 0;
01181 bordery = 0;
01182 break;
01183 }
01184 }
01185 if (verbose)
01186 printf ("Version %s\n", VERSION);
01187 if (!(display.dpy = XOpenDisplay (display.dname)))
01188 {
01189 HandleError ("Cannot open display.\n", FATAL);
01190 exit (-1);
01191 }
01192
01193 display.screen = DefaultScreen (display.dpy);
01194 display.root = RootWindow (display.dpy, display.screen);
01195
01196 winW = WINWIDTH + borderx * 2;
01197 winH = WINHEIGHT + bordery * 2;
01198 winX = (DisplayWidth (display.dpy, display.screen)
01199 - winW) / 2;
01200 winY = (DisplayHeight (display.dpy, display.screen)
01201 - winH) / 2;
01202 if (*geometry != NULL)
01203 XParseGeometry (*geometry, &winX, &winY, &winW, &winH);
01204 }
01205
01206 void
01207 Create_Window (char *geometry)
01208 {
01209 short q;
01210 XSetWindowAttributes xswa;
01211 XSizeHints sizehint;
01212 XWMHints wmhints;
01213 unsigned char wname[256];
01214
01215 xswa.event_mask = 0;
01216 xswa.background_pixel = display.bg;
01217 printf ("DefaultVisual id=%d bp-rgb=%d map-entries=%d\n"
01218 ,(*DefaultVisual (display.dpy, display.screen)).visualid
01219 ,(*DefaultVisual (display.dpy, display.screen)).bits_per_rgb
01220 ,(*DefaultVisual (display.dpy, display.screen)).map_entries);
01221 display.win = XCreateWindow (display.dpy, display.root,
01222 winX, winY,
01223 winW, winH, 0,
01224 DefaultDepth (display.dpy, display.screen),
01225 InputOutput, DefaultVisual (display.dpy, display.screen),
01226
01227 CWEventMask | CWBackPixel, &xswa);
01228
01229 sizehint.x = winX;
01230 sizehint.y = winY;
01231 sizehint.width = winW;
01232 sizehint.height = winH;
01233 sizehint.min_width = winW;
01234 sizehint.min_height = winH;
01235 if (geometry != NULL)
01236 sizehint.flags = USPosition | USSize | PMinSize;
01237 else
01238 sizehint.flags = PPosition | PSize | PMinSize;
01239 XSetNormalHints (display.dpy, display.win, &sizehint);
01240
01241 display.protocol_atom = XInternAtom (display.dpy, "WM_PROTOCOLS",
01242 False);
01243 display.kill_atom = XInternAtom (display.dpy, "WM_DELETE_WINDOW",
01244 False);
01245
01246
01247 sprintf ((char *) wname, "xpicedit, Version %s, by IJ Peters",
01248 VERSION);
01249 XChangeProperty (display.dpy, display.win,
01250 XA_WM_NAME, XA_STRING, 8, PropModeReplace, wname,
01251 strlen ((char *) wname));
01252
01253
01254 wmhints.flags = InputHint;
01255 wmhints.input = True;
01256 XSetWMHints (display.dpy, display.win, &wmhints);
01257 XMapWindow (display.dpy, display.win);
01258 XSelectInput (display.dpy, display.win,
01259 KeyPressMask | ButtonPressMask | ButtonReleaseMask
01260 | ExposureMask | StructureNotifyMask);
01261 for (q = 0; q < 256; q++)
01262 {
01263 display.pixcolour_gc[q] = XCreateGC (display.dpy
01264 ,display.win, 0, NULL);
01265 XSetForeground (display.dpy, display.pixcolour_gc[q], q);
01266 XSetBackground (display.dpy, display.pixcolour_gc[q]
01267 ,display.bg);
01268 }
01269 }
01270
01271 void
01272 HandleError (char *description, int degree)
01273 {
01274 fprintf (stderr, "An error has occurred. The description is below... \n");
01275 fprintf (stderr, "%s\n", description);
01276
01277 if (degree == FATAL)
01278 {
01279 fprintf (stderr, "Program aborting...\n");
01280 exit (-1);
01281 }
01282 }
01283
01284 void
01285 Fgl_setpixel (int x, int y, int col)
01286 {
01287 int i;
01288 col &= 0xff;
01289 i = (y + bordery) * (640 + BORDERX) + x + borderx;
01290 if ((int) *(pixmap + i) != col)
01291 {
01292 *(pixmap + i) = (unsigned char) col;
01293 XDrawPoint (display.dpy, display.win
01294 ,display.pixcolour_gc[col], x + borderx, y + bordery);
01295 }
01296 }
01297
01298 int
01299 Fgl_getpixel (int x, int y)
01300 {
01301 return (*(pixmap + (y + bordery) * (640 + BORDERX) + x + borderx));
01302 }
01303
01304 void
01305 Fgl_hline (int x1, int y1, int x2, int col)
01306 {
01307 int x, i;
01308 col &= 0xff;
01309 i = (y1 + bordery) * (640 + BORDERX);
01310 for (x = x1 + borderx; x < x2 + borderx; x++)
01311 *(pixmap + i + x) = col;
01312 XDrawLine (display.dpy, display.win
01313 ,display.pixcolour_gc[col], x1 + borderx
01314 ,y1 + bordery, x2 + borderx, y1 + bordery);
01315 }
01316
01317 void
01318 Fgl_line (int x1, int y1, int dummy, int y2, int col)
01319
01320 {
01321 int y, i;
01322 col &= 0xff;
01323 for (y = y1 + bordery; y < y2 + bordery; y++)
01324 *(pixmap + x1 + borderx + (y * (640 + BORDERX))) = col;
01325 XDrawLine (display.dpy, display.win
01326 ,display.pixcolour_gc[col], x1 + borderx
01327 ,y1 + bordery, x1 + borderx, y2 + bordery);
01328 }
01329
01330 void
01331 Fgl_write (int x, int y, char *s)
01332 {
01333 int i;
01334 for (i = 0; i < strlen (s); i++)
01335 my_x_putchar (x + i * 8, y, s[i]);
01336 }
01337
01338 void
01339 my_x_putchar (int xx, int yy, int c)
01340 {
01341 int x, y, b;
01342 for (y = 0; y < 8; y++)
01343 {
01344 b = myfont[c * 8 + y];
01345 for (x = 0; x < 8; x++)
01346 {
01347 if ((b & 0x80) == 0)
01348 Fgl_setpixel (xx + x, yy + y, text_bg);
01349 else
01350 Fgl_setpixel (xx + x, yy + y, text_fg);
01351 b = b << 1;
01352 }
01353 }
01354 }
01355
01356
01357 void
01358 Fgl_fillbox (int x1, int y1, int w, int h, int col)
01359 {
01360 int x, y;
01361 col &= 0xff;
01362 for (y = y1 + bordery; y < y1 + h + bordery; y++)
01363 {
01364 for (x = x1 + borderx; x < x1 + w + borderx; x++)
01365 *(pixmap + y * (640 + BORDERX) + x) = col;
01366 XDrawLine (display.dpy, display.win, display.pixcolour_gc[col]
01367 ,x1 + borderx, y, x1 + w - 1 + borderx, y);
01368 }
01369 }
01370
01371 void
01372 Fgl_putbox (int x1, int y1, int x2, int y2, unsigned char *buf)
01373 {
01374 }
01375
01376 void
01377 Fgl_getbox (int x1, int y1, int x2, int y2, unsigned char *buf)
01378 {
01379 }
01380
01381 void
01382 HandleEvent (XEvent * event)
01383 {
01384 switch (event->type)
01385 {
01386 case (KeyPress):
01387 {
01388 XKeyEvent *key_event = (XKeyEvent *) event;
01389 char buf[128];
01390 KeySym ks;
01391 XComposeStatus status;
01392 XLookupString (key_event, buf, 128, &ks, &status);
01393 if (buf[0] == 'q' || buf[0] == 'Q')
01394 stopflag = TRUE;
01395 else if (buf[0] == 'r' || buf[0] == 'R')
01396 refresh_screen (0, 0, 640, 480);
01397 }
01398 break;
01399
01400 case (ButtonPress):
01401 {
01402 XButtonEvent *ev = (XButtonEvent *) event;
01403 mouse_button = ev->button;
01404 }
01405 break;
01406
01407 case (ButtonRelease):
01408 {
01409 mouse_button = 0;
01410 }
01411 break;
01412
01413 case (Expose):
01414 {
01415 XExposeEvent *ev = (XExposeEvent *) event;
01416 refresh_screen (ev->x, ev->y
01417 ,ev->x + ev->width, ev->y + ev->height);
01418 }
01419 break;
01420
01421 default:
01422 printf ("Unknown event %d\n", event->type);
01423 }
01424 }
01425
01426 void
01427 refresh_screen (int x1, int y1, int x2, int y2)
01428 {
01429 int x, y;
01430 for (y = y1; y < y2; y++)
01431 for (x = x1; x < x2; x++)
01432 XDrawPoint (display.dpy, display.win
01433 ,display.pixcolour_gc[*(pixmap
01434 + x + y * (640 + BORDERX)) & 0xff], x, y);
01435 }
01436
01437 #endif
01438
01439 void
01440 lincityrc (void)
01441 {
01442 char s[256], s1[256];
01443 int i;
01444 FILE *rc;
01445
01446 strcpy (s, getenv ("HOME"));
01447 strcat (s, "/");
01448 strcat (s, ".lincityrc");
01449 if ((rc = fopen (s, "r")) == 0)
01450 {
01451 do
01452 {
01453 strcpy (s1, "cat ");
01454 strcat (s1, LIBDIR);
01455 strcat (s1, "/messages/mousetype.mes");
01456 system (s1);
01457 i = getchar ();
01458 }
01459 while (i < '0' || i > '6');
01460 if ((rc = fopen (s, "w")) == 0)
01461 {
01462 printf ("Can't open %s for writing, can't continue \n ", s);
01463 exit (1);
01464 }
01465 fprintf (rc, "mouse=%d\n", i - '0');
01466 fclose (rc);
01467 chown (s, getuid (), getgid ());
01468 if ((rc = fopen (s, "r")) == 0)
01469 {
01470 printf ("What!! can't open %s for reading after writing???\n", s);
01471 exit (1);
01472 }
01473 }
01474 while (feof (rc) == 0)
01475 {
01476 fgets (s, 99, rc);
01477 if (sscanf (s, "mouse=%d", &i) != 0)
01478 lc_mouse_type = i;
01479 }
01480 fclose (rc);
01481 }