Usermode/AxWin4 - Controls working, starting on text
authorJohn Hodge <[email protected]>
Mon, 25 Aug 2014 04:53:11 +0000 (12:53 +0800)
committerJohn Hodge <[email protected]>
Mon, 25 Aug 2014 04:53:11 +0000 (12:53 +0800)
13 files changed:
Usermode/Applications/axwin4_src/Server/CWindow.cpp
Usermode/Applications/axwin4_src/Server/draw_control.cpp
Usermode/Applications/axwin4_src/Server/draw_text.cpp [new file with mode: 0644]
Usermode/Applications/axwin4_src/Server/include/CWindow.hpp
Usermode/Applications/axwin4_src/Server/ipc.cpp
Usermode/Applications/axwin4_src/UI/Makefile
Usermode/Applications/axwin4_src/UI/include/common.h [new file with mode: 0644]
Usermode/Applications/axwin4_src/UI/include/taskbar.h [new file with mode: 0644]
Usermode/Applications/axwin4_src/UI/main.c
Usermode/Applications/axwin4_src/UI/taskbar.c [new file with mode: 0644]
Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/axwin.h
Usermode/Libraries/libaxwin4.so_src/include_exp/axwin4/definitions.h
Usermode/Libraries/libaxwin4.so_src/window_drawing.cpp

index 32ff4f6..a0067a7 100644 (file)
@@ -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");
index 264165f..59ea0bc 100644 (file)
@@ -8,6 +8,7 @@
  * Handles drawing of resizable controls defined by a bitmap and four region sizes
  */
 #include <draw_control.hpp>
+#include <axwin4/definitions.h>
 
 // === CODE ===
 namespace AxWin {
@@ -129,6 +130,15 @@ CControl StdButton(2, 1, 0, 2, 1, 0, ::std::vector<uint32_t> {
        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,
@@ -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 (file)
index 0000000..f20f213
--- /dev/null
@@ -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 <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
+
index 704f0c1..3c763de 100644 (file)
@@ -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();
        
index 4c5da25..4ed0352 100644 (file)
@@ -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) {
index 096cd9c..8cf7699 100644 (file)
@@ -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 (file)
index 0000000..f51cca6
--- /dev/null
@@ -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 (file)
index 0000000..728cece
--- /dev/null
@@ -0,0 +1,12 @@
+/*
+ */
+#ifndef _TASKBAR_H_
+#define _TASKBAR_H_
+
+#include <stdbool.h>
+
+extern void Taskbar_Create(void);
+extern void Taskbar_Redraw(void);
+
+#endif
+
index b00ce26..37ee08c 100644 (file)
@@ -7,20 +7,25 @@
  */
 #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) )
@@ -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 (file)
index 0000000..650e8e6
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * 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);
+}
+
index d4a3004..0a23ad7 100644 (file)
@@ -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
 }
index 8e347cf..5fe7e4d 100644 (file)
@@ -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
 
index a515d29..40f55a0 100644 (file)
@@ -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);
 }
 

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