2 * Acess2 Window Manager v3 (axwin3)
3 * - By John Hodge (thePowersGang)
10 #include <decorator.h>
11 #include <wm_messages.h>
14 extern tWindow *gpWM_FocusedWindow;
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);
22 #define BTN_CLOSE(win) win->W-16, -16, 14, 14
23 #define BTN_MIN(win) win->W-32, -16, 14, 14
24 tColour cColourActive_Titlebar = 0x00CC44;
25 tColour cColourActive_TitleText = 0x000000;
26 tColour cColourInactive_Titlebar = 0xD0D0D0;
27 tColour cColourInactive_TitleText= 0x000000;
28 tColour cColour_TitleTopBorder = 0xFFFFFF;
29 tColour cColour_SideBorder = 0x008000;
30 tColour cColour_BottomBorder = 0x008000;
31 tColour cColour_CloseBtn = 0xFF1100;
32 int ciTitlebarHeight = 18;
33 int ciSideBorderWidth = 2;
34 int ciBottomBorderWidth = 4;
37 void Decorator_UpdateBorderSize(tWindow *Window)
39 Window->BorderT = ciTitlebarHeight;
44 if( Window->Flags & WINFLAG_MAXIMIZED )
47 Window->BorderB = ciBottomBorderWidth;
48 Window->BorderR = ciSideBorderWidth;
49 Window->BorderL = ciSideBorderWidth;
52 void Decorator_Redraw(tWindow *Window)
55 int text_width, text_height;
57 // TODO: This could possibly be expensive, but is there a better way?
60 for(win = gpWM_FocusedWindow; win; win = win->Owner)
71 WM_Render_FillRect(Window,
72 0, -ciTitlebarHeight, Window->W, ciTitlebarHeight,
73 (bActive ? cColourActive_Titlebar : cColourInactive_Titlebar)
76 WM_Render_FillRect(Window,
77 0, -ciTitlebarHeight, Window->W, 1,
78 cColour_TitleTopBorder
81 WM_Render_FillRect(Window,
82 0, -ciTitlebarHeight, 1, ciTitlebarHeight,
85 WM_Render_FillRect(Window,
86 Window->W, -ciTitlebarHeight, 1, ciTitlebarHeight,
90 // Get the font height
91 WM_Render_GetTextDims(
92 NULL, // TODO: Select font
93 Window->Title ? Window->Title : "jI", -1,
94 &text_width, &text_height
96 // - Use that to draw the window title on the left of the window
97 WM_Render_DrawText(Window,
98 ciTitlebarHeight + 4, -(ciTitlebarHeight - (ciTitlebarHeight/2 - text_height/2)),
99 Window->W - ciTitlebarHeight - 4, text_height,
100 NULL, // TODO: Select font
101 (bActive ? cColourActive_TitleText : cColourInactive_TitleText),
102 Window->Title ? Window->Title : "--", -1
105 // TODO: Minimise, Maximise and Close
107 // Maximized windows don't have any other borders
108 if( Window->Flags & WINFLAG_MAXIMIZED )
112 WM_Render_FillRect(Window,
113 -ciSideBorderWidth, -ciTitlebarHeight,
114 ciSideBorderWidth, Window->H + ciTitlebarHeight + ciBottomBorderWidth,
118 WM_Render_FillRect(Window,
119 Window->W, -ciTitlebarHeight,
120 ciSideBorderWidth, Window->H + ciTitlebarHeight + ciBottomBorderWidth,
123 // Bottom Border (hard line)
124 WM_Render_FillRect(Window,
125 -ciSideBorderWidth, Window->H,
126 ciSideBorderWidth*2+Window->W, 1,
130 WM_Render_FillRect(Window,
131 -ciSideBorderWidth, Window->H+1,
132 ciSideBorderWidth*2+Window->W, ciBottomBorderWidth-1,
137 WM_Render_FillRect(Window, BTN_CLOSE(Window), cColour_CloseBtn);
138 // TODO: Conditional for each
141 static inline int Decorator_INT_CoordInRange(int X, int Y, int SX, int SY, int EX, int EY)
143 _SysDebug("(%i<=%i<%i, %i<=%i<%i", SX, X, EX, SY, Y, EY);
144 return (X >= SX && X < EX && Y >= SY && Y < EY);
146 static inline int Decorator_INT_CoordInRangeR(int X, int Y, int SX, int SY, int W, int H)
148 return Decorator_INT_CoordInRange(X, Y, SX, SY, SX+W, SY+H);
151 int Decorator_HandleMessage(tWindow *Window, int Message, int Length, const void *Data)
153 static tWindow *btn1_down;
162 case WNDMSG_MOUSEMOVE: {
163 const struct sWndMsg_MouseMove *msg = Data;
165 if( btn1_down == Window )
169 case BTN1_MOVE: // Move
170 WM_MoveWindow(Window, Window->X + msg->dX, Window->Y + msg->dY);
172 case BTN1_RLEFT: // Resize left
173 if( Window->W + msg->dX > 50 )
175 WM_MoveWindow(Window, Window->X + msg->dX, Window->Y);
176 WM_ResizeWindow(Window, Window->W - msg->dX, Window->H);
179 case BTN1_RRIGHT: // Resize right
180 if( Window->W + msg->dX > 50 )
182 WM_ResizeWindow(Window, Window->W + msg->dX, Window->H);
185 case BTN1_RBOTTOM: // Resize bottom
186 if( Window->H + msg->dY > 50 )
188 WM_ResizeWindow(Window, Window->W, Window->H + msg->dY);
195 // TODO: Change cursor when hovering over edges
197 if(msg->Y >= 0) return 1; // Pass
201 case WNDMSG_MOUSEBTN: {
202 const struct sWndMsg_MouseButton *msg = Data;
204 // TODO: Do something with other buttons
205 // - Window menu for example
206 if( msg->Button != 0 )
212 #define HOTSPOTR(x,y,w,h) Decorator_INT_CoordInRangeR(msg->X, msg->Y, x, y, w, h)
213 #define HOTSPOTA(sx,sy,ex,ey) Decorator_INT_CoordInRange(msg->X, msg->Y, sx, sy, ew, eh)
214 // Left resize border
215 if( msg->bPressed && HOTSPOTR(-ciSideBorderWidth, -ciTitlebarHeight,
216 ciSideBorderWidth, ciTitlebarHeight+Window->H+ciBottomBorderWidth) )
219 btn1_mode = BTN1_RLEFT;
222 // Right resize border
223 if( msg->bPressed && HOTSPOTR(Window->W, -ciTitlebarHeight,
224 ciSideBorderWidth, ciTitlebarHeight+Window->H+ciBottomBorderWidth) )
227 btn1_mode = BTN1_RRIGHT;
230 // Bottom resize border
231 if( msg->bPressed && HOTSPOTR(0, Window->H,
232 Window->W, ciTitlebarHeight) )
235 btn1_mode = BTN1_RBOTTOM;
239 if( msg->bPressed && Decorator_INT_CoordInRangeR(msg->X, msg->Y, BTN_CLOSE(Window)) )
241 WM_SendMessage(NULL, Window, WNDMSG_CLOSE, 0, NULL);
245 if( msg->bPressed && msg->Y < 0 )
248 btn1_mode = BTN1_MOVE;
255 default: // Anything unhandled is passed on