Compare commits
4 commits
88e6358346
...
2cd5a953c9
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2cd5a953c9 | ||
![]() |
ce213c9777 | ||
![]() |
827b96b0a3 | ||
![]() |
ee8fc5391b |
|
@ -1,57 +1,9 @@
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
|
#include "dice_container.h"
|
||||||
#include "style.h"
|
#include "style.h"
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <clay/clay.h>
|
#include <clay/clay.h>
|
||||||
|
|
||||||
static inline
|
|
||||||
void DiceSelectorContainer() {
|
|
||||||
CLAY(CLAY_ID("DiceSelector"), {
|
|
||||||
.layout = {
|
|
||||||
.layoutDirection = CLAY_TOP_TO_BOTTOM,
|
|
||||||
.sizing = { CLAY_SIZING_PERCENT(0.15), CLAY_SIZING_GROW(0) },
|
|
||||||
.padding = containerPadding,
|
|
||||||
.childGap = paragraphGap,
|
|
||||||
},
|
|
||||||
.INNER_CONTAINER(0),
|
|
||||||
}) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline
|
|
||||||
void ActiveDiceContainer() {
|
|
||||||
CLAY(CLAY_ID("ActiveDice"), {
|
|
||||||
.layout = {
|
|
||||||
.layoutDirection = CLAY_TOP_TO_BOTTOM,
|
|
||||||
.sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0) },
|
|
||||||
.padding = containerPadding,
|
|
||||||
.childGap = paragraphGap,
|
|
||||||
},
|
|
||||||
.INNER_CONTAINER(0),
|
|
||||||
}) {
|
|
||||||
CLAY_TEXT(CLAY_STRING("Header Text"), CLAY_TEXT_CONFIG({
|
|
||||||
.H(1, 0),
|
|
||||||
}));
|
|
||||||
CLAY_TEXT(CLAY_STRING("Content text"), CLAY_TEXT_CONFIG({
|
|
||||||
.BODY(0),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline
|
|
||||||
void DiceContainer() {
|
|
||||||
CLAY(CLAY_ID("DiceContainer"), {
|
|
||||||
.layout = {
|
|
||||||
.layoutDirection = CLAY_LEFT_TO_RIGHT,
|
|
||||||
.sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_PERCENT(0.4) },
|
|
||||||
.childGap = containerGap
|
|
||||||
},
|
|
||||||
}) {
|
|
||||||
DiceSelectorContainer();
|
|
||||||
ActiveDiceContainer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
void DiceLogContainer() {
|
void DiceLogContainer() {
|
||||||
CLAY(CLAY_ID("LogContainer"), {
|
CLAY(CLAY_ID("LogContainer"), {
|
||||||
|
@ -76,7 +28,7 @@ void InitiativeListContainer() {
|
||||||
|
|
||||||
Clay_RenderCommandArray RenderApplication() {
|
Clay_RenderCommandArray RenderApplication() {
|
||||||
Clay_BeginLayout();
|
Clay_BeginLayout();
|
||||||
CLAY(CLAY_ID("OuterContainer"), windowStyle) {
|
CLAY(CLAY_ID("OuterContainer"), WindowStyle()) {
|
||||||
DiceContainer();
|
DiceContainer();
|
||||||
CLAY(CLAY_ID("LowerSplitContainer"), {
|
CLAY(CLAY_ID("LowerSplitContainer"), {
|
||||||
.layout = {
|
.layout = {
|
||||||
|
|
44
src/dice.c
Normal file
44
src/dice.c
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
#include "dice.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <memory.h>
|
||||||
|
|
||||||
|
int roll_die(enum die_type die) {
|
||||||
|
int const max = die - 1;
|
||||||
|
return (rand() % max) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int current_active_count = 0;
|
||||||
|
static enum die_type active_dice_set[MAX_ACTIVE_DICE];
|
||||||
|
|
||||||
|
enum die_type const *get_active_dice_set(size_t *out_length) {
|
||||||
|
if (out_length != nullptr) {
|
||||||
|
*out_length = current_active_count;
|
||||||
|
}
|
||||||
|
return active_dice_set;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t add_die_to_active(enum die_type die) {
|
||||||
|
if (current_active_count >= MAX_ACTIVE_DICE) {
|
||||||
|
return MAX_ACTIVE_DICE;
|
||||||
|
}
|
||||||
|
active_dice_set[current_active_count] = die;
|
||||||
|
return current_active_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void remove_die_from_active(size_t index) {
|
||||||
|
memmove(active_dice_set + index + 1, active_dice_set + index, MAX_ACTIVE_DICE - index - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct roll_result_type roll_active_dice_set(enum die_type die) {
|
||||||
|
struct roll_result_type results = {
|
||||||
|
.individual_result_count = MAX_ACTIVE_DICE,
|
||||||
|
.total = 0
|
||||||
|
};
|
||||||
|
for (size_t i = 0; i < current_active_count; ++i) {
|
||||||
|
results.individual_results[i] = roll_die(active_dice_set[i]);
|
||||||
|
results.total += results.individual_results[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
33
src/dice.h
Normal file
33
src/dice.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#ifndef DICE_H
|
||||||
|
#define DICE_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifndef MAX_ACTIVE_DICE
|
||||||
|
#define MAX_ACTIVE_DICE 5
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum die_type {
|
||||||
|
COIN = 2,
|
||||||
|
D4 = 4,
|
||||||
|
D8 = 8,
|
||||||
|
D10 = 10,
|
||||||
|
D12 = 12,
|
||||||
|
D20 = 20,
|
||||||
|
D100 = 100
|
||||||
|
};
|
||||||
|
|
||||||
|
struct roll_result_type {
|
||||||
|
size_t individual_result_count;
|
||||||
|
int individual_results[MAX_ACTIVE_DICE];
|
||||||
|
int total;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern int roll_die(enum die_type die);
|
||||||
|
|
||||||
|
extern enum die_type const *get_active_dice_set(size_t *out_length);
|
||||||
|
extern size_t add_die_to_active(enum die_type die);
|
||||||
|
extern void remove_die_from_active(size_t index);
|
||||||
|
extern struct roll_result_type roll_active_dice_set(enum die_type die);
|
||||||
|
|
||||||
|
#endif // !DICE_H
|
42
src/dice_container.c
Normal file
42
src/dice_container.c
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#include "dice_container.h"
|
||||||
|
#include <clay/clay.h>
|
||||||
|
#include "style.h"
|
||||||
|
|
||||||
|
static inline
|
||||||
|
void DiceSelectorContainer() {
|
||||||
|
CLAY(CLAY_ID("DiceSelector"), {
|
||||||
|
.layout = {
|
||||||
|
.layoutDirection = CLAY_TOP_TO_BOTTOM,
|
||||||
|
.sizing = { CLAY_SIZING_PERCENT(0.15), CLAY_SIZING_GROW(0) },
|
||||||
|
.padding = containerPadding,
|
||||||
|
.childGap = paragraphGap,
|
||||||
|
},
|
||||||
|
.INNER_CONTAINER(0),
|
||||||
|
}) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
void ActiveDiceContainer() {
|
||||||
|
CLAY(CLAY_ID("ActiveDice"), {
|
||||||
|
.layout = {
|
||||||
|
.layoutDirection = CLAY_TOP_TO_BOTTOM,
|
||||||
|
.sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0) },
|
||||||
|
.padding = containerPadding,
|
||||||
|
.childGap = paragraphGap,
|
||||||
|
},
|
||||||
|
.INNER_CONTAINER(0),
|
||||||
|
}) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiceContainer() {
|
||||||
|
CLAY(CLAY_ID("DiceContainer"), {
|
||||||
|
.layout = {
|
||||||
|
.layoutDirection = CLAY_LEFT_TO_RIGHT,
|
||||||
|
.sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_PERCENT(0.4) },
|
||||||
|
.childGap = containerGap
|
||||||
|
},
|
||||||
|
}) {
|
||||||
|
DiceSelectorContainer();
|
||||||
|
ActiveDiceContainer();
|
||||||
|
}
|
||||||
|
}
|
6
src/dice_container.h
Normal file
6
src/dice_container.h
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef DICE_CONTAINER_H
|
||||||
|
#define DICE_CONTAINER_H
|
||||||
|
|
||||||
|
extern void DiceContainer();
|
||||||
|
|
||||||
|
#endif // !DICE_CONTAINER_H
|
|
@ -107,9 +107,6 @@ void InitSDL() {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "TTF_CreateRendererTextEngine failed: %s", SDL_GetError());
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "TTF_CreateRendererTextEngine failed: %s", SDL_GetError());
|
||||||
exit(5);
|
exit(5);
|
||||||
}
|
}
|
||||||
SDL_SetRenderScale(renderer, 1.0/renderScale, 1.0/renderScale);
|
|
||||||
InitFonts();
|
|
||||||
LogOutputResolution();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -126,6 +123,8 @@ extern void HandleEvent(SDL_Event event);
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
InitSDL();
|
InitSDL();
|
||||||
|
InitFonts();
|
||||||
|
LogOutputResolution();
|
||||||
InitClay();
|
InitClay();
|
||||||
backendData = (Clay_SDL3RendererData) {
|
backendData = (Clay_SDL3RendererData) {
|
||||||
.renderer = renderer,
|
.renderer = renderer,
|
||||||
|
@ -142,8 +141,8 @@ int main(int argc, char *argv[]) {
|
||||||
break;
|
break;
|
||||||
case SDL_EVENT_WINDOW_RESIZED:
|
case SDL_EVENT_WINDOW_RESIZED:
|
||||||
Clay_SetLayoutDimensions((Clay_Dimensions){
|
Clay_SetLayoutDimensions((Clay_Dimensions){
|
||||||
event.window.data1 * (double)renderScale,
|
event.window.data1,
|
||||||
event.window.data2 * (double)renderScale
|
event.window.data2
|
||||||
});
|
});
|
||||||
LogOutputResolution();
|
LogOutputResolution();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -51,7 +51,7 @@ static void SDL_Clay_RenderFillRoundedRect(Clay_SDL3RendererData *rendererData,
|
||||||
int numCircleSegments[4] = { 1, 1, 1, 1 };
|
int numCircleSegments[4] = { 1, 1, 1, 1 };
|
||||||
int totalVertices = 0;
|
int totalVertices = 0;
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
numCircleSegments[i] = SDL_clamp((int)radii[i] / 2, 1, NUM_CIRCLE_SEGMENTS);
|
numCircleSegments[i] = SDL_clamp((int)radii[i], 1, NUM_CIRCLE_SEGMENTS);
|
||||||
totalVertices += numCircleSegments[i];
|
totalVertices += numCircleSegments[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
44
src/style.c
44
src/style.c
|
@ -1 +1,45 @@
|
||||||
|
#include "style.h"
|
||||||
|
#include "defs.h"
|
||||||
|
|
||||||
|
Clay_Color ContainerBackgrounds(size_t idx) {
|
||||||
|
return (Clay_Color) {
|
||||||
|
255*containerBackgrounds[idx],
|
||||||
|
255*containerBackgrounds[idx],
|
||||||
|
255*containerBackgrounds[idx],
|
||||||
|
255
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Clay_Color ContainerBorders(size_t idx) {
|
||||||
|
return (Clay_Color) {
|
||||||
|
255*containerBorders[idx],
|
||||||
|
255*containerBorders[idx],
|
||||||
|
255*containerBorders[idx],
|
||||||
|
255
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Clay_Color TextColors(size_t idx) {
|
||||||
|
return (Clay_Color) {
|
||||||
|
255*textColorsP[idx],
|
||||||
|
255*textColorsP[idx],
|
||||||
|
255*textColorsP[idx],
|
||||||
|
255
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Clay_Color WindowBackground() {
|
||||||
|
return (Clay_Color) { 255*windowBackground, 255*windowBackground, 255*windowBackground, 255 };
|
||||||
|
}
|
||||||
|
|
||||||
|
Clay_ElementDeclaration WindowStyle() {
|
||||||
|
return (Clay_ElementDeclaration) {
|
||||||
|
.layout = {
|
||||||
|
.layoutDirection = CLAY_TOP_TO_BOTTOM,
|
||||||
|
.sizing = layoutExpand,
|
||||||
|
.padding = CLAY_PADDING_ALL(windowPadding),
|
||||||
|
.childGap = containerGap,
|
||||||
|
},
|
||||||
|
.backgroundColor = WindowBackground()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
97
src/style.h
97
src/style.h
|
@ -5,37 +5,33 @@
|
||||||
#include <clay/clay.h>
|
#include <clay/clay.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
constexpr int renderScale = 1;
|
|
||||||
|
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
// CONTAINER STYLE
|
// CONTAINER STYLE
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
|
|
||||||
constexpr uint16_t containerGap = 5 * renderScale;
|
constexpr uint16_t containerGap = 10;
|
||||||
|
constexpr double defaultRadius = 5.;
|
||||||
|
|
||||||
|
constexpr float containerBackgrounds[] = {
|
||||||
|
.2f,
|
||||||
|
.3f,
|
||||||
|
.4f
|
||||||
|
};
|
||||||
|
constexpr float containerBorders[] = {
|
||||||
|
.3f,
|
||||||
|
.4f,
|
||||||
|
.5f
|
||||||
|
};
|
||||||
|
|
||||||
constexpr Clay_Padding containerPadding = {
|
constexpr Clay_Padding containerPadding = {
|
||||||
32 * renderScale, 32 * renderScale,
|
32, 32,
|
||||||
16 * renderScale, 16 * renderScale
|
16, 16
|
||||||
};
|
|
||||||
constexpr Clay_Color containerColors[] = {
|
|
||||||
{ 255*0.25, 255*0.25, 255*0.25, 255 },
|
|
||||||
{ 255*0.2, 255*0.2, 255*0.2, 255 },
|
|
||||||
{ 255*0.1, 255*0.1, 255*0.1, 255 },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr Clay_Sizing layoutExpand = {
|
#define INNER_CONTAINER(depth_)\
|
||||||
.width = CLAY_SIZING_GROW(0),
|
backgroundColor = ContainerBackgrounds(depth_),\
|
||||||
.height = CLAY_SIZING_GROW(0)
|
.border = { ContainerBorders(depth_), CLAY_BORDER_ALL(2) },\
|
||||||
};
|
.cornerRadius = defaultRadiusAll
|
||||||
|
|
||||||
constexpr double defaultRadius = 5.0 * renderScale;
|
|
||||||
constexpr Clay_CornerRadius defaultRadiusAll = {
|
|
||||||
defaultRadius, defaultRadius,
|
|
||||||
defaultRadius, defaultRadius
|
|
||||||
};
|
|
||||||
|
|
||||||
#define INNER_CONTAINER(depth_) \
|
|
||||||
backgroundColor = containerColors[depth_],\
|
|
||||||
.cornerRadius = defaultRadiusAll
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
|
@ -43,39 +39,27 @@ backgroundColor = containerColors[depth_],\
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
|
|
||||||
constexpr uint16_t windowPadding = containerGap;
|
constexpr uint16_t windowPadding = containerGap;
|
||||||
constexpr Clay_Color windowBackground = {
|
constexpr float windowBackground = .18f;
|
||||||
255*0.35, 255*0.35, 255*0.35, 255
|
|
||||||
};
|
|
||||||
constexpr Clay_ElementDeclaration windowStyle = {
|
|
||||||
.layout = {
|
|
||||||
.layoutDirection = CLAY_TOP_TO_BOTTOM,
|
|
||||||
.sizing = layoutExpand,
|
|
||||||
.padding = CLAY_PADDING_ALL(windowPadding),
|
|
||||||
.childGap = containerGap,
|
|
||||||
},
|
|
||||||
.backgroundColor = windowBackground
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
// TEXT STYLE
|
// TEXT STYLE
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
|
|
||||||
constexpr float paragraphGap = 10 * renderScale;
|
constexpr float paragraphGap = 10;
|
||||||
constexpr uint16_t baseFontSize = 16 * renderScale;
|
constexpr uint16_t baseFontSize = 16;
|
||||||
|
constexpr float textColorsP[] = {
|
||||||
constexpr Clay_Color textColors[] = {
|
0.9f,
|
||||||
{ 250, 250, 250, 255 },
|
0.9f,
|
||||||
{ 250, 250, 250, 255 },
|
0.9f
|
||||||
{ 250, 250, 250, 255 },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr uint16_t headerSizes[] = {
|
constexpr uint16_t headerSizes[] = {
|
||||||
64 * renderScale, 32 * renderScale,
|
64, 32,
|
||||||
28 * renderScale, 16 * renderScale
|
28, 16
|
||||||
};
|
};
|
||||||
|
|
||||||
#define TEXT_STYLE(color_)\
|
#define TEXT_STYLE(color_)\
|
||||||
textColor = textColors[color_]
|
textColor = TextColors(color_)
|
||||||
|
|
||||||
#define BODY(color_)\
|
#define BODY(color_)\
|
||||||
fontId = FONT_DEFAULT,\
|
fontId = FONT_DEFAULT,\
|
||||||
|
@ -87,4 +71,25 @@ constexpr uint16_t headerSizes[] = {
|
||||||
.fontSize = headerSizes[(level_)-1],\
|
.fontSize = headerSizes[(level_)-1],\
|
||||||
.TEXT_STYLE(color_)
|
.TEXT_STYLE(color_)
|
||||||
|
|
||||||
|
////////////////////////////////////
|
||||||
|
// COMPILATIONS
|
||||||
|
// | Functions and expressions that combine styling data from the settings above.
|
||||||
|
////////////////////////////////////
|
||||||
|
|
||||||
|
extern Clay_Color ContainerBackgrounds(size_t idx);
|
||||||
|
extern Clay_Color ContainerBorders(size_t idx);
|
||||||
|
extern Clay_Color TextColors(size_t idx);
|
||||||
|
extern Clay_Color WindowBackground();
|
||||||
|
extern Clay_ElementDeclaration WindowStyle();
|
||||||
|
|
||||||
|
constexpr Clay_Sizing layoutExpand = {
|
||||||
|
.width = CLAY_SIZING_GROW(0),
|
||||||
|
.height = CLAY_SIZING_GROW(0)
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr Clay_CornerRadius defaultRadiusAll = {
|
||||||
|
defaultRadius, defaultRadius,
|
||||||
|
defaultRadius, defaultRadius
|
||||||
|
};
|
||||||
|
|
||||||
#endif // !STYLE_H
|
#endif // !STYLE_H
|
||||||
|
|
Loading…
Reference in a new issue