added worldarea -> will be responsible for world map rendering
[dboe.git] / graphutl.c
blobe83d90f197afa881e82d52e0d8bda8940caaff0c
1 #define xmin(a,b) ((a) < (b) ? (a) : (b))
3 #include <gtk/gtk.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include "global.h"
7 #include "text.h"
8 #include "string.h"
9 #include "exlsound.h"
11 #include "graphutl.h"
13 extern short ulx,uly;
14 //extern HBITMAP bw_bitmap,mixed_gworld,dialog_pattern_gworld,pattern_gworld,status_pattern_gworld;
15 extern char file_path_name[256];
17 Boolean pal_ok = FALSE;
18 Boolean syscolors_stored = FALSE;
19 // int elements[5] = {COLOR_ACTIVEBORDER,COLOR_ACTIVECAPTION,
20 // COLOR_WINDOWFRAME,COLOR_SCROLLBAR,COLOR_BTNFACE};
21 // COLORREF store_element_colors[5];
22 short dlog_pat_placed = 0;
23 short current_pattern = -1;
25 GdkPixmap * ReadDib(char * name) {
26 char real_name[256] = "", *name_ptr;
27 short i, last_slash = -1;
29 for (i = 0; i < 256; i++)
30 if ((file_path_name[i] == 92) || (file_path_name[i] == '/'))
31 last_slash = i;
32 if (last_slash < 0)
33 strcpy((char *) real_name,name);
34 else {
35 strcpy(real_name,file_path_name);
36 name_ptr = (char *) real_name;
37 name_ptr += last_slash + 1;
38 sprintf((char *) name_ptr,"%s",name);
39 //real_name -= last_slash + 1;
40 //ASB(real_name);
43 GError *err;
44 // gdk_pixbuf_new_from_file_at_scale
45 GdkPixbuf *pb = gdk_pixbuf_new_from_file(real_name, &err);
46 return gdk_pixmap_create_from_xpm(GDK_DRAWABLE(main_win), NULL, NULL, real_name);
49 // FIX transparency
50 void rect_draw_some_item(GdkPixmap * src, RECT src_rect, GdkPixmap * dest, RECT dest_rect, short trans, short main_win) {
51 // HBITMAP transbmp;
52 GdkColor white, black, x, oldcolor;
53 // COLORREF white = RGB(255,255,255),black = RGB(0,0,0),oldcolor,x = RGB(17,17,17);
54 RECT debug = {0,0,200,20};
55 UINT c;
56 // HBITMAP store,store2;
57 Boolean dlog_draw = FALSE;
58 gdk_color_parse("#FFFFFF", &white);
59 gdk_color_parse("#000000", &black);
60 gdk_color_parse("#A7A7A7", &x);
62 cairo_t *ctx = gdk_cairo_create(game);
63 gdk_cairo_set_source_pixmap(ctx, src, src_rect.left, src_rect.top);
64 cairo_paint(ctx);
65 cairo_destroy(ctx);
66 // gdk_cairo_set_source_pixbuf(ctx, src, src_rect.left, src_rect.top);
67 // StretchBlt(hdcMem2, dest_rect.left, dest_rect.top, dest_rect.right - dest_rect.left,
68 // dest_rect.bottom - dest_rect.top,
69 // hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
70 // src_rect.bottom - src_rect.top);
71 // }
75 void DisposeGWorld(HBITMAP bitmap) {
76 DeleteObject(bitmap);
79 void SectRect(RECT *a, RECT *b, RECT *c) {
80 IntersectRect(c,a,b);
83 // which_mode is 0 ... dest is a bitmap
84 // is 1 ... ignore dest ... paint on mainPtr
85 // is 2 ... dest is a dialog, use the dialog pattern
86 // both pattern gworlds are 192 x 256
87 void paint_pattern(HBITMAP dest,short which_mode,RECT dest_rect,short which_pattern)
89 HBITMAP source_pat;
90 RECT pattern_source = {32,168,96,232}, pat_dest_orig = {0,0,64,64},pat_dest;
91 short i,j;
93 RECT draw_from_orig = {0,0,192,256},draw_from,draw_to;
94 short store_ulx,store_uly;
96 if (which_mode == 2) {
97 source_pat = dialog_pattern_gworld;
98 if (dlog_pat_placed == 0) {
99 dlog_pat_placed = 1;
100 OffsetRect(&pattern_source, 64 * 2,0);
101 for (i = 0; i < 3; i++)
102 for (j = 0; j < 4; j++) {
103 pat_dest = pat_dest_orig;
104 OffsetRect(&pat_dest,64 * i, 64 * j);
105 rect_draw_some_item(mixed_gworld,pattern_source,
106 dialog_pattern_gworld,pat_dest,0,0);
110 else {
111 source_pat = pattern_gworld;
112 if (current_pattern != which_pattern) {
113 current_pattern = which_pattern;
114 OffsetRect(&pattern_source, 64 * (which_pattern % 5),
115 64 * (which_pattern / 5));
116 for (i = 0; i < 3; i++)
117 for (j = 0; j < 4; j++) {
118 pat_dest = pat_dest_orig;
119 OffsetRect(&pat_dest,64 * i, 64 * j);
120 rect_draw_some_item(mixed_gworld,pattern_source,
121 pattern_gworld,pat_dest,0,0);
126 // now patterns are loaded, so have fun
127 // first nullify ul shifting
128 store_ulx = ulx;
129 store_uly = uly;
130 ulx = uly = 0;
131 for (i = 0; i < (dest_rect.right / 192) + 1; i++)
132 for (j = 0; j < (dest_rect.bottom / 256) + 1; j++) {
133 draw_to = draw_from_orig;
134 OffsetRect(&draw_to,192 * i, 256 * j);
135 IntersectRect(&draw_to,&draw_to,&dest_rect);
136 if (draw_to.right != 0) {
137 draw_from = draw_to;
138 OffsetRect(&draw_from, -192 * i, -256 * j);
139 switch (which_mode) {
140 case 0:
141 rect_draw_some_item(source_pat,draw_from,
142 dest,draw_to,0,0); break;
143 case 1:
144 rect_draw_some_item(source_pat,draw_from,
145 source_pat,draw_to,0,1); break;
146 case 2:
147 rect_draw_some_item(source_pat,draw_from,
148 dest,draw_to,0,2); break;
152 ulx = store_ulx;
153 uly = store_uly;
156 HBITMAP load_pict(short pict_num,HDC model_hdc) {
157 HBITMAP got_bitmap;
159 switch(pict_num) {
160 case 700: case 701: case 702: got_bitmap = ReadDib("blscened/STATAREA.BMP",model_hdc); break;
161 case 703: got_bitmap = ReadDib("blscened/TEXTBAR.BMP",model_hdc); break;
162 case 704: got_bitmap = ReadDib("blscened/BUTTONS.BMP",model_hdc); break;
163 case 705: got_bitmap = ReadDib("blscened/TERSCRN.BMP",model_hdc); break;
164 case 800: got_bitmap = ReadDib("blscened/TER1.BMP",model_hdc); break;
165 case 801: got_bitmap = ReadDib("blscened/TER2.BMP",model_hdc); break;
166 case 802: got_bitmap = ReadDib("blscened/TER3.BMP",model_hdc); break;
167 case 803: got_bitmap = ReadDib("blscened/TER4.BMP",model_hdc); break;
168 case 804: got_bitmap = ReadDib("blscened/TER5.BMP",model_hdc); break;
169 case 805: got_bitmap = ReadDib("blscened/TER6.BMP",model_hdc); break;
170 case 820: got_bitmap = ReadDib("blscened/TERANIM.BMP",model_hdc); break;
171 case 821: got_bitmap = ReadDib("blscened/FIELDS.BMP",model_hdc); break;
172 case 830: got_bitmap = ReadDib("blscened/STARTUP.BMP",model_hdc); break;
173 case 831: got_bitmap = ReadDib("blscened/STANIM.BMP",model_hdc); break;
174 case 832: got_bitmap = ReadDib("blscened/STARTBUT.BMP",model_hdc); break;
175 case 850: got_bitmap = ReadDib("blscened/DLOGPICS.BMP",model_hdc); break;
176 case 851: got_bitmap = ReadDib("blscened/SCENPICS.BMP",model_hdc); break;
177 case 860: got_bitmap = ReadDib("blscened/TALKPORT.BMP",model_hdc); break;
178 case 875: got_bitmap = ReadDib("blscened/DLOGMAPS.BMP",model_hdc); break;
179 case 880: got_bitmap = ReadDib("blscened/MISSILES.BMP",model_hdc); break;
180 case 900: got_bitmap = ReadDib("blscened/TINYOBJ.BMP",model_hdc); break;
181 case 901: got_bitmap = ReadDib("blscened/OBJECTS.BMP",model_hdc); break;
182 case 902: got_bitmap = ReadDib("blscened/PCS.BMP",model_hdc); break;
183 case 905: got_bitmap = ReadDib("blscened/PCS.BMP",model_hdc); break;
184 case 903: case 904: got_bitmap = ReadDib("blscened/MIXED.BMP",model_hdc); break;
185 // case 903: case 904: got_bitmap = ReadDib("blscened/blscened\MIXED.BMP",model_hdc); break;
186 case 910: case 911: case 912: got_bitmap = ReadDib("blscened/BIGSCEN.BMP",model_hdc); break;
187 case 1100: case 1200: got_bitmap = ReadDib("blscened/MONST1.BMP",model_hdc); break;
188 case 1101: case 1201: got_bitmap = ReadDib("blscened/MONST2.BMP",model_hdc); break;
189 case 1102: case 1202: got_bitmap = ReadDib("blscened/MONST3.BMP",model_hdc); break;
190 case 1103: case 1203: got_bitmap = ReadDib("blscened/MONST4.BMP",model_hdc); break;
191 case 1104: case 1204: got_bitmap = ReadDib("blscened/MONST5.BMP",model_hdc); break;
192 case 1105: case 1205: got_bitmap = ReadDib("blscened/MONST6.BMP",model_hdc); break;
193 case 1106: case 1206: got_bitmap = ReadDib("blscened/MONST7.BMP",model_hdc); break;
194 case 1107: case 1207: got_bitmap = ReadDib("blscened/MONST8.BMP",model_hdc); break;
195 case 1108: case 1208: got_bitmap = ReadDib("blscened/MONST9.BMP",model_hdc); break;
196 case 1109: case 1209: got_bitmap = ReadDib("blscened/MONST10.BMP",model_hdc); break;
197 case 1400: got_bitmap = ReadDib("blscened/STSCICON.BMP",model_hdc); break;
198 case 1401: got_bitmap = ReadDib("blscened/HELPPICS.BMP",model_hdc); break;
199 case 1402: got_bitmap = ReadDib("blscened/APPIC.BMP",model_hdc); break;
200 case 1500: case 1501: case 1502: case 1503: case 1504: case 1505: case 1506: case 1507:
201 got_bitmap = ReadDib("blscened/BIGMAPS.BMP",model_hdc); break;
202 case 2000: got_bitmap = ReadDib("blscened/DLOGBTNS.BMP",model_hdc); break;
203 case 3000: got_bitmap = ReadDib("blscened/START.BMP",model_hdc); break;
204 case 3001: got_bitmap = ReadDib("blscened/SPIDLOGO.BMP",model_hdc); break;
206 default: got_bitmap = NULL;
208 return got_bitmap;