2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
29 grs_font
*gDPCFont
= NULL
;
30 IRes
*gDPCFontRes
= NULL
;
32 grs_font
*gDPCFontAA
= NULL
;
33 IRes
*gDPCFontAARes
= NULL
;
35 grs_font
*gDPCFontMono
= NULL
;
36 IRes
*gDPCFontMonoRes
= NULL
;
38 grs_font
*gDPCFontDimmed
= NULL
;
39 IRes
*gDPCFontDimmedRes
= NULL
;
41 grs_font
*gDPCFontBlue
= NULL
;
42 IRes
*gDPCFontBlueRes
= NULL
;
44 uint gDPCTextColor
= 0;
46 // For the DrawCursor methods:
47 static IRes
*gPendingHnd
= NULL
;
49 //--------------------------------------------------------------------------------------
50 void DPCUtilsInit(void)
53 IRes
*fontpal
= LoadPCX("fontpal");
54 AssertMsg(fontpal
, "Cannot find GUI font palette");
55 grs_bitmap
*fontpalbmp
= (grs_bitmap
*) fontpal
->Lock();
57 gDPCFontMonoRes
= pResMan
->Bind("mainfont",RESTYPE_FONT
, NULL
, "fonts\\");
58 if (gDPCFontMonoRes
!= NULL
)
60 gDPCFontMono
= (grs_font
*)gDPCFontMonoRes
->Lock();
63 //gDPCFontAA = gDPCFont;
64 //gDPCBoldFontAA = gDPCFont;
66 gDPCFontAARes
= pResMan
->Bind("mainaa",RESTYPE_FONT
, NULL
, "fonts\\");
67 if (gDPCFontAARes
!= NULL
)
69 gDPCFontAA
= (grs_font
*)gDPCFontAARes
->Lock();
70 AssertMsg(gDPCFontAA
, "Cannot lock mainaa font");
71 gDPCFontAA
->pal_id
= fontpalbmp
->align
;
74 gDPCFontDimmedRes
= pResMan
->Bind("Dimmed",RESTYPE_FONT
, NULL
, "fonts\\");
75 if (gDPCFontDimmedRes
!= NULL
)
77 gDPCFontDimmed
= (grs_font
*)gDPCFontDimmedRes
->Lock();
78 AssertMsg(gDPCFontDimmed
, "Cannot lock dimmed font");
79 gDPCFontDimmed
->pal_id
= fontpalbmp
->align
;
82 gDPCFontBlueRes
= pResMan
->Bind("BlueAA",RESTYPE_FONT
, NULL
, "fonts\\");
83 if (gDPCFontBlueRes
!= NULL
)
85 gDPCFontBlue
= (grs_font
*)gDPCFontBlueRes
->Lock();
86 AssertMsg(gDPCFontBlue
, "Cannot lock blue font");
87 gDPCFontBlue
->pal_id
= fontpalbmp
->align
;
90 // what is our default font?
91 gDPCFont
= gDPCFontAA
;
94 SafeFreeHnd(&fontpal
);
95 gPendingHnd
= LoadPCX("hourglas", DPC_INTERFACE_PATH
);
98 //--------------------------------------------------------------------------------------
99 void DPCUtilInitColor()
101 int color
[3] = {0,255,190}; // { 0, 255, 0};
102 gDPCTextColor
= FindColor(color
);
106 //--------------------------------------------------------------------------------------
107 void DPCUtilsTerm(void)
109 gDPCFontMonoRes
->Unlock();
110 gDPCFontMonoRes
->Release();
111 gDPCFontAARes
->Unlock();
112 gDPCFontAARes
->Release();
113 gDPCFontDimmedRes
->Unlock();
114 gDPCFontDimmedRes
->Release();
115 gDPCFontBlueRes
->Unlock();
116 gDPCFontBlueRes
->Release();
117 SafeFreeHnd(&gPendingHnd
);
120 //--------------------------------------------------------------------------------------
121 // Utility routine to load correct .PCX bitmap (based on current res).
122 // Ideally, in the long run, this should take an ISearchPath instead of
123 // the current char *path; it'll be more efficient.
125 // For the moment, this is doing a global Lock(), since we have a couple
126 // of DataPeeks around the system. If we can rid ourselves of the DataPeeks,
127 // then we can eliminate this Lock, and the Unlock in SafeFreeHnd.
129 // The returned resource should be freed with SafeFreeHnd().
130 //--------------------------------------------------------------------------------------
131 IRes
*LoadPCX(const char *name
, char *path
, eDPCLoadFlags flags
)
134 char hires[16], lores[16], name[16];
136 sscanf(str, "%s %s", hires, lores);
142 // We are not currently assuming that image files are .pcx. This is more
143 // flexible, but possibly slower. We should keep an eye on the time
145 // strcat(name, ".PCX");
148 IRes
*pRes
= pResMan
->Bind(name
, RESTYPE_IMAGE
, NULL
, path
);
153 // @NOTE: We are holding a permanent Lock on all images here (which is
154 // eventually Unlocked by SafeFreeHnd). This *may* want to go away later,
155 // but we need to think about the Palette ramifications...
156 grs_bitmap
*pbm
= (grs_bitmap
*) pRes
->Lock();
158 // Now that we have the Image, load the Palette as well.
159 // @TBD: We should create an ImageAndPalette resource type, which will
160 // load both of them at a shot, instead of having to do two disk hits.
161 if ((pbm
->align
== 0) && !(flags
& DPCLoadNoPalette
))
163 IRes
*pPallRes
= pResMan
->Retype(pRes
, RESTYPE_PALETTE
, 0);
166 uchar
*pPall
= (uchar
*) pPallRes
->Lock();
167 pbm
->align
= palmgr_alloc_pal(pPall
);
169 // keep it in memory, so don't drop it.
171 SafeRelease(pPallRes
);
178 //--------------------------------------------------------------------------------------
179 // Draw some art, specified by handle
180 //--------------------------------------------------------------------------------------
181 BOOL
DrawByHandle(IRes
*drawhand
, Point pt
)
183 if (drawhand
!= NULL
)
185 grs_bitmap
*bm
= (grs_bitmap
*) drawhand
->Lock();
186 gr_bitmap(bm
, pt
.x
, pt
.y
);
193 BOOL
DrawByHandleCenter(IRes
*drawhand
, Point pt
)
195 if (drawhand
!= NULL
)
197 grs_bitmap
*bm
= (grs_bitmap
*) drawhand
->Lock();
198 gr_bitmap(bm
, pt
.x
- (bm
->w
/ 2), pt
.y
- (bm
->h
/ 2));
205 BOOL
DrawByHandleCenterRotate(IRes
*drawhand
, Point pt
, fixang theta
)
207 if (drawhand
!= NULL
)
209 grs_bitmap
*bm
= (grs_bitmap
*) drawhand
->Lock();
210 gr_rotate_bitmap(bm
, theta
, fix_make(pt
.x
,0), fix_make(pt
.y
,0));
217 //--------------------------------------------------------------------------------------
218 // Similar to the above, but will do any additional manipulation appropriate
219 // for all cursors. At the moment, this just means that it will tack on the
220 // "pending" icon if a frob request is pending.
221 // This may be getting a little high-level for dpcutils; should we break
223 //--------------------------------------------------------------------------------------
224 BOOL
DrawCursorByHandle(IRes
*drawhand
, Point pt
)
226 if (drawhand
!= NULL
)
228 grs_bitmap
*bm
= (grs_bitmap
*) drawhand
->Lock();
229 gr_bitmap(bm
, pt
.x
, pt
.y
);
230 if (DPCFrobPending() && gPendingHnd
)
233 bm2
= (grs_bitmap
*) gPendingHnd
->Lock();
234 gr_bitmap(bm2
, pt
.x
+ bm
->w
, pt
.y
+ bm
->h
);
235 gPendingHnd
->Unlock();
243 BOOL
DrawCursorByHandleCenter(IRes
*drawhand
, Point pt
)
247 if (drawhand
!= NULL
)
249 bm
= (grs_bitmap
*) drawhand
->Lock();
250 dx
= pt
.x
- (bm
->w
/ 2);
251 dy
= pt
.y
- (bm
->h
/ 2);
252 gr_bitmap(bm
, dx
, dy
);
253 if (DPCFrobPending() && gPendingHnd
)
256 bm2
= (grs_bitmap
*) gPendingHnd
->Lock();
257 gr_bitmap(bm2
, pt
.x
+ (bm
->w
/ 2), pt
.y
+ (bm
->h
/ 2));
258 gPendingHnd
->Unlock();
262 // add in a stack count, potentially
263 if (DPC_cursor_mode
== SCM_DRAGOBJ
)
266 if (DPCObjGetQuantity(drag_obj
,temp
))
268 gr_set_fcolor(gDPCTextColor
);
269 gr_font_string(gDPCFontMono
, temp
, dx
+ 3 , dy
+ 3);
277 //--------------------------------------------------------------------------------------
278 // Free a IRes *, making sure not to free a NULL, and clearing the value afterwards
279 //--------------------------------------------------------------------------------------
280 void SafeFreeHnd(IRes
**hndPtr
)
285 (*hndPtr
)->Release();
290 //--------------------------------------------------------------------------------------
291 // Return the pixel value at x,y within the bitmap specified by the handle
292 //--------------------------------------------------------------------------------------
293 DWORD
HandleGetPix(IRes
*handle
, Point loc
)
299 bm
= (grs_bitmap
*) handle
->Lock();
300 if ((loc
.x
>= bm
->w
) || (loc
.y
>= bm
->h
) || (loc
.x
< 0) || (loc
.y
< 0))
303 retval
= gr_get_pixel_bm(bm
,loc
.x
,loc
.y
);
309 //--------------------------------------------------------------------------------------
310 // just does the mechanical UI elements, no state changes
311 IRes
*gCursorHnd
= NULL
;
312 extern IRes
*gDefaultHnd
;
316 gCursorHnd
= gDefaultHnd
;
319 //--------------------------------------------------------------------------------------
320 // Returns the cursor to it's default state
321 //--------------------------------------------------------------------------------------
322 // hmm, should this check to make sure that isn't going to pop down to nothing?
323 void ClearCursor(void)
325 if (DPC_cursor_mode
!= SCM_NORMAL
)
327 //mprintf("Clearing cursor\n");
330 DPC_cursor_mode
= SCM_NORMAL
;
335 //--------------------------------------------------------------------------------------
336 // Given a bitmap handle, makes that bitmap the current cursor
337 //--------------------------------------------------------------------------------------
338 // do we also want a grs_bitmap version of this?
339 bool SetCursorByHandle(IRes
*hnd
) // , Cursor *cursorp)
350 //--------------------------------------------------------------------------------------
351 // takes in a color triplet
352 int FindColor(int *color
)
354 // Lookup the correct color
356 for (int i
= 2; i
>= 0; i
--)
359 icol
|= color
[i
] & 0xFF;
361 return(gr_make_screen_fcolor(icol
));
363 //--------------------------------------------------------------------------------------
364 char *string_basepath
= "strings/";
365 BOOL
DPCStringFetch(char *temp
,int bufsize
, const char *name
, const char *table
,int offset
)
369 if (strlen(name
) == 0)
373 strcpy(usename
,name
);
375 sprintf(usename
,"%s%d",name
,offset
);
377 cAutoIPtr
<IRes
> res
= pResMan
->Bind(table
,
381 cAutoIPtr
<IStringRes
> strres (IID_IStringRes
,res
);
384 const char* s
= strres
->StringLock(usename
);
388 strncpy(temp
,s
,bufsize
);
389 strres
->StringUnlock(usename
);
398 //--------------------------------------------------------------------------------------
399 void DrawVerticalString(char *text
, int x
, int y
, int dy
)
408 gr_set_fcolor(gDPCTextColor
);
410 for (int j
=0; j
< strlen(text
); j
++)
413 //w = gr_font_string_width(gDPCFont, s);
414 gr_font_string(gDPCFont
, s
, drawpt
.x
, drawpt
.y
);
415 drawpt
.y
= drawpt
.y
+ dy
;
418 //--------------------------------------------------------------------------------------