Redo C widget/screen structs, more porting of ChatScreen

This commit is contained in:
UnknownShadow200 2018-03-24 10:42:25 +11:00
parent 3852e8e5c1
commit 6ca83a794c
6 changed files with 743 additions and 750 deletions

View File

@ -45,7 +45,8 @@ void Screen_Reset(Screen* screen) {
screen->OnResize = NULL;
}
void Widget_DoReposition(Widget* w) {
void Widget_DoReposition(GuiElement* elem) {
Widget* w = (Widget*)elem;
w->X = Gui_CalcPos(w->HorAnchor, w->XOffset, w->Width , Game_Width );
w->Y = Gui_CalcPos(w->VerAnchor, w->YOffset, w->Height, Game_Height);
}
@ -63,6 +64,10 @@ void Widget_Init(Widget* widget) {
widget->Reposition = Widget_DoReposition;
}
bool Widget_Contains(Widget* widget, Int32 x, Int32 y) {
return Gui_Contains(widget->X, widget->Y, widget->Width, widget->Height, x, y);
}
Int32 Gui_CalcPos(UInt8 anchor, Int32 offset, Int32 size, Int32 axisLen) {
if (anchor == ANCHOR_MIN) return offset;
@ -197,13 +202,13 @@ void Gui_RenderGui(Real64 delta) {
void Gui_OnResize(void) {
if (Gui_Active != NULL) {
Gui_Active->OnResize(Gui_Active);
Gui_Active->OnResize(&Gui_Active->Base);
}
Gui_HUD->OnResize(Gui_HUD);
Gui_HUD->OnResize(&Gui_HUD->Base);
UInt32 i;
for (i = 0; i < Gui_OverlayCount; i++) {
Gui_Overlays[i]->OnResize(Gui_Overlays[i]);
Gui_Overlays[i]->OnResize(&Gui_Overlays[i]->Base);
}
}

View File

@ -42,42 +42,34 @@ typedef struct GuiElement_ {
} GuiElement;
void GuiElement_Reset(GuiElement* elem);
struct Screen_;
/*
HandlesAllInput; / Whether this screen handles all input. Prevents user interacting with the world
BlocksWorld; / Whether this screen completely and opaquely covers the game world behind it
HidesHUD; / Whether this screen hides the normal in-game HUD
RenderHUDOver; / Whether the normal in-game HUD should be drawn over the top of this screen */
#define Screen_Layout GuiElement Base; bool HandlesAllInput, BlocksWorld; \
bool HidesHUD, RenderHUDOver; void (*OnResize)(GuiElement* elem);
/* Represents a container of widgets and other 2D elements. May cover entire window. */
typedef struct Screen_ {
GuiElement Base;
/* Whether this screen handles all mouse and keyboard input.
This prevents the user from interacting with the world. */
bool HandlesAllInput;
/* Whether this screen completely and opaquely covers the game world behind it. */
bool BlocksWorld;
/* Whether this screen hides the normal in-game HUD. */
bool HidesHUD;
/* Whether the normal in-game HUD should be drawn over the top of this screen. */
bool RenderHUDOver;
/* Called when the game window is resized. */
void (*OnResize)(struct Screen_* screen);
} Screen;
typedef struct Screen_ { Screen_Layout } Screen;
void Screen_Reset(Screen* screen);
struct Widget_;
/*
X, Y, Width, Height; / Top left corner, and dimensions, of this widget
Active; / Whether this widget is currently being moused over
Disabled; / Whether widget is prevented from being interacted with
HorAnchor, VerAnchor; / Specifies the reference point for when this widget is resized
XOffset, YOffset; / Offset from the reference point */
#define Widget_Layout GuiElement Base; Int32 X, Y, Width, Height; bool Active, Disabled; \
UInt8 HorAnchor, VerAnchor; Int32 XOffset, YOffset; void (*Reposition)(GuiElement* elem);
/* Represents an individual 2D gui component. */
typedef struct Widget_ {
GuiElement Base;
/* Top left corner, and dimensions, of this widget */
Int32 X, Y, Width, Height;
/* Whether this widget is currently being moused over. */
bool Active;
/* Whether widget is prevented from being interacted with. */
bool Disabled;
/* Specifies the reference point for when this widget is resized */
UInt8 HorAnchor, VerAnchor;
/* Offset from the reference point */
Int32 XOffset, YOffset;
void (*Reposition)(struct Widget_* widget);
} Widget;
void Widget_DoReposition(Widget* w);
typedef struct Widget_ { Widget_Layout } Widget;
void Widget_DoReposition(GuiElement* elem);
void Widget_Init(Widget* widget);
bool Widget_Contains(Widget* widget, Int32 x, Int32 y);
GfxResourceID Gui_GuiTex, Gui_GuiClassicTex, Gui_IconsTex;
Screen* Gui_HUD;
@ -103,6 +95,7 @@ void Gui_ShowOverlay(Screen* overlay);
void Gui_RenderGui(Real64 delta);
void Gui_OnResize(void);
#define TEXTATLAS_MAX_WIDTHS 16
typedef struct TextAtlas_ {
Texture Tex;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@
void Widget_SetLocation(Widget* widget, UInt8 horAnchor, UInt8 verAnchor, Int32 xOffset, Int32 yOffset);
typedef struct TextWidget_ {
Widget Base;
Widget_Layout
Texture Texture;
Int32 DefaultHeight;
FontDesc Font;
@ -32,7 +32,7 @@ typedef void (*ButtonWidget_SetValue)(STRING_TRANSIENT String* raw);
typedef void (*ButtonWidget_GetValue)(STRING_TRANSIENT String* raw);
typedef bool (*Gui_MouseHandler)(GuiElement* elem, Int32 x, Int32 y, MouseButton btn);
typedef struct ButtonWidget_ {
Widget Base;
Widget_Layout
Texture Texture;
Int32 DefaultHeight;
FontDesc Font;
@ -48,7 +48,7 @@ void ButtonWidget_SetText(ButtonWidget* widget, STRING_PURE String* text);
typedef struct ScrollbarWidget_ {
Widget Base;
Widget_Layout
Int32 TotalRows, ScrollY;
Real32 ScrollingAcc;
Int32 MouseOffset;
@ -60,7 +60,7 @@ void ScrollbarWidget_ClampScrollY(ScrollbarWidget* widget);
typedef struct HotbarWidget_ {
Widget Base;
Widget_Layout
Texture SelTex, BackTex;
Real32 BarHeight, SelBlockSize, ElemSize;
Real32 BarXOffset, BorderSize;
@ -72,7 +72,7 @@ void HotbarWidget_Create(HotbarWidget* widget);
typedef struct TableWidget_ {
Widget Base;
Widget_Layout
Int32 ElementsCount, ElementsPerRow, RowsCount;
Int32 LastCreatedIndex;
FontDesc Font;
@ -94,7 +94,7 @@ void TableWidget_OnInventoryChanged(TableWidget* widget);
#define INPUTWIDGET_MAX_LINES 3
#define INPUTWIDGET_LEN STRING_SIZE
typedef struct InputWidget_ {
Widget Base;
Widget_Layout
FontDesc Font;
Int32 (*GetMaxLines)(void);
void (*RemakeTexture)(GuiElement* elem); /* Remakes the raw texture containing all the chat lines. Also updates dimensions. */
@ -176,7 +176,7 @@ void ChatInputWidget_Create(ChatInputWidget* widget, FontDesc* font);
#define TEXTGROUPWIDGET_MAX_LINES 30
#define TEXTGROUPWIDGET_LEN (STRING_SIZE * 2)
typedef struct TextGroupWidget_ {
Widget Base;
Widget_Layout
Int32 LinesCount, DefaultHeight;
FontDesc Font, UnderlineFont;
bool PlaceholderHeight[TEXTGROUPWIDGET_MAX_LINES];
@ -188,13 +188,13 @@ typedef struct TextGroupWidget_ {
void TextGroupWidget_Create(TextGroupWidget* widget, Int32 linesCount, FontDesc* font, FontDesc* underlineFont);
void TextGroupWidget_SetUsePlaceHolder(TextGroupWidget* widget, Int32 index, bool placeHolder);
void TextGroupWidget_PushUpAndReplaceLast(TextGroupWidget* widget, STRING_PURE String* text);
Int32 TextGroupWidget_GetUsedHeight(TextGroupWidget* widget);
Int32 TextGroupWidget_UsedHeight(TextGroupWidget* widget);
void TextGroupWidget_GetSelected(TextGroupWidget* widget, STRING_TRANSIENT String* text, Int32 mouseX, Int32 mouseY);
void TextGroupWidget_SetText(TextGroupWidget* widget, Int32 index, STRING_PURE String* text);
typedef struct PlayerListWidget_ {
Widget Base;
Widget_Layout
FontDesc Font;
UInt16 NamesCount, ElementOffset;
Int32 XMin, XMax, YHeight;
@ -208,8 +208,6 @@ void PlayerListWidget_Create(PlayerListWidget* widget, FontDesc* font, bool clas
void PlayerListWidget_GetNameUnder(PlayerListWidget* widget, Int32 mouseX, Int32 mouseY, STRING_TRANSIENT String* name);
typedef void (*SpecialInputAppendFunc)(void* userData, UInt8 c);
typedef struct SpecialInputTab_ {
String Title;
@ -222,7 +220,7 @@ void SpecialInputTab_Init(SpecialInputTab* tab, STRING_REF String* title,
Int32 itemsPerRow, Int32 charsPerItem, STRING_REF String* contents);
typedef struct SpecialInputWidget_ {
Widget Base;
Widget_Layout
Size2D ElementSize;
Int32 SelectedIndex;
InputWidget* AppendObj;

View File

@ -557,8 +557,8 @@ void Window_SetClientSize(Size2D size) {
rect.right = size.Width; rect.bottom = size.Height;
AdjustWindowRect(&rect, style, false);
Size2D size = { RECT_WIDTH(rect), RECT_HEIGHT(rect) };
Window_SetSize(size);
Size2D adjSize = { RECT_WIDTH(rect), RECT_HEIGHT(rect) };
Window_SetSize(adjSize);
}
/* TODO: Set window icon