m_surface.Resize(W, H);
IPC::SendMessage_NotifyDims(m_client, W, H);
}
+void CWindow::SetFlags(uint32_t Flags)
+{
+ // TODO: CWindow::SetFlags
+ _SysDebug("TOOD: CWindow::SetFlags");
+}
uint64_t CWindow::ShareSurface()
{
assert(!"TODO: CWindow::ShareSurface");
* Handles drawing of resizable controls defined by a bitmap and four region sizes
*/
#include <draw_control.hpp>
+#include <axwin4/definitions.h>
// === CODE ===
namespace AxWin {
0xC0C0C0, 0xC0C0C0, 0xC0C0C0, 0xC0C0C0, 0xC0C0C0,
});
+// Toolbar
+CControl StdToolbar(2, 1, 0, 2, 1, 0, ::std::vector<uint32_t> {
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ 0x000000, 0xA0A0A0, 0x0A0000, 0xA0A0A0, 0x000000,
+ 0x000000, 0xA0A0A0, 0xFFFFFF, 0xA0A0A0, 0x000000,
+ 0x000000, 0xA0A0A0, 0x0A0000, 0xA0A0A0, 0x000000,
+ 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
+ });
+
// Text Area
CControl StdText(2, 1, 0, 2, 1, 0, ::std::vector<uint32_t> {
0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
{
switch(id)
{
- case 0x00: return &StdButton;
- case 0x01: return &StdText;
+ case AXWIN4_CTL_BUTTON: return &StdButton;
+ case AXWIN4_CTL_TOOLBAR: return &StdToolbar;
+ case AXWIN4_CTL_TEXTBOX: return &StdText;
default: return nullptr;
}
}
--- /dev/null
+/*
+ * Acess2 GUI v4
+ * - By John Hodge (thePowersGang)
+ *
+ * draw_text.cpp
+ * - Text Drawing
+ *
+ * Handles font selection and drawing of text to windows
+ */
+#include <draw_text.hpp>
+#include <axwin4/definitions.h>
+
+// === CODE ===
+namespace AxWin {
+
+CFont::CFont():
+
+{
+}
+
+CFont::CFont(const char *Path):
+
+{
+}
+
+/**
+ * \param Text height in pixels (not in points)
+ */
+void CFont::Render(CSurface& dest, const CRect& rect, const ::std::string& text, unsigned int Size) const
+{
+
+}
+
+}; // namespace AxWin
+
void Show(bool bShow);
void Move(int X, int Y);
void Resize(unsigned int W, unsigned int H);
+ void SetFlags(uint32_t Flags);
uint64_t ShareSurface();
win->Show( message.ReadU8() != 0 );
break;
case IPC_WINATTR_FLAGS:
- _SysDebug("TODO: IPC_WINATTR_FLAGS");
+ win->SetFlags( message.ReadU8() ); // TODO: U8? why so small?
break;
case IPC_WINATTR_TITLE:
assert(!"TODO: IPC_WINATTR_TITLE");
uint16_t w = message.ReadU16();
uint16_t h = message.ReadU16();
uint16_t ctrl_id = message.ReadU16();
+ uint16_t frame = message.ReadU16();
CWindow* win = client.GetWindow(win_id);
if(!win) {
DIR := Apps/AxWin/4.0
-OBJ := main.o
+OBJ := main.o taskbar.o
BIN := AxWinUI
--- /dev/null
+/*
+ */
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+extern unsigned int giScreenWidth;
+extern unsigned int giScreenHeight;
+
+#endif
+
--- /dev/null
+/*
+ */
+#ifndef _TASKBAR_H_
+#define _TASKBAR_H_
+
+#include <stdbool.h>
+
+extern void Taskbar_Create(void);
+extern void Taskbar_Redraw(void);
+
+#endif
+
*/
#include <axwin4/axwin.h>
#include <assert.h>
+#include "include/common.h"
+#include "include/taskbar.h"
+// === PROTOTYPES ===
tAxWin4_Window *CreateBGWin(int w, int h);
-tAxWin4_Window *CreateTaskbar(int w, int h);
+
+// === GLOABLS ===
+unsigned int giScreenWidth = 640;
+unsigned int giScreenHeight = 480;
// === CODE ===
int main(int argc, const char *argv[])
{
assert( AxWin4_Connect("ipcpipe:///Devices/ipcpipe/axwin4") );
- unsigned int w, h;
- AxWin4_GetScreenDimensions(0, &w, &h);
+ AxWin4_GetScreenDimensions(0, &giScreenWidth, &giScreenHeight);
- tAxWin4_Window *bgwin = CreateBGWin(w, h);
- tAxWin4_Window *menu = CreateTaskbar(w, h);
+ tAxWin4_Window *bgwin = CreateBGWin(giScreenWidth, giScreenHeight);
+ Taskbar_Create();
_SysDebug("Beginning queue");
while( AxWin4_WaitEventQueue(0) )
return bgwin;
}
-tAxWin4_Window *CreateTaskbar(int w, int h)
-{
- int winheight = 30;
- tAxWin4_Window *win = AxWin4_CreateWindow("taskbar");
- AxWin4_MoveWindow(win, 0, 0);
- AxWin4_ResizeWindow(win, w, winheight);
-
- AxWin4_SetWindowFlags(win, AXWIN4_WNDFLAG_NODECORATE);
- Taskbar_Redraw(win);
- AxWin4_ShowWindow(win, true);
-
- return win;
-}
-
-void Taskbar_Redraw(tAxWin4_Window *win)
-{
- int w = 640;
- int h = 30;
- AxWin4_DrawControl(win, 0, 0, w, h, 0x01); // Standard button, suitable for a toolbar
- AxWin4_DrawControl(win, 5, 5, h-10, h-10, 0x00); // Standard button
-
- AxWin4_DamageRect(bgwin, 0, 0, w, h);
-}
-
--- /dev/null
+/*
+ * AxWin4 GUI - UI Core
+ * - By John Hodge (thePowersGang)
+ *
+ * taskbar.c
+ * - Main toolbar (aka Taskbar)
+ */
+#include <axwin4/axwin.h>
+#include "include/common.h"
+#include "include/taskbar.h"
+#include <time.h>
+
+// === CONSTANTS ===
+#define TASKBAR_HEIGHT 30
+#define TASKBAR_BORDER 3 // Border between window edge and controls
+#define TASKBAR_SYSBTN_SIZE (TASKBAR_HEIGHT-TASKBAR_BORDER*2)
+#define TASKBAR_WIN_MAXSIZE 100
+#define TASKBAR_WIN_MINSIZE 24
+#define TASKBAR_CLOCKSIZE 60
+
+// === TYPES ===
+typedef struct sTaskbar_Win tTaskbar_Win;
+struct sTaskbar_Win
+{
+ tTaskbar_Win *Next;
+ const char *Title;
+};
+
+// === PROTOTYPES ===
+
+// === GLOBALS ===
+tAxWin4_Window *gpTaskbar_Window;
+unsigned int giTaskbar_NumWins = 0;
+tTaskbar_Win *gpTaskbar_FirstWin;
+
+// === CODE ===
+void Taskbar_Create(void)
+{
+ gpTaskbar_Window = AxWin4_CreateWindow("taskbar");
+ tAxWin4_Window * const win = gpTaskbar_Window;
+
+ AxWin4_MoveWindow(win, 0, 0);
+ AxWin4_ResizeWindow(win, giScreenWidth, TASKBAR_HEIGHT);
+
+ AxWin4_SetWindowFlags(win, AXWIN4_WNDFLAG_NODECORATE);
+ Taskbar_Redraw();
+ AxWin4_ShowWindow(win, true);
+}
+
+void Taskbar_Redraw(void)
+{
+ const int w = giScreenWidth;
+ const int h = TASKBAR_HEIGHT;
+
+ const int active_height = h - TASKBAR_BORDER*2;
+ const int winlist_start_x = TASKBAR_BORDER+TASKBAR_SYSBTN_SIZE+TASKBAR_BORDER;
+ const int clock_start_x = w - (TASKBAR_BORDER+TASKBAR_CLOCKSIZE);
+
+ // Window background: Toolbar skin
+ AxWin4_DrawControl(gpTaskbar_Window, 0, 0, w, h, AXWIN4_CTL_TOOLBAR, 0);
+
+ // System button
+ // TODO: Use an image instead
+ AxWin4_DrawControl(gpTaskbar_Window, TASKBAR_BORDER, TASKBAR_BORDER, TASKBAR_SYSBTN_SIZE, active_height, AXWIN4_CTL_BUTTON, 0);
+
+ // Windows
+ // TODO: Maintain/request a list of windows
+ if( giTaskbar_NumWins )
+ {
+ int winbutton_size = (clock_start_x - winlist_start_x) / giTaskbar_NumWins;
+ if(winbutton_size > TASKBAR_WIN_MAXSIZE) winbutton_size = TASKBAR_WIN_MAXSIZE;
+ int x = winlist_start_x;
+ for(tTaskbar_Win *win = gpTaskbar_FirstWin; win; win = win->Next )
+ {
+ AxWin4_DrawControl(gpTaskbar_Window, x, TASKBAR_BORDER, winbutton_size, active_height, AXWIN4_CTL_BUTTON, 0);
+ }
+ }
+
+ // Clock
+ {
+ char timestr[5];
+ time_t rawtime;
+ time(&rawtime);
+ strftime(timestr, 5, "%H%M", localtime(&rawtime));
+ //AxWin4_DrawControl(gpTaskbar_Window, clock_start_x, TASKBAR_BORDER, TASKBAR_CLOCKSIZE, active_height, AXWIN4_CTL_BOX);
+ AxWin4_DrawText(gpTaskbar_Window, clock_start_x, TASKBAR_BORDER, TASKBAR_CLOCKSIZE, active_height, 0, timestr);
+ }
+
+ AxWin4_DamageRect(gpTaskbar_Window, 0, 0, w, h);
+}
+
extern void AxWin4_DamageRect(tAxWin4_Window *Window, unsigned int X, unsigned int Y, unsigned int W, unsigned int H);
extern void* AxWin4_GetWindowBuffer(tAxWin4_Window *Window);
+/**
+ * \brief Set the render clipping region. Any attempts to render outside this area will silently fail
+ * \param Window Target window
+ *
+ * \note Allows clipping other render functions to avoid excessive redraws
+ * \note Cleared when \a AxWin4_DamageRect is called, or when called with a zero width or height
+ */
+extern void AxWin4_SetRenderClip(tAxWin4_Window *Window, int X, int Y, unsigned int W, unsigned int H);
+
+/**
+ * \brief Draw a user-supplied bitmap to the window
+ * \param Data Bitmap data in the same format as the window's back buffer
+ * \note VERY SLOW
+ */
extern void AxWin4_DrawBitmap(tAxWin4_Window *Window, int X, int Y, unsigned int W, unsigned int H, void *Data);
+/**
+ * \brief Draw a "control" to the window
+ * \param Window Target window
+ * \param X Destination X
+ * \param Y Destination Y
+ * \param W Control width
+ * \param H Control height
+ * \param ControlID Specifies which control to use. Can be a global or application-registered (See eAxWin4_GlobalControls)
+ * \param Frame Control frame number. Used to specify a variant of the control (e.g. hovered/pressed)
+ *
+ * Controls are server-side bitmaps that can be arbitarily scaled to fit a region.
+ */
+extern void AxWin4_DrawControl(tAxWin4_Window *Window, int X, int Y, unsigned int W, unsigned int H, uint16_t ControlID, unsigned int Frame);
-#include "definitions.h"
+extern void AxWin4_DrawText(tAxWin4_Window *Window, int X, int Y, unsigned int W, unsigned int H, uint16_t FontID, const char *String);
+#include "definitions.h"
#ifdef __cplusplus
}
#ifndef _LIBAXWIN4_AXWIN4_DEFINITIONS_H_
#define _LIBAXWIN4_AXWIN4_DEFINITIONS_H_
-#define AXWIN4_WNDFLAG_NODECORATE 0x01
-#define AXWIN4_WNDFLAG_KEEPBELOW 0x02
-#define AXWIN4_WNDFLAG_KEEPABOVE 0x04
+/**
+ * \name Window Flags
+ * \{
+ */
+#define AXWIN4_WNDFLAG_NODECORATE 0x01 //!< Disable automatic inclusion of window decorations
+#define AXWIN4_WNDFLAG_KEEPBELOW 0x02 //!< Keep the window below all others, even when it has focus
+#define AXWIN4_WNDFLAG_KEEPABOVE 0x04 //!< Keep window above all others, ecen when it loses focus
+/**
+ * \}
+ */
+
+/**
+ * \brief Global controls
+ */
+enum eAxWin4_GlobalControls {
+ AXWIN4_CTL_BUTTON, //!< Standard button (possibly rounded edges)
+ AXWIN4_CTL_BOX, //!< Grouping box in a window
+ AXWIN4_CTL_TOOLBAR, //!< Toolbar (raised region)
+ AXWIN4_CTL_TEXTBOX, //!< Text edit box
+};
+
+enum eAxWin4_GlobalFonts {
+ AXWIN4_FONT_DEFAULT, //!< Default font (usually a sans-serif)
+ AXWIN4_FONT_MONOSPACE, //!< Default monospace font
+};
#endif
}
}
-extern "C" void AxWin4_DrawControl(tAxWin4_Window *Window, int X, int Y, unsigned int W, unsigned int H, uint16_t ID)
+extern "C" void AxWin4_DrawControl(tAxWin4_Window *Window, int X, int Y, unsigned int W, unsigned int H, uint16_t ID, unsigned int Frame)
{
CSerialiser message;
message.WriteU8(IPCMSG_DRAWCTL);
message.WriteU16(W);
message.WriteU16(H);
message.WriteU16(ID);
+ message.WriteU16(Frame);
+ ::AxWin::SendMessage(message);
+}
+
+extern "C" void AxWin4_DrawText(tAxWin4_Window *Window, int X, int Y, unsigned int W, unsigned int H, uint16_t FontID, const char *String)
+{
+ CSerialiser message;
+ message.WriteU8(IPCMSG_DRAWTEXT);
+ message.WriteU16(Window->m_id);
+ message.WriteU16(X);
+ message.WriteU16(Y);
+ message.WriteU16(W);
+ message.WriteU16(H);
+ message.WriteU16(FontID);
+ message.WriteString(String);
::AxWin::SendMessage(message);
}