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 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
|
// lcwin32.cxx Win32 stuff - part of lin-city
// Copyright (c) I J Peters 1995,1996. Please read the file 'COPYRIGHT'.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <assert.h>
#include "lin-city.h"
#include "common.h"
#include "lctypes.h"
#define USE_WINDOWS_FONT 1
int
AdjustX (int x)
{
x <<= pix_double;
x += borderx;
return x;
}
int
AdjustY (int y)
{
y <<= pix_double;
y += bordery;
return y;
}
int
UnAdjustX (int x)
{
x -= borderx;
x >>= pix_double;
return x;
}
int
UnAdjustY (int y)
{
y -= bordery;
y >>= pix_double;
return y;
}
void
HandleError (char *description, int degree)
{
MessageBox (NULL, description, "ERROR", MB_OK);
if (degree == FATAL)
{
exit (-1);
}
}
void
setcustompalette (void)
{
char s[100];
unsigned int n, r, g, b;
int i, flag[256];
FILE *inf;
for (i = 0; i < 256; i++)
flag[i] = 0;
if ((inf = fopen (colour_pal_file, "r")) == 0)
HandleError ("Can't find the colour pallet file", FATAL);
while (feof (inf) == 0)
{
fgets (s, 99, inf);
if (sscanf (s, "%u %u %u %u", &n, &r, &g, &b) == 4)
{
r = ((r * (1 - gamma_correct_red))
+ (64 * sin ((float) r * M_PI / 128))
* gamma_correct_red);
g = ((g * (1 - gamma_correct_green))
+ (64 * sin ((float) g * M_PI / 128))
* gamma_correct_green);
b = ((b * (1 - gamma_correct_blue))
+ (64 * sin ((float) b * M_PI / 128))
* gamma_correct_blue);
AddPaletteEntry (n, r, g, b);
flag[n] = 1;
}
}
fclose (inf);
for (i = 0; i < 256; i++)
{
if (flag[i] == 0)
{
printf ("Colour %d not loaded\n", i);
HandleError ("Can't continue", FATAL);
}
}
UpdatePalette ();
}
COLORREF
GetPaletteColorref (int col)
{
assert (col >= 0 || col <= 255);
if (display.hasPalette)
return PALETTEINDEX (col);
else
return display.colorrefPal[col];
}
HBRUSH
GetPaletteBrush (int col)
{
assert (col >= 0 || col <= 255);
if (display.brushPal[col] == 0)
{
display.brushPal[col] = CreateSolidBrush (GetPaletteColorref (col));
}
return display.brushPal[col];
}
#if defined (WIN32)
int CALLBACK
EnumFontFamProc (
ENUMLOGFONT FAR * lpelf, // pointer to logical-font data
NEWTEXTMETRIC FAR * lpntm, // pointer to physical-font data
int FontType, // type of font
LPARAM lParam // address of application-defined data
)
{
if (0 != strcmp (lpelf->elfLogFont.lfFaceName, "Lincity"))
// if (0 != strcmp (lpelf->elfLogFont.lfFaceName, "Tester"))
return 0;
// GCS: I'm not sure if it's OK to just copy the pointer here.
// This may cause problems, but let's give it a whirl.
// *((LOGFONT**) lParam) = &(lpelf->elfLogFont);
// GCS: No wait, I changed my mind. Copy the entire LOGFONT struct.
*(LOGFONT *) lParam = lpelf->elfLogFont;
return 1;
}
#endif
void
initfont ()
{
#if defined (USE_WINDOWS_FONT)
int fonts_added = AddFontResource (windowsfontfile);
if (fonts_added != 1)
{
HandleError ("Can't open the font file", FATAL);
}
SendMessage (HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
ProcessPendingEvents ();
// GCS: This typedef is for the typecast...
// typedef int (FAR WINAPI *voidfnptr)(void);
// KSH: Changed the typedef to get around VC 6 strict type enformcement
#if defined (commentout)
typedef int (FAR WINAPI * voidfnptr) (const struct tagLOGFONTA *, const struct tagTEXTMETRICA *, unsigned long, long);
EnumFontFamilies (display.hdcMem, "Lincity", (voidfnptr) EnumFontFamProc, (LPARAM) & logfont);
#endif
// GCS: Hmm. There must be a way to get this to work on both compilers.
// How about this?
LOGFONT logfont;
EnumFontFamilies (display.hdcMem, "Lincity", (FONTENUMPROC) EnumFontFamProc, (LPARAM) & logfont);
#if defined (commentout)
LOGFONT logfont;
logfont.lfHeight = 8; // ??
logfont.lfWidth = 8; // ??
logfont.lfEscapement = 0; // ??
logfont.lfOrientation = 0; // ??
logfont.lfWeight = 0;
logfont.lfItalic = FALSE;
logfont.lfUnderline = FALSE;
logfont.lfStrikeOut = FALSE;
logfont.lfCharSet = ANSI_CHARSET;
logfont.lfOutPrecision = OUT_RASTER_PRECIS;
logfont.lfClipPrecision = 0;
logfont.lfQuality = DEFAULT_QUALITY;
logfont.lfPitchAndFamily = FIXED_PITCH | FF_ROMAN;
strcpy (logfont.lfFaceName, "alt-8x8");
#endif
display.hFont = CreateFontIndirect (&logfont);
if (!display.hFont)
{
HandleError ("Error executing CreateFontIndirect", FATAL);
}
SelectObject (display.hdcMem, display.hFont);
#endif
// Load non-windows version of font
int i;
FILE *finf;
#if defined (WIN32)
if ((finf = fopen (fontfile, "rb")) == 0)
HandleError ("Can't open the font file", FATAL);
#else
if ((finf = fopen (fontfile, "r")) == 0)
HandleError ("Can't open the font file", FATAL);
#endif
for (i = 0; i < 256 * 8; i++)
myfont[i] = fgetc (finf);
fclose (finf);
}
void
gl_setpalettecolor (long x, long r, long g, long b)
{
if (x >= 0 && x <= 255)
{
AddPaletteEntry (x, r, g, b);
}
}
void
Fgl_setfontcolors (int bg, int fg)
{
text_fg = fg;
text_bg = bg;
}
void
Fgl_setpixel (int x, int y, int col)
{
int i;
if (clipping_flag)
if (x < xclip_x1 || x > xclip_x2 || y < xclip_y1 || y > xclip_y2)
return;
col &= 0xff;
// Draw to pixmap buffer
i = (y + bordery) * (640 + BORDERX) + x + borderx;
*(pixmap + i) = (unsigned char) col;
// Draw to DC
if (display.useDIB)
{
BYTE *pixel = display.pBits;
unsigned long row = display.pbminfo->bmiHeader.biHeight - (y + bordery);
unsigned long rowlength = display.pbminfo->bmiHeader.biWidth;
unsigned long mod = rowlength % sizeof (DWORD);
if (mod)
{
rowlength += (sizeof (DWORD) - mod);
} // Pad out to DWORD boundary
pixel += row * rowlength + x + borderx; // Ptr arith w/ 4 bytes per pixel
*pixel = col;
}
else
{
if (pix_double)
{
RECT rect;
HBRUSH hbr, hbrOld;
rect.left = AdjustX (x);
rect.top = AdjustY (y);
rect.right = AdjustX (x + 1);
rect.bottom = AdjustY (y + 1);
hbr = GetPaletteBrush (col);
hbrOld = (HBRUSH) SelectObject (display.hdcMem, hbr);
FillRect (display.hdcMem, &rect, hbr);
hbr = (HBRUSH) SelectObject (display.hdcMem, hbrOld);
}
else
{
SetPixel (display.hdcMem, x + borderx, y + bordery, GetPaletteColorref (col));
}
}
// It's too slow to write directly to screen or to queue update event
// for every pixel. Instead, the caller will have to do this.
}
int
Fgl_getpixel (int x, int y)
{
return (*(pixmap + (y + bordery) * (640 + BORDERX) + x + borderx));
}
void
Fgl_hline (int x1, int y1, int x2, int col)
{
int x, i;
int xor = 0;
if (col == -1)
{
xor = 1;
}
col &= 0xff;
// Draw to pixmap buffer
i = (y1 + bordery) * (640 + BORDERX);
for (x = x1 + borderx; x <= x2 + borderx; x++)
*(pixmap + i + x) = col;
// Calculate extent of update rectangle
RECT rect;
rect.left = AdjustX (x1);
rect.top = AdjustY (y1);
rect.right = AdjustX (x2); // LineTo() does not include final pixel of line
rect.bottom = AdjustY (y1 + 1);
// Draw to DC
if (display.useDIB)
{
HPEN hpen, hpenOld;
HBITMAP hOldBitmapMem;
hpen = CreatePen (PS_SOLID, 0, GetPaletteColorref (col));
hpenOld = (HPEN) SelectObject (display.hdcMem, hpen);
hOldBitmapMem = (HBITMAP) SelectObject (display.hdcMem, display.hDIB);
MoveToEx (display.hdcMem, x1 + borderx, y1 + bordery, NULL);
int oldrop2;
if (xor)
oldrop2 = SetROP2 (display.hdcMem, R2_NOT);
LineTo (display.hdcMem, x2 + borderx, y1 + bordery);
if (xor)
SetROP2 (display.hdcMem, oldrop2);
display.hDIB = (HBITMAP) SelectObject (display.hdcMem, hOldBitmapMem);
hpen = (HPEN) SelectObject (display.hdcMem, hpenOld);
DeleteObject (hpen);
}
else
{
if (pix_double)
{
HBRUSH hbr, hbrOld;
hbr = GetPaletteBrush (col);
hbrOld = (HBRUSH) SelectObject (display.hdcMem, hbr);
int oldrop2;
if (xor)
oldrop2 = SetROP2 (display.hdcMem, R2_NOT);
FillRect (display.hdcMem, &rect, hbr);
if (xor)
SetROP2 (display.hdcMem, oldrop2);
hbr = (HBRUSH) SelectObject (display.hdcMem, hbrOld);
}
else
{
HPEN hpen, hpenOld;
hpen = CreatePen (PS_SOLID, 0, GetPaletteColorref (col));
hpenOld = (HPEN) SelectObject (display.hdcMem, hpen);
MoveToEx (display.hdcMem, x1 + borderx, y1 + bordery, NULL);
int oldrop2;
if (xor)
oldrop2 = SetROP2 (display.hdcMem, R2_NOT);
LineTo (display.hdcMem, x2 + borderx, y1 + bordery);
if (xor)
SetROP2 (display.hdcMem, oldrop2);
hpen = (HPEN) SelectObject (display.hdcMem, hpenOld);
DeleteObject (hpen);
}
}
// Queue update event
InvalidateRect (display.hWnd, &rect, FALSE);
}
void
Fgl_line (int x1, int y1, int dummy, int y2, int col)
// vertical lines only.
{
int y;
col &= 0xff;
// Draw to pixmap buffer
for (y = y1 + bordery; y <= y2 + bordery; y++)
*(pixmap + x1 + borderx + (y * (640 + BORDERX))) = col;
// Calculate extent of update rectangle
RECT rect;
rect.left = AdjustX (x1);
rect.top = AdjustY (y1);
rect.right = AdjustX (x1 + 1);
rect.bottom = AdjustY (y2); // LineTo() does not include final pixel of line
// Draw to DC
if (display.useDIB)
{
HPEN hpen, hpenOld;
HBITMAP hOldBitmapMem;
hpen = CreatePen (PS_SOLID, 0, GetPaletteColorref (col));
hpenOld = (HPEN) SelectObject (display.hdcMem, hpen);
hOldBitmapMem = (HBITMAP) SelectObject (display.hdcMem, display.hDIB);
MoveToEx (display.hdcMem, x1 + borderx, y1 + bordery, NULL);
LineTo (display.hdcMem, x1 + borderx, y2 + bordery);
display.hDIB = (HBITMAP) SelectObject (display.hdcMem, hOldBitmapMem);
hpen = (HPEN) SelectObject (display.hdcMem, hpenOld);
DeleteObject (hpen);
}
else
{
if (pix_double)
{
HBRUSH hbr, hbrOld;
hbr = GetPaletteBrush (col);
hbrOld = (HBRUSH) SelectObject (display.hdcMem, hbr);
FillRect (display.hdcMem, &rect, hbr);
hbr = (HBRUSH) SelectObject (display.hdcMem, hbrOld);
}
else
{
HPEN hpen, hpenOld;
hpen = CreatePen (PS_SOLID, 0, GetPaletteColorref (col));
hpenOld = (HPEN) SelectObject (display.hdcMem, hpen);
MoveToEx (display.hdcMem, AdjustX (x1), AdjustY (y1), NULL);
LineTo (display.hdcMem, AdjustX (x1), AdjustY (y2));
hpen = (HPEN) SelectObject (display.hdcMem, hpenOld);
DeleteObject (hpen);
}
}
// Queue update event
InvalidateRect (display.hWnd, &rect, FALSE);
}
void
Fgl_write (int x, int y, char *s)
{
#if defined (USE_WINDOWS_FONT)
// Select background and foreground colors
SetTextColor (display.hdcMem, GetPaletteColorref (text_fg));
SetBkColor (display.hdcMem, GetPaletteColorref (text_bg));
// Draw text to backing store
ExtTextOut (display.hdcMem, AdjustX (x), AdjustY (y), 0, NULL,
s, strlen (s), NULL);
// Calculate size of text
SIZE size;
GetTextExtentPoint32 (display.hdcMem, s, strlen (s), &size);
#endif
int i;
for (i = 0; i < (int) (strlen (s)); i++)
my_x_putchar (x + i * 8, y, s[i]);
// Queue update event
#if defined (USE_WINDOWS_FONT)
RECT rect;
rect.left = AdjustX (x);
rect.top = AdjustY (y);
rect.right = AdjustX (x + size.cx);
rect.bottom = AdjustY (y + size.cy);
InvalidateRect (display.hWnd, &rect, FALSE);
#else
RECT rect;
rect.left = AdjustX (x);
rect.top = AdjustY (y);
rect.right = AdjustX (x + i * 8);
rect.bottom = AdjustY (y + 8);
InvalidateRect (display.hWnd, &rect, FALSE);
#endif
}
void
open_write (int x, int y, char *s)
{
int i;
for (i = 0; i < (int) (strlen (s)); i++)
open_x_putchar (x + i * 8, y, s[i]);
// Queue update event
RECT rect;
rect.left = AdjustX (x);
rect.top = AdjustY (y);
rect.right = AdjustX (x + i * 8);
rect.bottom = AdjustY (y + open_font_height);
InvalidateRect (display.hWnd, &rect, FALSE);
}
void
my_x_putchar (int xx, int yy, int c)
{
int x, y, b;
#if defined (USE_WINDOWS_FONT)
int i;
#endif
for (y = 0; y < 8; y++)
{
b = myfont[c * 8 + y];
for (x = 0; x < 8; x++)
{
if ((b & 0x80) == 0)
{
#if defined (USE_WINDOWS_FONT)
// Draw to pixmap buffer
i = (yy + y + bordery) * (640 + BORDERX) + xx + x + borderx;
*(pixmap + i) = (unsigned char) text_bg;
#else
Fgl_setpixel (xx + x, yy + y, text_bg);
#endif
}
else
{
#if defined (USE_WINDOWS_FONT)
// Draw to pixmap buffer
i = (yy + y + bordery) * (640 + BORDERX) + xx + x + borderx;
*(pixmap + i) = (unsigned char) text_fg;
#else
Fgl_setpixel (xx + x, yy + y, text_fg);
#endif
}
b = b << 1;
}
}
}
void
open_x_putchar (int xx, int yy, int c)
{
int x, y, b;
for (y = 0; y < open_font_height; y++)
{
b = open_font[c * open_font_height + y];
for (x = 0; x < 8; x++)
{
if ((b & 0x80) == 0)
Fgl_setpixel (xx + x, yy + y, text_bg);
else
Fgl_setpixel (xx + x, yy + y, text_fg);
b = b << 1;
}
}
}
void
Fgl_fillbox (int x1, int y1, int w, int h, int col)
{
int x, y;
if (clipping_flag)
{
if (x1 < xclip_x1)
x1 = xclip_x1;
if (x1 + w > xclip_x2)
w = xclip_x2 - x1;
if (y1 < xclip_y1)
y1 = xclip_y1;
if (y1 + h > xclip_y2)
h = xclip_y2 - y1;
}
col &= 0xff;
// Draw to pixmap buffer
for (y = y1 + bordery; y < y1 + h + bordery; y++)
for (x = x1 + borderx; x < x1 + w + borderx; x++)
*(pixmap + y * (640 + BORDERX) + x) = col;
// Draw to DC
RECT rect;
if (display.useDIB)
{
HBITMAP hOldBitmapMem;
HBRUSH hbr, hbrOld;
rect.left = x1 + borderx;
rect.top = y1 + bordery;
rect.right = x1 + borderx + w;
rect.bottom = y1 + bordery + h;
hbr = GetPaletteBrush (col);
hbrOld = (HBRUSH) SelectObject (display.hdcMem, hbr);
hOldBitmapMem = (HBITMAP) SelectObject (display.hdcMem, display.hDIB);
FillRect (display.hdcMem, &rect, hbr);
display.hDIB = (HBITMAP) SelectObject (display.hdcMem, hOldBitmapMem);
hbr = (HBRUSH) SelectObject (display.hdcMem, hbrOld);
}
else
{
HBRUSH hbr, hbrOld;
rect.left = AdjustX (x1);
rect.top = AdjustY (y1);
rect.right = AdjustX (x1 + w);
rect.bottom = AdjustY (y1 + h);
hbr = GetPaletteBrush (col);
hbrOld = (HBRUSH) SelectObject (display.hdcMem, hbr);
FillRect (display.hdcMem, &rect, hbr);
hbr = (HBRUSH) SelectObject (display.hdcMem, hbrOld);
}
// Queue update event
InvalidateRect (display.hWnd, &rect, FALSE);
}
void
Fgl_putbox (int x1, int y1, int w, int h, void *buf)
{
unsigned char *b;
b = (unsigned char *) buf;
int x, y;
for (y = y1; y < y1 + h; y++)
for (x = x1; x < x1 + w; x++)
{
Fgl_setpixel (x, y, *(b++));
}
// Queue update event
RECT rect;
rect.left = AdjustX (x1);
rect.top = AdjustY (y1);
rect.right = AdjustX (x1 + w);
rect.bottom = AdjustY (y1 + h);
InvalidateRect (display.hWnd, &rect, FALSE);
// GCS: Don't update window here -- it causes farms to jump
// around when panning main screen
//UpdateWindow (display.hWnd);
}
void
Fgl_getbox (int x1, int y1, int w, int h, void *buf)
{
unsigned char *b;
b = (unsigned char *) buf;
int x, y;
for (y = y1; y < y1 + h; y++)
for (x = x1; x < x1 + w; x++)
*(b++) = (unsigned char) Fgl_getpixel (x, y);
}
void
RefreshScreen ()
{
InvalidateRect (display.hWnd, NULL, FALSE);
ProcessNextEvent ();
}
void
RefreshArea (int x1, int y1, int x2, int y2) // bounds of refresh area
{
RECT rect;
rect.left = AdjustX (x1);
rect.top = AdjustY (y1);
rect.right = AdjustX (x2);
rect.bottom = AdjustY (y2);
InvalidateRect (display.hWnd, &rect, FALSE);
UpdateWindow (display.hWnd);
}
void
SaveUnder (int x1, int y1, int w, int h, void *buf)
{
HBITMAP hBitmapOld;
HPALETTE hPalOld;
// Copy pixmap buf to caller's buf
unsigned char *b;
b = (unsigned char *) buf;
int x, y;
for (y = y1; y < y1 + h; y++)
for (x = x1; x < x1 + w; x++)
*(b++) = (unsigned char) Fgl_getpixel (x, y);
RECT rect;
rect.left = AdjustX (x1);
rect.top = AdjustY (y1);
rect.right = AdjustX (x1 + w);
rect.bottom = AdjustY (y1 + h);
int saveunder_width = rect.right - rect.left;
int saveunder_height = rect.bottom - rect.top;
assert (display.hSaveUnderHdc == 0);
assert (display.hSaveUnderBitmap == 0);
// Create HDC
display.hSaveUnderHdc = CreateCompatibleDC (display.hdcMem);
if (display.hasPalette)
{
hPalOld = SelectPalette (display.hSaveUnderHdc, (HPALETTE) display.hPal, FALSE);
RealizePalette (display.hSaveUnderHdc);
}
// Create and select bitmap
display.hSaveUnderBitmap = CreateCompatibleBitmap (display.hdcMem, saveunder_width, saveunder_height);
hBitmapOld = (HBITMAP) SelectObject (display.hSaveUnderHdc, display.hSaveUnderBitmap);
// Copy from backing store bitmap to save under bitmap
BitBlt (display.hSaveUnderHdc, 0, 0, saveunder_width, saveunder_height, display.hdcMem, rect.left, rect.top, SRCCOPY);
}
void
RestoreSaveUnder (int x1, int y1, int w, int h, void *buf)
{
// Copy pixmap buf to caller's buf
unsigned char *b;
b = (unsigned char *) buf;
int x, y;
for (y = y1; y < y1 + h; y++)
for (x = x1; x < x1 + w; x++)
{
// Draw to pixmap buffer
int i = (y + bordery) * (640 + BORDERX) + x + borderx;
*(pixmap + i) = (unsigned char) *(b++);
}
RECT rect;
rect.left = AdjustX (x1);
rect.top = AdjustY (y1);
rect.right = AdjustX (x1 + w);
rect.bottom = AdjustY (y1 + h);
int saveunder_width = rect.right - rect.left;
int saveunder_height = rect.bottom - rect.top;
assert (display.hSaveUnderHdc != 0);
assert (display.hSaveUnderBitmap != 0);
// Copy from backing store bitmap to save under bitmap
BitBlt (display.hdcMem, rect.left, rect.top, saveunder_width, saveunder_height, display.hSaveUnderHdc, 0, 0, SRCCOPY);
// Destroy Bitmap
DeleteObject (display.hSaveUnderBitmap);
display.hSaveUnderBitmap = 0;
// Destroy HDC
DeleteDC (display.hSaveUnderHdc);
display.hSaveUnderHdc = 0;
// Refresh Window
InvalidateRect (display.hWnd, &rect, FALSE);
UpdateWindow (display.hWnd);
}
void
Fgl_enableclipping (void)
{
clipping_flag = 1;
}
void
Fgl_setclippingwindow (int x1, int y1, int x2, int y2)
{
xclip_x1 = x1;
xclip_y1 = y1;
xclip_x2 = x2;
xclip_y2 = y2;
}
void
Fgl_disableclipping (void)
{
clipping_flag = 0;
}
void
do_call_event (int wait)
{
// Wait (if requested to do so)
if (wait)
lc_usleep (1000);
// Process mouse events
HandleMouse ();
}
void
call_event (void)
{
do_call_event (0);
}
void
call_wait_event (void)
{
do_call_event (1);
}
#ifdef USE_PIXMAPS
void
init_pixmaps ()
{
#if defined (WIN32)
for (int i = 1; i < NUM_OF_TYPES; i++)
{
icon_pixmap[i] = 0;
}
#endif
init_icon_pixmap (CST_GREEN);
// powerlines
init_icon_pixmap (CST_POWERL_H_L);
init_icon_pixmap (CST_POWERL_V_L);
init_icon_pixmap (CST_POWERL_LD_L);
init_icon_pixmap (CST_POWERL_RD_L);
init_icon_pixmap (CST_POWERL_LU_L);
init_icon_pixmap (CST_POWERL_RU_L);
init_icon_pixmap (CST_POWERL_LDU_L);
init_icon_pixmap (CST_POWERL_LDR_L);
init_icon_pixmap (CST_POWERL_LUR_L);
init_icon_pixmap (CST_POWERL_UDR_L);
init_icon_pixmap (CST_POWERL_LUDR_L);
prog_box ("", 6);
init_icon_pixmap (CST_POWERL_H_D);
init_icon_pixmap (CST_POWERL_V_D);
init_icon_pixmap (CST_POWERL_LD_D);
init_icon_pixmap (CST_POWERL_RD_D);
init_icon_pixmap (CST_POWERL_LU_D);
init_icon_pixmap (CST_POWERL_RU_D);
init_icon_pixmap (CST_POWERL_LDU_D);
init_icon_pixmap (CST_POWERL_LDR_D);
init_icon_pixmap (CST_POWERL_LUR_D);
init_icon_pixmap (CST_POWERL_UDR_D);
init_icon_pixmap (CST_POWERL_LUDR_D);
// HT windmills
init_icon_pixmap (CST_WINDMILL_1_G);
init_icon_pixmap (CST_WINDMILL_2_G);
init_icon_pixmap (CST_WINDMILL_3_G);
prog_box ("", 12);
init_icon_pixmap (CST_WINDMILL_1_RG);
init_icon_pixmap (CST_WINDMILL_2_RG);
init_icon_pixmap (CST_WINDMILL_3_RG);
init_icon_pixmap (CST_WINDMILL_1_R);
init_icon_pixmap (CST_WINDMILL_2_R);
init_icon_pixmap (CST_WINDMILL_3_R);
//LT windmills
init_icon_pixmap (CST_WINDMILL_1_W);
init_icon_pixmap (CST_WINDMILL_2_W);
init_icon_pixmap (CST_WINDMILL_3_W);
// communes
init_icon_pixmap (CST_COMMUNE_1);
init_icon_pixmap (CST_COMMUNE_2);
init_icon_pixmap (CST_COMMUNE_3);
init_icon_pixmap (CST_COMMUNE_4);
init_icon_pixmap (CST_COMMUNE_5);
prog_box ("", 18);
init_icon_pixmap (CST_COMMUNE_6);
init_icon_pixmap (CST_COMMUNE_7);
init_icon_pixmap (CST_COMMUNE_8);
init_icon_pixmap (CST_COMMUNE_9);
init_icon_pixmap (CST_COMMUNE_10);
init_icon_pixmap (CST_COMMUNE_11);
init_icon_pixmap (CST_COMMUNE_12);
init_icon_pixmap (CST_COMMUNE_13);
init_icon_pixmap (CST_COMMUNE_14);
// farms (3 7 11 and 15 are the only ones needed)
init_icon_pixmap (CST_FARM_O3);
init_icon_pixmap (CST_FARM_O7);
init_icon_pixmap (CST_FARM_O11);
init_icon_pixmap (CST_FARM_O15);
// Lt. Industry
prog_box ("", 24);
init_icon_pixmap (CST_INDUSTRY_L_C);
init_icon_pixmap (CST_INDUSTRY_L_Q1);
init_icon_pixmap (CST_INDUSTRY_L_Q2);
init_icon_pixmap (CST_INDUSTRY_L_Q3);
init_icon_pixmap (CST_INDUSTRY_L_Q4);
init_icon_pixmap (CST_INDUSTRY_L_L1);
init_icon_pixmap (CST_INDUSTRY_L_L2);
init_icon_pixmap (CST_INDUSTRY_L_L3);
init_icon_pixmap (CST_INDUSTRY_L_L4);
init_icon_pixmap (CST_INDUSTRY_L_M1);
init_icon_pixmap (CST_INDUSTRY_L_M2);
init_icon_pixmap (CST_INDUSTRY_L_M3);
init_icon_pixmap (CST_INDUSTRY_L_M4);
init_icon_pixmap (CST_INDUSTRY_L_H1);
init_icon_pixmap (CST_INDUSTRY_L_H2);
prog_box ("", 30);
init_icon_pixmap (CST_INDUSTRY_L_H3);
init_icon_pixmap (CST_INDUSTRY_L_H4);
// Hv. Industry
init_icon_pixmap (CST_INDUSTRY_H_C);
init_icon_pixmap (CST_INDUSTRY_H_L1);
init_icon_pixmap (CST_INDUSTRY_H_L2);
init_icon_pixmap (CST_INDUSTRY_H_L3);
init_icon_pixmap (CST_INDUSTRY_H_L4);
init_icon_pixmap (CST_INDUSTRY_H_L5);
init_icon_pixmap (CST_INDUSTRY_H_L6);
init_icon_pixmap (CST_INDUSTRY_H_L7);
init_icon_pixmap (CST_INDUSTRY_H_L8);
init_icon_pixmap (CST_INDUSTRY_H_M1);
init_icon_pixmap (CST_INDUSTRY_H_M2);
init_icon_pixmap (CST_INDUSTRY_H_M3);
init_icon_pixmap (CST_INDUSTRY_H_M4);
prog_box ("", 36);
init_icon_pixmap (CST_INDUSTRY_H_M5);
init_icon_pixmap (CST_INDUSTRY_H_M6);
init_icon_pixmap (CST_INDUSTRY_H_M7);
init_icon_pixmap (CST_INDUSTRY_H_M8);
init_icon_pixmap (CST_INDUSTRY_H_H1);
init_icon_pixmap (CST_INDUSTRY_H_H2);
init_icon_pixmap (CST_INDUSTRY_H_H3);
init_icon_pixmap (CST_INDUSTRY_H_H4);
init_icon_pixmap (CST_INDUSTRY_H_H5);
init_icon_pixmap (CST_INDUSTRY_H_H6);
init_icon_pixmap (CST_INDUSTRY_H_H7);
init_icon_pixmap (CST_INDUSTRY_H_H8);
// water
prog_box ("", 42);
init_icon_pixmap (CST_WATER);
init_icon_pixmap (CST_WATER_D);
init_icon_pixmap (CST_WATER_R);
init_icon_pixmap (CST_WATER_U);
init_icon_pixmap (CST_WATER_L);
init_icon_pixmap (CST_WATER_LR);
init_icon_pixmap (CST_WATER_UD);
init_icon_pixmap (CST_WATER_LD);
init_icon_pixmap (CST_WATER_RD);
init_icon_pixmap (CST_WATER_LU);
init_icon_pixmap (CST_WATER_UR);
init_icon_pixmap (CST_WATER_LUD);
init_icon_pixmap (CST_WATER_LRD);
init_icon_pixmap (CST_WATER_LUR);
init_icon_pixmap (CST_WATER_URD);
init_icon_pixmap (CST_WATER_LURD);
// tracks
init_icon_pixmap (CST_TRACK_LR);
prog_box ("", 48);
init_icon_pixmap (CST_TRACK_LU);
init_icon_pixmap (CST_TRACK_LD);
init_icon_pixmap (CST_TRACK_UD);
init_icon_pixmap (CST_TRACK_UR);
init_icon_pixmap (CST_TRACK_DR);
init_icon_pixmap (CST_TRACK_LUR);
init_icon_pixmap (CST_TRACK_LDR);
init_icon_pixmap (CST_TRACK_LUD);
init_icon_pixmap (CST_TRACK_UDR);
init_icon_pixmap (CST_TRACK_LUDR);
// roads
init_icon_pixmap (CST_ROAD_LR);
init_icon_pixmap (CST_ROAD_LU);
init_icon_pixmap (CST_ROAD_LD);
init_icon_pixmap (CST_ROAD_UD);
init_icon_pixmap (CST_ROAD_UR);
init_icon_pixmap (CST_ROAD_DR);
init_icon_pixmap (CST_ROAD_LUR);
init_icon_pixmap (CST_ROAD_LDR);
prog_box ("", 54);
init_icon_pixmap (CST_ROAD_LUD);
init_icon_pixmap (CST_ROAD_UDR);
init_icon_pixmap (CST_ROAD_LUDR);
// rail
init_icon_pixmap (CST_RAIL_LR);
init_icon_pixmap (CST_RAIL_LU);
init_icon_pixmap (CST_RAIL_LD);
init_icon_pixmap (CST_RAIL_UD);
init_icon_pixmap (CST_RAIL_UR);
init_icon_pixmap (CST_RAIL_DR);
init_icon_pixmap (CST_RAIL_LUR);
init_icon_pixmap (CST_RAIL_LDR);
init_icon_pixmap (CST_RAIL_LUD);
init_icon_pixmap (CST_RAIL_UDR);
init_icon_pixmap (CST_RAIL_LUDR);
// potteries
prog_box ("", 60);
init_icon_pixmap (CST_POTTERY_0);
init_icon_pixmap (CST_POTTERY_1);
init_icon_pixmap (CST_POTTERY_2);
init_icon_pixmap (CST_POTTERY_3);
init_icon_pixmap (CST_POTTERY_4);
init_icon_pixmap (CST_POTTERY_5);
init_icon_pixmap (CST_POTTERY_6);
init_icon_pixmap (CST_POTTERY_7);
init_icon_pixmap (CST_POTTERY_8);
init_icon_pixmap (CST_POTTERY_9);
init_icon_pixmap (CST_POTTERY_10);
// mills
init_icon_pixmap (CST_MILL_0);
init_icon_pixmap (CST_MILL_1);
init_icon_pixmap (CST_MILL_2);
init_icon_pixmap (CST_MILL_3);
init_icon_pixmap (CST_MILL_4);
prog_box ("", 66);
init_icon_pixmap (CST_MILL_5);
init_icon_pixmap (CST_MILL_6);
// blacksmiths
init_icon_pixmap (CST_BLACKSMITH_0);
init_icon_pixmap (CST_BLACKSMITH_1);
init_icon_pixmap (CST_BLACKSMITH_2);
init_icon_pixmap (CST_BLACKSMITH_3);
init_icon_pixmap (CST_BLACKSMITH_4);
init_icon_pixmap (CST_BLACKSMITH_5);
init_icon_pixmap (CST_BLACKSMITH_6);
// residences
init_icon_pixmap (CST_RESIDENCE_LL);
init_icon_pixmap (CST_RESIDENCE_ML);
init_icon_pixmap (CST_RESIDENCE_HL);
init_icon_pixmap (CST_RESIDENCE_LH);
init_icon_pixmap (CST_RESIDENCE_MH);
init_icon_pixmap (CST_RESIDENCE_HH);
// coal power
init_icon_pixmap (CST_POWERS_COAL_EMPTY);
init_icon_pixmap (CST_POWERS_COAL_LOW);
prog_box ("", 72);
init_icon_pixmap (CST_POWERS_COAL_MED);
init_icon_pixmap (CST_POWERS_COAL_FULL);
// substations
init_icon_pixmap (CST_SUBSTATION_R);
init_icon_pixmap (CST_SUBSTATION_G);
init_icon_pixmap (CST_SUBSTATION_RG);
// markets
init_icon_pixmap (CST_MARKET_EMPTY);
init_icon_pixmap (CST_MARKET_LOW);
init_icon_pixmap (CST_MARKET_MED);
init_icon_pixmap (CST_MARKET_FULL);
// coal mines
init_icon_pixmap (CST_COALMINE_EMPTY);
init_icon_pixmap (CST_COALMINE_LOW);
init_icon_pixmap (CST_COALMINE_MED);
init_icon_pixmap (CST_COALMINE_FULL);
// ore mines
prog_box ("", 78);
init_icon_pixmap (CST_OREMINE_1);
init_icon_pixmap (CST_OREMINE_2);
init_icon_pixmap (CST_OREMINE_3);
init_icon_pixmap (CST_OREMINE_4);
init_icon_pixmap (CST_OREMINE_5);
init_icon_pixmap (CST_OREMINE_6);
init_icon_pixmap (CST_OREMINE_7);
init_icon_pixmap (CST_OREMINE_8);
// tips
init_icon_pixmap (CST_TIP_0);
init_icon_pixmap (CST_TIP_1);
init_icon_pixmap (CST_TIP_2);
init_icon_pixmap (CST_TIP_3);
init_icon_pixmap (CST_TIP_4);
init_icon_pixmap (CST_TIP_5);
init_icon_pixmap (CST_TIP_6);
init_icon_pixmap (CST_TIP_7);
init_icon_pixmap (CST_TIP_8);
// rockets
prog_box ("", 84);
init_icon_pixmap (CST_ROCKET_1);
init_icon_pixmap (CST_ROCKET_2);
init_icon_pixmap (CST_ROCKET_3);
init_icon_pixmap (CST_ROCKET_4);
init_icon_pixmap (CST_ROCKET_5);
init_icon_pixmap (CST_ROCKET_6);
init_icon_pixmap (CST_ROCKET_7);
init_icon_pixmap (CST_ROCKET_FLOWN);
// fire stations
init_icon_pixmap (CST_FIRESTATION_1);
init_icon_pixmap (CST_FIRESTATION_2);
init_icon_pixmap (CST_FIRESTATION_3);
init_icon_pixmap (CST_FIRESTATION_4);
init_icon_pixmap (CST_FIRESTATION_5);
init_icon_pixmap (CST_FIRESTATION_6);
init_icon_pixmap (CST_FIRESTATION_7);
init_icon_pixmap (CST_FIRESTATION_8);
init_icon_pixmap (CST_FIRESTATION_9);
init_icon_pixmap (CST_FIRESTATION_10);
// cricket
prog_box ("", 90);
init_icon_pixmap (CST_CRICKET_1);
init_icon_pixmap (CST_CRICKET_2);
init_icon_pixmap (CST_CRICKET_3);
init_icon_pixmap (CST_CRICKET_4);
init_icon_pixmap (CST_CRICKET_5);
init_icon_pixmap (CST_CRICKET_6);
init_icon_pixmap (CST_CRICKET_7);
// fire
init_icon_pixmap (CST_FIRE_1);
init_icon_pixmap (CST_FIRE_2);
init_icon_pixmap (CST_FIRE_3);
init_icon_pixmap (CST_FIRE_4);
init_icon_pixmap (CST_FIRE_5);
init_icon_pixmap (CST_FIRE_DONE1);
init_icon_pixmap (CST_FIRE_DONE2);
init_icon_pixmap (CST_FIRE_DONE3);
init_icon_pixmap (CST_FIRE_DONE4);
// others
init_icon_pixmap (CST_PARKLAND_PLANE);
init_icon_pixmap (CST_RECYCLE);
init_icon_pixmap (CST_HEALTH);
init_icon_pixmap (CST_BURNT);
init_icon_pixmap (CST_MONUMENT_5);
init_icon_pixmap (CST_SCHOOL);
init_icon_pixmap (CST_SHANTY);
prog_box ("", 96);
init_icon_pixmap (CST_POWERS_SOLAR);
init_icon_pixmap (CST_UNIVERSITY);
init_icon_pixmap (CST_EX_PORT);
}
void
init_icon_pixmap (int type)
{
unsigned char *g;
int x, y;
HBITMAP hOldBitmapMem;
int w, h;
w = main_types[type].size * 16;
h = main_types[type].size * 16;
w <<= pix_double;
h <<= pix_double;
icon_pixmap[type] = CreateCompatibleBitmap (display.hdcMem, w, h);
hOldBitmapMem = (HBITMAP) SelectObject (display.hdcMem, icon_pixmap[type]);
// Copy bits to bitmap
g = (unsigned char *) main_types[type].graphic;
for (y = 0; y < main_types[type].size * 16; y++)
{
for (x = 0; x < main_types[type].size * 16; x++)
{
if (pix_double)
{
RECT rect;
HBRUSH hbr, hbrOld;
rect.left = x << 1;
rect.top = y << 1;
rect.right = (x + 1) << 1;
rect.bottom = (y + 1) << 1;
hbr = GetPaletteBrush (*g++);
hbrOld = (HBRUSH) SelectObject (display.hdcMem, hbr);
FillRect (display.hdcMem, &rect, hbr);
hbr = (HBRUSH) SelectObject (display.hdcMem, hbrOld);
}
else
{
SetPixel (display.hdcMem, x, y, GetPaletteColorref (*g++));
}
}
}
icon_pixmap[type] = (HBITMAP) SelectObject (display.hdcMem, hOldBitmapMem);
}
void
update_pixmap (int x1, int y1, int sizex, int sizey, int dx, int dy
,int real_size, char *g)
{
char *i, *j;
int x, y;
//printf("x1=%d y1=%d sizex=%d sizey=%d dx=%d dy=%d\n",x1,y1,sizex
//,sizey,dx,dy);
for (y = 0; y < sizey; y++)
{
i = (pixmap + ((dy + y + bordery) * (640 + BORDERX) + dx + borderx));
j = (g + ((y1 + y) * real_size * 16 + x1));
//printf("%p %p -> %p %p size=%d\n",pixmap,g,i,j,real_size);
for (x = 0; x < sizex; x++)
*(i++) = *(j++);
}
}
#endif
|