Usermode/AxWin3 - Cleaning up, graphics fixes and working on text cursor
[tpg/acess2.git] / Usermode / Applications / axwin3_src / WM / decorator.c
1 /*
2  * Acess2 Window Manager v3 (axwin3)
3  * - By John Hodge (thePowersGang)
4  *
5  * decorator.c
6  * - Window Decorator
7  */
8 #include <common.h>
9 #include <wm.h>
10 #include <decorator.h>
11 #include <wm_messages.h>
12
13 // === IMPORTS ===
14 extern tWindow  *gpWM_FocusedWindow;
15
16 // === PROTOTYPES ===
17 void    Decorator_UpdateBorderSize(tWindow *Window);
18 void    Decorator_Redraw(tWindow *Window);
19  int    Decorator_HandleMessage(tWindow *Window, int Message, int Length, const void *Data);
20
21 // === CONSTANTS ===
22 tColour cColourActive_Titlebar   = 0x00CC44;
23 tColour cColourActive_TitleText  = 0x000000;
24 tColour cColourInactive_Titlebar = 0xD0D0D0;
25 tColour cColourInactive_TitleText= 0x000000;
26 tColour cColour_TitleTopBorder   = 0xFFFFFF;
27 tColour cColour_SideBorder       = 0x008000;
28 tColour cColour_BottomBorder     = 0x008000;
29  int    ciTitlebarHeight        = 18;
30  int    ciSideBorderWidth       = 2;
31  int    ciBottomBorderWidth     = 4;
32
33 // === CODE ===
34 void Decorator_UpdateBorderSize(tWindow *Window)
35 {
36         Window->BorderT = ciTitlebarHeight;
37         Window->BorderB = 0;
38         Window->BorderL = 0;
39         Window->BorderR = 0;
40         
41         if( Window->Flags & WINFLAG_MAXIMIZED )
42                 return ;
43
44         _SysDebug("BorderL = %i", ciSideBorderWidth);
45         
46         Window->BorderB = ciBottomBorderWidth;
47         Window->BorderR = ciSideBorderWidth;
48         Window->BorderL = ciSideBorderWidth;
49 }
50
51 void Decorator_Redraw(tWindow *Window)
52 {
53          int    bActive;
54          int    text_width, text_height;
55         
56         // TODO: This could possibly be expensive, but is there a better way?
57         {
58                 tWindow *win;
59                 for(win = gpWM_FocusedWindow; win; win = win->Owner)
60                 {
61                         if(win == Window) {
62                                 bActive = 1;
63                                 break;
64                         }
65                 }
66         }
67
68         // Draw title bar
69         WM_Render_FillRect(Window,
70                 0, -ciTitlebarHeight, Window->W, ciTitlebarHeight,
71                 (bActive ? cColourActive_Titlebar : cColourInactive_Titlebar)
72                 );
73         WM_Render_FillRect(Window,
74                 0, -ciTitlebarHeight, Window->W, 1,
75                 cColour_TitleTopBorder
76                 );
77         WM_Render_FillRect(Window,
78                 0, -ciTitlebarHeight, 1, ciTitlebarHeight,
79                 cColour_SideBorder
80                 );
81         WM_Render_FillRect(Window,
82                 Window->W, -ciTitlebarHeight, 1, ciTitlebarHeight,
83                 cColour_SideBorder
84                 );
85
86         WM_Render_GetTextDims(
87                 NULL,   // TODO: Select font
88                 Window->Title ? Window->Title : "jI",
89                 &text_width, &text_height
90                 );
91         WM_Render_DrawText(Window,
92                 ciTitlebarHeight + 4, -(ciTitlebarHeight - (ciTitlebarHeight/2 - text_height/2)),
93                 Window->W - ciTitlebarHeight - 4, text_height,
94                 NULL,   // TODO: Select font
95                 (bActive ? cColourActive_TitleText : cColourInactive_TitleText),
96                 Window->Title ? Window->Title : "--"
97                 );
98         
99         // Maximized windows don't have any other borders
100         if( Window->Flags & WINFLAG_MAXIMIZED )
101                 return ;
102         
103         // Left
104         WM_Render_FillRect(Window,
105                 -ciSideBorderWidth, -ciTitlebarHeight,
106                 ciSideBorderWidth, Window->H + ciTitlebarHeight + ciBottomBorderWidth,
107                 cColour_SideBorder
108                 );
109         // Right
110         WM_Render_FillRect(Window,
111                 Window->W, -ciTitlebarHeight,
112                 ciSideBorderWidth, Window->H + ciTitlebarHeight + ciBottomBorderWidth,
113                 cColour_SideBorder
114                 );
115         // Bottom
116         WM_Render_FillRect(Window,
117                 -ciSideBorderWidth, Window->H,
118                 ciSideBorderWidth*2+Window->W, 1,
119                 0x000000
120                 );
121         WM_Render_FillRect(Window,
122                 -ciSideBorderWidth, Window->H+1,
123                 ciSideBorderWidth*2+Window->W, ciBottomBorderWidth-1,
124                 cColour_BottomBorder
125                 );
126 }
127
128 int Decorator_HandleMessage(tWindow *Window, int Message, int Length, const void *Data)
129 {
130         switch(Message)
131         {
132         case WNDMSG_MOUSEMOVE: {
133                 const struct sWndMsg_MouseMove  *msg = Data;
134                 if(msg->Y >= 0) return 1;       // Pass
135                 
136                 // TODO: Handle
137                 return 0; }
138         case WNDMSG_MOUSEBTN: {
139                 const struct sWndMsg_MouseButton        *msg = Data;
140                 if(msg->Y >= 0) return 1;       // Pass
141                 
142                 // TODO: Handle
143                 return 0; }
144         default:        // Anything unhandled is passed on
145                 return 1;
146         }
147 }
148

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