2 Copyright © 2010-2011, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <libraries/asl.h>
11 #include <zune/customclasses.h>
12 #include <zune/prefseditor.h>
14 #include <proto/alib.h>
15 #include <proto/intuition.h>
16 #include <proto/muimaster.h>
18 #include <aros/debug.h>
25 /*** Instance Data **********************************************************/
29 Object
*pted_previewImage
;
30 Object
*pted_typeCycle
;
31 Object
*pted_fileString
;
32 Object
*pted_alphaSlider
;
33 Object
*pted_hotspotButton
;
34 struct Hook pted_cycleHook
;
35 struct Hook pted_filenameHook
;
38 STATIC VOID
PTPrefs2Gadgets(struct PTEditor_DATA
*data
);
39 STATIC VOID
Gadgets2PTPrefs(struct PTEditor_DATA
*data
);
41 /*** Macros *****************************************************************/
42 #define SETUP_INST_DATA struct PTEditor_DATA *data = INST_DATA(CLASS, self)
44 /*** Hooks ******************************************************************/
45 AROS_UFH3(VOID
, cycleFunction
,
46 AROS_UFHA(struct Hook
*, h
, A0
),
47 AROS_UFHA(Object
*, obj
, A2
),
48 AROS_UFHA(APTR
, msg
, A1
))
52 struct PTEditor_DATA
*data
= h
->h_Data
;
54 ULONG entry
= XGET(data
->pted_typeCycle
, MUIA_Cycle_Active
);
56 D(bug("[POINTERPREF] entry %d oldentry %d\n", entry
, data
->pded_oldentry
));
58 // store data from previous entry
61 pointerprefs
[data
->pded_oldentry
].filename
,
62 (STRPTR
)XGET(data
->pted_fileString
, MUIA_String_Contents
),
65 pointerprefs
[data
->pded_oldentry
].npp
.npp_AlphaValue
=
66 XGET(data
->pted_alphaSlider
, MUIA_Numeric_Value
) * 0x0101;
67 pointerprefs
[data
->pded_oldentry
].npp
.npp_X
=
68 - XGET(data
->pted_previewImage
, MUIA_PPreview_HSpotX
);
69 pointerprefs
[data
->pded_oldentry
].npp
.npp_Y
=
70 - XGET(data
->pted_previewImage
, MUIA_PPreview_HSpotY
);
72 // set data of current entry
73 NNSET(data
->pted_fileString
, MUIA_String_Contents
, pointerprefs
[entry
].filename
);
74 NNSET(data
->pted_alphaSlider
, MUIA_Numeric_Value
, pointerprefs
[entry
].npp
.npp_AlphaValue
>> 8);
78 data
->pted_previewImage
,
79 MUIA_PPreview_FileName
, pointerprefs
[entry
].filename
,
80 MUIA_PPreview_Alpha
, pointerprefs
[entry
].npp
.npp_AlphaValue
,
81 MUIA_PPreview_HSpotX
, - pointerprefs
[entry
].npp
.npp_X
,
82 MUIA_PPreview_HSpotY
, - pointerprefs
[entry
].npp
.npp_Y
85 data
->pded_oldentry
= entry
;
90 AROS_UFH3(VOID
, filenameFunction
,
91 AROS_UFHA(struct Hook
*, h
, A0
),
92 AROS_UFHA(Object
*, obj
, A2
),
93 AROS_UFHA(APTR
, msg
, A1
))
97 struct PTEditor_DATA
*data
= h
->h_Data
;
99 STRPTR filename
= (STRPTR
)XGET(data
->pted_fileString
, MUIA_String_Contents
);
100 SET(data
->pted_previewImage
, MUIA_PPreview_FileName
, filename
);
101 SET(obj
, MUIA_PrefsEditor_Changed
, TRUE
);
106 /*** Methods ****************************************************************/
107 Object
*PTEditor__OM_NEW(Class
*CLASS
, Object
*self
, struct opSet
*message
)
109 static CONST_STRPTR type_entries
[3];
110 type_entries
[0] = (CONST_STRPTR
) __(MSG_TYPE_NORMAL
);
111 type_entries
[1] = (CONST_STRPTR
) __(MSG_TYPE_BUSY
);
112 type_entries
[2] = NULL
;
114 Object
*previewImage
, *typeCycle
, *fileString
, *alphaSlider
, *hotspotButton
;
116 self
= (Object
*) DoSuperNewTags
119 MUIA_PrefsEditor_Name
, _(MSG_WINTITLE
),
120 MUIA_PrefsEditor_Path
, (IPTR
)"SYS/pointer.prefs",
121 MUIA_PrefsEditor_IconTool
, (IPTR
)"SYS:Prefs/Pointer",
124 Child
, (IPTR
)(previewImage
= (Object
*)PPreviewObject
,
127 Child
, (IPTR
)ColGroup(2),
129 Child
, (IPTR
)Label2(__(MSG_TYPE
)),
130 Child
, (IPTR
)(typeCycle
= (Object
*)CycleObject
,
131 MUIA_Cycle_Entries
, (IPTR
)type_entries
,
134 Child
, (IPTR
)Label2(__(MSG_FILENAME
)),
135 Child
, (IPTR
)PopaslObject
,
136 MUIA_Popasl_Type
, ASL_FileRequest
,
137 MUIA_Popstring_String
, (IPTR
)(fileString
= (Object
*)StringObject
,
138 MUIA_String_MaxLen
, NAMEBUFLEN
,
142 MUIA_Popstring_Button
, (IPTR
)PopButton(MUII_PopFile
),
144 Child
, (IPTR
)Label2(__(MSG_ALPHA
)),
145 Child
, (IPTR
)(alphaSlider
= (Object
*)SliderObject
,
146 MUIA_Numeric_Min
, 20,
147 MUIA_Numeric_Max
, 255,
150 Child
, (IPTR
)Label2(__(MSG_HOTSPOT
)),
151 Child
, (IPTR
)(hotspotButton
= MUI_NewObject(MUIC_Text
,
153 MUIA_Font
, MUIV_Font_Button
,
154 MUIA_Text_Contents
, (IPTR
)__(MSG_SETVIEW
),
155 MUIA_Text_PreParse
, (IPTR
)"\33c",
156 MUIA_InputMode
, MUIV_InputMode_Toggle
,
157 MUIA_Background
, MUII_ButtonBack
,
169 data
->pted_cycleHook
.h_Entry
= (HOOKFUNC
)cycleFunction
;
170 data
->pted_cycleHook
.h_Data
= data
;
172 data
->pted_filenameHook
.h_Entry
= (HOOKFUNC
)filenameFunction
;
173 data
->pted_filenameHook
.h_Data
= data
;
175 data
->pted_previewImage
= previewImage
;
176 data
->pted_typeCycle
= typeCycle
;
177 data
->pted_fileString
= fileString
;
178 data
->pted_alphaSlider
= alphaSlider
;
179 data
->pted_hotspotButton
= hotspotButton
;
183 data
->pted_typeCycle
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
184 (IPTR
) self
, 2, MUIM_CallHook
, &data
->pted_cycleHook
189 data
->pted_fileString
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
190 (IPTR
) self
, 2, MUIM_CallHook
, &data
->pted_filenameHook
195 data
->pted_alphaSlider
, MUIM_Notify
, MUIA_Numeric_Value
, MUIV_EveryTime
,
196 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
201 data
->pted_hotspotButton
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
202 (IPTR
) data
->pted_previewImage
, 3, MUIM_Set
, MUIA_PPreview_SetHSpot
, MUIV_TriggerValue
211 STATIC
void Gadgets2PTPrefs(struct PTEditor_DATA
*data
)
213 ULONG entry
= XGET(data
->pted_typeCycle
, MUIA_Cycle_Active
);
216 SET(data
->pted_typeCycle
, MUIA_Cycle_Active
, entry
);
220 STATIC VOID
PTPrefs2Gadgets(struct PTEditor_DATA
*data
)
222 ULONG entry
= XGET(data
->pted_typeCycle
, MUIA_Cycle_Active
);
224 NNSET(data
->pted_fileString
, MUIA_String_Contents
, pointerprefs
[entry
].filename
);
225 NNSET(data
->pted_alphaSlider
, MUIA_Numeric_Value
, pointerprefs
[entry
].npp
.npp_AlphaValue
>> 8);
229 data
->pted_previewImage
,
230 MUIA_PPreview_FileName
, pointerprefs
[entry
].filename
,
231 MUIA_PPreview_Alpha
, pointerprefs
[entry
].npp
.npp_AlphaValue
,
232 MUIA_PPreview_HSpotX
, - pointerprefs
[entry
].npp
.npp_X
,
233 MUIA_PPreview_HSpotY
, - pointerprefs
[entry
].npp
.npp_Y
237 IPTR PTEditor__MUIM_PrefsEditor_ImportFH
239 Class
*CLASS
, Object
*self
,
240 struct MUIP_PrefsEditor_ImportFH
*message
246 success
= Prefs_ImportFH(message
->fh
);
247 if (success
) PTPrefs2Gadgets(data
);
252 IPTR PTEditor__MUIM_PrefsEditor_ExportFH
254 Class
*CLASS
, Object
*self
,
255 struct MUIP_PrefsEditor_ExportFH
*message
261 Gadgets2PTPrefs(data
);
262 success
= Prefs_ExportFH(message
->fh
);
267 IPTR PTEditor__MUIM_PrefsEditor_SetDefaults
269 Class
*CLASS
, Object
*self
, Msg message
275 success
= Prefs_Default();
276 if (success
) PTPrefs2Gadgets(data
);
281 /*** Setup ******************************************************************/
284 PTEditor
, NULL
, MUIC_PrefsEditor
, NULL
,
285 OM_NEW
, struct opSet
*,
286 MUIM_PrefsEditor_ImportFH
, struct MUIP_PrefsEditor_ImportFH
*,
287 MUIM_PrefsEditor_ExportFH
, struct MUIP_PrefsEditor_ExportFH
*,
288 MUIM_PrefsEditor_SetDefaults
, Msg