1 /*
2 
3 Copyright (C) 2015-2018 Night Dive Studios, LLC.
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 /*
20  * $Source: r:/prj/cit/src/RCS/popups.c $
21  * $Revision: 1.9 $
22  * $Author: xemu $
23  * $Date: 1994/10/31 06:31:46 $
24  *
25  */
26 
27 #include <string.h>
28 //#include <TextUtils.h>
29 
30 #include "popups.h"
31 #include "citres.h"
32 #include "criterr.h"
33 #include "gamestrn.h"
34 
35 #include "gamescr.h"
36 #include "cybstrng.h"
37 #include "colors.h"
38 #include "cit2d.h"
39 #include "gr2ss.h"
40 
41 #include "curdat.h"
42 
43 #define BUF_SIZ 80
44 #define EMAIL_CURS_WID 40
45 #define EMAIL_CURS_MARG 5
46 #define EMAIL_CURS_FONT RES_tinyTechFont
47 
48 uchar popup_cursors = TRUE;
49 grs_bitmap popup_bitmaps[NUM_POPUPS];
50 LGRect popup_rects[NUM_POPUPS];
51 LGPoint popup_hotspots[NUM_POPUPS] = {
52     // in 0-16 dimension-independent units
53     {0, 8}, {16, 8}, {8, 16}, {0, 8}, {16, 8},
54 };
55 
56 #define CURSOR_TEXT_COLOR 0x36
57 
init_popups(void)58 void init_popups(void) {
59     for (int i = 0; i < NUM_POPUPS; i++) {
60         Ref id = MKREF(RES_popups, i);
61         FrameDesc *f = RefGet(id);
62         popup_rects[i] = f->anchorArea;
63         if (load_res_bitmap(&popup_bitmaps[i], id, TRUE) != OK)
64             critical_error(CRITERR_RES | 0xA);
65     }
66     ResUnlock(RES_popups);
67     ResDrop(RES_popups);
68 }
69 
make_popup_cursor(LGCursor * c,grs_bitmap * bm,char * s,uint tmplt,uchar allocate,LGPoint offset)70 void make_popup_cursor(LGCursor *c, grs_bitmap *bm, char *s, uint tmplt, uchar allocate, LGPoint offset) {
71     LGRect *r = &popup_rects[tmplt];
72     grs_bitmap *pbm = &popup_bitmaps[tmplt];
73     grs_canvas gc;
74     short x, y, w, h;
75     LGPoint p, ph;
76     uchar old_over = gr2ss_override;
77     uchar *bptr;
78     uchar *bits = bm->bits;
79     extern void ss_scale_string(char *s, short x, short y);
80 
81     MouseLock++;
82     *bm = *pbm;
83 
84     // CC - Convert this to be the right size for the screen mode
85     int sw, sh;
86     sw = SCONV_X(bm->w);
87     sh = SCONV_Y(bm->h);
88 
89     if (allocate) {
90         bptr = (uchar *)malloc(sw * sh * 2);
91         if (bptr == NULL)
92             critical_error(CRITERR_MEM | 4);
93     } else {
94         bptr = bits;
95     }
96     gr_init_bm(bm, bptr, BMT_FLAT8, BMF_TRANS, sw, sh);
97     gr_make_canvas(bm, &gc);
98     gr_push_canvas(&gc);
99 
100     gr_clear(0);
101     ss_bitmap(pbm, 0, 0);
102     gr_set_font(ResLock(RES_tinyTechFont));
103     gr_string_size(s, &w, &h);
104     // ss_point_convert(&w, &h, FALSE);
105 
106     x = (r->ul.x + r->lr.x - w) / 2 + offset.x + 1;
107     y = (r->ul.y + r->lr.y - h) / 2 + offset.y - 1;
108 
109     // ss_point_convert(&x, &y, TRUE);
110     gr_set_fcolor(CURSOR_TEXT_COLOR);
111     ss_string(s, x, y + 1);
112     ResUnlock(RES_tinyTechFont);
113     gr_pop_canvas();
114     ph = popup_hotspots[tmplt];
115     p.x = (bm->w * ph.x) >> 4;
116     p.y = (bm->h * ph.y) >> 4;
117     uiMakeBitmapCursor(c, bm, p);
118 
119     MouseLock--;
120 }
121 
load_string_array(Ref first,char * arry[],char buf[],int bufsz,int n)122 void load_string_array(Ref first, char *arry[], char buf[], int bufsz, int n) {
123     int off = 0;
124     int i;
125     for (i = 0; i < n; i++) {
126         short sz = bufsz - off;
127         get_string(first + i, buf + off, sz);
128         arry[i] = buf + off;
129         off += strlen(buf + off) + 1;
130     }
131 }
132 
133 #ifdef SVGA_SUPPORT
134 static char cursor_buf[4096];
135 #else
136 static char cursor_buf[512];
137 #endif
138 
make_email_cursor(LGCursor * c,grs_bitmap * bm,uchar page,bool init)139 void make_email_cursor(LGCursor *c, grs_bitmap *bm, uchar page, bool init) {
140     grs_canvas gc;
141     short x, y, w, h;
142     int len;
143     LGPoint p;
144     char s[BUF_SIZ];
145 #ifdef SVGA_SUPPORT
146     short temp;
147     uchar old_over = gr2ss_override;
148     gr2ss_override = OVERRIDE_ALL;
149     ss_set_hack_mode(2, &temp);
150 #endif
151 
152     gr_font_char_size(ResGet(EMAIL_CURS_FONT), 'X', &w, &h);
153     h += 2;
154     w = EMAIL_CURS_WID;
155 #ifdef SVGA_SUPPORT
156     ss_point_convert(&w, &h, FALSE);
157 #endif
158     if (init)
159         gr_init_bm(bm, NULL, BMT_FLAT8, BMF_TRANS, w, h);
160     sprintf(s, "%s %d", get_string(REF_STR_WordPage, NULL, BUF_SIZ), page);
161     MouseLock++;
162     if (sizeof(cursor_buf) < w * h)
163         critical_error(CRITERR_MEM | 7);
164     bm->bits = (uchar *)cursor_buf;
165     gr_make_canvas(bm, &gc);
166     gr_push_canvas(&gc);
167     gr_clear(0);
168     gr_set_font(ResLock(EMAIL_CURS_FONT));
169     gr_string_size("Page goof", &w, &h);
170     x = EMAIL_CURS_MARG;
171     y = 1;
172     gr_set_fcolor(CURSOR_TEXT_COLOR);
173     draw_shadowed_string(s, x, y, TRUE);
174     ResUnlock(RES_tinyTechFont);
175     gr_set_fcolor(BLACK + 1);
176     ss_vline(1, h / 2 - 1, h / 2 + 1);
177     ss_hline(0, h / 2, 2);
178     ss_set_pixel(CURSOR_TEXT_COLOR, 1, h / 2);
179     gr_pop_canvas();
180     p.x = 1;
181     p.y = h / 2;
182     uiMakeBitmapCursor(c, bm, p);
183     MouseLock--;
184 #ifdef SVGA_SUPPORT
185     ss_set_hack_mode(0, &temp);
186     gr2ss_override = old_over;
187 #endif
188 }
189