2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
6 #include <intuition/intuition.h>
7 #include <intuition/intuitionbase.h>
8 #include <graphics/gfx.h>
9 #include <graphics/gfxbase.h>
10 #include <cybergraphx/cybergraphics.h>
11 #include <libraries/commodities.h>
12 #include <libraries/locale.h>
13 #include <proto/exec.h>
14 #include <proto/dos.h>
15 #include <proto/intuition.h>
16 #include <proto/graphics.h>
17 #include <proto/cybergraphics.h>
18 #include <proto/layers.h>
19 #include <proto/commodities.h>
20 #include <proto/locale.h>
21 #include <proto/alib.h>
23 #include <aros/debug.h>
28 #define CATCOMP_NUMBERS
29 #define CATCOMP_STRINGS
32 #include "../strings.h"
39 /************************************************************************************/
41 UBYTE version
[] = "$VER: StartMenu 0.2 (13.10.2001)";
43 #define ARG_TEMPLATE "CX_PRIORITY=PRI/N/K,HIDE/S"
49 struct IntuitionBase
*IntuitionBase
= NULL
;
50 struct GfxBase
*GfxBase
= NULL
;
51 struct Library
*CyberGfxBase
= NULL
;
52 struct Library
*LayersBase
= NULL
;
53 struct Library
*CxBase
= NULL
;
54 struct LocaleBase
*LocaleBase
= NULL
;
56 /* Libraries to open */
65 { &IntuitionBase
, "intuition.library", 39L },
66 { &GfxBase
, "graphics.library", 39L },
67 { &CyberGfxBase
, "cybergraphics.library", 39L },
68 { &LayersBase
, "layers.library", 39L },
69 { &CxBase
, "commodities.library", 39L },
73 static struct NewBroker nb
=
79 NBU_NOTIFY
| NBU_UNIQUE
,
86 static struct Catalog
*catalogPtr
;
88 static struct MsgPort
*cxport
;
90 static struct RDArgs
*myargs
;
91 static struct Screen
*scr
;
92 static struct Window
*panelwin
;
93 static struct DrawInfo
*dri
;
94 static struct TextFont
*scrfont
;
95 static struct RastPort
*panelrp
;
97 static CxObj
*cxbroker
, *cxcust
;
98 static UBYTE
*logodata
;
99 static ULONG
*logopal
;
100 static UWORD
*scrpens
;
101 static ULONG cxmask
, panelmask
;
102 static WORD scrfontw
, scrfonth
, logowidth
, logoheight
, logocols
, logomod
;
103 static WORD logobutwidth
, logobutheight
, panelbutheight
, panelwidth
, panelheight
, visiblepanelheight
;
104 static WORD panelstuffy
, logobutposx
, logobutposy
, logoposx
, logoposy
;
105 static WORD scrwidth
, scrheight
, scrdepth
, shinepen
, shadowpen
, bgpen
;
106 static WORD textpen
, hitextpen
;
107 static BOOL quitme
, disabled
, is_truecolor
, panellogodown
;
109 static LONG args
[NUM_ARGS
];
112 static struct Task
*maintask
;
113 static ULONG actionbit
;
114 static ULONG actionmask
;
118 #define MINIMUM_VISIBLE 3
120 STRPTR
getCatalog(struct Catalog
*catalogPtr
, ULONG id
)
125 string
= GetCatalogStr(catalogPtr
, id
, CatCompArray
[id
].cca_Str
);
127 string
= CatCompArray
[id
].cca_Str
;
132 static void HideAction(CxMsg
*msg
,CxObj
*obj
)
134 struct InputEvent
*ie
= (struct InputEvent
*)CxMsgData(msg
);
136 if (ie
->ie_Class
== IECLASS_RAWMOUSE
)
138 tohide
= ie
->ie_position
.ie_xy
.ie_y
< (scrheight
- visiblepanelheight
);
139 if (tohide
!= hidden
)
142 Signal(maintask
, actionmask
);
147 static void HandleHide(void)
150 while (--visiblepanelheight
> MINIMUM_VISIBLE
)
151 MoveWindow(panelwin
, 0, 1);
153 while (++visiblepanelheight
< panelheight
)
154 MoveWindow(panelwin
, 0, -1);
157 /************************************************************************************/
159 static void Cleanup(char *msg
)
161 struct Message
*cxmsg
;
162 struct LibTable
*tmpLibTable
= libTable
;
172 CloseWindow(panelwin
);
175 FreeScreenDrawInfo(scr
, dri
);
178 UnlockPubScreen(0, scr
);
183 DeleteCxObjAll(cxbroker
);
187 while((cxmsg
= GetMsg(cxport
)))
191 DeleteMsgPort(cxport
);
199 CloseCatalog(catalogPtr
);
200 CloseLibrary((struct Library
*)LocaleBase
); /* Passing NULL is valid */
201 kprintf("Closed locale.library!\n");
204 while(tmpLibTable
->lT_Name
) /* Check for name rather than pointer */
206 if((*(struct Library
**)tmpLibTable
->lT_Library
))
208 CloseLibrary((*(struct Library
**)tmpLibTable
->lT_Library
));
209 kprintf("Closed %s!\n", tmpLibTable
->lT_Name
);
216 FreeSignal(actionbit
);
221 /************************************************************************************/
223 static void DosError(void)
225 Fault(IoErr(),0,s
,255);
229 /************************************************************************************/
231 static void Init(void)
235 logodata
= logo2_data
;
237 logowidth
= LOGO2_WIDTH
;
238 logoheight
= LOGO2_HEIGHT
;
239 logocols
= LOGO2_COLORS
;
240 logomod
= LOGO2_MODULO
;
243 logodata
= logo1_data
;
245 logowidth
= LOGO1_WIDTH
;
246 logoheight
= LOGO1_HEIGHT
;
247 logocols
= LOGO1_COLORS
;
248 logomod
= LOGO1_MODULO
;
252 /************************************************************************************/
254 static void OpenLibs(void)
256 struct LibTable
*tmpLibTable
= libTable
;
257 UBYTE tmpString
[128]; /* petah: What if library name plus error message exceeds 128 bytes? */
259 if((LocaleBase
= (struct LocaleBase
*)OpenLibrary("locale.library", 40)))
261 catalogPtr
= OpenCatalog(NULL
, "Sys/Commodities.catalog", OC_BuiltInLanguage
, "english", TAG_DONE
);
264 kprintf("Warning: Can't open locale.library V40!\n");
266 while(tmpLibTable
->lT_Library
)
268 if(!((*(struct Library
**)tmpLibTable
->lT_Library
= OpenLibrary(tmpLibTable
->lT_Name
, tmpLibTable
->lT_Version
))))
270 sprintf(tmpString
, getCatalog(catalogPtr
, MSG_CANT_OPEN_LIB
), tmpLibTable
->lT_Name
, tmpLibTable
->lT_Version
);
274 kprintf("Library %s opened!\n", tmpLibTable
->lT_Name
);
280 /************************************************************************************/
282 static void GetArguments(void)
284 if (!(myargs
= ReadArgs(ARG_TEMPLATE
, args
, 0)))
289 if (args
[ARG_PRI
]) nb
.nb_Pri
= *(LONG
*)args
[ARG_PRI
];
292 /************************************************************************************/
294 static void InitCX(void)
296 if (!(cxport
= CreateMsgPort()))
298 Cleanup(getCatalog(catalogPtr
, MSG_CANT_CREATE_MSGPORT
));
303 cxmask
= 1L << cxport
->mp_SigBit
;
305 if (!(cxbroker
= CxBroker(&nb
, 0)))
307 Cleanup(getCatalog(catalogPtr
, MSG_CANT_CREATE_BROKER
));
312 if (!(cxcust
= CxCustom(HideAction
, 0)))
314 Cleanup(getCatalog(catalogPtr
, MSG_CANT_CREATE_CUSTOM
));
317 AttachCxObj(cxbroker
, cxcust
);
319 ActivateCxObj(cxbroker
, 1);
323 /***********************************************************************************/
325 static void GetVisual(void)
327 if (!(scr
= LockPubScreen(NULL
)))
329 Cleanup(getCatalog(catalogPtr
, MSG_CANT_LOCK_SCR
));
332 if (!(dri
= GetScreenDrawInfo(scr
)))
334 Cleanup("Can't get screen drawinfo! (This shouldn't happen?!)\n");
337 scrwidth
= scr
->Width
;
338 scrheight
= scr
->Height
;
340 scrdepth
= GetBitMapAttr(scr
->RastPort
.BitMap
, BMA_DEPTH
);
341 if (scrdepth
> 8) is_truecolor
= TRUE
;
343 scrfont
= dri
->dri_Font
;
344 scrfontw
= scrfont
->tf_XSize
;
345 scrfonth
= scrfont
->tf_YSize
;
347 scrpens
= dri
->dri_Pens
;
348 shinepen
= scrpens
[SHINEPEN
];
349 shadowpen
= scrpens
[SHADOWPEN
];
350 bgpen
= scrpens
[BACKGROUNDPEN
];
351 textpen
= scrpens
[TEXTPEN
];
352 hitextpen
= scrpens
[HIGHLIGHTTEXTPEN
];
356 /***********************************************************************************/
358 static void RenderPanelLogo(BOOL recessed
)
364 logobutposx
+ logobutwidth
- 1,
365 logobutposy
+ logobutheight
- 1,
370 FillPixelArray(panelrp
,
377 WriteLUTPixelArray(logodata
,
383 logoposx
+ (recessed
? 1 : 0),
384 logoposy
+ (recessed
? 1 : 0),
392 /***********************************************************************************/
394 static void RenderPanelWin(void)
396 if (!panelwin
) return;
398 RenderFrame(panelrp
, dri
, 0, 0, panelwidth
- 1, panelheight
-1, FALSE
);
400 SetAPen(panelrp
, bgpen
);
401 RectFill(panelrp
, 1, 1, panelwidth
- 2, panelheight
- 2);
403 RenderPanelLogo(panellogodown
);
406 /***********************************************************************************/
408 static void MakePanelWin(void)
412 h1
= scrfonth
+ BUTTON_EXTRA_HEIGHT
;
413 h2
= logoheight
+ LOGO_EXTRA_HEIGHT
;
415 panelwidth
= scrwidth
;
417 panelbutheight
= (h1
> h2
) ? h1
: h2
;
418 panelheight
= panelbutheight
+ PANEL_EXTRA_HEIGHT
;
419 panelstuffy
= (panelheight
- panelbutheight
) / 2;
421 logobutwidth
= logowidth
+ LOGO_EXTRA_WIDTH
;
422 logobutheight
= panelbutheight
;
424 logobutposx
= LOGO_POS_X
;
425 logobutposy
= panelstuffy
;
427 logoposx
= logobutposx
+ LOGO_EXTRA_WIDTH
/ 2;
428 logoposy
= logobutposy
+ (logobutheight
- logoheight
) / 2;
430 panelwin
= OpenWindowTags(0, WA_PubScreen
, scr
,
432 WA_Top
, scrheight
- panelheight
,
434 WA_Height
, panelheight
,
437 WA_SimpleRefresh
, FALSE
,
438 WA_BackFill
, LAYERS_NOBACKFILL
,
439 WA_IDCMP
, IDCMP_MOUSEBUTTONS
| IDCMP_REFRESHWINDOW
,
443 Cleanup(getCatalog(catalogPtr
, MSG_CANT_CREATE_WIN
));
445 visiblepanelheight
= panelheight
;
447 if(args
[ARG_HIDE
] && (panelwin
->WLayer
->LayerInfo
->Flags
& LIFLG_SUPPORTS_OFFSCREEN_LAYERS
))
449 maintask
= FindTask(0);
450 actionbit
= AllocSignal(-1);
451 actionmask
= 1 << actionbit
;
458 args
[ARG_HIDE
] = actionbit
= actionmask
= 0;
460 panelmask
= 1L << panelwin
->UserPort
->mp_SigBit
;
461 panelrp
= panelwin
->RPort
;
463 SetFont(panelrp
, scrfont
);
468 /************************************************************************************/
470 static void HandleCx(void)
474 while((msg
= (CxMsg
*)GetMsg(cxport
)))
476 switch(CxMsgType(msg
))
482 ActivateCxObj(cxbroker
,0L);
487 ActivateCxObj(cxbroker
,1L);
495 } /* switch(CxMsgID(msg)) */
498 } /* switch (CxMsgType(msg))*/
500 ReplyMsg((struct Message
*)msg
);
502 } /* while((msg = (CxMsg *)GetMsg(cxport))) */
505 /************************************************************************************/
507 static void HandlePanel(void)
509 struct IntuiMessage
*msg
;
511 while((msg
= (struct IntuiMessage
*)GetMsg(panelwin
->UserPort
)))
515 case IDCMP_REFRESHWINDOW
:
516 BeginRefresh(panelwin
);
518 EndRefresh(panelwin
, TRUE
);
521 } /* switch(msg->Class) */
523 } /* while ((msg = (struct IntuiMessage *)GetMsg(panelwin->UserPort))) */
526 /************************************************************************************/
528 static void HandleAll(void)
534 sigs
= Wait(cxmask
| panelmask
| actionmask
| SIGBREAKF_CTRL_C
);
536 if (sigs
& actionmask
) HandleHide();
537 if (sigs
& cxmask
) HandleCx();
538 if (sigs
& panelmask
) HandlePanel();
539 if (sigs
& SIGBREAKF_CTRL_C
) quitme
= TRUE
;
541 } /* while(!quitme) */
545 /************************************************************************************/
552 nb
.nb_Name
= getCatalog(catalogPtr
, MSG_STARTMENU_CXNAME
);
553 nb
.nb_Title
= getCatalog(catalogPtr
, MSG_STARTMENU_CXTITLE
);
554 nb
.nb_Descr
= getCatalog(catalogPtr
, MSG_STARTMENU_CXDESCR
);
567 /************************************************************************************/