Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
ui: move console ui to libtrx
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Sep 25, 2024
1 parent 02abd9b commit 533c207
Show file tree
Hide file tree
Showing 29 changed files with 122 additions and 965 deletions.
3 changes: 0 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,12 @@ dll_sources = [
'src/game/text.c',
'src/game/ui/common.c',
'src/game/ui/controllers/controls.c',
'src/game/ui/events.c',
'src/game/ui/widgets/console.c',
'src/game/ui/widgets/controls_column.c',
'src/game/ui/widgets/controls_dialog.c',
'src/game/ui/widgets/controls_input_selector.c',
'src/game/ui/widgets/controls_layout_selector.c',
'src/game/ui/widgets/label.c',
'src/game/ui/widgets/prompt.c',
'src/game/ui/widgets/stack.c',
'src/game/ui/widgets/window.c',
'src/global/enum_str.c',
'src/global/vars.c',
Expand Down
5 changes: 3 additions & 2 deletions src/decomp/decomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
#include "game/shell.h"
#include "game/sound.h"
#include "game/text.h"
#include "game/ui/common.h"
#include "global/const.h"
#include "global/funcs.h"
#include "global/vars.h"
#include "lib/ddraw.h"
#include "lib/dinput.h"
#include "specific/s_flagged_string.h"

#include <libtrx/game/ui/common.h>
#include <libtrx/utils.h>

#include <assert.h>
Expand Down Expand Up @@ -757,7 +757,8 @@ bool __cdecl WinVidSpinMessageLoop(bool need_wait)
UI_HandleKeyUp(msg.wParam);
return 0;
} else if (msg.message == WM_CHAR) {
UI_HandleChar(msg.wParam);
char insert_string[2] = { msg.wParam, '\0' };
UI_HandleTextEdit(insert_string);
return 0;
}
}
Expand Down
68 changes: 2 additions & 66 deletions src/game/console/common.c
Original file line number Diff line number Diff line change
@@ -1,83 +1,19 @@
#include "game/console/common.h"

#include "game/console/setup.h"
#include "game/input.h"
#include "game/text.h"
#include "game/ui/widgets/console.h"

#include <libtrx/game/console/common.h>

static bool m_IsOpened = false;
static UI_WIDGET *m_Console;

void Console_Init(void)
{
m_Console = UI_Console_Create();
}

void Console_Shutdown(void)
{
if (m_Console != NULL) {
m_Console->free(m_Console);
m_Console = NULL;
}

m_IsOpened = false;
}

void Console_Open(void)
{
if (m_IsOpened) {
UI_Console_HandleClose(m_Console);
}
m_IsOpened = true;
UI_Console_HandleOpen(m_Console);
}

void Console_Close(void)
{
UI_Console_HandleClose(m_Console);
m_IsOpened = false;
}

bool Console_IsOpened(void)
{
return m_IsOpened;
}

int32_t Console_GetMaxLineLength(void)
{
return TEXT_MAX_STRING_SIZE - 1;
}

void Console_LogImpl(const char *const text)
{
UI_Console_HandleLog(m_Console, text);
}

CONSOLE_COMMAND **Console_GetCommands(void)
{
return g_ConsoleCommands;
}

void Console_Draw(void)
void Console_DrawBackdrop(void)
{
UI_Console_ScrollLogs(m_Console);

#if 0
// TODO: draw screen quad
int32_t sx = 0;
int32_t sw = Viewport_GetWidth();
int32_t sh = Screen_GetRenderScale(
// not entirely accurate, but good enough
TEXT_HEIGHT * m_PromptScale
+ MAX_LOG_LINES * TEXT_HEIGHT * m_LogScale,
RSR_TEXT);
int32_t sy = Viewport_GetHeight() - sh;

RGBA_8888 top = { 0, 0, 0, 0 };
RGBA_8888 bottom = { 0, 0, 0, 196 };

Output_DrawScreenGradientQuad(sx, sy, sw, sh, top, top, bottom, bottom);
#endif
// TODO: implement me
}
12 changes: 1 addition & 11 deletions src/game/console/common.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
#pragma once

#include <stdbool.h>
#include <stdint.h>
#include <libtrx/game/console/common.h>

void Console_Init(void);
void Console_Shutdown(void);
void Console_Draw(void);

void Console_Open(void);
void Console_Close(void);
bool Console_IsOpened(void);

void Console_Log(const char *fmt, ...);
void Console_ScrollLogs(void);
2 changes: 1 addition & 1 deletion src/game/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#include "game/input.h"
#include "game/music.h"
#include "game/sound.h"
#include "game/ui/common.h"
#include "global/funcs.h"
#include "global/vars.h"

#include <libtrx/game/ui/common.h>
#include <libtrx/memory.h>

#include <stdarg.h>
Expand Down
54 changes: 15 additions & 39 deletions src/game/ui/common.c
Original file line number Diff line number Diff line change
@@ -1,43 +1,19 @@
#include "game/ui/common.h"
#include <libtrx/game/ui/common.h>

#include <libtrx/vector.h>
#include <windows.h>

void UI_Init(void)
UI_INPUT UI_TranslateInput(uint32_t system_keycode)
{
UI_Events_Init();
}

void UI_Shutdown(void)
{
UI_Events_Shutdown();
}

void UI_HandleKeyDown(const uint32_t key)
{
const UI_EVENT event = {
.name = "key_down",
.sender = NULL,
.data = (void *)(uintptr_t)key,
};
UI_Events_Fire(&event);
}

void UI_HandleKeyUp(const uint32_t key)
{
const UI_EVENT event = {
.name = "key_up",
.sender = NULL,
.data = (void *)(uintptr_t)key,
};
UI_Events_Fire(&event);
}

void UI_HandleChar(const uint32_t char_)
{
const UI_EVENT event = {
.name = "char",
.sender = NULL,
.data = (void *)(uintptr_t)char_,
};
UI_Events_Fire(&event);
// clang-format off
switch (system_keycode) {
case VK_LEFT: return UI_KEY_LEFT;
case VK_RIGHT: return UI_KEY_RIGHT;
case VK_HOME: return UI_KEY_HOME;
case VK_END: return UI_KEY_END;
case VK_BACK: return UI_KEY_BACK;
case VK_RETURN: return UI_KEY_RETURN;
case VK_ESCAPE: return UI_KEY_ESCAPE;
}
// clang-format on
return -1;
}
10 changes: 0 additions & 10 deletions src/game/ui/common.h

This file was deleted.

65 changes: 0 additions & 65 deletions src/game/ui/events.c

This file was deleted.

22 changes: 0 additions & 22 deletions src/game/ui/events.h

This file was deleted.

23 changes: 0 additions & 23 deletions src/game/ui/widgets/base.h

This file was deleted.

Loading

0 comments on commit 533c207

Please sign in to comment.