Moved DejaVue fonts to contrib. They are only needed by applications
[AROS-Contrib.git] / bgui / separatorclass.c
blob26898e1c8f7910fd2fb536a0d69c7efe6e2f499e
1 /*
2 * @(#) $Header$
4 * BGUI library
5 * separatorclass.c
7 * (C) Copyright 1998 Manuel Lemos.
8 * (C) Copyright 1996-1997 Ian J. Einman.
9 * (C) Copyright 1993-1996 Jaba Development.
10 * (C) Copyright 1993-1996 Jan van den Baard.
11 * All Rights Reserved.
13 * $Log$
14 * Revision 42.3 2004/06/16 20:16:48 verhaegs
15 * Use METHODPROTO, METHOD_END and REGFUNCPROTOn where needed.
17 * Revision 42.2 2000/08/17 15:09:18 chodorowski
18 * Fixed compiler warnings.
20 * Revision 42.1 2000/05/15 19:27:02 stegerg
21 * another hundreds of REG() macro replacements in func headers/protos.
23 * Revision 42.0 2000/05/09 22:10:11 mlemos
24 * Bumped to revision 42.0 before handing BGUI to AROS team
26 * Revision 41.11 2000/05/09 19:55:05 mlemos
27 * Merged with the branch Manuel_Lemos_fixes.
29 * Revision 41.10.2.2 1999/07/28 23:18:15 mlemos
30 * Fixed superclass call to dispose the objects.
32 * Revision 41.10.2.1 1998/11/23 14:59:51 mlemos
33 * Removed needless OM_GET method code.
35 * Revision 41.10 1998/02/25 21:13:06 mlemos
36 * Bumping to 41.10
38 * Revision 1.1 1998/02/25 17:09:44 mlemos
39 * Ian sources
44 /// Class definitions.
46 #include "include/classdefs.h"
49 * Object Instance data.
51 typedef struct {
52 ULONG sd_Flags; /* See below. */
53 Object *sd_Title; /* Separator title. */
54 UWORD sd_Place; /* Position. */
55 } SD;
57 #define SDF_THIN (1<<0) /* Thin lines. */
58 #define SDF_HIGHLIGHT (1<<1) /* Highlight title. */
59 #define SDF_HORIZONTAL (1<<2) /* Horizontal separator.*/
60 #define SDF_CENTER (1<<3) /* Center title. */
61 #define SDF_RECESSED (1<<4) /* Recess lines. */
63 ///
64 /// OM_NEW
66 * Create a shiny new object.
68 METHOD(SepClassNew, struct opSet *, ops)
70 IPTR rc;
73 * Let the superclass create an object.
75 if ((rc = AsmDoSuperMethodA(cl, obj, (Msg)ops)))
77 AsmCoerceMethod(cl, (Object *)rc, OM_SET, ops->ops_AttrList, NULL);
79 return rc;
81 METHOD_END
82 ///
83 /// OM_DISPOSE
85 * Dispose of this.
87 METHOD(SepClassDispose, Msg, msg)
89 SD *sd = INST_DATA(cl, obj);
91 if (sd->sd_Title) DisposeObject(sd->sd_Title);
93 return AsmDoSuperMethodA(cl, obj, msg);
95 METHOD_END
96 ///
97 /// OM_SET
99 * Set.
101 METHOD(SepClassSet, struct opSet *, ops)
103 SD *sd = INST_DATA(cl, obj);
104 ULONG rc, data;
105 struct TagItem *tag;
106 struct TagItem *tstate = ops->ops_AttrList;
108 rc = AsmDoSuperMethodA(cl, obj, (Msg)ops);
110 while ((tag = NextTagItem(&tstate)))
112 data = tag->ti_Data;
113 switch (tag->ti_Tag)
115 case FRM_ThinFrame:
116 case SEP_Thin:
118 * Pickup thin lines.
120 if (data) sd->sd_Flags |= SDF_THIN;
121 else sd->sd_Flags &= ~SDF_THIN;
122 break;
124 case SEP_CenterTitle:
125 if (data) sd->sd_Flags |= SDF_CENTER;
126 else sd->sd_Flags &= ~SDF_CENTER;
127 break;
129 case SEP_Horiz:
130 if (data) sd->sd_Flags |= SDF_HORIZONTAL;
131 else sd->sd_Flags &= ~SDF_HORIZONTAL;
132 break;
134 case SEP_Highlight:
135 if (data) sd->sd_Flags |= SDF_HIGHLIGHT;
136 else sd->sd_Flags &= ~SDF_HIGHLIGHT;
137 break;
139 case SEP_Recessed:
140 if (data) sd->sd_Flags |= SDF_RECESSED;
141 else sd->sd_Flags &= ~SDF_RECESSED;
142 break;
144 case SEP_TitleLeft:
145 if (data) sd->sd_Place = 1;
146 else sd->sd_Place = 0;
147 break;
149 case SEP_TitleRight:
150 if (data) sd->sd_Place = 2;
151 else sd->sd_Place = 0;
152 break;
154 case SEP_Title:
155 if (!sd->sd_Title) sd->sd_Title = BGUI_NewObject(BGUI_TEXT_GRAPHIC, TEXTA_CopyText, TRUE, TAG_DONE);
156 if (sd->sd_Title) DoSetMethodNG(sd->sd_Title, TEXTA_Text, data, TAG_DONE);
157 break;
159 case SEP_TitleID:
160 if (!sd->sd_Title) sd->sd_Title = BGUI_NewObject(BGUI_TEXT_GRAPHIC, TEXTA_CopyText, TRUE, TAG_DONE);
161 if (sd->sd_Title) DoSetMethodNG(sd->sd_Title, TEXTA_TextID, data, TAG_DONE);
162 break;
165 return rc;
167 METHOD_END
169 /// BASE_RENDER
171 * Render.
173 METHOD(SepClassRender, struct bmRender *, bmr)
175 SD *sd = INST_DATA(cl, obj);
176 BC *bc = BASE_DATA(obj);
177 struct BaseInfo *bi = bmr->bmr_BInfo;
178 struct RastPort *rp = bi->bi_RPort;
179 int l, t, w, h, s;
180 BOOL recessed;
183 * Render the baseclass.
185 AsmDoSuperMethodA(cl, obj, (Msg)bmr);
188 * Get left and top.
190 l = bc->bc_OuterBox.Left;
191 t = bc->bc_OuterBox.Top;
192 w = bc->bc_OuterBox.Width;
193 h = bc->bc_OuterBox.Height;
195 recessed = sd->sd_Flags & SDF_RECESSED;
198 * Only a single pen.
200 BSetDrMd(bi, JAM1);
203 * Horizontal?
205 if (sd->sd_Flags & SDF_HORIZONTAL)
208 * Shiny side.
210 BSetDPenA(bi, recessed ? SHADOWPEN : SHINEPEN);
213 * Center it in the given space?
215 if (sd->sd_Title)
217 if (sd->sd_Flags & SDF_CENTER) t += h >> 1;
218 else t += h - (rp->TxHeight - rp->TxBaseline);
222 * Move to the correct location.
224 Move(rp, l, t);
225 Draw(rp, l + w - 2, t);
226 WritePixel(rp, l, t + 1);
229 * Shadow side.
231 BSetDPenA(bi, recessed ? SHINEPEN : SHADOWPEN);
234 * Move to the correct location.
236 Move(rp, l + 1, t + 1);
237 Draw(rp, l + w - 1, t + 1);
238 WritePixel(rp, l + w - 1, t);
241 * Title?
243 if (sd->sd_Title)
246 * Set font if necessary.
248 if (bc->bc_TextFont) BSetFont(bi, bc->bc_TextFont);
251 * Render the title.
253 RenderTitle(sd->sd_Title, bi, l, t, w,
254 sd->sd_Flags & SDF_HIGHLIGHT, sd->sd_Flags & SDF_CENTER, sd->sd_Place);
257 else
260 * Shiny side.
262 BSetDPenA(bi, recessed ? SHADOWPEN : SHINEPEN);
265 * Thin or thick.
267 s = sd->sd_Flags & SDF_THIN ? 1 : 2;
270 * Pick position.
272 l += (w >> 1) - s;
275 * Render shiny side.
277 Move(rp, l, t);
278 Draw(rp, l, t + h - 1);
281 * Thick?
283 if (!(sd->sd_Flags & SDF_THIN))
285 Draw(rp, l + 1, t + h - 1);
286 Draw(rp, l + 1, t);
287 Draw(rp, l + 3, t);
289 else
291 Move(rp, l, t);
292 Draw(rp, l + 1, t);
296 * Shadow side.
298 BSetDPenA(bi, recessed ? SHINEPEN : SHADOWPEN);
301 * Render.
303 Move(rp, l + s, t + 1);
304 Draw(rp, l + s, t + h - 1);
307 * Thick?
309 if (!(sd->sd_Flags & SDF_THIN))
311 s++;
312 Draw(rp, l + s, t + h - 1);
313 Draw(rp, l + s, t + 1);
314 Move(rp, l, t + h - 1);
315 Draw(rp, l + s, t + h - 1);
317 else
318 Draw(rp, l, t + h - 1);
320 return 1;
322 METHOD_END
324 /// GM_HITTEST
326 * Hit test.
328 METHOD(SepClassHitTest, Msg, msg)
330 return 0;
332 METHOD_END
334 /// BASE_DIMENSIONS
336 * Dimensions.
338 METHOD(SepClassDimensions, struct bmDimensions *, bmd)
340 SD *sd = INST_DATA(cl, obj);
341 struct BaseInfo *bi = bmd->bmd_BInfo;
342 BC *bc = BASE_DATA(obj);
343 int mx, my;
346 * Minimum width.
348 if (sd->sd_Flags & SDF_HORIZONTAL)
351 * Do we have a font?
353 if (bc->bc_TextFont && sd->sd_Title)
354 BSetFont(bi, bc->bc_TextFont);
356 mx = 2;
358 if (sd->sd_Title) my = bi->bi_RPort->TxHeight;
359 else my = 2;
361 else
363 mx = sd->sd_Flags & SDF_THIN ? 2 : 4;
364 my = 2;
366 return CalcDimensions(cl, obj, bmd, mx, my);
368 METHOD_END
370 /// BASE_LOCALIZE
372 METHOD(SepClassLocalize, struct bmLocalize *, bml)
374 SD *sd = INST_DATA(cl, obj);
375 ULONG rc = 0;
377 if (sd->sd_Title) rc = AsmDoMethodA(sd->sd_Title, (Msg)bml);
379 return rc;
381 METHOD_END
383 /// Class initialization.
385 * Class function table.
387 STATIC DPFUNC ClassFunc[] = {
388 { BASE_RENDER, SepClassRender, },
389 { GM_HITTEST, SepClassHitTest, },
390 { BASE_DIMENSIONS, SepClassDimensions, },
391 { OM_NEW, SepClassNew, },
392 { OM_DISPOSE, SepClassDispose, },
393 { OM_SET, SepClassSet, },
394 { BASE_LOCALIZE, SepClassLocalize, },
395 { DF_END, NULL },
399 * Initialize the separator class.
401 makeproto Class *InitSepClass(void)
403 return BGUI_MakeClass(CLASS_SuperClassBGUI, BGUI_BASE_GADGET,
404 CLASS_ObjectSize, sizeof(SD),
405 CLASS_DFTable, ClassFunc,
406 TAG_DONE);