1
0
Fork 0

Control: Add Button dummy and restructure headers

master
Marrub 2016-10-18 05:49:47 -04:00
parent d4faa148ee
commit f0a59423e7
9 changed files with 303 additions and 74 deletions

View File

@ -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

View File

@ -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

53
lithos_c/inc/Lth_button.h Normal file
View File

@ -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

View File

@ -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

View File

@ -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

24
lithos_c/inc/Lth_draw.h Normal file
View File

@ -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

View File

@ -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

45
lithos_c/inc/Lth_window.h Normal file
View File

@ -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

76
lithos_c/src/button.c Normal file
View File

@ -0,0 +1,76 @@
//-----------------------------------------------------------------------------
//
// Copyright © 2016 Project Golan
//
// See "LICENSE" for more information.
//
//-----------------------------------------------------------------------------
//
// Window functions.
//
//-----------------------------------------------------------------------------
#include "Lth.h"
#include <stdlib.h>
//----------------------------------------------------------------------------|
// 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