3f632682bd4c6766daba1e5572cd676bedf2215e
[tpg/acess2.git] / Usermode / Applications / axwin4_src / UI / taskbar.c
1 /*
2  * AxWin4 GUI - UI Core
3  * - By John Hodge (thePowersGang)
4  *
5  * taskbar.c
6  * - Main toolbar (aka Taskbar) 
7  */
8 #include <axwin4/axwin.h>
9 #include "include/common.h"
10 #include "include/taskbar.h"
11 #include <time.h>
12
13 // === CONSTANTS ===
14 #define TASKBAR_HEIGHT  30
15 #define TASKBAR_BORDER  3       // Border between window edge and controls
16 #define TASKBAR_SYSBTN_SIZE     (TASKBAR_HEIGHT-TASKBAR_BORDER*2)
17 #define TASKBAR_WIN_MAXSIZE     100
18 #define TASKBAR_WIN_MINSIZE     24
19 #define TASKBAR_CLOCKSIZE       60
20
21 // === TYPES ===
22 typedef struct sTaskbar_Win     tTaskbar_Win;
23 struct sTaskbar_Win
24 {
25         tTaskbar_Win    *Next;
26         const char      *Title;
27 };
28
29 // === PROTOTYPES ===
30
31 // === GLOBALS ===
32 tAxWin4_Window  *gpTaskbar_Window;
33 unsigned int giTaskbar_NumWins = 0;
34 tTaskbar_Win    *gpTaskbar_FirstWin;
35
36 // === CODE ===
37 void Taskbar_Create(void)
38 {
39         gpTaskbar_Window = AxWin4_CreateWindow("taskbar");
40         tAxWin4_Window * const win = gpTaskbar_Window;
41
42         AxWin4_MoveWindow(win, 0, 0);
43         AxWin4_ResizeWindow(win, giScreenWidth, TASKBAR_HEIGHT);
44         
45         AxWin4_SetWindowFlags(win, AXWIN4_WNDFLAG_NODECORATE);
46         Taskbar_Redraw();
47         AxWin4_ShowWindow(win, true);
48 }
49
50 void Taskbar_Redraw(void)
51 {
52         const int       w = giScreenWidth;
53         const int       h = TASKBAR_HEIGHT;
54         
55         const int       active_height = h - TASKBAR_BORDER*2;
56         const int       winlist_start_x = TASKBAR_BORDER+TASKBAR_SYSBTN_SIZE+TASKBAR_BORDER;
57         const int       clock_start_x = w - (TASKBAR_BORDER+TASKBAR_CLOCKSIZE);
58         
59         // Window background: Toolbar skin
60         AxWin4_DrawControl(gpTaskbar_Window, 0, 0, w, h, AXWIN4_CTL_TOOLBAR, 0);
61         
62         // System button
63         // TODO: Use an image instead
64         AxWin4_DrawControl(gpTaskbar_Window, TASKBAR_BORDER, TASKBAR_BORDER, TASKBAR_SYSBTN_SIZE, active_height, AXWIN4_CTL_BUTTON, 0);
65         
66         // Windows
67         // TODO: Maintain/request a list of windows
68         if( giTaskbar_NumWins )
69         {
70                 int winbutton_size = (clock_start_x - winlist_start_x) / giTaskbar_NumWins;
71                 if(winbutton_size > TASKBAR_WIN_MAXSIZE)        winbutton_size = TASKBAR_WIN_MAXSIZE;
72                 int x = winlist_start_x;
73                 for(tTaskbar_Win *win = gpTaskbar_FirstWin; win; win = win->Next )
74                 {
75                         AxWin4_DrawControl(gpTaskbar_Window, x, TASKBAR_BORDER, winbutton_size, active_height, AXWIN4_CTL_BUTTON, 0);
76                 }
77         }
78         
79         // Clock
80         {
81                 char timestr[5];
82                 time_t  rawtime;
83                 time(&rawtime);
84                 strftime(timestr, 5, "%H%M", localtime(&rawtime));
85                 //AxWin4_DrawControl(gpTaskbar_Window, clock_start_x, TASKBAR_BORDER, TASKBAR_CLOCKSIZE, active_height, AXWIN4_CTL_BOX);
86                 AxWin4_DrawText(gpTaskbar_Window, clock_start_x, TASKBAR_BORDER, TASKBAR_CLOCKSIZE, active_height, 0, timestr);
87                 //AxWin4_DrawText(gpTaskbar_Window, clock_start_x, TASKBAR_BORDER, TASKBAR_CLOCKSIZE, 16, 0, timestr);
88         }
89         
90         AxWin4_DamageRect(gpTaskbar_Window, 0, 0, w, h);
91 }
92

UCC git Repository :: git.ucc.asn.au