From 327dc4547b437dca7e6e839119a1ca1481b8a40a Mon Sep 17 00:00:00 2001 From: John Hodge Date: Mon, 25 Aug 2014 12:53:11 +0800 Subject: [PATCH] Usermode/AxWin4 - Controls working, starting on text --- .../axwin4_src/Server/CWindow.cpp | 5 + .../axwin4_src/Server/draw_control.cpp | 15 ++- .../axwin4_src/Server/draw_text.cpp | 35 +++++++ .../axwin4_src/Server/include/CWindow.hpp | 1 + .../Applications/axwin4_src/Server/ipc.cpp | 3 +- Usermode/Applications/axwin4_src/UI/Makefile | 2 +- .../axwin4_src/UI/include/common.h | 10 ++ .../axwin4_src/UI/include/taskbar.h | 12 +++ Usermode/Applications/axwin4_src/UI/main.c | 39 ++------ Usermode/Applications/axwin4_src/UI/taskbar.c | 91 +++++++++++++++++++ .../include_exp/axwin4/axwin.h | 30 +++++- .../include_exp/axwin4/definitions.h | 28 +++++- .../libaxwin4.so_src/window_drawing.cpp | 17 +++- 13 files changed, 250 insertions(+), 38 deletions(-) create mode 100644 Usermode/Applications/axwin4_src/Server/draw_text.cpp create mode 100644 Usermode/Applications/axwin4_src/UI/include/common.h create mode 100644 Usermode/Applications/axwin4_src/UI/include/taskbar.h create mode 100644 Usermode/Applications/axwin4_src/UI/taskbar.c diff --git a/Usermode/Applications/axwin4_src/Server/CWindow.cpp b/Usermode/Applications/axwin4_src/Server/CWindow.cpp index 32ff4f6b..a0067a72 100644 --- a/Usermode/Applications/axwin4_src/Server/CWindow.cpp +++ b/Usermode/Applications/axwin4_src/Server/CWindow.cpp @@ -59,6 +59,11 @@ void CWindow::Resize(unsigned int W, unsigned int H) 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"); diff --git a/Usermode/Applications/axwin4_src/Server/draw_control.cpp b/Usermode/Applications/axwin4_src/Server/draw_control.cpp index 264165f3..59ea0bc9 100644 --- a/Usermode/Applications/axwin4_src/Server/draw_control.cpp +++ b/Usermode/Applications/axwin4_src/Server/draw_control.cpp @@ -8,6 +8,7 @@ * Handles drawing of resizable controls defined by a bitmap and four region sizes */ #include +#include // === CODE === namespace AxWin { @@ -129,6 +130,15 @@ CControl StdButton(2, 1, 0, 2, 1, 0, ::std::vector { 0xC0C0C0, 0xC0C0C0, 0xC0C0C0, 0xC0C0C0, 0xC0C0C0, }); +// Toolbar +CControl StdToolbar(2, 1, 0, 2, 1, 0, ::std::vector { + 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 { 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, @@ -152,8 +162,9 @@ const CControl* CControl::GetByID(uint16_t id) { 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; } } diff --git a/Usermode/Applications/axwin4_src/Server/draw_text.cpp b/Usermode/Applications/axwin4_src/Server/draw_text.cpp new file mode 100644 index 00000000..f20f213f --- /dev/null +++ b/Usermode/Applications/axwin4_src/Server/draw_text.cpp @@ -0,0 +1,35 @@ +/* + * Acess2 GUI v4 + * - By John Hodge (thePowersGang) + * + * draw_text.cpp + * - Text Drawing + * + * Handles font selection and drawing of text to windows + */ +#include +#include + +// === 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 + diff --git a/Usermode/Applications/axwin4_src/Server/include/CWindow.hpp b/Usermode/Applications/axwin4_src/Server/include/CWindow.hpp index 704f0c16..3c763de2 100644 --- a/Usermode/Applications/axwin4_src/Server/include/CWindow.hpp +++ b/Usermode/Applications/axwin4_src/Server/include/CWindow.hpp @@ -31,6 +31,7 @@ public: 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(); diff --git a/Usermode/Applications/axwin4_src/Server/ipc.cpp b/Usermode/Applications/axwin4_src/Server/ipc.cpp index 4c5da258..4ed0352f 100644 --- a/Usermode/Applications/axwin4_src/Server/ipc.cpp +++ b/Usermode/Applications/axwin4_src/Server/ipc.cpp @@ -208,7 +208,7 @@ void HandleMessage_SetWindowAttr(CClient& client, CDeserialiser& message) 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"); @@ -306,6 +306,7 @@ void HandleMessage_DrawCtl(CClient& client, CDeserialiser& message) 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) { diff --git a/Usermode/Applications/axwin4_src/UI/Makefile b/Usermode/Applications/axwin4_src/UI/Makefile index 096cd9cd..8cf7699f 100644 --- a/Usermode/Applications/axwin4_src/UI/Makefile +++ b/Usermode/Applications/axwin4_src/UI/Makefile @@ -3,7 +3,7 @@ include ../../Makefile.cfg DIR := Apps/AxWin/4.0 -OBJ := main.o +OBJ := main.o taskbar.o BIN := AxWinUI diff --git a/Usermode/Applications/axwin4_src/UI/include/common.h b/Usermode/Applications/axwin4_src/UI/include/common.h new file mode 100644 index 00000000..f51cca64 --- /dev/null +++ b/Usermode/Applications/axwin4_src/UI/include/common.h @@ -0,0 +1,10 @@ +/* + */ +#ifndef _COMMON_H_ +#define _COMMON_H_ + +extern unsigned int giScreenWidth; +extern unsigned int giScreenHeight; + +#endif + diff --git a/Usermode/Applications/axwin4_src/UI/include/taskbar.h b/Usermode/Applications/axwin4_src/UI/include/taskbar.h new file mode 100644 index 00000000..728cecee --- /dev/null +++ b/Usermode/Applications/axwin4_src/UI/include/taskbar.h @@ -0,0 +1,12 @@ +/* + */ +#ifndef _TASKBAR_H_ +#define _TASKBAR_H_ + +#include + +extern void Taskbar_Create(void); +extern void Taskbar_Redraw(void); + +#endif + diff --git a/Usermode/Applications/axwin4_src/UI/main.c b/Usermode/Applications/axwin4_src/UI/main.c index b00ce261..37ee08c7 100644 --- a/Usermode/Applications/axwin4_src/UI/main.c +++ b/Usermode/Applications/axwin4_src/UI/main.c @@ -7,20 +7,25 @@ */ #include #include +#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) ) @@ -55,27 +60,3 @@ tAxWin4_Window *CreateBGWin(int w, int h) 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); -} - diff --git a/Usermode/Applications/axwin4_src/UI/taskbar.c b/Usermode/Applications/axwin4_src/UI/taskbar.c new file mode 100644 index 00000000..650e8e65 --- /dev/null +++ b/Usermode/Applications/axwin4_src/UI/taskbar.c @@ -0,0 +1,91 @@ +/* + * AxWin4 GUI - UI Core + * - By John Hodge (thePowersGang) + * + * taskbar.c + * - Main toolbar (aka Taskbar) + */ +#include +#include "include/common.h" +#include "include/taskbar.h" +#include + +// === 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); +} + diff --git a/Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/axwin.h b/Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/axwin.h index d4a30040..0a23ad76 100644 --- a/Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/axwin.h +++ b/Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/axwin.h @@ -37,10 +37,38 @@ extern void AxWin4_ResizeWindow(tAxWin4_Window *Window, unsigned int W, unsigned 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 } diff --git a/Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/definitions.h b/Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/definitions.h index 8e347cf2..5fe7e4db 100644 --- a/Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/definitions.h +++ b/Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/definitions.h @@ -8,9 +8,31 @@ #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 diff --git a/Usermode/Libraries/libaxwin4.so_src/window_drawing.cpp b/Usermode/Libraries/libaxwin4.so_src/window_drawing.cpp index a515d299..40f55a00 100644 --- a/Usermode/Libraries/libaxwin4.so_src/window_drawing.cpp +++ b/Usermode/Libraries/libaxwin4.so_src/window_drawing.cpp @@ -45,7 +45,7 @@ extern "C" void AxWin4_DrawBitmap(tAxWin4_Window *Window, int X, int Y, unsigned } } -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); @@ -55,6 +55,21 @@ extern "C" void AxWin4_DrawControl(tAxWin4_Window *Window, int X, int Y, unsigne 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); } -- 2.20.1