-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbitmap_selector.c
More file actions
346 lines (298 loc) · 9.62 KB
/
bitmap_selector.c
File metadata and controls
346 lines (298 loc) · 9.62 KB
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
/******************************************************************************
* BitmapSelector *
******************************************************************************/
///Defines
#define MUIM_BitmapSelector_Close 0x80430D00
#define MUIM_BitmapSelector_Update 0x80430D01
#define MUIM_BitmapSelector_CheckValidity 0x80430D02
#define CLOSE_BY_GADGET 0
#define CLOSE_BY_SELECT 1
#define CLOSE_BY_CANCEL 2
///
///Includes
//standard headers
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include <proto/exec.h>
#include <proto/utility.h> // <-- Required for tag redirection
#include <libraries/mui.h>
#include <proto/muimaster.h>
#include <clib/alib_protos.h> // <-- Required for DoSuperMethod()
#include <SDI_compiler.h> // Required for
#include <SDI_hook.h> // <-- multi platform
#include <SDI_stdarg.h> // compatibility
#include "dosupernew.h"
#include "utility.h"
#include "popasl_string.h"
#include "bitmap_selector.h"
///
///Structs
struct cl_ObjTable
{
Object* file;
Object* chk_displayable;
Object* chk_interleaved;
Object* btn_select;
Object* btn_cancel;
};
struct cl_Data
{
struct cl_ObjTable obj_table;
//<SUBCLASS VARIABLES HERE>
STRPTR bitmap_string;
};
struct close_Msg
{
ULONG MethodID;
ULONG close_by;
};
struct cl_Msg
{
ULONG MethodID;
//<SUBCLASS METHOD MESSAGE PAYLOAD HERE>
};
///
///Globals
extern APTR g_MemoryPool;
extern struct FileRequester* g_FileReq;
extern struct MUI_CustomClass* MUIC_PopASLString;
extern struct Project {
STRPTR directory;
STRPTR settings_header;
STRPTR assets_header;
STRPTR palettes_header;
STRPTR data_drawer;
STRPTR assets_drawer;
ULONG screen_depth;
}g_Project;
static struct {
STRPTR file;
STRPTR displayable;
STRPTR interleaved;
STRPTR select;
STRPTR cancel;
}help_string = {
"The ILBM file to be loaded with this level.",
"The bitmap for the ILBM file loaded\nwill be allocated in Chip RAM.",
"The bitmap for the ILBM file loaded\nwill be an interleaved bitmap.",
"Add the selected ILBM file to the level\nand close this window.",
"Close this window."
};
///
///prepBitmapString(data)
STRPTR prepBitmapString(struct cl_Data *data)
{
STRPTR bitmap_string = NULL;
STRPTR options = "[NN]";
STRPTR file;
ULONG displayable;
ULONG interleaved;
get(data->obj_table.file, MUIA_String_Contents, &file);
get(data->obj_table.chk_displayable, MUIA_Selected, &displayable);
get(data->obj_table.chk_interleaved, MUIA_Selected, &interleaved);
if (file && strlen(file)) {
if (displayable) options[1] = 'D';
else options[1] = 'N';
if (interleaved) options[2] = 'I';
else options[2] = 'N';
bitmap_string = makeString2(options, file);
}
return bitmap_string;
}
///
//<DEFINE SUBCLASS METHODS HERE>
///m_CheckValidity()
STATIC ULONG m_CheckValidity(struct IClass* cl, Object* obj, Msg msg)
{
struct cl_Data *data = INST_DATA(cl, obj);
STRPTR file;
ULONG disable = FALSE;
get(data->obj_table.file, MUIA_String_Contents, &file);
if (file && strlen(file)) {
ULONG data_drawer_len = strlen(g_Project.data_drawer);
if (!strncmp(file, g_Project.data_drawer, data_drawer_len)) {
file += data_drawer_len;
DoMethod(data->obj_table.file, MUIM_Set, MUIA_String_Contents, (ULONG)file);
if (!*file) disable = TRUE;
}
}
else disable = TRUE;
DoMethod(data->obj_table.btn_select, MUIM_Set, MUIA_Disabled, disable);
return 0;
}
///
///m_Close(close_by)
static ULONG m_Close(struct IClass* cl, Object* obj, struct close_Msg* msg)
{
struct cl_Data *data = INST_DATA(cl, obj);
switch (msg->close_by) {
case CLOSE_BY_SELECT:
freeString(data->bitmap_string);
if ((data->bitmap_string = prepBitmapString(data))) {
DoMethod(obj, MUIM_Set, MUIA_BitmapSelector_Selected, (ULONG)data->bitmap_string);
}
case CLOSE_BY_GADGET:
case CLOSE_BY_CANCEL:
DoMethod(obj, MUIM_Set, MUIA_Window_Open, FALSE);
break;
}
DoMethod(data->obj_table.file, MUIM_Set, MUIA_String_Contents, (ULONG)"");
return 0;
}
///
///Overridden OM_NEW
static ULONG m_New(struct IClass* cl, Object* obj, struct opSet* msg)
{
struct cl_Data *data;
struct {
Object* file;
Object* str_file;
Object* pop_file;
Object* chk_displayable;
Object* chk_interleaved;
Object* btn_select;
Object* btn_cancel;
}objects;
if ((obj = (Object *) DoSuperNew(cl, obj,
MUIA_Window_ID, MAKE_ID('S','V','G','D'),
MUIA_Window_Title, "Select ILBM File",
MUIA_Window_RootObject, MUI_NewObject(MUIC_Group,
MUIA_Group_Child, MUI_NewObject(MUIC_Group,
MUIA_Group_Horiz, TRUE,
MUIA_Group_Child, MUI_NewObject(MUIC_Text, MUIA_Text_Contents, "File:", MUIA_HorizWeight, 0, MUIA_ShortHelp, help_string.file, TAG_END),
MUIA_Group_Child, (objects.file = NewObject(MUIC_PopASLString->mcc_Class, NULL,
MUIA_PopASLString_Requester, g_FileReq,
MUIA_PopASLString_IgnoreContents, TRUE,
MUIA_ShortHelp, help_string.file,
MUIA_Image_Spec, MUII_PopFile,
ASLFR_TitleText, "Select an ILBM file",
ASLFR_PositiveText, "Select",
ASLFR_DoSaveMode, FALSE,
ASLFR_DrawersOnly, FALSE,
ASLFR_DoPatterns, TRUE,
ASLFR_InitialPattern, "#?.(iff|ilbm)",
TAG_END)),
TAG_END),
MUIA_Group_Child, MUI_NewCheckMark(&objects.chk_displayable, FALSE, "Displayable", 'd', help_string.displayable),
MUIA_Group_Child, MUI_NewCheckMark(&objects.chk_interleaved, FALSE, "Interleaved", 'i', help_string.interleaved),
MUIA_Group_Child, MUI_NewObject(MUIC_Group,
MUIA_Group_Horiz, TRUE,
MUIA_Group_Child, (objects.btn_select = MUI_NewButton("Select", 's', help_string.select)),
MUIA_Group_Child, (objects.btn_cancel = MUI_NewButton("Cancel", 'c', help_string.cancel)),
TAG_END),
TAG_END),
//<SUPERCLASS TAGS HERE>
TAG_MORE, msg->ops_AttrList)))
{
data = (struct cl_Data *) INST_DATA(cl, obj);
get(objects.file, MUIA_PopASLString_StringObject, &objects.str_file);
get(objects.file, MUIA_PopASLString_PopButton, &objects.pop_file);
DoMethod(obj, MUIM_Window_SetCycleChain, objects.str_file,
objects.pop_file,
objects.chk_displayable,
objects.chk_interleaved,
objects.btn_select,
objects.btn_cancel,
NULL);
DoMethod(obj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, obj, 2,
MUIM_BitmapSelector_Close, CLOSE_BY_GADGET);
DoMethod(objects.btn_select, MUIM_Notify, MUIA_Pressed, FALSE, obj, 2,
MUIM_BitmapSelector_Close, CLOSE_BY_SELECT);
DoMethod(objects.btn_cancel, MUIM_Notify, MUIA_Pressed, FALSE, obj, 2,
MUIM_BitmapSelector_Close, CLOSE_BY_CANCEL);
DoMethod(objects.file, MUIM_Notify, MUIA_String_Contents, MUIV_EveryTime, obj, 1,
MUIM_BitmapSelector_CheckValidity);
DoMethod(objects.btn_select, MUIM_Set, MUIA_Disabled, TRUE);
data->bitmap_string = NULL;
data->obj_table.file = objects.file;
data->obj_table.chk_displayable = objects.chk_displayable;
data->obj_table.chk_interleaved = objects.chk_interleaved;
data->obj_table.btn_select = objects.btn_select;
data->obj_table.btn_cancel = objects.btn_cancel;
//<SUBCLASS INITIALIZATION HERE>
if (/*<Success of your initializations>*/ TRUE) {
return((ULONG) obj);
}
else CoerceMethod(cl, obj, OM_DISPOSE);
}
return (ULONG) NULL;
}
///
///Overridden OM_DISPOSE
static ULONG m_Dispose(struct IClass* cl, Object* obj, Msg msg)
{
struct cl_Data *data = INST_DATA(cl, obj);
//<FREE SUBCLASS INITIALIZATIONS HERE>
freeString(data->bitmap_string);
return DoSuperMethodA(cl, obj, msg);
}
///
///Overridden OM_SET
//*****************
static ULONG m_Set(struct IClass* cl, Object* obj, struct opSet* msg)
{
struct cl_Data *data = INST_DATA(cl, obj);
struct TagItem *tags, *tag;
for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags));)
{
switch (tag->ti_Tag)
{
case MUIA_BitmapSelector_DataDrawer:
DoMethod(data->obj_table.file, MUIM_Set, ASLFR_InitialDrawer, tag->ti_Data);
break;
}
}
return (DoSuperMethodA(cl, obj, (Msg) msg));
}
///
///Overridden OM_GET
//*****************
static ULONG m_Get(struct IClass* cl, Object* obj, struct opGet* msg)
{
//struct cl_Data *data = INST_DATA(cl, obj);
switch (msg->opg_AttrID)
{
//<SUBCLASS ATTRIBUTES HERE>
/*
case MUIA_bitmap_selector_{Attribute}:
*msg->opg_Storage = data->{Variable};
return TRUE;
*/
}
return (DoSuperMethodA(cl, obj, (Msg) msg));
}
///
///Dispatcher
SDISPATCHER(cl_Dispatcher)
{
struct cl_Data *data;
if (! (msg->MethodID == OM_NEW)) data = INST_DATA(cl, obj);
switch(msg->MethodID)
{
case OM_NEW:
return m_New(cl, obj, (struct opSet*) msg);
case OM_DISPOSE:
return m_Dispose(cl, obj, msg);
case OM_SET:
return m_Set(cl, obj, (struct opSet*) msg);
case OM_GET:
return m_Get(cl, obj, (struct opGet*) msg);
case MUIM_BitmapSelector_Close:
return m_Close(cl, obj, (struct close_Msg*)msg);
case MUIM_BitmapSelector_CheckValidity:
return m_CheckValidity(cl, obj, msg);
//<DISPATCH SUBCLASS METHODS HERE>
default:
return DoSuperMethodA(cl, obj, msg);
}
}
///
///Class Creator
struct MUI_CustomClass* MUI_Create_BitmapSelector(void)
{
return (MUI_CreateCustomClass(NULL, MUIC_Window, NULL, sizeof(struct cl_Data), ENTRY(cl_Dispatcher)));
}
///