1 /***************************************************************************
3 TheBar.mcc - Next Generation Toolbar MUI Custom Class
4 Copyright (C) 2003-2005 Alfonso Ranieri
5 Copyright (C) 2005-2013 by TheBar.mcc Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 TheBar class Support Site: http://www.sf.net/projects/thebar
21 ***************************************************************************/
24 #include <proto/datatypes.h>
25 #include <datatypes/pictureclass.h>
26 #include <libraries/asl.h>
28 /***********************************************************************/
30 static struct MUI_CustomClass
*patterns
= NULL
;
31 #define patternsObject NewObject(patterns->mcc_Class,NULL
33 static struct MUI_CustomClass
*dtpic
= NULL
;
34 #define dtpicObject NewObject(dtpic->mcc_Class,NULL
36 static struct MUI_CustomClass
*bitmap
= NULL
;
37 #define bitmapObject NewObject(bitmap->mcc_Class,NULL
39 static struct MUI_CustomClass
*gradientfield
;
40 #define gradientfieldObject NewObject(gradientfield->mcc_Class,NULL
42 static struct MUI_CustomClass
*gradient
= NULL
;
43 #define gradientObject NewObject(gradient->mcc_Class,NULL
45 /***********************************************************************/
54 struct MUI_EventHandlerNode eh
;
59 /***********************************************************************/
62 mPatternsNew(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
66 if((obj
= (Object
*)DoSuperNew(cl
,obj
,
70 Child
, (IPTR
)(pgroup
= (Object
*)RowGroup(3), End
),
74 TAG_MORE
, msg
->ops_AttrList
)))
76 struct patternsData
*data
= INST_DATA(cl
,obj
);
79 for (i
= 0; i
<18; i
++)
81 snprintf(data
->specs
[i
], sizeof(data
->specs
[i
]), (STRPTR
)"0:%d", (int)(i
+MUII_BACKGROUND
));
83 data
->patterns
[i
] = (Object
*)ImageObject
,
85 MUIA_Background
, MUII_ButtonBack
,
86 MUIA_InputMode
, MUIV_InputMode_Immediate
,
93 MUIA_Image_FreeHoriz
, TRUE
,
94 MUIA_Image_FreeVert
, TRUE
,
95 MUIA_Image_Spec
, (IPTR
)data
->specs
[i
],
98 if (data
->patterns
[i
])
100 DoMethod(pgroup
,OM_ADDMEMBER
,data
->patterns
[i
]);
101 DoMethod(data
->patterns
[i
],MUIM_Notify
,MUIA_Selected
,TRUE
,obj
,2,MUIM_Popbackground_SelectPattern
,i
);
105 CoerceMethod(cl
->cl_Super
,obj
,OM_DISPOSE
);
110 data
->pop
= (Object
*)GetTagData(MUIA_Popbackground_PopObj
, 0, msg
->ops_AttrList
);
111 data
->back
= (Object
*)GetTagData(MUIA_Popbackground_BackObj
, 0, msg
->ops_AttrList
);
118 /***********************************************************************/
121 mPatternsShow(struct IClass
*cl
,Object
*obj
,Msg msg
)
123 struct patternsData
*data
= INST_DATA(cl
,obj
);
125 if (!DoSuperMethodA(cl
,obj
,msg
)) return FALSE
;
127 memset(&data
->eh
,0,sizeof(data
->eh
));
128 data
->eh
.ehn_Class
= cl
;
129 data
->eh
.ehn_Object
= obj
;
130 data
->eh
.ehn_Events
= IDCMP_MOUSEBUTTONS
|IDCMP_RAWKEY
;
131 data
->eh
.ehn_Flags
= MUI_EHF_ALWAYSKEYS
;
132 DoMethod(_win(obj
),MUIM_Window_AddEventHandler
,&data
->eh
);
137 /***********************************************************************/
140 mPatternsHide(struct IClass
*cl
,Object
*obj
,Msg msg
)
142 struct patternsData
*data
= INST_DATA(cl
,obj
);
144 DoMethod(_win(obj
),MUIM_Window_RemEventHandler
,&data
->eh
);
146 return DoSuperMethodA(cl
,obj
,msg
);
149 /***********************************************************************/
152 mPatternsHandleEvent(struct IClass
*cl
,Object
*obj
,struct MUIP_HandleEvent
*msg
)
156 struct patternsData
*data
= INST_DATA(cl
,obj
);
157 LONG p
= data
->pattern
;
159 if (msg
->imsg
->Class
==IDCMP_MOUSEBUTTONS
)
161 Object
*o
= data
->patterns
[p
];
162 UWORD mx
= msg
->imsg
->MouseX
, my
= msg
->imsg
->MouseY
;
165 msg
->imsg
->Qualifier
==0xc000 &&
166 _left(o
)<mx
&& _right(o
)>mx
&& _top(o
)<my
&& _bottom(o
)>my
&&
167 DoubleClick(data
->secs
,data
->micros
,msg
->imsg
->Seconds
,msg
->imsg
->Micros
))
169 DoMethod(_app(obj
),MUIM_Application_PushMethod
,data
->pop
,2,MUIM_Popbackground_Close
,TRUE
);
176 get(_win(obj
),MUIA_Window_ActiveObject
,&o
);
177 if (o
) return DoSuperMethodA(cl
,obj
,(Msg
)msg
);
183 else if (p
-6>=0) p
-= 6;
184 else if (p
==0) p
= 17;
190 else if (p
+6<=17) p
+= 6;
191 else if (p
==17) p
= 0;
197 else if (p
-1>=0) p
-= 1;
203 else if (p
+1<=17) p
+= 1;
210 DoMethod(_app(obj
),MUIM_Application_PushMethod
,data
->pop
,2,MUIM_Popbackground_Close
,TRUE
);
215 if (p
!=data
->pattern
)
217 set(data
->patterns
[p
],MUIA_Selected
,TRUE
);
221 data
->secs
= msg
->imsg
->Seconds
;
222 data
->micros
= msg
->imsg
->Micros
;
225 return DoSuperMethodA(cl
,obj
,(Msg
)msg
);
228 /***********************************************************************/
231 mPatternsSetSpec(struct IClass
*cl
,Object
*obj
,struct MUIP_Popbackground_SetSpec
*msg
)
233 struct patternsData
*data
= INST_DATA(cl
,obj
);
234 char *spec
= msg
->spec
;
237 if (!spec
|| (*spec
++!='0') || (!*spec
++==':') || !*spec
) return MUIV_Popbackground_SetSpec_Fail
;
239 v
= atoi(spec
)-MUII_BACKGROUND
;
240 if (v
<0 || v
>17) return FALSE
;
242 set(data
->patterns
[v
],MUIA_Selected
,TRUE
);
244 return MUIV_Popbackground_SetSpec_Spec
;
247 /***********************************************************************/
250 mPatternsGetSpec(struct IClass
*cl
,Object
*obj
,struct MUIP_Popbackground_GetSpec
*msg
)
252 struct patternsData
*data
= INST_DATA(cl
,obj
);
254 if (data
->pattern
>=0)
256 sprintf(msg
->spec
, (STRPTR
)"0:%ld", data
->pattern
+MUII_BACKGROUND
);
257 return MUIV_Popbackground_GetSpec_Spec
;
261 return MUIV_Popbackground_GetSpec_Fail
;
264 /***********************************************************************/
267 mPatternsSelectPattern(struct IClass
*cl
,Object
*obj
,struct MUIP_Popbackground_SelectPattern
*msg
)
269 struct patternsData
*data
= INST_DATA(cl
,obj
);
272 if((data
->pattern
>= 0) && (data
->pattern
!= (LONG
)msg
->id
))
273 set(data
->patterns
[data
->pattern
],MUIA_Selected
,FALSE
);
275 get(data
->patterns
[msg
->id
],MUIA_Selected
,&x
);
276 if (!x
) nnset(data
->patterns
[msg
->id
],MUIA_Selected
,TRUE
);
278 data
->pattern
= msg
->id
;
283 /***********************************************************************/
285 DISPATCHER(patternsDispatcher
)
287 switch (msg
->MethodID
)
289 case OM_NEW
: return mPatternsNew(cl
,obj
,(APTR
)msg
);
290 case MUIM_Show
: return mPatternsShow(cl
,obj
,(APTR
)msg
);
291 case MUIM_Hide
: return mPatternsHide(cl
,obj
,(APTR
)msg
);
292 case MUIM_HandleEvent
: return mPatternsHandleEvent(cl
,obj
,(APTR
)msg
);
293 case MUIM_Popbackground_SetSpec
: return mPatternsSetSpec(cl
,obj
,(APTR
)msg
);
294 case MUIM_Popbackground_GetSpec
: return mPatternsGetSpec(cl
,obj
,(APTR
)msg
);
295 case MUIM_Popbackground_SelectPattern
: return mPatternsSelectPattern(cl
,obj
,(APTR
)msg
);
296 default: return DoSuperMethodA(cl
,obj
,msg
);
300 /***********************************************************************/
307 MUI_DeleteCustomClass(patterns
);
312 /***********************************************************************/
317 if((patterns
= MUI_CreateCustomClass(NULL
, MUIC_Group
, NULL
, sizeof(struct patternsData
), ENTRY(patternsDispatcher
))))
319 if(lib_flags
& BASEFLG_MUI20
)
320 patterns
->mcc_Class
->cl_ID
= (STRPTR
)"Backgroundadjust_Patterns";
328 /***********************************************************************/
334 struct BitMapHeader
*bmhd
;
335 struct BitMap
*bitmap
;
345 /***********************************************************************/
348 freeDTO(struct dtpicData
*data
)
355 DisposeDTObject(data
->dto
);
360 /***********************************************************************/
363 build(UNUSED
struct IClass
*cl
,Object
*obj
,struct dtpicData
*data
)
367 if ((data
->flags
& FLG_Setup
) && *data
->file
)
369 struct Process
*me
= (struct Process
*)FindTask(NULL
);
370 APTR win
= me
->pr_WindowPtr
;
371 ULONG cyber
= CyberGfxBase
&& IsCyberModeID(GetVPModeID(&_screen(obj
)->ViewPort
));
373 me
->pr_WindowPtr
= (APTR
)-1;
375 data
->dto
= NewDTObject(data
->file
,DTA_GroupID
, GID_PICTURE
,
376 PDTA_Screen
, _screen(obj
),
377 PDTA_FreeSourceBitMap
, TRUE
,
378 PDTA_UseFriendBitMap
, cyber
,
379 cyber
? PDTA_DestMode
: TAG_IGNORE
, PMODE_V43
,
382 me
->pr_WindowPtr
= win
;
386 struct FrameInfo fri
;
388 memset(&fri
, 0, sizeof(struct FrameInfo
));
390 DoMethod(data
->dto
,DTM_FRAMEBOX
,NULL
,&fri
,&fri
,sizeof(struct FrameInfo
),0);
392 if (fri
.fri_Dimensions
.Depth
>0)
394 if (DoMethod(data
->dto
,DTM_PROCLAYOUT
,NULL
,TRUE
))
396 get(data
->dto
,PDTA_BitMapHeader
,&data
->bmhd
);
400 GetDTAttrs(data
->dto
,PDTA_DestBitMap
,&data
->bitmap
,TAG_DONE
);
401 if (!data
->bitmap
) GetDTAttrs(data
->dto
,PDTA_BitMap
,&data
->bitmap
,TAG_DONE
);
406 GetDTAttrs(data
->dto
,PDTA_MaskPlane
,&storage
,TAG_DONE
);
407 data
->plane
= (APTR
)storage
;
422 /***********************************************************************/
425 mDTPicNew(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
427 if((obj
= (Object
*)DoSuperMethodA(cl
,obj
,(Msg
)msg
)))
429 msg
->MethodID
= OM_SET
;
430 DoMethodA(obj
,(Msg
)msg
);
431 msg
->MethodID
= OM_NEW
;
437 /***********************************************************************/
440 mDTPicDispose(struct IClass
*cl
,Object
*obj
,Msg msg
)
442 struct dtpicData
*data
= INST_DATA(cl
, obj
);
444 if (data
->dto
) DisposeDTObject(data
->dto
);
446 return DoSuperMethodA(cl
,obj
,msg
);
449 /***********************************************************************/
452 mDTPicSets(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
454 struct dtpicData
*data
= INST_DATA(cl
, obj
);
455 struct TagItem
*tags
;
457 BOOL rebuild
, redraw
;
460 rebuild
= redraw
= FALSE
;
462 for(tags
= msg
->ops_AttrList
; (tag
= NextTagItem((APTR
)&tags
)); )
464 IPTR tidata
= tag
->ti_Data
;
468 case MUIA_Popbackground_File
:
471 strlcpy(data
->file
, (STRPTR
)tidata
, sizeof(data
->file
));
481 res
= DoSuperMethodA(cl
,obj
,(Msg
)msg
);
483 if (data
->flags
& FLG_Setup
)
488 struct BitMap
*bm
= data
->bitmap
;
490 set(_app(obj
),MUIA_Application_Sleep
,TRUE
);
495 MUI_Redraw(obj
,MADF_DRAWOBJECT
);
499 superget(cl
,obj
,MUIA_Parent
,&parent
);
500 if (parent
) DoMethod(parent
,MUIM_Group_InitChange
);
504 if (parent
) DoMethod(parent
,MUIM_Group_ExitChange
);
506 MUI_Redraw(obj
,MADF_DRAWOBJECT
);
508 set(_app(obj
),MUIA_Application_Sleep
,FALSE
);
511 if (redraw
) MUI_Redraw(obj
,MADF_DRAWOBJECT
);
517 /***************************************************************************/
520 mDTPicSetup(struct IClass
*cl
,Object
*obj
,Msg msg
)
522 struct dtpicData
*data
= INST_DATA(cl
,obj
);
524 if (!DoSuperMethodA(cl
,obj
,(Msg
)msg
)) return FALSE
;
526 data
->flags
|= FLG_Setup
;
532 /***********************************************************************/
535 mDTPicCleanup(struct IClass
*cl
,Object
*obj
,Msg msg
)
537 struct dtpicData
*data
= INST_DATA(cl
,obj
);
540 data
->flags
&= ~FLG_Setup
;
542 return DoSuperMethodA(cl
,obj
,(Msg
)msg
);
545 /***********************************************************************/
548 mDTPicAskMinMax(struct IClass
*cl
,Object
*obj
,struct MUIP_AskMinMax
*msg
)
550 struct dtpicData
*data
= INST_DATA(cl
,obj
);
551 struct MUI_MinMax
*mi
;
553 DoSuperMethodA(cl
,obj
,(Msg
)msg
);
555 mi
= msg
->MinMaxInfo
;
559 mi
->MinWidth
+= data
->bmhd
->bmh_Width
;
560 mi
->MinHeight
+= data
->bmhd
->bmh_Height
;
561 mi
->DefWidth
+= data
->bmhd
->bmh_Width
;
562 mi
->DefHeight
+= data
->bmhd
->bmh_Height
;
565 mi
->MaxWidth
+= MUI_MAXMAX
;
566 mi
->MaxHeight
+= MUI_MAXMAX
;
571 /***********************************************************************/
574 mDTPicDraw(struct IClass
*cl
,Object
*obj
,struct MUIP_Draw
*msg
)
576 struct dtpicData
*data
= INST_DATA(cl
,obj
);
578 DoSuperMethodA(cl
,obj
,(Msg
)msg
);
580 if ((msg
->flags
& MADF_DRAWOBJECT
) && data
->bitmap
)
582 WORD l
, t
, w
, h
, bw
, bh
;
589 bw
= data
->bmhd
->bmh_Width
;
590 bh
= data
->bmhd
->bmh_Height
;
595 BltBitMapRastPort(data
->bitmap
,0,0,_rp(obj
),l
,t
,w
,h
,0xc0);
601 /***********************************************************************/
603 DISPATCHER(dtpicDispatcher
)
605 switch(msg
->MethodID
)
607 case OM_NEW
: return mDTPicNew(cl
,obj
,(APTR
)msg
);
608 case OM_DISPOSE
: return mDTPicDispose(cl
,obj
,(APTR
)msg
);
609 case OM_SET
: return mDTPicSets(cl
,obj
,(APTR
)msg
);
610 case MUIM_Draw
: return mDTPicDraw(cl
,obj
,(APTR
)msg
);
611 case MUIM_AskMinMax
: return mDTPicAskMinMax(cl
,obj
,(APTR
)msg
);
612 case MUIM_Setup
: return mDTPicSetup(cl
,obj
,(APTR
)msg
);
613 case MUIM_Cleanup
: return mDTPicCleanup(cl
,obj
,(APTR
)msg
);
614 default: return DoSuperMethodA(cl
,obj
,msg
);
618 /***********************************************************************/
625 MUI_DeleteCustomClass(dtpic
);
631 /***********************************************************************/
636 if((dtpic
= MUI_CreateCustomClass(NULL
, MUIC_Area
, NULL
, sizeof(struct dtpicData
), ENTRY(dtpicDispatcher
))))
638 if(lib_flags
& BASEFLG_MUI20
)
639 dtpic
->mcc_Class
->cl_ID
= (STRPTR
)"Backgroundadjust_dtpic";
647 /***********************************************************************/
655 /***********************************************************************/
658 mBitmapNew(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
660 Object
*pic
, *bitmap
, *abt
, *pbt
;
662 if((obj
= (Object
*)DoSuperNew(cl
,obj
,
663 Child
, ScrollgroupObject
,
664 MUIA_Scrollgroup_Contents
, VirtgroupObject
,
665 MUIA_Frame
, MUIV_Frame_Virtual
,
666 Child
, (IPTR
)(pic
= (Object
*)dtpicObject
, End
),
670 MUIA_Group_HorizSpacing
, 1,
672 MUIA_Popstring_String
, (IPTR
)(bitmap
= (Object
*)StringObject
,
673 MUIA_CycleChain
, TRUE
,
675 MUIA_String_MaxLen
, 256,
677 MUIA_Popstring_Button
, (IPTR
)(abt
= PopButton(MUII_PopFile
)),
678 MUIA_Popasl_Type
, ASL_FileRequest
,
680 Child
, (IPTR
)(pbt
= PopButton(MUII_PopUp
)),
682 TAG_MORE
, msg
->ops_AttrList
)))
684 struct bitmapData
*data
= INST_DATA(cl
,obj
);
687 data
->bitmap
= bitmap
;
689 DoSuperMethod(cl
,obj
,MUIM_MultiSet
,MUIA_CycleChain
,TRUE
,abt
,pbt
,NULL
);
690 DoMethod(pbt
,MUIM_Notify
,MUIA_Pressed
,FALSE
,obj
,1,MUIM_Popbackground_ShowBitmap
);
696 /***********************************************************************/
699 mBitmapSetSpec(struct IClass
*cl
,Object
*obj
,struct MUIP_Popbackground_SetSpec
*msg
)
701 struct bitmapData
*data
= INST_DATA(cl
,obj
);
702 char *spec
= msg
->spec
;
704 if (!spec
|| (*spec
++!='5') || (!*spec
++==':') || !*spec
) return MUIV_Popbackground_SetSpec_Fail
;
706 set(data
->pic
,MUIA_Popbackground_File
,NULL
);
707 set(data
->bitmap
,MUIA_String_Contents
,spec
);
708 return MUIV_Popbackground_SetSpec_Spec
;
711 /***********************************************************************/
714 mBitmapGetSpec(struct IClass
*cl
,Object
*obj
,struct MUIP_Popbackground_GetSpec
*msg
)
716 struct bitmapData
*data
= INST_DATA(cl
,obj
);
719 get(data
->bitmap
,MUIA_String_Contents
,&x
);
720 sprintf(msg
->spec
,(STRPTR
)"5:%s",x
);
721 return MUIV_Popbackground_GetSpec_Spec
;
724 /***********************************************************************/
727 mBitmapShowBitmap(struct IClass
*cl
,Object
*obj
, UNUSED Msg msg
)
729 struct bitmapData
*data
= INST_DATA(cl
,obj
);
732 get(data
->bitmap
,MUIA_String_Contents
,&x
);
733 set(data
->pic
,MUIA_Popbackground_File
,x
);
738 /***********************************************************************/
740 DISPATCHER(bitmapDispatcher
)
742 switch (msg
->MethodID
)
744 case OM_NEW
: return mBitmapNew(cl
,obj
,(APTR
)msg
);
745 case MUIM_Popbackground_SetSpec
: return mBitmapSetSpec(cl
,obj
,(APTR
)msg
);
746 case MUIM_Popbackground_GetSpec
: return mBitmapGetSpec(cl
,obj
,(APTR
)msg
);
747 case MUIM_Popbackground_ShowBitmap
: return mBitmapShowBitmap(cl
,obj
,(APTR
)msg
);
748 default: return DoSuperMethodA(cl
,obj
,msg
);
752 /***********************************************************************/
761 MUI_DeleteCustomClass(bitmap
);
766 /***********************************************************************/
772 (bitmap
= MUI_CreateCustomClass(NULL
,MUIC_Group
,NULL
,sizeof(struct bitmapData
),ENTRY(bitmapDispatcher
))))
774 if (lib_flags
& BASEFLG_MUI20
)
775 bitmap
->mcc_Class
->cl_ID
= (STRPTR
)"Backgroundadjust_Bitmap";
785 /***********************************************************************/
787 struct gradientFieldData
789 struct MUIS_TheBar_Gradient grad
;
795 FLG_CyberDeep
= 1<<0,
798 /***********************************************************************/
801 mGradientFieldNew(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
803 if((obj
= (Object
*)DoSuperNew(cl
,obj
,
808 TAG_MORE
,msg
->ops_AttrList
)))
810 struct gradientFieldData
*data
= INST_DATA(cl
,obj
);
812 if (GetTagData(MUIA_Popbackground_Horiz
,TRUE
,msg
->ops_AttrList
))
813 data
->grad
.flags
|= MUIV_TheBar_Gradient_Horiz
;
815 data
->grad
.from
= 0xffffff;
816 data
->grad
.to
= 0xffffff;
822 /***********************************************************************/
825 mGradientFieldSets(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
827 struct gradientFieldData
*data
= INST_DATA(cl
,obj
);
829 struct TagItem
*tstate
;
832 for(tstate
= msg
->ops_AttrList
; (tag
= NextTagItem((APTR
)&tstate
)); )
834 IPTR tidata
= tag
->ti_Data
;
838 case MUIA_Popbackground_From
:
839 if (data
->grad
.from
!=tidata
)
841 data
->grad
.from
= tidata
;
846 case MUIA_Popbackground_To
:
847 if (data
->grad
.to
!=tidata
)
849 data
->grad
.to
= tidata
;
856 if (redraw
) MUI_Redraw(obj
,MADF_DRAWUPDATE
);
858 return DoSuperMethodA(cl
,obj
,(Msg
)msg
);
861 /***********************************************************************/
864 mGradientFieldSetup(struct IClass
*cl
,Object
*obj
,Msg msg
)
866 struct gradientFieldData
*data
= INST_DATA(cl
,obj
);
868 if (!DoSuperMethodA(cl
,obj
,(Msg
)msg
)) return FALSE
;
870 if ((GetBitMapAttr(_screen(obj
)->RastPort
.BitMap
,BMA_DEPTH
)>8) &&
871 CyberGfxBase
&& IsCyberModeID(GetVPModeID(&_screen(obj
)->ViewPort
)))
872 data
->flags
|= FLG_CyberDeep
;
873 else data
->flags
&= ~FLG_CyberDeep
;
878 /***********************************************************************/
881 mGradientFieldDraw(struct IClass
*cl
,Object
*obj
,struct MUIP_Draw
*msg
)
883 struct gradientFieldData
*data
= INST_DATA(cl
,obj
);
885 DoSuperMethodA(cl
,obj
,(Msg
)msg
);
887 if ((data
->flags
& FLG_CyberDeep
) && (msg
->flags
& (MADF_DRAWUPDATE
|MADF_DRAWOBJECT
)))
888 drawGradient(obj
,&data
->grad
);
893 /***********************************************************************/
895 DISPATCHER(gradientFieldDispatcher
)
897 switch (msg
->MethodID
)
899 case OM_NEW
: return mGradientFieldNew(cl
,obj
,(APTR
)msg
);
900 case OM_SET
: return mGradientFieldSets(cl
,obj
,(APTR
)msg
);
901 case MUIM_Setup
: return mGradientFieldSetup(cl
,obj
,(APTR
)msg
);
902 case MUIM_Draw
: return mGradientFieldDraw(cl
,obj
,(APTR
)msg
);
903 default: return DoSuperMethodA(cl
,obj
,msg
);
907 /***********************************************************************/
910 freeGradientfield(void)
914 MUI_DeleteCustomClass(gradientfield
);
915 gradientfield
= NULL
;
919 /***********************************************************************/
922 initGradientfield(void)
924 if((gradientfield
= MUI_CreateCustomClass(NULL
, MUIC_Rectangle
, NULL
, sizeof(struct gradientFieldData
), ENTRY(gradientFieldDispatcher
))))
926 if(lib_flags
& BASEFLG_MUI20
)
927 gradientfield
->mcc_Class
->cl_ID
= (STRPTR
)"Gradientfield";
935 /***********************************************************************/
945 /***********************************************************************/
948 mGradientNew(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
950 Object
*vgrad
, *hgrad
, *from
, *to
, *swap
;
952 if((obj
= (Object
*)DoSuperNew(cl
,obj
,
953 MUIA_Group_Horiz
, TRUE
,
955 Child
, vgrad
= (Object
*)gradientfieldObject
,
956 MUIA_ShortHelp
, (IPTR
)tr(Msg_Popback_VertGradientHelp
),
958 MUIA_Background
, MUII_ButtonBack
,
959 MUIA_InputMode
, MUIV_InputMode_Immediate
,
961 MUIA_Popbackground_Horiz
, FALSE
,
965 Child
, hgrad
= (Object
*)gradientfieldObject
,
966 MUIA_ShortHelp
, (IPTR
)tr(Msg_Popback_HorizGradientHelp
),
968 MUIA_Background
, MUII_ButtonBack
,
969 MUIA_InputMode
, MUIV_InputMode_Immediate
,
975 Child
, from
= coloradjustObject
, MUIA_Coloradj_Colorfield
, NULL
, End
,
976 Child
, RectangleObject
, MUIA_Weight
, 0, MUIA_Rectangle_VBar
, TRUE
, End
,
977 Child
, to
= coloradjustObject
, MUIA_Coloradj_Colorfield
, NULL
, End
,
982 Child
, oclabel(Msg_Popback_From
),
984 Child
, swap
= obutton(Msg_Popback_Swap
,Msg_Popback_SwapHelp
),
986 Child
, oclabel(Msg_Popback_To
),
990 TAG_MORE
, msg
->ops_AttrList
)))
992 struct gradientData
*data
= INST_DATA(cl
,obj
);
999 set(swap
,MUIA_Weight
,20);
1000 DoMethod(swap
,MUIM_Notify
,MUIA_Pressed
,FALSE
,obj
,1,MUIM_Popbackground_Swap
);
1001 DoMethod(from
,MUIM_Notify
,MUIA_Coloradjust_RGB
,MUIV_EveryTime
,obj
,2,MUIM_Popbackground_GradientCol
,TRUE
);
1002 DoMethod(to
,MUIM_Notify
,MUIA_Coloradjust_RGB
,MUIV_EveryTime
,obj
,2,MUIM_Popbackground_GradientCol
,FALSE
);
1004 DoMethod(hgrad
,MUIM_Notify
,MUIA_Selected
,TRUE
,vgrad
,3,MUIM_Set
,MUIA_Selected
,FALSE
);
1005 DoMethod(vgrad
,MUIM_Notify
,MUIA_Selected
,TRUE
,hgrad
,3,MUIM_Set
,MUIA_Selected
,FALSE
);
1011 /***********************************************************************/
1014 mGradientSetSpec(struct IClass
*cl
,Object
*obj
,struct MUIP_Popbackground_SetSpec
*msg
)
1016 struct gradientData
*data
= INST_DATA(cl
,obj
);
1017 struct MUIS_TheBar_Gradient
*grad
= msg
->grad
;
1018 struct MUI_RGBcolor rgb1
, rgb2
;
1021 if (!grad
) return MUIV_Popbackground_SetSpec_Fail
;
1024 rgb1
.red
= (x
<<24)|(x
<<16)|(x
<<8)|x
;
1025 x
= (grad
->from
>>8) & 0xff;
1026 rgb1
.green
= (x
<<24)|(x
<<16)|(x
<<8)|x
;
1027 x
= grad
->from
& 0xff;
1028 rgb1
.blue
= (x
<<24)|(x
<<16)|(x
<<8)|x
;
1031 rgb2
.red
= (x
<<24)|(x
<<16)|(x
<<8)|x
;
1032 x
= (grad
->to
>>8) & 0xff;
1033 rgb2
.green
= (x
<<24)|(x
<<16)|(x
<<8)|x
;
1034 x
= grad
->to
& 0xff;
1035 rgb2
.blue
= (x
<<24)|(x
<<16)|(x
<<8)|x
;
1037 set(data
->from
,MUIA_Coloradjust_RGB
,&rgb1
);
1038 set(data
->to
,MUIA_Coloradjust_RGB
,&rgb2
);
1040 if (grad
->flags
& MUIV_TheBar_Gradient_Horiz
) set(data
->hgrad
,MUIA_Selected
,TRUE
);
1041 else set(data
->vgrad
,MUIA_Selected
,TRUE
);
1043 return MUIV_Popbackground_SetSpec_Grad
;
1046 /***********************************************************************/
1049 mGradientGetSpec(struct IClass
*cl
,Object
*obj
,struct MUIP_Popbackground_GetSpec
*msg
)
1051 struct gradientData
*data
= INST_DATA(cl
,obj
);
1052 struct MUIS_TheBar_Gradient
*grad
= msg
->grad
;
1053 struct MUI_RGBcolor
*rgb1
, *rgb2
;
1056 get(data
->from
,MUIA_Coloradjust_RGB
,&rgb1
);
1057 get(data
->to
,MUIA_Coloradjust_RGB
,&rgb2
);
1059 grad
->from
= ((rgb1
->red
>>24)<<16)|((rgb1
->green
>>24)<<8)|(rgb1
->blue
>>24);
1060 grad
->to
= ((rgb2
->red
>>24)<<16)|((rgb2
->green
>>24)<<8)|(rgb2
->blue
>>24);
1062 get(data
->hgrad
,MUIA_Selected
,&x
);
1063 if (x
) grad
->flags
|= MUIV_TheBar_Gradient_Horiz
;
1064 else grad
->flags
&= ~MUIV_TheBar_Gradient_Horiz
;
1066 return MUIV_Popbackground_GetSpec_Grad
;
1069 /***********************************************************************/
1072 mGradientGradientCol(struct IClass
*cl
,Object
*obj
,struct MUIP_Popbackground_GradientCol
*msg
)
1074 struct gradientData
*data
= INST_DATA(cl
,obj
);
1075 struct MUI_RGBcolor
*rgb
;
1083 tag
= MUIA_Popbackground_From
;
1088 tag
= MUIA_Popbackground_To
;
1091 get(c
,MUIA_Coloradjust_RGB
,&rgb
);
1092 col
= ((rgb
->red
>>24)<<16)|((rgb
->green
>>24)<<8)|(rgb
->blue
>>24);
1094 set(data
->hgrad
,tag
,col
);
1095 set(data
->vgrad
,tag
,col
);
1100 /***********************************************************************/
1103 mGradientSwap(struct IClass
*cl
,Object
*obj
, UNUSED Msg msg
)
1105 struct gradientData
*data
= INST_DATA(cl
,obj
);
1106 struct MUI_RGBcolor
*rgb1
, *rgb2
, rgb
;
1108 get(data
->from
,MUIA_Coloradjust_RGB
,&rgb1
);
1109 get(data
->to
,MUIA_Coloradjust_RGB
,&rgb2
);
1111 memcpy(&rgb
,rgb1
,sizeof(rgb
));
1113 set(data
->from
,MUIA_Coloradjust_RGB
,rgb2
);
1114 set(data
->to
,MUIA_Coloradjust_RGB
,&rgb
);
1119 /***********************************************************************/
1121 DISPATCHER(gradientDispatcher
)
1123 switch (msg
->MethodID
)
1125 case OM_NEW
: return mGradientNew(cl
,obj
,(APTR
)msg
);
1126 case MUIM_Popbackground_GradientCol
: return mGradientGradientCol(cl
,obj
,(APTR
)msg
);
1127 case MUIM_Popbackground_Swap
: return mGradientSwap(cl
,obj
,(APTR
)msg
);
1128 case MUIM_Popbackground_SetSpec
: return mGradientSetSpec(cl
,obj
,(APTR
)msg
);
1129 case MUIM_Popbackground_GetSpec
: return mGradientGetSpec(cl
,obj
,(APTR
)msg
);
1130 default: return DoSuperMethodA(cl
,obj
,msg
);
1134 /***********************************************************************/
1139 freeGradientfield();
1143 MUI_DeleteCustomClass(gradient
);
1148 /***********************************************************************/
1153 if (initGradientfield() &&
1154 (gradient
= MUI_CreateCustomClass(NULL
,MUIC_Group
,NULL
,sizeof(struct gradientData
), ENTRY(gradientDispatcher
))))
1156 if (lib_flags
& BASEFLG_MUI20
)
1157 gradient
->mcc_Class
->cl_ID
= (STRPTR
)"Gradient";
1167 /***********************************************************************/
1177 /***********************************************************************/
1183 char spec
[POPBACKGROUNDSPECSIZE
];
1184 struct MUIS_TheBar_Gradient grad
;
1190 FLG_Gradient
= 1<<0,
1191 FLG_GradientMode
= 1<<1,
1194 /***********************************************************************/
1197 mBackNew(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
1199 struct backData
*data
;
1204 if (GetTagData(MUIA_Popbackground_Gradient
,FALSE
,msg
->ops_AttrList
))
1206 static const char *titles
[5];
1208 titles
[0] = tr(Msg_Popback_Pattern
);
1209 titles
[1] = tr(Msg_Popback_Color
);
1210 titles
[2] = tr(Msg_Popback_Bitmap
);
1211 titles
[3] = tr(Msg_Popback_Gradient
);
1219 static const char *ngtitles
[4];
1221 ngtitles
[0] = tr(Msg_Popback_Pattern
);
1222 ngtitles
[1] = tr(Msg_Popback_Color
);
1223 ngtitles
[2] = tr(Msg_Popback_Bitmap
);
1226 useGradient
= FALSE
;
1230 if (!(obj
= (Object
*)DoSuperNew(cl
,obj
,MUIA_Register_Titles
,t
,MUIA_CycleChain
,TRUE
,TAG_MORE
,msg
->ops_AttrList
)))
1233 data
= INST_DATA(cl
,obj
);
1235 pop
= (Object
*)GetTagData(MUIA_Popbackground_PopObj
, (IPTR
)NULL
, msg
->ops_AttrList
);
1237 if (!(data
->pages
[0] = patternsObject
, MUIA_Popbackground_PopObj
, pop
, MUIA_Popbackground_BackObj
, obj
, End
))
1239 CoerceMethod(cl
->cl_Super
,obj
,OM_DISPOSE
);
1242 DoMethod(obj
,OM_ADDMEMBER
,data
->pages
[0]);
1244 if (!(data
->pages
[1] = penadjustObject
, MUIA_Popbackground_PopObj
, pop
, MUIA_Popbackground_BackObj
, obj
, End
))
1246 CoerceMethod(cl
->cl_Super
,obj
,OM_DISPOSE
);
1249 DoMethod(obj
,OM_ADDMEMBER
,data
->pages
[1]);
1251 if (!(data
->pages
[2] = bitmapObject
, MUIA_Popbackground_PopObj
, pop
, MUIA_Popbackground_BackObj
, obj
, End
))
1253 CoerceMethod(cl
->cl_Super
,obj
,OM_DISPOSE
);
1256 DoMethod(obj
,OM_ADDMEMBER
,data
->pages
[2]);
1260 if (!(data
->pages
[3] = gradientObject
, MUIA_Popbackground_PopObj
, pop
, MUIA_Popbackground_BackObj
, obj
, End
))
1262 CoerceMethod(cl
->cl_Super
,obj
,OM_DISPOSE
);
1265 DoMethod(obj
,OM_ADDMEMBER
,data
->pages
[3]);
1267 data
->flags
|= FLG_Gradient
;
1272 msg
->MethodID
= OM_SET
;
1273 DoMethodA(obj
,(Msg
)msg
);
1274 msg
->MethodID
= OM_NEW
;
1279 /***********************************************************************/
1282 specToGadgets(struct IClass
*cl
,Object
*obj
,STRPTR spec
,struct MUIS_TheBar_Gradient
*grad
)
1284 struct backData
*data
= INST_DATA(cl
,obj
);
1287 for (i
= 0; data
->pages
[i
]; i
++)
1289 switch(DoMethod(data
->pages
[i
],MUIM_Popbackground_SetSpec
,spec
,grad
,MUIV_Popbackground_SetSpec_Image
))
1291 case MUIV_Popbackground_SetSpec_Fail
:
1294 case MUIV_Popbackground_SetSpec_Spec
:
1296 strlcpy(data
->spec
, spec
, sizeof(data
->spec
));
1297 set(obj
,MUIA_Group_ActivePage
,i
);
1298 data
->flags
&= ~FLG_GradientMode
;
1303 case MUIV_Popbackground_SetSpec_Grad
:
1305 memcpy(&data
->grad
,grad
,sizeof(data
->grad
));
1306 set(obj
,MUIA_Group_ActivePage
,i
);
1307 data
->flags
|= FLG_GradientMode
;
1317 /***********************************************************************/
1320 gadgetsToSpec(struct backData
*data
)
1322 switch(DoMethod(data
->pages
[data
->page
],MUIM_Popbackground_GetSpec
,&data
->spec
,&data
->grad
,MUIV_Popbackground_GetSpec_Image
))
1324 case MUIV_Popbackground_GetSpec_Fail
:
1325 data
->flags
&= ~FLG_GradientMode
;
1328 case MUIV_Popbackground_GetSpec_Spec
:
1329 data
->flags
&= ~FLG_GradientMode
;
1332 case MUIV_Popbackground_GetSpec_Grad
:
1333 data
->flags
|= FLG_GradientMode
;
1338 /***********************************************************************/
1341 mBackGet(struct IClass
*cl
,Object
*obj
,struct opGet
*msg
)
1343 struct backData
*data
= INST_DATA(cl
,obj
);
1345 switch (msg
->opg_AttrID
)
1347 case MUIA_Imagedisplay_Spec
:
1348 gadgetsToSpec(data
);
1349 if (data
->flags
& FLG_GradientMode
) return FALSE
;
1350 *msg
->opg_Storage
= (IPTR
)data
->spec
;
1353 case MUIA_Popbackground_Grad
:
1354 gadgetsToSpec(data
);
1355 if (!(data
->flags
& FLG_GradientMode
)) return FALSE
;
1356 *msg
->opg_Storage
= (IPTR
)&data
->grad
;
1360 return DoSuperMethodA(cl
,obj
,(Msg
)msg
);
1364 /***********************************************************************/
1367 mBackSets(struct IClass
*cl
,Object
*obj
,struct opSet
*msg
)
1369 struct backData
*data
= INST_DATA(cl
,obj
);
1370 struct TagItem
*tag
;
1371 struct TagItem
*tstate
;
1373 for(tstate
= msg
->ops_AttrList
; (tag
= NextTagItem((APTR
)&tstate
)); )
1375 IPTR tidata
= tag
->ti_Data
;
1379 case MUIA_Group_ActivePage
:
1380 data
->page
= tidata
;
1383 case MUIA_Imagedisplay_Spec
:
1384 specToGadgets(cl
,obj
,(STRPTR
)tidata
,NULL
);
1387 case MUIA_Popbackground_Grad
:
1388 specToGadgets(cl
,obj
,NULL
,(struct MUIS_TheBar_Gradient
*)tidata
);
1393 return DoSuperMethodA(cl
,obj
,(Msg
)msg
);
1396 /***********************************************************************/
1399 mBackDragQuery(UNUSED
struct IClass
*cl
,Object
*obj
,struct MUIP_DragQuery
*msg
)
1403 if (obj
==msg
->obj
) return MUIV_DragQuery_Refuse
;
1405 if (((get(msg
->obj
,MUIA_Imagedisplay_Spec
,&x
) || get(msg
->obj
,MUIA_Pendisplay_Spec
,&x
)) && x
&& *x
) ||
1406 get(msg
->obj
,MUIA_Popbackground_Grad
,&x
))
1407 return MUIV_DragQuery_Accept
;
1409 return MUIV_DragQuery_Refuse
;
1412 /***********************************************************************/
1415 mBackDragDrop(struct IClass
*cl
,Object
*obj
,struct MUIP_DragDrop
*msg
)
1417 struct backData
*data
= INST_DATA(cl
,obj
);
1420 if ((data
->flags
& FLG_Gradient
) && get(msg
->obj
,MUIA_Popbackground_Grad
,&x
))
1421 set(obj
,MUIA_Popbackground_Grad
,x
);
1423 if (get(msg
->obj
,MUIA_Imagedisplay_Spec
,&x
)) set(obj
,MUIA_Imagedisplay_Spec
,x
);
1425 if (get(msg
->obj
,MUIA_Pendisplay_Spec
,&x
))
1429 snprintf(buf
,sizeof(buf
),(STRPTR
)"2:%s",(char *)x
);
1430 set(obj
,MUIA_Imagedisplay_Spec
,buf
);
1436 /***********************************************************************/
1438 DISPATCHER(backDispatcher
)
1440 switch (msg
->MethodID
)
1442 case OM_NEW
: return mBackNew(cl
,obj
,(APTR
)msg
);
1443 case OM_GET
: return mBackGet(cl
,obj
,(APTR
)msg
);
1444 case OM_SET
: return mBackSets(cl
,obj
,(APTR
)msg
);
1445 case MUIM_DragQuery
: return mBackDragQuery(cl
,obj
,(APTR
)msg
);
1446 case MUIM_DragDrop
: return mBackDragDrop(cl
,obj
,(APTR
)msg
);
1447 default: return DoSuperMethodA(cl
,obj
,msg
);
1451 /***********************************************************************/
1454 freeBackgroundadjust(void)
1460 if (lib_backgroundadjust
)
1462 MUI_DeleteCustomClass(lib_backgroundadjust
);
1463 lib_backgroundadjust
= NULL
;
1467 /***********************************************************************/
1470 initBackgroundadjust(void)
1472 if (initPatterns() &&
1475 (lib_backgroundadjust
= MUI_CreateCustomClass(NULL
,MUIC_Register
,NULL
,sizeof(struct backData
),ENTRY(backDispatcher
))))
1477 if (lib_flags
& BASEFLG_MUI20
)
1478 lib_backgroundadjust
->mcc_Class
->cl_ID
= (STRPTR
)"Backgroundadjust";
1483 freeBackgroundadjust();
1488 /***********************************************************************/