grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / prefs / palette / paleditor.c
blob4d4afa72844026604d59ab9c023a744ad4f2bd33
1 /*
2 Copyright 2010, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <exec/types.h>
9 #include <utility/tagitem.h>
10 #include <libraries/asl.h>
11 #include <libraries/mui.h>
12 #include <prefs/palette.h>
13 #include <prefs/prefhdr.h>
14 /* #define DEBUG 1 */
15 #include <zune/customclasses.h>
16 #include <zune/prefseditor.h>
18 #include <proto/alib.h>
19 #include <proto/exec.h>
20 #include <proto/intuition.h>
21 #include <proto/utility.h>
22 #include <proto/muimaster.h>
23 #include <proto/dos.h>
24 #include <proto/iffparse.h>
26 #include <string.h>
27 #include <stdio.h>
28 #include <stdlib.h>
30 #include <aros/debug.h>
32 #include "locale.h"
33 #include "paleditor.h"
34 #include "prefs.h"
36 STATIC CONST_STRPTR pennames[9];
39 without this initial palette we can't later set MUIA_Palette_Entries.
40 This is probably a bug in Zune.
42 STATIC const struct MUI_Palette_Entry initialpens[9] =
44 {0, 0, 0, 0, 0},
45 {1, 0, 0, 0, 0},
46 {2, 0, 0, 0, 0},
47 {3, 0, 0, 0, 0},
48 {4, 0, 0, 0, 0},
49 {5, 0, 0, 0, 0},
50 {6, 0, 0, 0, 0},
51 {7, 0, 0, 0, 0},
52 {MUIV_Palette_Entry_End, 0, 0, 0, 0}
55 /*** Instance Data **********************************************************/
56 struct PalEditor_DATA
58 Object *palpe_palette;
61 STATIC VOID PalPrefs2Gadgets(struct PalEditor_DATA *data);
62 STATIC VOID Gadgets2PalPrefs(struct PalEditor_DATA *data);
64 /*** Macros *****************************************************************/
65 #define SETUP_INST_DATA struct PalEditor_DATA *data = INST_DATA(CLASS, self)
67 /*** Methods ****************************************************************/
68 Object *PalEditor__OM_NEW(Class *CLASS, Object *self, struct opSet *message)
70 Object *palpe_palette;
72 pennames[0] = _(MSG_PEN0);
73 pennames[1] = _(MSG_PEN1);
74 pennames[2] = _(MSG_PEN2);
75 pennames[3] = _(MSG_PEN3);
76 pennames[4] = _(MSG_PEN4);
77 pennames[5] = _(MSG_PEN5);
78 pennames[6] = _(MSG_PEN6);
79 pennames[7] = _(MSG_PEN7);
81 self = (Object *) DoSuperNewTags
83 CLASS, self, NULL,
84 MUIA_PrefsEditor_Name, _(MSG_WINTITLE),
85 MUIA_PrefsEditor_Path, (IPTR) "SYS/palette.prefs",
86 MUIA_PrefsEditor_IconTool, (IPTR) "SYS:Prefs/Palette",
87 Child, HGroup,
88 Child, (IPTR)(palpe_palette = (Object *)PaletteObject,
89 MUIA_Palette_Entries, (IPTR)initialpens,
90 MUIA_Palette_Names, (IPTR)pennames,
91 End),
92 End,
93 TAG_DONE
96 if (self)
98 SETUP_INST_DATA;
100 data->palpe_palette = palpe_palette;
102 DoMethod
104 data->palpe_palette, MUIM_Notify, MUIA_Palette_Entries, MUIV_EveryTime,
105 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
109 return self;
112 STATIC VOID Gadgets2PalPrefs (struct PalEditor_DATA *data)
114 LONG i;
115 struct MUI_Palette_Entry *currentpens =
116 (struct MUI_Palette_Entry *)XGET(data->palpe_palette, MUIA_Palette_Entries);
118 for (i = 0; i < 8; i++)
120 paletteprefs.pap_Colors[i].ColorIndex = currentpens[i].mpe_ID;
121 paletteprefs.pap_Colors[i].Red = currentpens[i].mpe_Red >> 16;
122 paletteprefs.pap_Colors[i].Green = currentpens[i].mpe_Green >> 16;
123 paletteprefs.pap_Colors[i].Blue = currentpens[i].mpe_Blue >> 16;
127 STATIC VOID PalPrefs2Gadgets(struct PalEditor_DATA *data)
129 LONG i;
130 struct MUI_Palette_Entry currentpens[9];
132 for (i = 0; i < 8; i++)
134 currentpens[i].mpe_ID = paletteprefs.pap_Colors[i].ColorIndex;
135 currentpens[i].mpe_Red = paletteprefs.pap_Colors[i].Red << 16;
136 currentpens[i].mpe_Green = paletteprefs.pap_Colors[i].Green << 16;
137 currentpens[i].mpe_Blue = paletteprefs.pap_Colors[i].Blue << 16;
139 currentpens[8].mpe_ID = MUIV_Palette_Entry_End;
140 NNSET(data->palpe_palette, MUIA_Palette_Entries, currentpens);
143 IPTR PalEditor__MUIM_PrefsEditor_ImportFH
145 Class *CLASS, Object *self,
146 struct MUIP_PrefsEditor_ImportFH *message
149 SETUP_INST_DATA;
150 BOOL success = TRUE;
152 success = Prefs_ImportFH(message->fh);
153 if (success) PalPrefs2Gadgets(data);
155 return success;
158 IPTR PalEditor__MUIM_PrefsEditor_ExportFH
160 Class *CLASS, Object *self,
161 struct MUIP_PrefsEditor_ExportFH *message
164 SETUP_INST_DATA;
165 BOOL success = TRUE;
167 Gadgets2PalPrefs(data);
168 success = Prefs_ExportFH(message->fh);
170 return success;
173 IPTR PalEditor__MUIM_PrefsEditor_SetDefaults
175 Class *CLASS, Object *self, Msg message
178 SETUP_INST_DATA;
179 BOOL success = TRUE;
181 success = Prefs_Default();
182 if (success) PalPrefs2Gadgets(data);
184 return success;
187 /*** Setup ******************************************************************/
188 ZUNE_CUSTOMCLASS_4
190 PalEditor, NULL, MUIC_PrefsEditor, NULL,
191 OM_NEW, struct opSet *,
192 MUIM_PrefsEditor_ImportFH, struct MUIP_PrefsEditor_ImportFH *,
193 MUIM_PrefsEditor_ExportFH, struct MUIP_PrefsEditor_ExportFH *,
194 MUIM_PrefsEditor_SetDefaults, Msg