Control: Rename "control" to "ctrl" and pretty things
parent
44ae7d93e7
commit
d4faa148ee
BIN
acs/lithos3.bin
BIN
acs/lithos3.bin
Binary file not shown.
BIN
acs/lithos3l.bin
BIN
acs/lithos3l.bin
Binary file not shown.
|
@ -131,11 +131,11 @@ 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 *control_);
|
||||
void Lth_ControlConnect(void *control_, Lth_Signal signal, Lth_Callback_t cb);
|
||||
void Lth_ControlDestroy(void *control_);
|
||||
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 *control, char const *title);
|
||||
void Lth_WindowSetTitle(Lth_Window *ctrl, char const *title);
|
||||
|
||||
#endif//lithos3__Lth_control_h
|
||||
|
|
|
@ -40,21 +40,20 @@ Lth_Context *Lth_ContextNew(int w, int h, Lth_HID hidBase, Lth_HID hidEnd)
|
|||
//
|
||||
// Lth_ContextMap
|
||||
//
|
||||
void Lth_ContextMap(Lth_Context *ctx, Lth_Window *window)
|
||||
void Lth_ContextMap(Lth_Context *ctx, Lth_Window *ctrl)
|
||||
{
|
||||
Lth_assert(ctx != NULL);
|
||||
Lth_assert(window != NULL);
|
||||
Lth_assert(ctrl != NULL);
|
||||
|
||||
// TODO: should use last window's position + some divisor of screenspace
|
||||
if(window->x == -1) window->x = ctx->w / 2;
|
||||
if(window->y == -1) window->y = ctx->h / 2;
|
||||
if(ctrl->x == -1) ctrl->x = ctx->w / 2;
|
||||
if(ctrl->y == -1) ctrl->y = ctx->h / 2;
|
||||
|
||||
if(ctx->map)
|
||||
Lth_LinkListInsert(&window->desclink, window, &ctx->map);
|
||||
Lth_LinkListInsert(&ctrl->desclink, ctrl, &ctx->map);
|
||||
else
|
||||
{
|
||||
ctx->map = &window->desclink;
|
||||
ctx->map->owner = window;
|
||||
ctx->map = &ctrl->desclink;
|
||||
ctx->map->owner = ctrl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,10 +67,8 @@ void Lth_ContextDestroy(Lth_Context *ctx)
|
|||
|
||||
if(ctx->map)
|
||||
{
|
||||
for(Lth_LinkList *list = ctx->map; list;)
|
||||
Lth_ListFor(Lth_Control *owner, ctx->map)
|
||||
{
|
||||
Lth_LinkList *next = list->next;
|
||||
Lth_Control *owner = list->owner;
|
||||
Lth_LinkListRemove(list);
|
||||
if(owner) Lth_ControlDestroy(owner);
|
||||
list = next;
|
||||
|
@ -92,8 +89,8 @@ void Lth_ContextRun(Lth_Context *ctx)
|
|||
ctx->hid.cur = ctx->hid.base;
|
||||
|
||||
if(ctx->map)
|
||||
for(Lth_LinkList *list = ctx->map; list; list = list->next)
|
||||
Lth_ControlRun(ctx, list->owner);
|
||||
Lth_ListForEach(Lth_Control *owner, ctx->map)
|
||||
Lth_ControlRun(ctx, owner);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -103,8 +100,25 @@ void Lth_ContextClipPush(Lth_Context *ctx, int x, int y, int w, int h)
|
|||
{
|
||||
Lth_assert(ctx != NULL);
|
||||
|
||||
ctx->clip.rects[++ctx->clip.num] = (Lth_Rect){ x, y, w, h };
|
||||
ACS_SetHudClipRect(x, y, w, h);
|
||||
Lth_Rect rect = ctx->clip.rects[ctx->clip.num++];
|
||||
|
||||
if(!(rect.x == 0 && rect.y == 0 && rect.w == 0 && rect.h == 0))
|
||||
{
|
||||
if(rect.x < x) rect.x = x;
|
||||
if(rect.y < y) rect.y = y;
|
||||
if(rect.x + rect.w > x + w) rect.w = w;
|
||||
if(rect.y + rect.h > y + h) rect.h = h;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.x = x;
|
||||
rect.y = y;
|
||||
rect.h = h;
|
||||
rect.w = w;
|
||||
}
|
||||
|
||||
ctx->clip.rects[ctx->clip.num] = rect;
|
||||
ACS_SetHudClipRect(rect.x, rect.y, rect.w, rect.h);
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
//
|
||||
// Control functions.
|
||||
//
|
||||
// # of rewrites because of DavidPH: 1
|
||||
// # of rewrites because of DavidPH: 2
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
@ -24,66 +24,64 @@
|
|||
//
|
||||
// Lth_ControlRun
|
||||
//
|
||||
void Lth_ControlRun(Lth_Context *ctx, void *control_)
|
||||
void Lth_ControlRun(Lth_Context *ctx, void *ctrl_)
|
||||
{
|
||||
Lth_assert(ctx != NULL);
|
||||
Lth_assert(control_ != NULL);
|
||||
Lth_assert(ctrl_ != NULL);
|
||||
|
||||
Lth_Control *control = control_;
|
||||
Lth_Control *ctrl = ctrl_;
|
||||
|
||||
Lth_Call(control->cb.update, ctx, control);
|
||||
Lth_Call(control->cb.draw, ctx, control);
|
||||
Lth_ControlCall(ctrl, update, ctx, ctrl);
|
||||
Lth_ControlCall(ctrl, draw, ctx, ctrl);
|
||||
Lth_ControlCall(ctrl, postdraw, ctx, ctrl);
|
||||
}
|
||||
|
||||
//
|
||||
// Lth_ControlConnect
|
||||
//
|
||||
void Lth_ControlConnect(void *control_, Lth_Signal signal, Lth_Callback_t cb)
|
||||
void Lth_ControlConnect(void *ctrl_, Lth_Signal signal, Lth_Callback_t cb)
|
||||
{
|
||||
Lth_assert(control_ != NULL);
|
||||
Lth_assert(ctrl_ != NULL);
|
||||
Lth_assert(signal < Lth_SIGMAX && signal >= 0);
|
||||
Lth_assert(cb != NULL);
|
||||
|
||||
Lth_Control *control = control_;
|
||||
Lth_Control *ctrl = ctrl_;
|
||||
|
||||
switch(signal)
|
||||
{
|
||||
#define vec(name) control->cb.name
|
||||
#define Lth_X(sig, name, ret, ...) \
|
||||
case Lth_##sig: \
|
||||
vec(name).data = \
|
||||
realloc(vec(name).data, \
|
||||
sizeof(Lth_##sig##_t) * (vec(name).size + 1)); \
|
||||
vec(name).data[vec(name).size++] = (Lth_##sig##_t)cb; \
|
||||
ctrl->cb.name.data = realloc(ctrl->cb.name.data, \
|
||||
sizeof(Lth_##sig##_t) * (ctrl->cb.name.size + 1)); \
|
||||
ctrl->cb.name.data[ctrl->cb.name.size++] = (Lth_##sig##_t)cb; \
|
||||
break;
|
||||
#include "Lth_callback.h"
|
||||
#undef vec
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Lth_ControlDestroy
|
||||
//
|
||||
void Lth_ControlDestroy(void *control_)
|
||||
void Lth_ControlDestroy(void *ctrl_)
|
||||
{
|
||||
Lth_assert(control_ != NULL);
|
||||
if(ctrl_ == NULL) return;
|
||||
|
||||
Lth_Control *control = control_;
|
||||
Lth_Control *ctrl = ctrl_;
|
||||
|
||||
for(Lth_LinkList *list = control->descendants; list;)
|
||||
Lth_ListFor(Lth_Control *owner, ctrl->descendants)
|
||||
{
|
||||
Lth_LinkList *next = list->next;
|
||||
Lth_Control *owner = list->owner;
|
||||
|
||||
Lth_ControlDestroy(owner);
|
||||
|
||||
list = next;
|
||||
}
|
||||
|
||||
Lth_CallReverse(control->cb.destroy, control);
|
||||
Lth_LinkListRemove(&control->desclink);
|
||||
Lth_CallReverse(ctrl->cb.destroy, ctrl);
|
||||
Lth_LinkListRemove(&ctrl->desclink);
|
||||
|
||||
free(control);
|
||||
#define Lth_X(sig, name, ret, ...) \
|
||||
free(ctrl->cb.name.data);
|
||||
#include "Lth_callback.h"
|
||||
|
||||
free(ctrl);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,13 +22,30 @@
|
|||
//
|
||||
// Lth_WindowDraw
|
||||
//
|
||||
static void Lth_WindowDraw(Lth_Context *ctx, Lth_Window *window)
|
||||
static void Lth_WindowDraw(Lth_Context *ctx, Lth_Window *ctrl)
|
||||
{
|
||||
Lth_DrawRect(ctx, window->x, window->y, window->w, window->h, 0.5k);
|
||||
ACS_SetFont(s"CONFONT");
|
||||
Lth_PrintString(window->title);
|
||||
Lth_HudMessagePlain(ctx->hid.cur--, window->x - 8 + Lth_A_Lef,
|
||||
window->y - 8 + Lth_A_Top);
|
||||
Lth_PrintString(ctrl->title);
|
||||
Lth_HudMessagePlain(ctx->hid.cur--, ctrl->x - 8 + Lth_A_Lef,
|
||||
ctrl->y - 8 + Lth_A_Top);
|
||||
Lth_DrawRectAndClip(ctx, ctrl->x, ctrl->y, ctrl->w, ctrl->h, 0.5k);
|
||||
}
|
||||
|
||||
//
|
||||
// Lth_WindowPostDraw
|
||||
//
|
||||
static void Lth_WindowPostDraw(Lth_Context *ctx, Lth_Window *ctrl)
|
||||
{
|
||||
Lth_ContextClipPop(ctx);
|
||||
}
|
||||
|
||||
//
|
||||
// Lth_WindowDestroy
|
||||
//
|
||||
static void Lth_WindowDestroy(Lth_Window *ctrl)
|
||||
{
|
||||
if(ctrl->title)
|
||||
free(ctrl->title);
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,31 +58,33 @@ static void Lth_WindowDraw(Lth_Context *ctx, Lth_Window *window)
|
|||
//
|
||||
Lth_Window *Lth_WindowNew(char const *title, int w, int h, int x, int y)
|
||||
{
|
||||
Lth_Window *control = calloc(1, sizeof(Lth_Window));
|
||||
Lth_assert(control != NULL);
|
||||
Lth_Window *ctrl = calloc(1, sizeof(Lth_Window));
|
||||
Lth_assert(ctrl != NULL);
|
||||
|
||||
control->w = w;
|
||||
control->h = h;
|
||||
control->x = x;
|
||||
control->y = y;
|
||||
ctrl->w = w;
|
||||
ctrl->h = h;
|
||||
ctrl->x = x;
|
||||
ctrl->y = y;
|
||||
|
||||
Lth_WindowSetTitle(control, title);
|
||||
Lth_ControlConnect(control, Lth_SIGDRAW, Lth_Callback(Lth_WindowDraw));
|
||||
Lth_WindowSetTitle(ctrl, title);
|
||||
Lth_ControlConnect(ctrl, Lth_SIGDRAW, Lth_Callback(Lth_WindowDraw));
|
||||
Lth_ControlConnect(ctrl, Lth_SIGPSTDRAW, Lth_Callback(Lth_WindowPostDraw));
|
||||
Lth_ControlConnect(ctrl, Lth_SIGDESTROY, Lth_Callback(Lth_WindowDestroy));
|
||||
|
||||
return control;
|
||||
return ctrl;
|
||||
}
|
||||
|
||||
//
|
||||
// Lth_WindowSetTitle
|
||||
//
|
||||
void Lth_WindowSetTitle(Lth_Window *control, char const *title)
|
||||
void Lth_WindowSetTitle(Lth_Window *ctrl, char const *title)
|
||||
{
|
||||
Lth_assert(control != NULL);
|
||||
Lth_assert(ctrl != NULL);
|
||||
|
||||
if(title != NULL)
|
||||
control->title = Lth_strdup(title);
|
||||
ctrl->title = Lth_strdup(title);
|
||||
else
|
||||
control->title = Lth_strdup("<untitled>");
|
||||
ctrl->title = Lth_strdup("<untitled>");
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
|
Loading…
Reference in New Issue