minor update
[AROS-Contrib.git] / scalos / main / IconifyClass.c
bloba26b232fb699a65fdc2f185dd4a85642cd3d63f1
1 // IconifyClass.c
2 // $Date$
3 // $Revision$
6 #include <exec/types.h>
7 #include <graphics/rastport.h>
8 #include <intuition/classes.h>
9 #include <intuition/classusr.h>
10 #include <utility/hooks.h>
11 #include <intuition/gadgetclass.h>
12 #include <intuition/newmouse.h>
13 #include <workbench/workbench.h>
14 #include <workbench/startup.h>
16 #define __USE_SYSBASE
18 #include <proto/dos.h>
19 #include <proto/exec.h>
20 #include <proto/layers.h>
21 #include <proto/intuition.h>
22 #include <proto/graphics.h>
23 #include <proto/utility.h>
24 #include <proto/locale.h>
25 #include "debug.h"
26 #include <proto/scalos.h>
28 #include <clib/alib_protos.h>
30 #include <defs.h>
31 #include <scalos/scalos.h>
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
37 #include "scalos_structures.h"
38 #include "functions.h"
39 #include "Variables.h"
41 //----------------------------------------------------------------------------
42 // Revision history :
44 // 20010902 jl initial history
45 //----------------------------------------------------------------------------
47 // local data definitions
49 struct IconifyClassInst
51 ULONG ici_Dummy;
54 //----------------------------------------------------------------------------
56 // local functions
58 static SAVEDS(IPTR) INTERRUPT IconifyClassDispatcher(Class *cl, Object *o, Msg msg);
59 static IPTR Iconify_New(Class *cl, Object *o, Msg msg);
60 static ULONG Iconify_Draw(Class *cl, Object *o, Msg msg);
62 static LONG RenderYPos(const struct Image *img, LONG MinY, LONG y);
63 static void DrawSquare(struct RastPort *rp, LONG x1, LONG y1, LONG x2, LONG y2);
65 //----------------------------------------------------------------------------
67 // public data items :
69 //----------------------------------------------------------------------------
71 Class * initIconifyClass(void)
73 Class *IconifyClass;
75 IconifyClass = MakeClass( NULL,
76 (STRPTR) "imageclass",
77 NULL,
78 sizeof(struct IconifyClassInst),
79 0 );
81 if (IconifyClass)
83 // initialize the cl_Dispatcher Hook
84 SETHOOKFUNC(IconifyClass->cl_Dispatcher, IconifyClassDispatcher);
87 return IconifyClass;
91 static SAVEDS(IPTR) INTERRUPT IconifyClassDispatcher(Class *cl, Object *o, Msg msg)
93 IPTR Result;
95 switch (msg->MethodID)
97 case OM_NEW:
98 Result = Iconify_New(cl, o, msg);
99 break;
101 case IM_DRAW:
102 Result = Iconify_Draw(cl, o, msg);
103 break;
105 default:
106 Result = DoSuperMethodA(cl, o, msg);
107 break;
110 return Result;
114 static IPTR Iconify_New(Class *cl, Object *o, Msg msg)
116 o = (Object *) DoSuperMethodA(cl, o, msg);
118 if (o)
120 struct Image *img = (struct Image *) o;
122 img->LeftEdge = -1;
123 img->Width = 25;
126 return (IPTR) o;
130 static ULONG Iconify_Draw(Class *cl, Object *o, Msg msg)
132 struct impDraw *imp = (struct impDraw *) msg;
133 struct Image *img = (struct Image *) o;
134 LONG MinX, MaxX, MinY, MaxY;
135 LONG x;
136 UBYTE Pen;
138 MinX = MaxX = imp->imp_Offset.X + img->LeftEdge;
139 MinY = MaxY = imp->imp_Offset.Y + img->TopEdge;
140 MaxX += img->Width - 1;
141 MaxY += img->Height - 1;
143 SetAPen(imp->imp_RPort, iInfos.xii_iinfos.ii_DrawInfo->dri_Pens[SHADOWPEN]);
144 Move(imp->imp_RPort, MinX - 1, MinY + 1);
145 Draw(imp->imp_RPort, MinX - 1, MaxY);
147 if (IDS_SELECTED == imp->imp_State)
148 Pen = SHINEPEN;
149 else
150 Pen = SHADOWPEN;
152 SetAPen(imp->imp_RPort, iInfos.xii_iinfos.ii_DrawInfo->dri_Pens[Pen]);
154 Move(imp->imp_RPort, MinX + 1, MaxY);
155 Draw(imp->imp_RPort, MaxX, MaxY);
156 Draw(imp->imp_RPort, MaxX, MinY);
158 if (IDS_SELECTED == imp->imp_State)
159 Pen = SHADOWPEN;
160 else
161 Pen = SHINEPEN;
163 SetAPen(imp->imp_RPort, iInfos.xii_iinfos.ii_DrawInfo->dri_Pens[Pen]);
165 Draw(imp->imp_RPort, MinX + 1, MinY);
166 Draw(imp->imp_RPort, MinX + 1, MaxY);
168 switch (imp->imp_State)
170 case IDS_SELECTED:
171 case IDS_NORMAL:
172 Pen = FILLPEN;
173 break;
174 default:
175 Pen = BACKGROUNDPEN;
176 break;
179 SetAPen(imp->imp_RPort, iInfos.xii_iinfos.ii_DrawInfo->dri_Pens[Pen]);
180 RectFill(imp->imp_RPort, MinX + 2, MinY + 1,
181 MaxX - 1, MaxY - 1);
183 SetAPen(imp->imp_RPort, iInfos.xii_iinfos.ii_DrawInfo->dri_Pens[SHADOWPEN]);
185 if (IDS_SELECTED == imp->imp_State)
186 x = MinX + 14;
187 else
188 x = MinX + 19;
190 DrawSquare(imp->imp_RPort, x, RenderYPos(img, MinY, 25), MinX + 6, RenderYPos(img, MinY, 75));
192 if (IDS_INACTIVENORMAL == imp->imp_State)
193 Pen = BACKGROUNDPEN;
194 else
195 Pen = SHINEPEN;
197 SetAPen(imp->imp_RPort, iInfos.xii_iinfos.ii_DrawInfo->dri_Pens[Pen]);
199 RectFill(imp->imp_RPort, MinX + 8, RenderYPos(img, MinY, 45), MinX + 11, RenderYPos(img, MinY, 60));
201 SetAPen(imp->imp_RPort, iInfos.xii_iinfos.ii_DrawInfo->dri_Pens[SHADOWPEN]);
203 DrawSquare(imp->imp_RPort, MinX + 8, RenderYPos(img, MinY, 45), MinX + 11, RenderYPos(img, MinY, 60));
205 return 1;
209 static LONG RenderYPos(const struct Image *img, LONG MinY, LONG y)
211 return MinY + (y * img->Height) / 100;
215 static void DrawSquare(struct RastPort *rp, LONG x1, LONG y1, LONG x2, LONG y2)
217 Move(rp, x1, y1);
218 Draw(rp, x1, y2);
219 Draw(rp, x2, y2);
220 Draw(rp, x2, y1);
221 Draw(rp, x1, y1);