grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / tools / BoingIconBar / iconbar.c
blob743cdc132f933841523224eea26b7cefba7edcd9
1 // News: Labeling Icons
2 // Version of BiB based on 1.0.2 68K 26.10.2013 source
3 // New features added by Phibrizzo
5 //////////////////////////////////////////////////////////////
6 // //
7 // AROS PORT by LuKeJerry (at) gmail.com //
8 // -- translated to ENG from 26-09-2011 //
9 // //
10 //////////////////////////////////////////////////////////////
13 #include <stdio.h>
14 #include <string.h>
15 #include <stdlib.h>
17 #include <proto/workbench.h>
18 #include <proto/icon.h>
19 #include <proto/exec.h>
20 #include <proto/intuition.h>
21 #include <proto/graphics.h>
22 #include <proto/gadtools.h>
23 #include <proto/dos.h>
24 #include <proto/datatypes.h>
25 #include <proto/diskfont.h>
27 #include <exec/types.h>
28 #include <exec/libraries.h>
29 #include <exec/exec.h>
30 #include <workbench/icon.h>
31 #include <workbench/startup.h>
32 #include <intuition/intuition.h>
33 #include <intuition/imageclass.h>
34 #include <datatypes/datatypes.h>
35 #include <datatypes/pictureclass.h>
36 #include <dos/dos.h>
37 #include <devices/rawkeycodes.h>
38 #include <aros/detach.h>
40 #include "locale.h"
42 //#define DEBUG 1
43 #include <aros/debug.h>
45 // ------------------------------
47 #define SUM_ICON 200
48 #define ICON_ACTIVE (1<<7)
49 #define SELECTED_ICON (1<<6)
51 #define TEMPLATE "SPACE/N/K,STATIC/N/K,AUTOREMAP/S,NAMES/S"
53 // ------------------------------
55 #define ARG_SPACE 0
56 #define ARG_STATIC 1
57 #define ARG_AUTOREMAP 2
58 #define ARG_NAMES 3
60 #define BIB_PREFS "ENV:Iconbar.prefs"
63 static BOOL BiB_Exit=FALSE, Icon_Remap=FALSE, PositionMenuOK=FALSE;
64 static BOOL Window_Active=FALSE, Window_Open=FALSE, MenuWindow_Open=FALSE, FirstOpening=TRUE;
66 static BOOL B_Labels=FALSE;
67 static TEXT IT_Labels[100]; // buffer for label
69 // -----------
71 static LONG WindowHeight, WindowWidth, ScreenHeight, ScreenWidth, IconWidth;
72 static LONG Static=0, Position, OldPosition;
73 static LONG IconCounter, LevelCounter, CurrentLevel=0, lbm=0, rbm=0, MouseIcon, Spacing=5;
74 static LONG Lenght, BeginningWindow, EndingWindow, Window_Max_X, Window_Max_Y;
75 static BYTE MovingTable[8]={0, 4, 7, 9, 10, 9, 7, 4};
76 TEXT version[]="$VER: BoingIconBar 1.10 (03.03.2016) by Robert 'Phibrizzo' Krajcarz - AROS port by LuKeJerry";
77 static TEXT BufferList[20];
78 static ULONG WindowMask=0, MenuMask=0, WindowSignal;
80 static IPTR args[]={ (IPTR)&Spacing, (IPTR)&Static, 0, 0 };
82 static struct DiskObject *Icon[SUM_ICON];
84 static struct Window *MainWindow, *MenuWindow;
85 static struct Screen *MyScreen;
87 static struct BitMap *BMP_Buffer, *BMP_DoubleBuffer;
88 static struct RastPort RP_Buffer, RP_DoubleBuffer;
90 // struct of icons
92 static struct Icon_Struct {
93 LONG Icon_Height; // height icon
94 LONG Icon_Width; // width icon
95 LONG Icon_PositionX; // X position on main window
96 LONG Icon_PositionY; // Y position on main window
97 LONG Icon_Status; // status of icon: normal or selected
98 BOOL Icon_OK; // everything OK with icon
99 TEXT Icon_Path[255]; // name to path of icon
100 LONG IK_Label_Length; // length of label under icon in chars
101 STRPTR IK_Label; // icon label
103 } Icons[SUM_ICON];
105 // struct of submenu
107 static struct Level_Struct {
108 TEXT Level_Name[20]; // name submenu - level name
109 LONG Beginning; // first icon on menu
110 LONG WindowPos_X; // X position main window
111 LONG WindowPos_Y; // Y position main window
112 } Levels[11];
114 // --- Define labels fonts
116 static struct TextFont *TF_XHelvetica;
117 //struct TextAttr XHelvetica = {"XHelvetica.font", 9, 0, FPF_DISKFONT};
118 static struct TextAttr XHelvetica = {"arial.font", 9, 0, FPF_DISKFONT};
120 // --------------------
122 static struct TextAttr Topaz8 = {"topaz.font",8,0,FPF_ROMFONT};
124 static struct IntuiText Names = {1, 0, JAM1, 0, 0, &Topaz8, BufferList, NULL};
125 static struct IntuiText Labels = {1, 0, JAM1, 0, 0, &XHelvetica, IT_Labels, NULL};
127 // background pictures
129 static Object *picture[3];
130 static struct BitMap *bm[3];
132 static struct Struct_BackgroundData {
133 LONG Width; // width
134 LONG Height; // height
135 } BackgroundData[3];
139 // functions
140 static BOOL ReadPrefs(void); // load prefs
141 static void LoadBackground(void); //load background pictures
142 static BOOL SetWindowParameters(void); // check window sizes
143 static void Decode_Toolbar_IDCMP(struct IntuiMessage *KomIDCMP); // decode IDCMP main signals
144 static void Change_State(LONG Mode); // change icon state
145 static void Insert_Icon(LONG Tryb, LONG NrIcon); // draw icon
146 static void Blink_Icon(LONG NrIcon); // blink the icon
147 static BOOL OpenMainWindow(void); // open main window
148 static void CloseMainWindow(void); // close main window
149 static void CheckMousePosition(void); // check mouse position
150 static void Show_Selected_Level(void); // change the submenu
151 static void OpenMenuWindow(void); // open menu window
152 static void CloseMenuWindow(void); // close menu window
153 static void Decode_Menu_IDCMP(struct IntuiMessage *KomIDCMP); // decode IDCMP menu signals
154 static void Launch_Program(STRPTR Program); // start the chosed program
155 static void Settings(void); // open the prefs program
156 static void Reload(void); // reload the BiB
157 static void IconLabel(void); // add label to icon
159 // -------------
161 int main(int argc, char *argv[])
163 LONG retval = RETURN_OK;
165 LONG x;
167 struct IntuiMessage *KomIDCMP,CopyIDCMP;
168 struct RDArgs *rda=NULL;
169 struct DiskObject *dob=NULL;
170 struct NotifyRequest *NotRequest = NULL;
171 struct MsgPort *BIBport = NULL;
173 if (argc) // reading command line parameters
175 if (!(rda = ReadArgs(TEMPLATE, args, NULL)))
177 PrintFault(IoErr(), argv[0]);
178 retval = RETURN_ERROR;
179 goto bailout;
182 if (args[ARG_AUTOREMAP])
184 Icon_Remap = TRUE;
187 if (args[ARG_NAMES])
189 B_Labels = TRUE;
192 if (args[ARG_SPACE])
194 Spacing = *(LONG*)args[ARG_SPACE];
197 if (args[ARG_STATIC])
199 Static = *(LONG*)args[ARG_STATIC];
202 else
203 { //reading ToolTypes parameters
204 struct WBArg *wba;
205 struct WBStartup *wbs=(struct WBStartup*)argv;
206 BPTR oldcd;
208 if (wbs && wbs->sm_NumArgs > 0)
210 wba = &wbs->sm_ArgList[0];
211 if (wba && wba->wa_Lock && wba->wa_Name)
213 oldcd=CurrentDir(wba->wa_Lock);
214 if ((dob=GetDiskObjectNew(wba->wa_Name)))
216 TEXT *str;
218 if ((str=FindToolType(dob->do_ToolTypes, "SPACE")))
219 Spacing = atoi(str);
221 if ((str=FindToolType(dob->do_ToolTypes, "STATIC")))
222 Static = atoi(str);
224 if ((str=FindToolType(dob->do_ToolTypes, "AUTOREMAP")))
225 Icon_Remap = TRUE;
227 if ((str=FindToolType(dob->do_ToolTypes, "NAMES")))
228 B_Labels = TRUE;
230 CurrentDir(oldcd);
235 if (rda)
237 FreeArgs(rda);
238 rda = NULL;
240 if (dob)
242 FreeDiskObject(dob);
243 dob = NULL;
246 Detach(); // must be done after ReadArgs()
248 D(bug("[IconBar] space %d static %d autoremap %d names %d\n", Spacing, Static, Icon_Remap, B_Labels));
250 // start notification on prefs file
251 BIBport = CreateMsgPort();
252 if (BIBport)
254 NotRequest = AllocVec(sizeof(struct NotifyRequest), MEMF_CLEAR);
255 if (NotRequest)
257 NotRequest->nr_Name = BIB_PREFS;
258 NotRequest->nr_Flags = NRF_SEND_MESSAGE;
259 NotRequest->nr_stuff.nr_Msg.nr_Port = BIBport;
261 if (StartNotify(NotRequest) == DOSFALSE)
263 printf("StartNotify failed: %ld\n", IoErr());
264 retval = RETURN_ERROR;
265 goto bailout;
268 else
270 puts("Can't allocate NotifyRequest");
271 retval = RETURN_ERROR;
272 goto bailout;
275 else
277 puts("Can't create MsgPort for notification");
278 retval = RETURN_ERROR;
279 goto bailout;
282 // ------ Opening font if parameter NAMES is active
284 if(B_Labels == TRUE)
286 if((TF_XHelvetica = OpenDiskFont(&XHelvetica)) == NULL)
288 B_Labels = FALSE;
289 puts("No Arial 9 font. Labelling disabled\n");
293 // ------------------------------
295 if(ReadPrefs())
297 LoadBackground();
298 if(Static)
300 Delay(Static * 50);
301 OpenMainWindow();
302 FirstOpening = FALSE;
305 // ---- main loop
307 while (BiB_Exit==FALSE)
310 if (GetMsg(BIBport) != NULL)
312 Reload();
316 if(Window_Open || MenuWindow_Open)
318 WindowSignal = Wait(WindowMask | MenuMask);
320 if(WindowSignal & WindowMask)
322 while((KomIDCMP=GT_GetIMsg(MainWindow->UserPort)))
324 CopyMem(KomIDCMP,&CopyIDCMP,sizeof(struct IntuiMessage));
325 GT_ReplyIMsg(KomIDCMP);
326 Decode_Toolbar_IDCMP(&CopyIDCMP);
329 if(!(Static) && Window_Active == FALSE)
330 CloseMainWindow();
333 if(WindowSignal & MenuMask)
335 while((KomIDCMP=GT_GetIMsg(MenuWindow->UserPort)))
337 CopyMem(KomIDCMP,&CopyIDCMP,sizeof(struct IntuiMessage));
338 GT_ReplyIMsg(KomIDCMP);
339 Decode_Menu_IDCMP(&CopyIDCMP);
342 if(MenuWindow_Open == FALSE)
343 CloseMenuWindow();
346 else
348 Delay(50);
349 CheckMousePosition();
352 // ---- end of main loop
354 else
356 printf("No prefs\n");
357 retval = RETURN_ERROR;
360 bailout:
361 CloseMainWindow();
363 EndNotify(NotRequest); // replies all pending messages
364 FreeVec(NotRequest);
366 if (BIBport)
367 DeleteMsgPort(BIBport);
369 for(x=0; x<SUM_ICON; x++)
371 if(Icon[x] != NULL)
373 FreeDiskObject(Icon[x]);
377 if(BMP_Buffer)
378 FreeBitMap(BMP_Buffer);
379 if(BMP_DoubleBuffer)
380 FreeBitMap(BMP_DoubleBuffer);
382 for(x=0; x<3; x++)
384 if(picture[x])
385 DisposeDTObject(picture[x]);
388 if(TF_XHelvetica)
389 CloseFont(TF_XHelvetica);
390 if (rda)
391 FreeArgs(rda);
392 if (dob)
393 FreeDiskObject(dob);
395 return retval;
399 static BOOL ReadPrefs(void)
401 BPTR Prefs;
402 LONG x, LengthText, NumberCharacters;
404 Icons[0].Icon_OK = FALSE;
405 IconCounter = 0;
406 LevelCounter = 0;
407 Lenght = 0;
409 if((Prefs = Open(BIB_PREFS, MODE_OLDFILE)))
411 FGets(Prefs, Icons[0].Icon_Path, 255);
413 if(strncmp(Icons[0].Icon_Path, "BOING_PREFS", 11) != 0)
415 Close(Prefs);
416 puts("Prefs error\n");
417 return FALSE;
420 if((MyScreen=LockPubScreen(NULL)))
422 while(FGets(Prefs, Icons[IconCounter].Icon_Path, 255) ) //&& IconCounter < SUM_ICON)
424 NumberCharacters = strlen(Icons[IconCounter].Icon_Path);
425 Icons[IconCounter].Icon_Path[NumberCharacters-1] = '\0';
426 if(Icons[IconCounter].Icon_Path[0] == ';')
428 if(NumberCharacters > 20)
429 NumberCharacters = 20;
430 Icons[IconCounter].Icon_Path[19] = '\0';
432 for(x=1; x<NumberCharacters; x++)
434 Levels[LevelCounter].Level_Name[x-1] = Icons[IconCounter].Icon_Path[x];
437 strcpy(BufferList, Levels[LevelCounter].Level_Name);
438 LengthText = IntuiTextLength(&Names);
439 if(LengthText > Lenght)
440 Lenght = LengthText;
442 Levels[LevelCounter].Beginning = IconCounter;
443 LevelCounter++;
445 else
447 if((Icon[IconCounter] = GetIconTags(Icons[IconCounter].Icon_Path,
448 ICONGETA_RemapIcon, FALSE,
449 TAG_DONE)))
451 IconControl(Icon[IconCounter],
452 ICONCTRLA_GetWidth, &Icons[IconCounter].Icon_Width,
453 ICONCTRLA_GetHeight, &Icons[IconCounter].Icon_Height,
454 ICONCTRLA_SetNewIconsSupport, TRUE,
455 TAG_END);
457 if(Icons[IconCounter].Icon_Width == 0)
459 Icons[IconCounter].Icon_Width = Icon[IconCounter]->do_Gadget.Width;
462 if(Icons[IconCounter].Icon_Height == 0)
464 Icons[IconCounter].Icon_Height = Icon[IconCounter]->do_Gadget.Height;
467 LayoutIcon(Icon[IconCounter], MyScreen, NULL);
469 // ---------------------- Extract Label from path to icon
471 Icons[IconCounter].IK_Label = FilePart((Icons[IconCounter].Icon_Path));
473 // --------------------------------------------------
475 Icons[IconCounter].Icon_OK = TRUE;
476 IconCounter++;
478 if(IconCounter == SUM_ICON)
479 break;
481 else
482 printf("No icon %s.\n", Icons[IconCounter].Icon_Path);
485 Close(Prefs);
487 ScreenWidth = MyScreen->Width;
488 ScreenHeight = MyScreen->Height;
490 UnlockPubScreen(NULL, MyScreen);
492 Levels[LevelCounter].Beginning = IconCounter;
493 if (SetWindowParameters() == FALSE)
495 puts("Failed to set window parameters");
496 return FALSE;
499 IconCounter = Levels[1].Beginning;
500 WindowWidth = Levels[0].WindowPos_X;
501 WindowHeight = Levels[0].WindowPos_Y;
502 BeginningWindow = ScreenWidth / 2 - WindowWidth / 2;
503 EndingWindow = ScreenWidth / 2 + WindowWidth / 2;
504 CurrentLevel= 0;
506 // add Settings menu entry
507 sprintf(Levels[LevelCounter].Level_Name, _(MSG_MENU_SETTINGS));
508 sprintf(Names.IText, "%s", Levels[LevelCounter].Level_Name);
509 LengthText = IntuiTextLength(&Names);
510 if(LengthText > Lenght)
511 Lenght = LengthText;
512 LevelCounter++;
514 // add Quit menu entry
515 sprintf(Levels[LevelCounter].Level_Name, _(MSG_MENU_QUIT));
516 sprintf(Names.IText, "%s", Levels[LevelCounter].Level_Name);
517 LengthText = IntuiTextLength(&Names);
518 if(LengthText > Lenght)
519 Lenght = LengthText;
520 LevelCounter++;
522 Lenght += 10;
524 else
525 puts("Can't lock public screen");
527 return Icons[0].Icon_OK;
531 static void LoadBackground(void)
533 LONG x;
535 STRPTR names[3] = {"Images:bibgfx/left",
536 "Images:bibgfx/middle",
537 "Images:bibgfx/right"};
539 for(x=0; x<3; x++)
541 picture[x] = NewDTObject (names[x],
542 DTA_GroupID, GID_PICTURE,
543 PDTA_Remap, TRUE,
544 PDTA_DestMode, PMODE_V43,
545 OBP_Precision, PRECISION_IMAGE,
546 PDTA_Screen, (IPTR)MyScreen,
547 TAG_END);
549 if(picture[x])
551 DoDTMethod (picture[x], NULL, NULL, DTM_PROCLAYOUT, NULL, DTSIF_NEWSIZE);
553 GetDTAttrs (picture[x],
554 PDTA_DestBitMap, (IPTR)&bm[x],
555 DTA_NominalHoriz, (IPTR)&BackgroundData[x].Width,
556 DTA_NominalVert, (IPTR)&BackgroundData[x].Height,
557 TAG_END);
563 static BOOL SetWindowParameters(void)
565 LONG x, y, z;
567 Window_Max_X=0;
568 Window_Max_Y=0;
570 Icons[0].Icon_PositionX = 0;
572 for(y=0; y<(LevelCounter); y++)
574 WindowHeight = 0;
575 WindowWidth = 0;
577 IconCounter = Levels[y+1].Beginning;
579 for(x=Levels[y].Beginning; x<IconCounter; x++)
581 if(Icons[x].Icon_OK)
583 if(Icons[x].Icon_Height > WindowHeight)
585 WindowHeight = Icons[x].Icon_Height;
588 if(Icons[x].Icon_Width > IconWidth)
590 IconWidth = Icons[x].Icon_Width;
593 // ------------- Calculate lenght of Label
595 strcpy(IT_Labels, Icons[x].IK_Label);
597 for(z=strlen(Icons[x].IK_Label); z>1; z--)
599 IT_Labels[z - 1] = '\0';
601 if(IntuiTextLength(&Labels) < Icons[x].Icon_Width)
603 Icons[x].IK_Label_Length = z;
604 break;
608 // ----------------------------------------
610 if((WindowWidth + Icons[x].Icon_Width + 35) > ScreenWidth)
612 IconCounter = x;
613 Levels[y+1].Beginning = x;
614 break;
617 WindowWidth = WindowWidth + Icons[x].Icon_Width + Spacing;
618 Icons[x].Icon_PositionY = 10;
620 if((x+1) != IconCounter)
622 Icons[x+1].Icon_PositionX = WindowWidth;
625 else
626 break;
629 for(x=Levels[y].Beginning; x<IconCounter; x++)
631 if(Icons[x].Icon_OK)
633 Icons[x].Icon_PositionX = Icons[x].Icon_PositionX + 15;
634 Icons[x].Icon_PositionY = WindowHeight / 2 - Icons[x].Icon_Height / 2 + 15;
638 Levels[y].WindowPos_X = WindowWidth + 30;
639 Levels[y].WindowPos_Y = WindowHeight + 20;
641 // ------------- Up the icon if labeling is ON
643 if(B_Labels == TRUE)
645 Levels[y].WindowPos_Y = Levels[y].WindowPos_Y + 10;
648 // ----------------------------------
650 if(Levels[y].WindowPos_X > ScreenWidth)
651 Levels[y].WindowPos_X = WindowWidth;
653 if(Window_Max_X < Levels[y].WindowPos_X)
654 Window_Max_X = Levels[y].WindowPos_X;
656 if(Window_Max_Y < Levels[y].WindowPos_Y)
657 Window_Max_Y = Levels[y].WindowPos_Y;
660 if((MyScreen=LockPubScreen(NULL)))
662 BMP_Buffer = AllocBitMap(Window_Max_X,
663 Window_Max_Y,
664 GetBitMapAttr(MyScreen->RastPort.BitMap,
665 BMA_DEPTH),
666 BMF_MINPLANES|BMF_CLEAR,
667 MyScreen->RastPort.BitMap);
669 if (BMP_Buffer == NULL)
671 return FALSE;
674 InitRastPort(&RP_Buffer);
675 RP_Buffer.BitMap = BMP_Buffer;
676 RP_Buffer.Layer = NULL;
678 BMP_DoubleBuffer = AllocBitMap(IconWidth + 8,
679 Window_Max_Y,
680 GetBitMapAttr(MyScreen->RastPort.BitMap,
681 BMA_DEPTH),
682 BMF_MINPLANES|BMF_CLEAR,
683 MyScreen->RastPort.BitMap);
684 if (BMP_DoubleBuffer == NULL)
686 return FALSE;
689 InitRastPort(&RP_DoubleBuffer);
690 RP_DoubleBuffer.BitMap = BMP_DoubleBuffer;
691 RP_DoubleBuffer.Layer = NULL;
693 UnlockPubScreen(NULL,MyScreen);
695 return TRUE;
699 static void Decode_Toolbar_IDCMP(struct IntuiMessage *KomIDCMP)
701 LONG x;
703 switch(KomIDCMP->Class)
705 case IDCMP_CLOSEWINDOW:
706 BiB_Exit = TRUE;
707 break;
709 case IDCMP_MOUSEMOVE:
710 for(MouseIcon=Levels[CurrentLevel].Beginning; MouseIcon<IconCounter; MouseIcon++)
712 if(Icons[MouseIcon].Icon_OK)
715 if((ScreenHeight - MyScreen->MouseY) > WindowHeight)
717 Window_Active = FALSE;
720 if(KomIDCMP->MouseX > Icons[MouseIcon].Icon_PositionX &&
721 KomIDCMP->MouseX < Icons[MouseIcon].Icon_PositionX + Icons[MouseIcon].Icon_Width &&
722 KomIDCMP->MouseY > 0 &&
723 KomIDCMP->MouseY < WindowHeight - 5)
725 if((Icons[MouseIcon].Icon_Status & ICON_ACTIVE) != ICON_ACTIVE)
727 for(x=Levels[CurrentLevel].Beginning; x<IconCounter; x++)
729 Icons[x].Icon_Status = Icons[x].Icon_Status & 0x07;
732 Icons[MouseIcon].Icon_Status = ICON_ACTIVE | (SELECTED_ICON * lbm);
734 break;
736 Icons[MouseIcon].Icon_Status = Icons[MouseIcon].Icon_Status & 0x07;
739 break;
742 case IDCMP_MOUSEBUTTONS:
743 switch (KomIDCMP->Code)
745 case SELECTDOWN:
746 Icons[MouseIcon].Icon_Status = Icons[MouseIcon].Icon_Status | SELECTED_ICON;
747 lbm = 1;
749 break;
751 case SELECTUP:
752 lbm = 0;
754 if((Icons[MouseIcon].Icon_Status & (SELECTED_ICON | ICON_ACTIVE)) == (SELECTED_ICON | ICON_ACTIVE))
756 Blink_Icon(MouseIcon);
757 Launch_Program(Icons[MouseIcon].Icon_Path);
760 Icons[MouseIcon].Icon_Status = Icons[MouseIcon].Icon_Status & 0xBF; //10001111b
762 break;
764 case MENUDOWN:
765 rbm = 1;
766 OpenMenuWindow();
767 break;
770 break;
772 case IDCMP_RAWKEY:
773 switch(KomIDCMP->Code)
775 case RAWKEY_ESCAPE:
776 if((KomIDCMP->Qualifier) & IEQUALIFIER_LSHIFT)
778 BiB_Exit = TRUE;
780 break;
782 case RAWKEY_F1:
783 for(x=0; x<SUM_ICON; x++)
785 if(Icon[x] != NULL)
787 LayoutIcon(Icon[x],
788 MyScreen,
789 NULL);
793 for(x=Levels[CurrentLevel].Beginning; x<IconCounter; x++)
795 if(Icon[x] != NULL)
797 DrawIconState(MainWindow->RPort,
798 Icon[x],
799 NULL,
800 Icons[x].Icon_PositionX,
801 Icons[x].Icon_PositionY,
802 IDS_NORMAL,
803 ICONDRAWA_Frameless, TRUE,
804 ICONDRAWA_EraseBackground, FALSE,
805 TAG_DONE);
808 break;
810 case RAWKEY_F2:
811 case RAWKEY_NM_WHEEL_DOWN:
812 CurrentLevel++;
813 if(CurrentLevel == (LevelCounter - 2 ))
814 CurrentLevel = 0;
815 Show_Selected_Level();
816 break;
818 case RAWKEY_F3:
819 case RAWKEY_NM_WHEEL_UP:
820 CurrentLevel--;
821 if(CurrentLevel < 0)
822 CurrentLevel = LevelCounter - 3;
823 Show_Selected_Level();
824 break;
826 case RAWKEY_F4:
827 Settings();
828 break;
830 break;
832 case IDCMP_INACTIVEWINDOW:
833 if(rbm == 0)
834 Window_Active = FALSE;
835 lbm = 0;
837 if(Static)
839 for(x=Levels[CurrentLevel].Beginning; x<IconCounter; x++)
841 if(Icons[x].Icon_Status != 0)
843 Icons[x].Icon_Status = 0;
844 Insert_Icon(IDS_NORMAL, x);
848 break;
850 case IDCMP_INTUITICKS:
851 Change_State(0);
852 break;
857 static void Change_State(LONG Mode)
859 LONG x;
861 for(x=Levels[CurrentLevel].Beginning; x<IconCounter; x++)
863 if(Icons[x].Icon_OK)
865 if(Icons[x].Icon_Status != 0)
867 if(Mode == 0)
869 if((Icons[x].Icon_Status & ICON_ACTIVE) == 0 && Icons[x].Icon_Status < 4)
871 Icons[x].Icon_Status = (Icons[x].Icon_Status - 1) & 0xC7; // 11000111b
873 else
875 Icons[x].Icon_Status = (Icons[x].Icon_Status + 1) & 0xC7;
878 else
880 Icons[x].Icon_Status = 0;
883 Insert_Icon((Icons[x].Icon_Status & SELECTED_ICON) ? IDS_SELECTED : IDS_NORMAL, x);
890 static void Insert_Icon(LONG Mode, LONG NrIcon)
892 BltBitMapRastPort(BMP_Buffer,
893 Icons[NrIcon].Icon_PositionX,
895 &RP_DoubleBuffer,
898 Icons[NrIcon].Icon_Width + 1,
899 WindowHeight,
900 0xC0);
902 DrawIconState(&RP_DoubleBuffer,
903 Icon[NrIcon],
904 NULL,
906 Icons[NrIcon].Icon_PositionY - MovingTable[(Icons[NrIcon].Icon_Status & 0x07)],
907 Mode,
908 ICONDRAWA_Frameless, TRUE,
909 ICONDRAWA_EraseBackground, FALSE,
910 TAG_DONE);
912 BltBitMapRastPort(BMP_DoubleBuffer,
915 MainWindow->RPort,
916 Icons[NrIcon].Icon_PositionX,
918 Icons[NrIcon].Icon_Width + 1,
919 WindowHeight,
920 0xC0);
924 static void Blink_Icon(LONG NrIcon)
926 LONG x, Mode=IDS_SELECTED;
928 for(x=0; x<8; x++)
930 Insert_Icon(Mode, NrIcon);
931 Delay(3);
933 if(Mode == IDS_NORMAL)
934 Mode = IDS_SELECTED;
935 else
936 Mode = IDS_NORMAL;
941 static BOOL OpenMainWindow(void)
943 LONG x, y, a;
945 if((MyScreen=LockPubScreen(NULL)))
947 BltBitMapRastPort(MyScreen->RastPort.BitMap,
948 ScreenWidth / 2 - WindowWidth / 2,
949 ScreenHeight - WindowHeight,
950 &RP_Buffer,
951 0, 0,
952 Window_Max_X,
953 Window_Max_Y,
954 0xC0);
956 UnlockPubScreen(NULL,MyScreen);
959 if(picture[0] && picture[1] && picture[2])
961 y = WindowWidth - BackgroundData[0].Width - BackgroundData[2].Width;
962 a = y / BackgroundData[1].Width;
964 BltBitMapRastPort(bm[0],
967 &RP_Buffer,
969 WindowHeight - BackgroundData[0].Height,
970 BackgroundData[0].Width,
971 BackgroundData[0].Height,
972 0xC0);
974 for(x=0; x<a; x++)
976 BltBitMapRastPort(bm[1],
979 &RP_Buffer,
980 BackgroundData[0].Width + x * BackgroundData[1].Width,
981 WindowHeight - BackgroundData[1].Height,
982 BackgroundData[1].Width,
983 BackgroundData[1].Height,
984 0xC0);
987 BltBitMapRastPort(bm[1],
990 &RP_Buffer,
991 BackgroundData[0].Width + x * BackgroundData[1].Width,
992 WindowHeight - BackgroundData[1].Height,
993 y - BackgroundData[1].Width * a,
994 BackgroundData[1].Height,
995 0xC0);
997 BltBitMapRastPort(bm[2],
1000 &RP_Buffer,
1001 WindowWidth - BackgroundData[2].Width,
1002 WindowHeight - BackgroundData[2].Height,
1003 BackgroundData[2].Width,
1004 BackgroundData[2].Height,
1005 0xC0);
1007 else if(picture[1])
1009 for(x=0; x<WindowWidth; x=x+BackgroundData[1].Width)
1011 BltBitMapRastPort(bm[1],
1014 &RP_Buffer,
1016 WindowHeight - BackgroundData[1].Height,
1017 BackgroundData[1].Width,
1018 BackgroundData[1].Height,
1019 0xC0);
1023 // ---------- Labeling icon if NAMES is ON
1024 if(B_Labels == TRUE)
1025 IconLabel();
1027 if(Icon_Remap == TRUE)
1029 for(x=Levels[CurrentLevel].Beginning; x<IconCounter; x++)
1031 if(Icon[x]!=NULL)
1033 LayoutIcon(Icon[x], MyScreen, NULL);
1038 if((MainWindow=OpenWindowTags(NULL,
1039 WA_Left, BeginningWindow,
1040 WA_Top, ScreenHeight - WindowHeight,
1041 WA_InnerWidth, WindowWidth,
1042 WA_InnerHeight, WindowHeight,
1043 WA_ReportMouse, TRUE,
1044 WA_MouseQueue, 3,
1045 WA_Borderless, TRUE,
1046 WA_SizeGadget, FALSE,
1047 WA_Activate, ((FirstOpening && Static) ? FALSE : TRUE),
1048 WA_PubScreenName, NULL,
1049 WA_BackFill, LAYERS_NOBACKFILL,
1050 WA_Flags, WFLG_NOCAREREFRESH|
1051 WFLG_SMART_REFRESH|
1052 WFLG_RMBTRAP,
1053 WA_IDCMP, IDCMP_NEWSIZE|
1054 IDCMP_RAWKEY|
1055 IDCMP_INACTIVEWINDOW|
1056 IDCMP_MOUSEMOVE|
1057 IDCMP_INTUITICKS|
1058 IDCMP_MOUSEBUTTONS,
1059 TAG_END)))
1061 WindowMask = 1 << MainWindow->UserPort->mp_SigBit;
1063 BltBitMapRastPort(BMP_Buffer,
1064 0, 0,
1065 MainWindow->RPort,
1066 0, 0,
1067 WindowWidth,
1068 WindowHeight,
1069 0xC0);
1071 for(x=Levels[CurrentLevel].Beginning; x<IconCounter; x++)
1073 if(Icon[x] != NULL)
1075 DrawIconState(MainWindow->RPort,
1076 Icon[x],
1077 NULL,
1078 Icons[x].Icon_PositionX,
1079 Icons[x].Icon_PositionY,
1080 IDS_NORMAL,
1081 ICONDRAWA_Frameless, TRUE,
1082 ICONDRAWA_EraseBackground, FALSE,
1083 TAG_DONE);
1087 else
1089 printf("Can't open main toolbar window\n");
1090 return FALSE;
1093 Window_Open = TRUE;
1094 Window_Active = TRUE;
1096 return TRUE;
1100 static void CloseMainWindow(void)
1102 LONG x;
1103 if(MainWindow)
1104 CloseWindow(MainWindow);
1105 for(x=Levels[CurrentLevel].Beginning; x<IconCounter; x++)
1107 Icons[x].Icon_Status = 0;
1110 Window_Open = FALSE;
1111 WindowMask = 0;
1115 static void CheckMousePosition(void)
1117 if((MyScreen->MouseY > ScreenHeight - 8) &&
1118 Window_Open == FALSE &&
1119 MyScreen->MouseX > BeginningWindow &&
1120 MyScreen->MouseX < EndingWindow)
1122 if(OpenMainWindow() == FALSE)
1124 BiB_Exit = TRUE;
1128 // LJ: trying to make window active when going to very bottom of the screen
1129 // even in static mode - but it doesn't work because this code is checked
1130 // only in static=0 mode
1132 else
1133 if ((MyScreen->MouseY > ScreenHeight - 8) &&
1134 Window_Open == TRUE &&
1135 MyScreen->MouseX > BeginningWindow &&
1136 MyScreen->MouseX < EndingWindow)
1138 printf("LJ: You're at the very bottom! I should make this window active!\n");
1139 Window_Active = TRUE;
1144 static void Show_Selected_Level(void)
1146 CloseMainWindow();
1148 IconCounter = Levels[CurrentLevel+1].Beginning;
1149 WindowWidth = Levels[CurrentLevel].WindowPos_X;
1150 WindowHeight = Levels[CurrentLevel].WindowPos_Y;
1151 BeginningWindow = ScreenWidth / 2 - WindowWidth / 2;
1152 EndingWindow = ScreenWidth / 2 + WindowWidth / 2;
1154 //LJ: delay needed for AROS, otherwise garbage from old icons remains
1155 Delay(10); // 200 ms seems to be enough
1157 if(OpenMainWindow() == FALSE)
1159 BiB_Exit = TRUE;
1164 static void OpenMenuWindow(void)
1166 LONG x;
1168 if((MenuWindow = OpenWindowTags(NULL,
1169 WA_Left, MyScreen->MouseX,
1170 WA_Top, MyScreen->MouseY,
1171 WA_InnerWidth, Lenght + 1,
1172 WA_InnerHeight, LevelCounter * 16,
1173 WA_AutoAdjust, TRUE,
1174 WA_ReportMouse, TRUE,
1175 WA_Borderless, TRUE,
1176 WA_IDCMP,IDCMP_MOUSEBUTTONS|
1177 IDCMP_MOUSEMOVE|
1178 IDCMP_INACTIVEWINDOW,
1179 WA_Flags,WFLG_ACTIVATE|
1180 WFLG_RMBTRAP|
1181 WFLG_SMART_REFRESH,
1182 TAG_END)))
1184 MenuMask = 1 << MenuWindow->UserPort->mp_SigBit;
1186 SetAPen(MenuWindow->RPort, 1);
1187 Move(MenuWindow->RPort, Lenght, 0);
1188 Draw(MenuWindow->RPort, Lenght, LevelCounter * 16);
1189 Draw(MenuWindow->RPort, 0, LevelCounter * 16);
1190 SetAPen(MenuWindow->RPort, 2);
1191 Draw(MenuWindow->RPort, 0, 0);
1192 Draw(MenuWindow->RPort, Lenght, 0);
1194 // draw bar
1195 SetAPen(MenuWindow->RPort, 1);
1196 Move(MenuWindow->RPort, 0, (LevelCounter - 2) * 16);
1197 Draw(MenuWindow->RPort, Lenght - 1, (LevelCounter - 2) * 16);
1199 SetAPen(MenuWindow->RPort, 2);
1200 Move(MenuWindow->RPort, 0, ((LevelCounter - 2) * 16) + 1);
1201 Draw(MenuWindow->RPort, Lenght - 1, ((LevelCounter - 2) * 16) + 1);
1203 for(x=0; x<LevelCounter; x++)
1205 if(x == CurrentLevel)
1206 Names.FrontPen = 2;
1207 else
1208 Names.FrontPen = 1;
1210 strcpy(BufferList, Levels[x].Level_Name);
1212 PrintIText(MenuWindow->RPort,
1213 &Names,
1215 (x * 16) + 5);
1217 MenuWindow_Open = TRUE;
1219 else
1220 printf("Can't open menu\n");
1224 static void CloseMenuWindow(void)
1226 CloseWindow(MenuWindow);
1227 MenuMask = 0;
1229 if(PositionMenuOK == TRUE)
1231 if(Position == (LevelCounter - 1))
1233 BiB_Exit = TRUE;
1235 else if(Position == (LevelCounter - 2))
1237 Settings();
1239 else
1241 CurrentLevel = Position;
1242 Show_Selected_Level();
1248 static void Decode_Menu_IDCMP(struct IntuiMessage *KomIDCMP)
1250 LONG x, kolA, kolB, dluG, x4;
1252 dluG = Lenght - 2;
1254 switch(KomIDCMP->Class)
1256 case IDCMP_MOUSEMOVE:
1257 if(MenuWindow->MouseX > 0 &&
1258 MenuWindow->MouseX < Lenght &&
1259 MenuWindow->MouseY >0)
1261 Position = MenuWindow->MouseY / 16;
1263 else
1265 Position = 100;
1268 if(Position != OldPosition)
1270 for(x=0; x<LevelCounter; x++)
1272 x4 = (x * 16) + 2;
1274 if(x == Position)
1276 kolA = 2;
1277 kolB = 1;
1279 else
1281 kolA = 0;
1282 kolB = 0;
1285 SetAPen(MenuWindow->RPort, kolA);
1286 Move(MenuWindow->RPort, dluG, x4);
1287 Draw(MenuWindow->RPort, dluG, x4 + 13);
1288 Draw(MenuWindow->RPort, 2, x4 + 13);
1289 SetAPen(MenuWindow->RPort, kolB);
1290 Draw(MenuWindow->RPort, 2, x4);
1291 Draw(MenuWindow->RPort, dluG, x4);
1294 if(Position != CurrentLevel && Position != 100)
1295 PositionMenuOK = TRUE;
1296 else
1297 PositionMenuOK = FALSE;
1299 OldPosition = Position;
1302 break;
1304 case IDCMP_MOUSEBUTTONS:
1305 switch (KomIDCMP->Code)
1307 case MENUUP:
1308 MenuWindow_Open = FALSE;
1309 rbm = 0;
1310 break;
1312 break;
1314 case IDCMP_INACTIVEWINDOW:
1315 MenuWindow_Open = FALSE;
1316 break;
1321 static void Launch_Program(STRPTR Program)
1323 BPTR oldlock;
1325 // Get current directory lock
1326 oldlock = CurrentDir(NULL);
1328 OpenWorkbenchObject(Program, TAG_DONE);
1330 // Go back to old directory
1331 CurrentDir(oldlock);
1335 static void Settings(void)
1337 OpenWorkbenchObject("SYS:Prefs/BoingIconBar", TAG_DONE);
1341 static void Reload(void)
1343 LONG x;
1345 if (Window_Open == TRUE)
1347 CloseMainWindow();
1350 for(x=0; x<SUM_ICON; x++)
1352 if(Icon[x] != NULL)
1354 FreeDiskObject(Icon[x]);
1355 Icon[x]=NULL;
1357 Icons[x].Icon_Height = 0;
1358 Icons[x].Icon_Width = 0;
1359 Icons[x].Icon_PositionX = 0;
1360 Icons[x].Icon_PositionY = 0;
1363 if(BMP_Buffer)
1364 FreeBitMap(BMP_Buffer);
1365 if(BMP_DoubleBuffer)
1366 FreeBitMap(BMP_DoubleBuffer);
1368 if(ReadPrefs() == FALSE)
1370 puts("Prefs error\n");
1371 return;
1374 if(Static)
1376 Delay(Static * 50);
1377 OpenMainWindow();
1378 FirstOpening = FALSE;
1383 static void IconLabel(void)
1385 LONG x, y, pos_x;
1387 for(x=Levels[CurrentLevel].Beginning; x<IconCounter; x++)
1389 for(y=0; y<Icons[x].IK_Label_Length; y++)
1391 IT_Labels[y] = Icons[x].IK_Label[y];
1394 IT_Labels[y] = '\0';
1396 pos_x = Icons[x].Icon_PositionX + Icons[x].Icon_Width / 2 - IntuiTextLength(&Labels) / 2;
1398 Labels.FrontPen = 1;
1400 PrintIText(&RP_Buffer,
1401 &Labels,
1402 pos_x,
1403 WindowHeight - 12);
1405 Labels.FrontPen = 2;
1407 PrintIText(&RP_Buffer,
1408 &Labels,
1409 pos_x + 1,
1410 WindowHeight - 13);