1 /***************************************************************************
3 NBitmap.mcc - New Bitmap MUI Custom Class
4 Copyright (C) 2006 by Daniel Allsopp
5 Copyright (C) 2007-2013 by NList 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 NList classes Support Site: http://www.sf.net/projects/nlist-classes
21 ***************************************************************************/
27 #include <clib/alib_protos.h>
28 #include <proto/exec.h>
29 #include <proto/intuition.h>
30 #include <proto/muimaster.h>
31 #include <proto/graphics.h>
32 #include <proto/utility.h>
33 #include <proto/locale.h>
34 #include <mui/NBitmap_mcc.h>
42 /* Object *DoSuperNew() */
43 #if !defined(__MORPHOS__)
45 static __attribute__ ((noinline
)) Object
* VARARGS68K
DoSuperNew(struct IClass
*cl
, Object
*obj
, Tag tag1
, ...)
47 AROS_SLOWSTACKTAGS_PRE_AS(tag1
, Object
*)
48 retval
= (Object
*)DoSuperMethod(cl
, obj
, OM_NEW
, AROS_SLOWSTACKTAGS_ARG(tag1
), NULL
);
49 AROS_SLOWSTACKTAGS_POST
52 static Object
* VARARGS68K
DoSuperNew(struct IClass
*cl
, Object
*obj
, ...)
60 rc
= (Object
*)DoSuperMethod(cl
, obj
, OM_NEW
, VA_ARG(args
, ULONG
), NULL
);
67 #endif // !__MORPHOS__
70 static VOID
setstr(STRPTR
*dest
, STRPTR str
)
84 len
= strlen(str
) + 1;
85 if((*dest
= AllocVecShared(len
, MEMF_ANY
)) != NULL
)
86 strlcpy(*dest
, str
, len
);
92 /* ULONG NBitmap_New() */
93 static IPTR
NBitmap_New(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
95 if((obj
= (Object
*)DoSuperNew(cl
, obj
,
96 MUIA_CycleChain
, TRUE
,
97 //MUIA_FillArea, FALSE,
98 MUIA_Font
, MUIV_Font_Tiny
,
99 TAG_MORE
, msg
->ops_AttrList
)) != NULL
)
101 struct InstData
*data
= NULL
;
103 if((data
= INST_DATA(cl
, obj
)) != NULL
)
105 // assume a valid data type for the moment
108 struct TagItem
*tags
= NULL
, *tag
= NULL
;
110 memset(data
, 0, sizeof(struct InstData
));
112 data
->type
= MUIV_NBitmap_Type_File
;
113 data
->alpha
= 0xffffffffUL
;
116 for(tags
= ((struct opSet
*)msg
)->ops_AttrList
; (tag
= NextTagItem((APTR
)&tags
)) != NULL
; )
120 case MUIA_NBitmap_Type
:
121 data
->type
= tag
->ti_Data
;
124 case MUIA_NBitmap_Normal
:
125 data
->data
[0] = (uint32
*)tag
->ti_Data
;
128 case MUIA_NBitmap_Ghosted
:
129 data
->data
[1] = (uint32
*)tag
->ti_Data
;
132 case MUIA_NBitmap_Selected
:
133 data
->data
[2] = (uint32
*)tag
->ti_Data
;
136 case MUIA_NBitmap_Button
:
137 data
->button
= (BOOL
)tag
->ti_Data
;
140 case MUIA_NBitmap_Label
:
141 setstr(&data
->label
, (STRPTR
)tag
->ti_Data
);
144 case MUIA_NBitmap_Width
:
145 data
->width
= tag
->ti_Data
;
148 case MUIA_NBitmap_Height
:
149 data
->height
= tag
->ti_Data
;
152 case MUIA_NBitmap_CLUT
:
153 data
->clut
= (const uint32
*)tag
->ti_Data
;
156 case MUIA_NBitmap_Alpha
:
157 data
->alpha
= tag
->ti_Data
;
165 case MUIV_NBitmap_Type_File
:
169 if(data
->data
[i
] != NULL
)
170 NBitmap_LoadImage((STRPTR
)data
->data
[i
], i
, cl
, obj
);
175 case MUIV_NBitmap_Type_DTObject
:
179 if(data
->data
[i
] != NULL
)
180 data
->dt_obj
[i
] = (Object
*)data
->data
[i
];
185 case MUIV_NBitmap_Type_CLUT8
:
186 case MUIV_NBitmap_Type_RGB24
:
187 case MUIV_NBitmap_Type_ARGB32
:
189 // nothing to do here
195 // this is an invalid type
202 if(typeOk
== TRUE
&& NBitmap_NewImage(cl
, obj
) == TRUE
)
207 CoerceMethod(cl
, obj
, OM_DISPOSE
);
211 /* ULONG NBitmap_Get() */
212 static ULONG
NBitmap_Get(struct IClass
*cl
, Object
*obj
, struct opGet
*msg
)
214 ULONG result
= FALSE
;
215 IPTR
*store
= msg
->opg_Storage
;
216 struct InstData
*data
= INST_DATA(cl
, obj
);
220 switch (((struct opGet
*)msg
)->opg_AttrID
)
222 case MUIA_NBitmap_Width
:
223 *store
= (LONG
) data
->width
;
227 case MUIA_NBitmap_Height
:
228 *store
= (LONG
) data
->height
;
232 case MUIA_NBitmap_MaxWidth
:
233 *store
= (LONG
) data
->maxwidth
;
237 case MUIA_NBitmap_MaxHeight
:
238 *store
= (LONG
) data
->maxheight
;
244 result
= DoSuperMethodA(cl
, obj
, (Msg
)msg
);
250 /* ULONG NBitmap_Set() */
251 static IPTR
NBitmap_Set(struct IClass
*cl
,Object
*obj
, struct opSet
*msg
)
253 struct InstData
*data
= INST_DATA(cl
, obj
);
254 struct TagItem
*tags
, *tag
;
259 for(tags
= msg
->ops_AttrList
; (tag
= NextTagItem((APTR
)&tags
)) != NULL
; )
263 case MUIA_NBitmap_Normal
:
265 if(data
->type
== MUIV_NBitmap_Type_File
)
267 data
->data
[0] = (uint32
*)tag
->ti_Data
;
268 NBitmap_UpdateImage(0, (STRPTR
)data
->data
[0], cl
, obj
);
269 MUI_Redraw(obj
, MADF_DRAWOBJECT
);
272 tag
->ti_Tag
= TAG_IGNORE
;
276 case MUIA_NBitmap_Ghosted
:
278 if(data
->type
== MUIV_NBitmap_Type_File
)
280 data
->data
[1] = (uint32
*)tag
->ti_Data
;
281 NBitmap_UpdateImage(1, (STRPTR
)data
->data
[1], cl
, obj
);
282 MUI_Redraw(obj
, MADF_DRAWOBJECT
);
285 tag
->ti_Tag
= TAG_IGNORE
;
289 case MUIA_NBitmap_Selected
:
291 if(data
->type
== MUIV_NBitmap_Type_File
)
293 data
->data
[2] = (uint32
*)tag
->ti_Data
;
294 NBitmap_UpdateImage(2, (STRPTR
)data
->data
[2], cl
, obj
);
295 MUI_Redraw(obj
, MADF_DRAWOBJECT
);
298 tag
->ti_Tag
= TAG_IGNORE
;
302 case MUIA_NBitmap_MaxWidth
:
303 data
->maxwidth
= (uint32
)tag
->ti_Data
;
304 tag
->ti_Tag
= TAG_IGNORE
;
307 case MUIA_NBitmap_MaxHeight
:
308 data
->maxheight
= (uint32
)tag
->ti_Data
;
309 tag
->ti_Tag
= TAG_IGNORE
;
314 result
= DoSuperMethodA(cl
, obj
, (Msg
)msg
);
320 /* ULONG NBitmap_Dispose() */
321 static IPTR
NBitmap_Dispose(struct IClass
*cl
, Object
*obj
, Msg msg
)
327 NBitmap_DisposeImage(cl
, obj
);
329 result
= DoSuperMethodA(cl
, obj
, msg
);
335 /* ULONG NBitmap_Setup() */
336 static IPTR
NBitmap_Setup(struct IClass
*cl
, Object
*obj
, Msg msg
)
342 if((result
= DoSuperMethodA(cl
, obj
, msg
)) != 0)
344 result
= NBitmap_SetupImage(cl
, obj
);
351 /* ULONG NBitmap_Cleanup() */
352 static IPTR
NBitmap_Cleanup(struct IClass
*cl
, Object
*obj
, Msg msg
)
358 NBitmap_CleanupImage(cl
, obj
);
360 result
= DoSuperMethodA(cl
, obj
, msg
);
366 /* ULONG NBitmap_HandleEvent() */
367 static IPTR
NBitmap_HandleEvent(struct IClass
*cl
, Object
*obj
, struct MUIP_HandleEvent
*msg
)
369 struct InstData
*data
;
376 if((data
= INST_DATA(cl
, obj
)) != NULL
)
378 if(msg
->imsg
!= NULL
)
380 switch(msg
->imsg
->Class
)
382 case IDCMP_MOUSEBUTTONS
:
384 if(_isinobject(msg
->imsg
->MouseX
, msg
->imsg
->MouseY
))
386 if(msg
->imsg
->Code
== SELECTDOWN
)
388 if(data
->pressed
== FALSE
)
390 data
->pressed
= TRUE
;
392 MUI_Redraw(obj
, MADF_DRAWUPDATE
);
393 SetAttrs(obj
, MUIA_Pressed
, TRUE
, TAG_DONE
);
396 else if(msg
->imsg
->Code
== SELECTUP
)
398 if(data
->overlay
&& data
->pressed
)
400 data
->pressed
= FALSE
;
401 data
->overlay
= FALSE
;
403 MUI_Redraw(obj
, MADF_DRAWUPDATE
);
404 SetAttrs(obj
, MUIA_Pressed
, FALSE
, TAG_DONE
);
408 result
= MUI_EventHandlerRC_Eat
;
412 if(msg
->imsg
->Code
==SELECTUP
)
414 data
->pressed
= FALSE
;
420 case IDCMP_MOUSEMOVE
:
422 if(_isinobject(msg
->imsg
->MouseX
, msg
->imsg
->MouseY
))
424 if(data
->overlay
== FALSE
)
426 data
->overlay
= TRUE
;
428 MUI_Redraw(obj
, MADF_DRAWUPDATE
);
431 //result = MUI_EventHandlerRC_Eat;
437 data
->overlay
= FALSE
;
439 MUI_Redraw(obj
, MADF_DRAWUPDATE
);
449 result
= DoSuperMethodA(cl
, obj
, (Msg
)msg
);
455 /* ULONG NBitmap_AskMinMax() */
456 static IPTR
NBitmap_AskMinMax(struct IClass
*cl
, Object
*obj
, struct MUIP_AskMinMax
*msg
)
458 struct InstData
*data
;
462 DoSuperMethodA(cl
, obj
, (Msg
)msg
);
464 if((data
= INST_DATA(cl
, obj
)) != NULL
)
466 uint32 oldBorderHoriz
= data
->border_horiz
;
467 uint32 oldBorderVert
= data
->border_vert
;
470 data
->border_horiz
= 0;
471 data
->border_vert
= 0;
475 data
->border_horiz
+= 4;
476 data
->border_horiz
+= data
->prefs
.spacing_horiz
* 2;
478 data
->border_vert
+= 4;
479 data
->border_vert
+= data
->prefs
.spacing_vert
* 2;
483 data
->label_horiz
= 0;
484 data
->label_vert
= 0;
486 if(data
->label
!= NULL
&& data
->button
!= FALSE
)
490 memcpy(&rp
, &_screen(obj
)->RastPort
, sizeof(rp
));
492 SetFont(&rp
, _font(obj
));
493 TextExtent(&rp
, (STRPTR
)data
->label
, strlen(data
->label
), &data
->labelte
);
495 if(data
->width
< (uint32
)data
->labelte
.te_Width
)
496 data
->border_horiz
+= (data
->labelte
.te_Width
- data
->width
);
498 data
->label_vert
= data
->labelte
.te_Height
;
499 data
->border_vert
+= data
->labelte
.te_Height
;
500 data
->border_vert
+= 2;
503 // standard width & height
504 msg
->MinMaxInfo
->MinWidth
= data
->width
+ data
->border_horiz
;
505 msg
->MinMaxInfo
->DefWidth
= data
->width
+ data
->border_horiz
;
506 msg
->MinMaxInfo
->MaxWidth
= data
->width
+ data
->border_horiz
;
508 msg
->MinMaxInfo
->MinHeight
= data
->height
+ data
->border_vert
;
509 msg
->MinMaxInfo
->DefHeight
= data
->height
+ data
->border_vert
;
510 msg
->MinMaxInfo
->MaxHeight
= data
->height
+ data
->border_vert
;
512 if(data
->border_horiz
!= oldBorderHoriz
|| data
->border_vert
!= oldBorderVert
)
514 if(data
->depth
> 8) {
515 // the border size has changed and we must recalculate the shade arrays
516 NBitmap_CleanupShades(data
);
517 NBitmap_SetupShades(data
);
526 /* ULONG NBitmap_Draw() */
527 static IPTR
NBitmap_Draw(struct IClass
*cl
, Object
*obj
, struct MUIP_Draw
*msg
)
533 result
= DoSuperMethodA(cl
, obj
, (Msg
)msg
);
535 if((msg
->flags
& MADF_DRAWUPDATE
) || (msg
->flags
& MADF_DRAWOBJECT
))
537 NBitmap_DrawImage(cl
, obj
);
545 DISPATCHER(_Dispatcher
)
551 switch(msg
->MethodID
)
554 result
= NBitmap_New(cl
, obj
, (struct opSet
*)msg
);
558 result
= NBitmap_Set(cl
, obj
, (struct opSet
*)msg
);
562 result
= NBitmap_Get(cl
, obj
, (struct opGet
*)msg
);
566 result
= NBitmap_Dispose(cl
, obj
, msg
);
570 result
= NBitmap_Setup(cl
, obj
, msg
);
573 case MUIM_HandleEvent
:
574 result
= NBitmap_HandleEvent(cl
, obj
, (struct MUIP_HandleEvent
*)msg
);
578 result
= NBitmap_Cleanup(cl
, obj
, msg
);
582 result
= NBitmap_AskMinMax(cl
, obj
, (struct MUIP_AskMinMax
*)msg
);
586 result
= NBitmap_Draw(cl
, obj
, (struct MUIP_Draw
*)msg
);
590 result
= DoSuperMethodA(cl
, obj
, msg
);