-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen.c
314 lines (265 loc) · 9.84 KB
/
screen.c
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
/* screen management
*
* Copyright 1996-©2008 pinc Software. All Rights Reserved.
* Licensed under the terms of the GNU General Public License, version 3.
*/
#include "types.h"
#include "funcs.h"
#include "version.h"
void
FreeArrows(void)
{
DisposeObject((Object *)upImg);
DisposeObject((Object *)downImg);
DisposeObject((Object *)rightImg);
DisposeObject((Object *)leftImg);
}
bool
AllocArrows(void)
{
if ((rightImg = (struct Image *)NewObject(NULL, "sysiclass", SYSIA_Which, RIGHTIMAGE, SYSIA_DrawInfo, dri, TAG_END)) != 0) {
if ((leftImg = (struct Image *)NewObject(NULL, "sysiclass", SYSIA_Which, LEFTIMAGE, SYSIA_DrawInfo, dri, TAG_END)) != 0) {
if ((upImg = (struct Image *)NewObject(NULL, "sysiclass", SYSIA_Which, UPIMAGE, SYSIA_DrawInfo, dri, TAG_END)) != 0) {
if ((downImg = (struct Image *)NewObject(NULL, "sysiclass", SYSIA_Which, DOWNIMAGE, SYSIA_DrawInfo, dri, TAG_END)) != 0)
return true;
DisposeObject((Object *)upImg);
}
DisposeObject((Object *)leftImg);
}
DisposeObject((Object *)rightImg);
}
return false;
}
void
ChangeAppScreen(bool closescreen)
{
struct MinList list;
struct saveWin *sw;
// Save all additional window data
MyNewList(&list);
while ((win = GetAppWindow(WDT_ANY)) != 0) {
if ((sw = AllocPooled(pool, sizeof(struct saveWin))) != 0) {
sw->sw_Type = ((struct winData *)win->UserData)->wd_Type;
sw->sw_Left = win->LeftEdge;
sw->sw_Top = win->TopEdge;
sw->sw_Width = win->Width;
sw->sw_Height = win->Height;
if (sw->sw_Type == WDT_PROJECT)
sw->sw_WinData = ((struct winData *)win->UserData)->wd_Data;
else {
sw->sw_Title = win->Title;
if ((sw->sw_WinData = AllocPooled(pool,sizeof(struct winData))) != 0)
CopyMem(win->UserData,sw->sw_WinData,sizeof(struct winData));
MyNewList(&sw->sw_WinData->wd_Objs);
}
MyAddTail(&list, sw);
}
CloseAppWindow(win, FALSE);
}
if (closescreen) {
CloseAppScreen(scr);
scr = NULL;
}
if (!closescreen || (scr = OpenAppScreen())) {
while ((sw = (struct saveWin *)MyRemTail(&list)) != 0) {
if (sw->sw_Type == WDT_PROJECT) {
OpenProjWindow((struct Page *)sw->sw_WinData,WA_Left, sw->sw_Left,
WA_Top, sw->sw_Top,
WA_Width, sw->sw_Width,
WA_Height,sw->sw_Height,
TAG_END);
} else {
OpenAppWindow(sw->sw_Type,WA_Left, sw->sw_Left,
WA_Top, sw->sw_Top,
WA_Width, sw->sw_Width,
WA_Height, sw->sw_Height,
WA_WinData,sw->sw_WinData,
TAG_END);
}
FreePooled(pool, sw, sizeof(struct saveWin));
}
}
gScreenHasChanged = true;
}
void
RefreshItemSize(void)
{
struct PrefIcon pi;
struct Mappe *mp;
pi.pi_Width = pi.pi_Height = 0;
RefreshIconSizeFromList(&pi, &prefs.pr_AppCmds, false);
foreach (&gProjects, mp) {
RefreshIconSizeFromList(&pi, &mp->mp_Prefs.pr_AppCmds, false);
}
itemheight = max(pi.pi_Height + 2, fontheight + 2);
itemwidth = pi.pi_Width - 2;
}
void
CloseAppScreen(struct Screen *scr)
{
if (!scr)
return;
gRemoveObjectsFromScreen(NULL, scr);
FreeDoubleBufferBitMap();
FreeArrows();
FreeImages();
RefreshImageObjs(NULL);
FreeVisualInfo(vi);
FreeScreenDrawInfo(scr, dri);
if (gAmigaGuide) {
CloseAmigaGuide(gAmigaGuide);
gAmigaGuide = NULL;
}
ReleasePen(scr->ViewPort.ColorMap, (LONG)treeHook.h_Data);
if (scr->UserData == (APTR)iport) {
// this is our own screen
// wait until the screen can be closed
while (!CloseScreen(scr)) {
Wait(1L << SIGBREAKB_CTRL_C);
}
/* // wait for half a second if the screen couldn't be closed
while (!CloseScreen(scr))
Delay(25);*/
} else {
ReleaseAppColors(scr);
UnlockPubScreen(NULL, scr);
}
}
void
InitAppScreen(struct Screen *scr)
{
fontheight = barheight = scr->Font->ta_YSize;
barheight += scr->WBorTop + 1;
linelen = TLn("_");
lborder = scr->WBorLeft + 4;
bborder = scr->WBorBottom;
rborder = scr->WBorRight + 4;
vi = GetVisualInfo(scr, TAG_END);
}
struct Screen *
OpenAppScreen(void)
{
struct Screen *scr = NULL;
long depth;
struct Rectangle dims;
#ifdef __amigaos4__
ULONG dispid;
#endif
switch (prefs.pr_Screen->ps_Type) {
case PST_OWN:
if ((scr = OpenScreenTags(NULL,SA_LikeWorkbench, TRUE,
SA_PubName, pubname,
SA_Title, SCREEN_TITLE,
#ifndef __amigaos4__
SA_Interleaved, TRUE,
SA_Colors32, standardPalette,
#endif
SA_Font, &prefs.pr_Screen->ps_TextAttr,
SA_DisplayID, prefs.pr_Screen->ps_ModeID,
SA_Width, prefs.pr_Screen->ps_Width,
SA_Height, prefs.pr_Screen->ps_Height,
SA_Depth, prefs.pr_Screen->ps_Depth,
#ifndef __amigaos4__
SA_BackFill, prefs.pr_Screen->ps_BackFill ? &fillHook : NULL,
#endif
SA_PubTask, FindTask(NULL),
SA_PubSig, SIGBREAKB_CTRL_C,
TAG_END)) != 0)
scr->UserData = (APTR)iport;
break;
case PST_LIKEWB:
if ((scr = LockPubScreen("Workbench")) != 0) {
// if the depth of the Workbench screen is lower than 3 (fewer than 8 colours),
// we will set our amount of colours to a minimum of 8 colours.
if ((depth = scr->RastPort.BitMap->Depth) < 3)
depth = 3;
#ifdef __amigaos4__
dispid = GetVPModeID(&scr->ViewPort);
#endif
UnlockPubScreen(NULL, scr);
}
if ((scr = OpenScreenTags(NULL,SA_LikeWorkbench, TRUE,
#ifdef __amigaos4__
SA_DisplayID, dispid,
#endif
SA_PubName, pubname,
SA_Title, SCREEN_TITLE,
#ifndef __amigaos4__
SA_Interleaved, TRUE,
SA_Colors32, standardPalette,
#endif
SA_Depth, depth,
#ifndef __amigaos4__
SA_BackFill, prefs.pr_Screen->ps_BackFill ? &fillHook : NULL,
#endif
SA_PubTask, FindTask(NULL),
SA_PubSig, SIGBREAKB_CTRL_C,
TAG_END)) != 0)
scr->UserData = (APTR)iport;
break;
case PST_PUBLIC:
scr = LockPubScreen(prefs.pr_Screen->ps_PubName);
break;
}
if (!scr) {
ErrorRequest(GetString(&gLocaleInfo, MSG_OPEN_SCREEN_ERR));
scr = LockPubScreen(NULL);
}
ScreenToFront(scr);
if (scr) {
ULONG xdpi, ydpi;
if (scr->UserData == (APTR)iport) {
// reserve the first 8 screen colors
PubScreenStatus(scr, 0);
for (depth = 0; depth < 8; depth++) {
ObtainPen(scr->ViewPort.ColorMap, depth, 0, 0, 0, /*PEN_EXCLUSIVE |*/ PEN_NO_SETCOLOR);
//for (depth = 0; depth < 8; depth++) {
//ObtainPen(scr->ViewPort.ColorMap, depth, standardPalette[depth * 3 + 1], standardPalette[depth * 3 + 2], standardPalette[depth * 3 + 3], PEN_EXCLUSIVE | PEN_NO_SETCOLOR);
}
}
ObtainAppColors(scr,TRUE);
MakeTmpRas(scr->Width, scr->Height);
RefreshImageObjs(scr);
treeHook.h_Data = (APTR)ObtainBestPen(scr->ViewPort.ColorMap, 0x44444444, 0x44444444, 0x44444444,
OBP_Precision, PRECISION_GUI, TAG_END);
InitAppScreen(scr);
RefreshItemSize();
itext.ITextFont = scr->Font;
{
struct Mappe *mp;
RefreshContextMenus(&prefs);
foreach (&gProjects, mp) {
RefreshContextMenus(&mp->mp_Prefs);
}
}
dri = GetScreenDrawInfo(scr);
boxwidth = max((fontheight + 5) * dri->dri_Resolution.Y / dri->dri_Resolution.X, 9);
if (!(boxwidth % 2))
boxwidth++;
wd_StatusWidth = TLn(GetString(&gLocaleInfo, MSG_INTERACTIVE_STATUS))+8;
wd_PosWidth = TLn("AAA999:AAA999")+42;
prefs.pr_Screen->ps_dimWidth = scr->Width;
prefs.pr_Screen->ps_dimHeight = scr->Height;
if (QueryOverscan(GetVPModeID(&scr->ViewPort), &dims, OSCAN_TEXT)) {
prefs.pr_Screen->ps_dimWidth = dims.MaxX + 1 - dims.MinX;
prefs.pr_Screen->ps_dimHeight = dims.MaxY + 1 - dims.MinY;
}
xdpi = ((LONG)prefs.pr_Screen->ps_dimWidth * (LONG)(25.4*1024)/prefs.pr_Screen->ps_mmWidth);
ydpi = ((LONG)prefs.pr_Screen->ps_dimHeight * (LONG)(25.4*1024)/prefs.pr_Screen->ps_mmHeight);
gDPI = (xdpi << 16) | ydpi;
if (prefs.pr_Screen->ps_BackFill) {
scrRp = scr->RastPort;
scrRp.Layer = NULL; SetAPen(&scrRp, prefs.pr_Screen->ps_BFColor);
scrRp.AreaPtrn = (short *)&dithPtrn; scrRp.AreaPtSz = 1;
if (scr->UserData == (APTR)iport)
RectFill(&scrRp, 0, scr->BarHeight + 1, scr->Width - 1, scr->Height - 1);
}
LayoutMenus(prefs.pr_Menu, vi, GTMN_NewLookMenus, TRUE, TAG_END);
AllocImages(scr);
AllocArrows();
InitHelp(scr);
AllocDoubleBufferBitMap(scr);
gAddObjectsToScreen(NULL, scr);
}
return scr;
}