diff --git a/lithos_c/Makefile b/lithos_c/Makefile index d023579..478dbdb 100644 --- a/lithos_c/Makefile +++ b/lithos_c/Makefile @@ -37,6 +37,7 @@ ALLOCMIN=--alloc-min Sta "" ## Sources SOURCES= \ + $(SRC)/button.c \ $(SRC)/context.c \ $(SRC)/control.c \ $(SRC)/draw.c \ @@ -47,12 +48,16 @@ SOURCES= \ HEADERS= \ $(INC)/Lth.h \ $(INC)/Lth_assert.h \ - $(INC)/Lth_control.h \ + $(INC)/Lth_button.h \ $(INC)/Lth_callback.h \ + $(INC)/Lth_context.h \ + $(INC)/Lth_control.h \ + $(INC)/Lth_draw.h \ $(INC)/Lth_hudmessage.h \ $(INC)/Lth_linklist.h \ $(INC)/Lth_stdlib.h \ - $(INC)/Lth_types.h + $(INC)/Lth_types.h \ + $(INC)/Lth_window.h ## Output diff --git a/lithos_c/inc/Lth.h b/lithos_c/inc/Lth.h index 3d56fce..50f9902 100644 --- a/lithos_c/inc/Lth.h +++ b/lithos_c/inc/Lth.h @@ -14,10 +14,15 @@ #define lithos3__Lth_h #include "Lth_assert.h" +#include "Lth_button.h" +#include "Lth_callback.h" +#include "Lth_context.h" #include "Lth_control.h" +#include "Lth_draw.h" #include "Lth_hudmessage.h" #include "Lth_linklist.h" #include "Lth_stdlib.h" #include "Lth_types.h" +#include "Lth_window.h" #endif//lithos3__Lth_h diff --git a/lithos_c/inc/Lth_button.h b/lithos_c/inc/Lth_button.h new file mode 100644 index 0000000..f5bc2e3 --- /dev/null +++ b/lithos_c/inc/Lth_button.h @@ -0,0 +1,53 @@ +//----------------------------------------------------------------------------- +// +// Copyright © 2016 Project Golan +// +// See "LICENSE" for more information. +// +//----------------------------------------------------------------------------- +// +// Button control. +// +//----------------------------------------------------------------------------- + +#ifndef lithos3__Lth_button_h +#define lithos3__Lth_button_h + +#include "Lth_control.h" + + +//----------------------------------------------------------------------------| +// Type Definitions | +// + +// +// Lth_ButtonState +// +enum Lth_ButtonState +{ + Lth_BS_Normal, + Lth_BS_Hover, + Lth_BS_Depressed, + Lth_BS_Clicked, + Lth_BS_Max +}; + +// +// Lth_Button +// +typedef struct Lth_Button +{ + Lth_Inherits(Lth_LayoutControl); + char *label; + int state; +} Lth_Button; + + +//----------------------------------------------------------------------------| +// Extern Functions | +// + +Lth_Button *Lth_ButtonNew(char const *label); +void Lth_ButtonSetLabel(Lth_Button *ctrl, char const *title); + +#endif//lithos3__Lth_button_h diff --git a/lithos_c/inc/Lth_context.h b/lithos_c/inc/Lth_context.h new file mode 100644 index 0000000..42dd2bd --- /dev/null +++ b/lithos_c/inc/Lth_context.h @@ -0,0 +1,57 @@ +//----------------------------------------------------------------------------- +// +// Copyright © 2016 Project Golan +// +// See "LICENSE" for more information. +// +//----------------------------------------------------------------------------- +// +// Context for drawing. +// +//----------------------------------------------------------------------------- + +#ifndef lithos3__Lth_context_h +#define lithos3__Lth_context_h + + +//----------------------------------------------------------------------------| +// Type Definitions | +// + +// +// Lth_Context +// +// internal data +// clip +// map +// +// read-only +// w: width of screen +// h: height of screen +// +// read-write +// hid: HUD ID range +// +typedef struct Lth_Context +{ + struct { Lth_Rect rects[16]; int num; } clip; + Lth_LinkList *map; + + int w, h; + + Lth_HIDRange hid; +} Lth_Context; + + +//----------------------------------------------------------------------------| +// Extern Functions | +// + +Lth_Context *Lth_ContextNew(int w, int h, Lth_HID hidBase, Lth_HID hidEnd); +void Lth_ContextMap(Lth_Context *ctx, struct Lth_Window *window); +void Lth_ContextDestroy(Lth_Context *ctx); +void Lth_ContextRun(Lth_Context *ctx); +void Lth_ContextClipPush(Lth_Context *ctx, int x, int y, int w, int h); +void Lth_ContextClipPop(Lth_Context *ctx); + +#endif//lithos3__Lth_context_h diff --git a/lithos_c/inc/Lth_control.h b/lithos_c/inc/Lth_control.h index 5d42e22..b2be290 100644 --- a/lithos_c/inc/Lth_control.h +++ b/lithos_c/inc/Lth_control.h @@ -13,65 +13,16 @@ #ifndef lithos3__Lth_control_h #define lithos3__Lth_control_h +#include "Lth_callback.h" #include "Lth_linklist.h" #include "Lth_types.h" -#include "Lth_callback.h" +#include "Lth_context.h" //----------------------------------------------------------------------------| // Type Definitions | // -// -// Lth_Rect -// -typedef struct Lth_Rect -{ - int x, y; - int w, h; -} Lth_Rect; - -// -// Lth_HIDRange -// -// read-only -// base: beginning of HID range (must be more than end) -// end: end of HID range (must be less than base) -// -// read-write -// cur: current HID -// -typedef struct Lth_HIDRange -{ - Lth_HID base; - Lth_HID end; - Lth_HID cur; -} Lth_HIDRange; - -// -// Lth_Context -// -// internal data -// clip -// map -// -// read-only -// w: width of screen -// h: height of screen -// -// read-write -// hid: HUD ID range -// -typedef struct Lth_Context -{ - struct { Lth_Rect rects[16]; int num; } clip; - Lth_LinkList *map; - - int w, h; - - Lth_HIDRange hid; -} Lth_Context; - // // Lth_Control // @@ -91,11 +42,12 @@ typedef struct Lth_Context // typedef struct Lth_Control { + Lth_CallbackSet cb; Lth_LinkList desclink; Lth_LinkList *descendants; - Lth_CallbackSet cb; struct Lth_Control *parent; + int lx, ly; void *userdata; @@ -103,39 +55,25 @@ typedef struct Lth_Control } Lth_Control; // -// Lth_Window -// -// Inherits Lth_Control (read-write). +// Lth_LayoutControl // // read-only -// title: title of window (see also: Lth_WindowSetTitle) +// lx: layout x +// ly: layout y // -typedef struct Lth_Window +typedef struct Lth_LayoutControl { Lth_Inherits(Lth_Control); - char *title; -} Lth_Window; + int lx, ly; +} Lth_LayoutControl; //----------------------------------------------------------------------------| // Extern Functions | // -Lth_Context *Lth_ContextNew(int w, int h, Lth_HID hidBase, Lth_HID hidEnd); -void Lth_ContextMap(Lth_Context *ctx, Lth_Window *window); -void Lth_ContextDestroy(Lth_Context *ctx); -void Lth_ContextRun(Lth_Context *ctx); -void Lth_ContextClipPush(Lth_Context *ctx, int x, int y, int w, int h); -void Lth_ContextClipPop(Lth_Context *ctx); - -void Lth_DrawRectAndClip(Lth_Context *ctx, int x, int y, int w, int h, __fixed alpha); -void Lth_DrawRect(Lth_Context *ctx, int x, int y, int w, int h, __fixed alpha); - void Lth_ControlRun(Lth_Context *ctx, void *ctrl_); void Lth_ControlConnect(void *ctrl_, Lth_Signal signal, Lth_Callback_t cb); void Lth_ControlDestroy(void *ctrl_); -Lth_Window *Lth_WindowNew(char const *title, int w, int h, int x, int y); -void Lth_WindowSetTitle(Lth_Window *ctrl, char const *title); - #endif//lithos3__Lth_control_h diff --git a/lithos_c/inc/Lth_draw.h b/lithos_c/inc/Lth_draw.h new file mode 100644 index 0000000..334117d --- /dev/null +++ b/lithos_c/inc/Lth_draw.h @@ -0,0 +1,24 @@ +//----------------------------------------------------------------------------- +// +// Copyright © 2016 Project Golan +// +// See "LICENSE" for more information. +// +//----------------------------------------------------------------------------- +// +// Drawing. +// +//----------------------------------------------------------------------------- + +#ifndef lithos3__Lth_draw_h +#define lithos3__Lth_draw_h + + +//----------------------------------------------------------------------------| +// Extern Functions | +// + +void Lth_DrawRectAndClip(Lth_Context *ctx, int x, int y, int w, int h, __fixed alpha); +void Lth_DrawRect(Lth_Context *ctx, int x, int y, int w, int h, __fixed alpha); + +#endif//lithos3__Lth_draw_h diff --git a/lithos_c/inc/Lth_types.h b/lithos_c/inc/Lth_types.h index 3437653..26007a0 100644 --- a/lithos_c/inc/Lth_types.h +++ b/lithos_c/inc/Lth_types.h @@ -34,4 +34,30 @@ typedef enum Lth_Signal Lth_SIGMAX } Lth_Signal; +// +// Lth_Rect +// +typedef struct Lth_Rect +{ + int x, y; + int w, h; +} Lth_Rect; + +// +// Lth_HIDRange +// +// read-only +// base: beginning of HID range (must be more than end) +// end: end of HID range (must be less than base) +// +// read-write +// cur: current HID +// +typedef struct Lth_HIDRange +{ + Lth_HID base; + Lth_HID end; + Lth_HID cur; +} Lth_HIDRange; + #endif//lithos3__Lth_types_h diff --git a/lithos_c/inc/Lth_window.h b/lithos_c/inc/Lth_window.h new file mode 100644 index 0000000..0c9a74a --- /dev/null +++ b/lithos_c/inc/Lth_window.h @@ -0,0 +1,45 @@ +//----------------------------------------------------------------------------- +// +// Copyright © 2016 Project Golan +// +// See "LICENSE" for more information. +// +//----------------------------------------------------------------------------- +// +// Window control. +// +//----------------------------------------------------------------------------- + +#ifndef lithos3__Lth_window_h +#define lithos3__Lth_window_h + +#include "Lth_control.h" + + +//----------------------------------------------------------------------------| +// Type Definitions | +// + +// +// Lth_Window +// +// Inherits Lth_Control (read-write). +// +// read-only +// title: title of window (see also: Lth_WindowSetTitle) +// +typedef struct Lth_Window +{ + Lth_Inherits(Lth_Control); + char *title; +} Lth_Window; + + +//----------------------------------------------------------------------------| +// Extern Functions | +// + +Lth_Window *Lth_WindowNew(char const *title, int w, int h, int x, int y); +void Lth_WindowSetTitle(Lth_Window *ctrl, char const *title); + +#endif//lithos3__Lth_window_h diff --git a/lithos_c/src/button.c b/lithos_c/src/button.c new file mode 100644 index 0000000..a8fc59e --- /dev/null +++ b/lithos_c/src/button.c @@ -0,0 +1,76 @@ +//----------------------------------------------------------------------------- +// +// Copyright © 2016 Project Golan +// +// See "LICENSE" for more information. +// +//----------------------------------------------------------------------------- +// +// Window functions. +// +//----------------------------------------------------------------------------- + +#include "Lth.h" + +#include + + +//----------------------------------------------------------------------------| +// Static Functions | +// + +// +// Lth_ButtonDraw +// +static void Lth_ButtonDraw(Lth_Context *ctx, Lth_Button *ctrl) +{ + ACS_SetFont(s"CONFONT"); + Lth_PrintString(ctrl->label); + Lth_HudMessagePlain(ctx->hid.cur--, ctrl->x - 8 + Lth_A_Lef, + ctrl->y - 8 + Lth_A_Top); + Lth_DrawRect(ctx, ctrl->x, ctrl->y, ctrl->w, ctrl->h, 0.5k); +} + +// +// Lth_ButtonDestroy +// +static void Lth_ButtonDestroy(Lth_Button *ctrl) +{ + if(ctrl->label) + free(ctrl->label); +} + + +//----------------------------------------------------------------------------| +// Extern Functions | +// + +// +// Lth_ButtonNew +// +Lth_Button *Lth_ButtonNew(char const *label) +{ + Lth_Button *ctrl = calloc(1, sizeof(Lth_Button)); + Lth_assert(ctrl != NULL); + + Lth_ButtonSetLabel(ctrl, label); + Lth_ControlConnect(ctrl, Lth_SIGDRAW, Lth_Callback(Lth_ButtonDraw)); + Lth_ControlConnect(ctrl, Lth_SIGDESTROY, Lth_Callback(Lth_ButtonDestroy)); + + return ctrl; +} + +// +// Lth_ButtonSetLabel +// +void Lth_ButtonSetLabel(Lth_Button *ctrl, char const *title) +{ + Lth_assert(ctrl != NULL); + + if(title != NULL) + ctrl->label = Lth_strdup(title); + else + ctrl->label = Lth_strdup(""); +} + +// EOF