-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui.h
93 lines (82 loc) · 3.04 KB
/
ui.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/******************************************************************************
File: ui.h
Created: 2019-06-27
Updated: 2019-08-01
Author: Aaron Oman
Notice: Creative Commons Attribution 4.0 International License (CC-BY 4.0)
******************************************************************************/
//! \file ui.h
//!
//! The UI system uses nuklear internally for an immediate-mode UI.
//! The UI isn't a general purpose UI, rather it's a graphical debugger embedded
//! within the CHIP-8 emulator.
//!
//! \image html debugger-ui.png
//!
//! \see Nuklear: https://github.com/vurtun/nuklear
//! \see Immediate mode GUI: https://caseymuratori.com/blog_0001
#ifndef UI_VERSION
//! include guard
#define UI_VERSION "0.1.0"
#include "SDL2/SDL.h"
struct system;
struct opcode;
struct ui;
//! \brief Creates and initializes a new ui object instance
//! \param[in] shouldBeEnabled whether the UI will be rendered or not
//! \param[in] widgetWidth standard width of UI widgets
//! \param[in] widgetHeight standard height of UI widgets
//! \param[in] window SDL Window initialized by the graphics subsystem
//! \return The initialized ui object
struct ui *
UIInit(int shouldBeEnabled, unsigned int widgetWidth, unsigned int widgetHeight, SDL_Window *window);
//! \brief De-initializes and frees memory for the given ui object
//! \param[in,out] ui The initialized ui object to be cleaned and reclaimed
void
UIDeinit(struct ui *ui);
//! \brief Updates state of the UI to allow input processing
//!
//! This needs to be called every frame before UIHandleEvent() and should
//! be concluded with a call to UIInputEnd()
//!
//! \param[in,out] ui UI state to be updated
void
UIInputBegin(struct ui *ui);
//! \brief Updates state of the UI to stop input processing
//!
//! This needs to be called every frame after UIHandleEvent() and should be
//! preceded with a call to UIInputBegin()
//!
//! \param[in,out] ui UI state to be updated
void
UIInputEnd(struct ui *ui);
//! \brief Processes SDL input events
//!
//! This needs to be called every frame between UIInputBegin() and UIInputEnd()
//!
//! \param[in,out] ui UI state to be updated
//! \param[in] event The SDL_Event that occurred and should be processed
void
UIHandleEvent(struct ui *ui, SDL_Event *event);
//! \brief Sets up all UI widgets before rendering
//!
//! This needs to be called every frame and should be succeeded with a call to
//! UIRender().
//!
//! NOTE: UIRender() is invoked in gfxinputthread.c via a wrapper function:
//! UIRenderFn(). This is done to simplify the graphics API.
//!
//! \param[in,out] ui UI state to be updated
//! \param[in] system system state to be read and presented in the ui
//! \param[in] opcode opcode state to be read and presented in the ui
void
UIWidgets(struct ui *ui, struct system *system, struct opcode *opcode);
//! \brief Renders the ui
//!
//! Uses the SDL_Window used in UIInit() to render the configured UI widgets.
//! This must be called every frame aftr UIWidgets()
//!
//! \param[in,out] ui UI state to be used for rendering
void
UIRender(struct ui *ui);
#endif // UI_VERSION