Compare commits

..

No commits in common. "033597f4c91a84b6681a379f5622b4bdf6bdedc6" and "420f4e5244860969560b0794b7cf80f4c74a5d9c" have entirely different histories.

16 changed files with 104 additions and 154 deletions

View file

@ -12,9 +12,6 @@
xml:space="preserve" xml:space="preserve"
inkscape:export-batch-path="../assets/icons" inkscape:export-batch-path="../assets/icons"
inkscape:export-batch-name="" inkscape:export-batch-name=""
inkscape:export-filename="dice_icons.svg"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
@ -28,9 +25,9 @@
inkscape:pagecheckerboard="true" inkscape:pagecheckerboard="true"
inkscape:deskcolor="#d1d1d1" inkscape:deskcolor="#d1d1d1"
inkscape:document-units="mm" inkscape:document-units="mm"
inkscape:zoom="0.28641836" inkscape:zoom="0.089092089"
inkscape:cx="2646.4784" inkscape:cx="2575.9863"
inkscape:cy="677.33087" inkscape:cy="-836.21342"
inkscape:current-layer="layer1"><inkscape:page inkscape:current-layer="layer1"><inkscape:page
x="0" x="0"
y="0" y="0"
@ -105,9 +102,9 @@
sodipodi:arg2="-1.0471975" sodipodi:arg2="-1.0471975"
inkscape:rounded="0" inkscape:rounded="0"
inkscape:randomized="0" inkscape:randomized="0"
d="m 72.788858,-0.84280396 58.211902,33.60865896 0,67.217316 -58.211905,33.608659 -58.211902,-33.608662 1e-6,-67.217316 z" d="m 72.788858,-0.84280396 58.211902,33.60865896 0,67.217316 -58.211905,33.608659 -58.211902,-33.608662 1e-6,-67.217315 z"
inkscape:transform-center-y="-10.356297" inkscape:transform-center-y="-10.356297"
transform="matrix(0.72805306,0,0,0.72805306,887.53916,19.409163)" transform="matrix(0.72805306,0,0,0.72805306,887.53914,23.277513)"
inkscape:transform-center-x="4.5682712e-06" /><path inkscape:transform-center-x="4.5682712e-06" /><path
sodipodi:type="star" sodipodi:type="star"
style="fill:#ffffff;fill-opacity:1;stroke-width:0;stroke-linecap:round;stroke-linejoin:round" style="fill:#ffffff;fill-opacity:1;stroke-width:0;stroke-linecap:round;stroke-linejoin:round"
@ -124,12 +121,12 @@
inkscape:randomized="0" inkscape:randomized="0"
d="M 72.788858,-0.84280396 140.00617,66.374514 72.788855,133.59183 5.5715408,66.37451 Z" d="M 72.788858,-0.84280396 140.00617,66.374514 72.788855,133.59183 5.5715408,66.37451 Z"
inkscape:transform-center-y="-11.404593" inkscape:transform-center-y="-11.404593"
transform="matrix(0.80174873,0,0,0.80174873,445.77495,14.517649)" transform="matrix(0.80174873,0,0,0.80174873,445.77494,17.337703)"
inkscape:transform-center-x="3.2442312e-06" /><path inkscape:transform-center-x="3.2442312e-06" /><path
id="path6" id="path6"
style="fill:#ffffff;stroke-width:0;stroke-linecap:round;stroke-linejoin:round" style="fill:#ffffff;stroke-width:0;stroke-linecap:round;stroke-linejoin:round"
inkscape:transform-center-y="-11.822122" inkscape:transform-center-y="-10.700688"
d="m 649.59996,11.868888 49.16646,39.571907 V 87.171717 L 649.59996,123.59777 600.4335,87.171714 V 51.440793 Z" d="m 649.59996,20.692099 52.86152,35.81815 V 88.851767 L 649.59996,121.82248 596.73844,88.851765 V 56.510248 Z"
sodipodi:nodetypes="ccccccc" sodipodi:nodetypes="ccccccc"
inkscape:transform-center-x="-3.5000013e-06" /><path inkscape:transform-center-x="-3.5000013e-06" /><path
sodipodi:type="star" sodipodi:type="star"
@ -147,7 +144,7 @@
inkscape:randomized="0" inkscape:randomized="0"
d="M 72.788858,-0.84280396 136.71632,45.603221 112.2982,120.75446 l -79.018692,0 L 8.861391,45.603217 Z" d="M 72.788858,-0.84280396 136.71632,45.603221 112.2982,120.75446 l -79.018692,0 L 8.861391,45.603217 Z"
inkscape:transform-center-y="-10.963325" inkscape:transform-center-y="-10.963325"
transform="matrix(0.77072736,0,0,0.77072736,738.96626,16.635767)" transform="matrix(0.77072736,0,0,0.77072736,738.96626,19.478952)"
inkscape:transform-center-x="2.911147e-06" /><path inkscape:transform-center-x="2.911147e-06" /><path
sodipodi:type="star" sodipodi:type="star"
style="fill:#ffffff;fill-opacity:1;stroke-width:0;stroke-linecap:round;stroke-linejoin:round" style="fill:#ffffff;fill-opacity:1;stroke-width:0;stroke-linecap:round;stroke-linejoin:round"
@ -163,9 +160,9 @@
inkscape:rounded="0" inkscape:rounded="0"
inkscape:randomized="0" inkscape:randomized="0"
d="M 72.788858,-0.84280396 131.00076,99.983171 l -116.423807,-3e-6 z" d="M 72.788858,-0.84280396 131.00076,99.983171 l -116.423807,-3e-6 z"
inkscape:transform-center-y="-20.021908" inkscape:transform-center-y="13.37152"
transform="matrix(0.94002452,0,0,0.94002452,144.77667,10.368405)" transform="matrix(-0.94002452,0,0,-0.94002452,281.6233,129.60578)"
inkscape:transform-center-x="8.3514896e-06" /><rect inkscape:transform-center-x="-3.5441139e-06" /><rect
style="fill:#ffffff;fill-opacity:1;stroke-width:0;stroke-linecap:round;stroke-linejoin:round" style="fill:#ffffff;fill-opacity:1;stroke-width:0;stroke-linecap:round;stroke-linejoin:round"
id="rect8" id="rect8"
width="85.237946" width="85.237946"

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

View file

@ -15,4 +15,4 @@
transform="translate(-581.86667)"><path transform="translate(-581.86667)"><path
id="path6" id="path6"
style="fill:#ffffff;stroke-width:0;stroke-linecap:round;stroke-linejoin:round" style="fill:#ffffff;stroke-width:0;stroke-linecap:round;stroke-linejoin:round"
d="m 649.59996,11.868888 49.16646,39.571907 V 87.171717 L 649.59996,123.59777 600.4335,87.171714 V 51.440793 Z" /></g></svg> d="M 649.59996,5.3149838 715.72918,50.123127 V 90.582038 L 649.59996,131.82806 583.47073,90.582036 V 50.123125 Z" /></g></svg>

Before

Width:  |  Height:  |  Size: 662 B

After

Width:  |  Height:  |  Size: 664 B

View file

@ -16,4 +16,4 @@
style="fill:#ffffff;fill-opacity:1;stroke-width:0;stroke-linecap:round;stroke-linejoin:round" style="fill:#ffffff;fill-opacity:1;stroke-width:0;stroke-linecap:round;stroke-linejoin:round"
id="path7" id="path7"
d="M 72.788858,-0.84280396 136.71632,45.603221 112.2982,120.75446 l -79.018692,0 L 8.861391,45.603217 Z" d="M 72.788858,-0.84280396 136.71632,45.603221 112.2982,120.75446 l -79.018692,0 L 8.861391,45.603217 Z"
transform="matrix(0.77072736,0,0,0.77072736,738.96626,16.635767)" /></g></svg> transform="matrix(0.9748178,0,0,0.9748178,724.11075,4.3394261)" /></g></svg>

Before

Width:  |  Height:  |  Size: 743 B

After

Width:  |  Height:  |  Size: 741 B

View file

@ -16,4 +16,4 @@
id="path9" id="path9"
cx="67.73333" cx="67.73333"
cy="67.73333" cy="67.73333"
r="49.017395" /></g></svg> r="60.523819" /></g></svg>

Before

Width:  |  Height:  |  Size: 584 B

After

Width:  |  Height:  |  Size: 584 B

View file

@ -16,4 +16,4 @@
style="fill:#ffffff;fill-opacity:1;stroke-width:0;stroke-linecap:round;stroke-linejoin:round" style="fill:#ffffff;fill-opacity:1;stroke-width:0;stroke-linecap:round;stroke-linejoin:round"
id="path1" id="path1"
d="m 72.788858,-0.84280396 58.211902,33.60865896 0,67.217316 -58.211905,33.608659 -58.211902,-33.608662 1e-6,-67.217316 z" d="m 72.788858,-0.84280396 58.211902,33.60865896 0,67.217316 -58.211905,33.608659 -58.211902,-33.608662 1e-6,-67.217316 z"
transform="matrix(0.72805306,0,0,0.72805306,887.53916,19.409163)" /></g></svg> transform="matrix(0.99238809,0,0,0.99238809,868.2985,1.9723317)" /></g></svg>

Before

Width:  |  Height:  |  Size: 761 B

After

Width:  |  Height:  |  Size: 760 B

View file

@ -16,4 +16,4 @@
style="fill:#ffffff;fill-opacity:1;stroke-width:0;stroke-linecap:round;stroke-linejoin:round" style="fill:#ffffff;fill-opacity:1;stroke-width:0;stroke-linecap:round;stroke-linejoin:round"
id="path8" id="path8"
d="M 72.788858,-0.84280396 131.00076,99.983171 l -116.423807,-3e-6 z" d="M 72.788858,-0.84280396 131.00076,99.983171 l -116.423807,-3e-6 z"
transform="matrix(0.94002452,0,0,0.94002452,144.77667,10.368405)" /></g></svg> transform="matrix(-1.1132862,0,0,-1.1132862,294.23482,132.96171)" /></g></svg>

Before

Width:  |  Height:  |  Size: 708 B

After

Width:  |  Height:  |  Size: 708 B

View file

@ -15,8 +15,8 @@
transform="translate(-290.93332)"><rect transform="translate(-290.93332)"><rect
style="fill:#ffffff;fill-opacity:1;stroke-width:0;stroke-linecap:round;stroke-linejoin:round" style="fill:#ffffff;fill-opacity:1;stroke-width:0;stroke-linecap:round;stroke-linejoin:round"
id="rect8" id="rect8"
width="85.237946" width="110.25191"
height="85.237946" height="110.25191"
x="316.04767" x="303.54068"
y="25.114355" y="12.607375"
ry="0" /></g></svg> ry="0" /></g></svg>

Before

Width:  |  Height:  |  Size: 665 B

After

Width:  |  Height:  |  Size: 665 B

View file

@ -16,4 +16,4 @@
style="fill:#ffffff;fill-opacity:1;stroke-width:0;stroke-linecap:round;stroke-linejoin:round" style="fill:#ffffff;fill-opacity:1;stroke-width:0;stroke-linecap:round;stroke-linejoin:round"
id="path5" id="path5"
d="M 72.788858,-0.84280396 140.00617,66.374514 72.788855,133.59183 5.5715408,66.37451 Z" d="M 72.788858,-0.84280396 140.00617,66.374514 72.788855,133.59183 5.5715408,66.37451 Z"
transform="matrix(0.80174873,0,0,0.80174873,445.77495,14.517649)" /></g></svg> transform="translate(431.34446,1.3588174)" /></g></svg>

Before

Width:  |  Height:  |  Size: 727 B

After

Width:  |  Height:  |  Size: 704 B

View file

@ -1,27 +1,22 @@
#include "dice.h" #include "dice.h"
#include <memory.h> #include <memory.h>
static int activeDiceCount = 0; int Die_Roll(enum Die_Dice die) {
static enum Dice_Die activeDice[MAX_ACTIVE_DICE];
static struct Dice_ResultType rollResult[MAX_ACTIVE_DICE];
static struct Dice_ResultType rollTotal = {
.string = "0",
.roll = 0, .string_len = 1,
};
int Dice_Roll(enum Dice_Die die) {
if (die == COIN) {
return (rand() % 2);
} else {
int const max = die; int const max = die;
return (rand() % max) + 1; return (rand() % max) + 1;
}
} }
static int current_active_count = 0;
static enum Die_Dice active_dice_set[MAX_ACTIVE_DICE];
static struct Die_ResultType roll_results[MAX_ACTIVE_DICE];
static struct Die_ResultType roll_total = {
.roll = 0, .string_len = 0
};
static static
struct Dice_ResultType Dice_RollToResultType(int roll, enum Dice_Die die) { struct Die_ResultType Die_RollToResultType(int roll, enum Die_Dice die) {
struct Dice_ResultType result = { }; struct Die_ResultType result = { };
result.roll = roll; result.roll = roll;
if (die == COIN) { if (die == COIN) {
result.string_len = SDL_snprintf(result.string, MAX_ROLL_STR_LEN, roll == 1 ? "H" : "T"); result.string_len = SDL_snprintf(result.string, MAX_ROLL_STR_LEN, roll == 1 ? "H" : "T");
@ -36,66 +31,43 @@ struct Dice_ResultType Dice_RollToResultType(int roll, enum Dice_Die die) {
return result; return result;
} }
enum Dice_Die const *Dice_GetActiveSet(size_t *out_length) { enum Die_Dice const *Die_GetActiveSet(size_t *out_length) {
if (out_length != nullptr) { if (out_length != nullptr) {
*out_length = activeDiceCount; *out_length = current_active_count;
} }
return activeDice; return active_dice_set;
} }
size_t Dice_AddToActiveSet(enum Dice_Die die) { size_t Die_AddToActiveSet(enum Die_Dice die) {
if (activeDiceCount >= MAX_ACTIVE_DICE) { if (current_active_count >= MAX_ACTIVE_DICE) {
return MAX_ACTIVE_DICE; return MAX_ACTIVE_DICE;
} }
activeDice[activeDiceCount] = die; active_dice_set[current_active_count] = die;
rollResult[activeDiceCount] = Dice_RollToResultType(die, die); roll_results[current_active_count] = Die_RollToResultType(die, die);
rollTotal.roll += die; return current_active_count++;
rollTotal = Dice_RollToResultType(rollTotal.roll, 0);
return activeDiceCount++;
} }
void Dice_RemoveFromActiveSet(size_t index) { void Die_RemoveFromActiveSet(size_t index) {
if (index >= MAX_ACTIVE_DICE) { memcpy(active_dice_set + index, active_dice_set + index + 1, MAX_ACTIVE_DICE - index - 1);
return; --current_active_count;
}
void Die_RollActiveSet() {
for (size_t i = 0; i < current_active_count; ++i) {
roll_results[i] = Die_RollToResultType(Die_Roll(active_dice_set[i]), active_dice_set[i]);
roll_total.roll += roll_results[i].roll;
} }
rollTotal.roll -= rollResult[index].roll; roll_total.string_len = SDL_snprintf(roll_total.string, MAX_ROLL_STR_LEN, "%d", roll_total.roll);
rollTotal = Dice_RollToResultType(rollTotal.roll, 0);
memcpy(activeDice + index, activeDice + index + 1, MAX_ACTIVE_DICE - index - 1);
--activeDiceCount;
} }
void Dice_ClearActiveSet() { struct Die_ResultType *Die_GetLastResult(size_t *out_length) {
rollTotal.roll = 0;
rollTotal = Dice_RollToResultType(rollTotal.roll, 0);
activeDiceCount = 0;
}
void Dice_RollActiveSet() {
int total = 0;
for (size_t i = 0; i < activeDiceCount; ++i) {
rollResult[i] = Dice_RollToResultType(Dice_Roll(activeDice[i]), activeDice[i]);
total += rollResult[i].roll;
}
rollTotal = Dice_RollToResultType(total, 0);
}
struct Dice_ResultType *Dice_GetLastResult(size_t *out_length) {
if (out_length != nullptr) { if (out_length != nullptr) {
*out_length = activeDiceCount; *out_length = current_active_count;
} }
return rollResult; return roll_results;
} }
struct Dice_ResultType *Dice_GetLastResultTotal() { Clay_String Die_ToString(enum Die_Dice die) {
rollTotal.clay_string = (Clay_String) {
.chars = rollTotal.string,
.length = rollTotal.string_len,
.isStaticallyAllocated = false
};
return &rollTotal;
}
Clay_String Dice_ToString(enum Dice_Die die) {
switch (die) { switch (die) {
case COIN: return CLAY_STRING("C"); case COIN: return CLAY_STRING("C");
case D4: return CLAY_STRING("4"); case D4: return CLAY_STRING("4");

View file

@ -4,8 +4,16 @@
#include "renderer/clay_renderer_SDL3.h" #include "renderer/clay_renderer_SDL3.h"
#include <stdlib.h> #include <stdlib.h>
enum Dice_Die { #ifndef MAX_ACTIVE_DICE
COIN = 1, #define MAX_ACTIVE_DICE 20
#endif
#ifndef MAX_ROLL_STR_LEN
#define MAX_ROLL_STR_LEN 10
#endif
enum Die_Dice {
COIN = 2,
D4 = 4, D4 = 4,
D6 = 6, D6 = 6,
D8 = 8, D8 = 8,
@ -15,32 +23,23 @@ enum Dice_Die {
D100 = 100 D100 = 100
}; };
#ifndef MAX_ROLL_STR_LEN struct Die_ResultType {
#define MAX_ROLL_STR_LEN 10
#endif
struct Dice_ResultType {
int roll; int roll;
size_t string_len; size_t string_len;
char string[MAX_ROLL_STR_LEN]; char string[MAX_ROLL_STR_LEN];
Clay_String clay_string; Clay_String clay_string;
}; };
#ifndef MAX_ACTIVE_DICE extern int Die_Roll(enum Die_Dice die);
#define MAX_ACTIVE_DICE 20
#endif
extern int Dice_Roll(enum Dice_Die die); extern enum Die_Dice const *Die_GetActiveSet(size_t *out_length);
extern size_t Die_AddToActiveSet(enum Die_Dice die);
extern void Die_RemoveFromActiveSet(size_t index);
extern enum Dice_Die const *Dice_GetActiveSet(size_t *out_length); extern struct Die_ResultType *Die_GetLastResult(size_t *out_length);
extern size_t Dice_AddToActiveSet(enum Dice_Die die);
extern void Dice_RemoveFromActiveSet(size_t index);
extern void Dice_ClearActiveSet();
extern struct Dice_ResultType *Dice_GetLastResult(size_t *out_length); extern void Die_RollActiveSet();
extern struct Dice_ResultType *Dice_GetLastResultTotal();
extern void Dice_RollActiveSet(); extern Clay_String Die_ToString(enum Die_Dice die);
extern Clay_String Dice_ToString(enum Dice_Die die);
#endif // !DICE_H #endif // !DICE_H

View file

@ -10,26 +10,30 @@
static static
void HandleRollSetButtonInteraction(Clay_ElementId element, Clay_PointerData pointer, intptr_t data) { void HandleRollSetButtonInteraction(Clay_ElementId element, Clay_PointerData pointer, intptr_t data) {
if (pointer.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) { if (pointer.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) {
Dice_RollActiveSet(); Die_RollActiveSet();
} }
} }
static static inline
void HandleClearSetButtonInteraction(Clay_ElementId element, Clay_PointerData pointer, intptr_t data) { void RollSetButton() {
if (pointer.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) { CLAY(CLAY_ID("RollSetButton"), {
Dice_ClearActiveSet(); .layout = {
.padding = { 30, 30, 10, 10 },
}
}) {
TextButton(CLAY_STRING("Roll"), buttonBackground, &HandleRollSetButtonInteraction, 0);
} }
} }
static static
void HandleAddDieButtonInteraction(Clay_ElementId element, Clay_PointerData pointer, intptr_t die) { void HandleAddDieButtonInteraction(Clay_ElementId element, Clay_PointerData pointer, intptr_t die) {
if (pointer.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) { if (pointer.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) {
Dice_AddToActiveSet((enum Dice_Die)die); Die_AddToActiveSet((enum Die_Dice)die);
} }
} }
static inline static inline
void AddDieButton(enum Dice_Die die) { void AddDieButton(enum Die_Dice die) {
CLAY(CLAY_IDI("AddDieButton", die), { CLAY(CLAY_IDI("AddDieButton", die), {
.layout = { .layout = {
.sizing = { CLAY_SIZING_FIXED(100), CLAY_SIZING_FIXED(100) }, .sizing = { CLAY_SIZING_FIXED(100), CLAY_SIZING_FIXED(100) },
@ -38,10 +42,9 @@ void AddDieButton(enum Dice_Die die) {
.image = { GetDiceImage(die) } .image = { GetDiceImage(die) }
}) { }) {
Clay_OnHover(&HandleAddDieButtonInteraction, die); Clay_OnHover(&HandleAddDieButtonInteraction, die);
CLAY_TEXT(Dice_ToString(die), CLAY_TEXT_CONFIG({ CLAY_TEXT(Die_ToString(die), CLAY_TEXT_CONFIG({
.textColor = TextColors(0), .textColor = TextColors(0),
.H(2), .H(2),
.textAlignment = CLAY_TEXT_ALIGN_CENTER
})); }));
} }
} }
@ -64,9 +67,10 @@ void DiceSelectorContainer() {
.padding = panelPadding, .padding = panelPadding,
}, },
.clip = { .clip = {
true, true, Clay_GetScrollOffset(), false, true, Clay_GetScrollOffset(),
}, },
}) { }) {
AddDieButton(COIN);
AddDieButton(D4); AddDieButton(D4);
AddDieButton(D6); AddDieButton(D6);
AddDieButton(D8); AddDieButton(D8);
@ -74,7 +78,6 @@ void DiceSelectorContainer() {
AddDieButton(D12); AddDieButton(D12);
AddDieButton(D20); AddDieButton(D20);
AddDieButton(D100); AddDieButton(D100);
AddDieButton(COIN);
} }
} }
} }
@ -82,12 +85,12 @@ void DiceSelectorContainer() {
static static
void HandleRemoveDieButtonInteraction(Clay_ElementId element, Clay_PointerData pointer, intptr_t index) { void HandleRemoveDieButtonInteraction(Clay_ElementId element, Clay_PointerData pointer, intptr_t index) {
if (pointer.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) { if (pointer.state == CLAY_POINTER_DATA_PRESSED_THIS_FRAME) {
Dice_RemoveFromActiveSet(index); Die_RemoveFromActiveSet(index);
} }
} }
static inline static inline
void RemoveDieButton(enum Dice_Die die, int index) { void RemoveDieButton(enum Die_Dice die, int index) {
CLAY(CLAY_IDI("RemoveDieButton", index), { CLAY(CLAY_IDI("RemoveDieButton", index), {
.layout = { .layout = {
.sizing = { CLAY_SIZING_FIXED(200), CLAY_SIZING_FIXED(200) }, .sizing = { CLAY_SIZING_FIXED(200), CLAY_SIZING_FIXED(200) },
@ -96,7 +99,7 @@ void RemoveDieButton(enum Dice_Die die, int index) {
.image = { GetDiceImage(die) }, .image = { GetDiceImage(die) },
}) { }) {
size_t result_length; size_t result_length;
struct Dice_ResultType const *result = Dice_GetLastResult(&result_length); struct Die_ResultType const *result = Die_GetLastResult(&result_length);
Clay_String string = { Clay_String string = {
.chars = result[index].string, .chars = result[index].string,
.length = result[index].string_len, .length = result[index].string_len,
@ -105,8 +108,7 @@ void RemoveDieButton(enum Dice_Die die, int index) {
Clay_OnHover(&HandleRemoveDieButtonInteraction, index); Clay_OnHover(&HandleRemoveDieButtonInteraction, index);
CLAY_TEXT(string, CLAY_TEXT_CONFIG({ CLAY_TEXT(string, CLAY_TEXT_CONFIG({
.H(1), .H(1),
.textColor = TextColors(0), .textColor = TextColors(0)
.textAlignment = CLAY_TEXT_ALIGN_CENTER,
})); }));
} }
} }
@ -135,26 +137,12 @@ void ActiveDiceContainer() {
}, },
}) { }) {
size_t dice_count = 0; size_t dice_count = 0;
enum Dice_Die const *dice = Dice_GetActiveSet(&dice_count); enum Die_Dice const *dice = Die_GetActiveSet(&dice_count);
for (size_t i = 0; i < dice_count; ++i) { for (size_t i = 0; i < dice_count; ++i) {
RemoveDieButton(dice[i], i); RemoveDieButton(dice[i], i);
} }
} }
CLAY(CLAY_ID("ActiveDiceControls"), { RollSetButton();
.layout = {
.layoutDirection = CLAY_LEFT_TO_RIGHT,
.childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER },
.childGap = 20,
.padding = { 0, 0, 0, 10 },
},
}) {
TextButton(CLAY_STRING("Roll"), proceedButton, &HandleRollSetButtonInteraction, 0);
CLAY_TEXT(Dice_GetLastResultTotal()->clay_string, CLAY_TEXT_CONFIG({
.H(3),
.textColor = TextColors(0),
}));
TextButton(CLAY_STRING("Clear"), warningButton, &HandleClearSetButtonInteraction, 0);
}
} }
} }

View file

@ -2,20 +2,17 @@
#include "style.h" #include "style.h"
void TextButton(Clay_String text, Clay_Color color, OnHoveredFn onHovered, intptr_t onHoveredData) { void TextButton(Clay_String text, Clay_Color color, OnHoveredFn onHovered, intptr_t onHoveredData) {
Clay_Color hovered = ToHoveredColor(color);
CLAY_AUTO_ID({ CLAY_AUTO_ID({
.layout = { .layout = {
.childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER }, .childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER },
.padding = buttonPadding, .padding = buttonPadding,
}, },
.cornerRadius = buttonRadii, .cornerRadius = buttonRadii,
.backgroundColor = Clay_Hovered() ? hovered : color, .backgroundColor = Clay_Hovered() ? ToHoveredColor(color) : color,
.border = { ToHoveredColor(Clay_Hovered() ? hovered : color), CLAY_BORDER_ALL(1) }
}) { }) {
CLAY_TEXT(text, CLAY_TEXT_CONFIG({ CLAY_TEXT(text, CLAY_TEXT_CONFIG({
.BODY(), .BODY(),
.textColor = TextColors(0), .textColor = TextColors(0),
.textAlignment = CLAY_TEXT_ALIGN_CENTER,
})); }));
Clay_OnHover(onHovered, onHoveredData); Clay_OnHover(onHovered, onHoveredData);
} }

View file

@ -67,7 +67,7 @@ void LoadResources() {
LoadDiceImages(); LoadDiceImages();
} }
SDL_Texture *GetDiceImage(enum Dice_Die die) { SDL_Texture *GetDiceImage(enum Die_Dice die) {
switch (die) { switch (die) {
case COIN: case COIN:
return diceImages[COIN_IMAGE]; return diceImages[COIN_IMAGE];

View file

@ -29,6 +29,6 @@ extern SDL_Texture *diceImages[DICE_IMAGE_MAX];
extern void LoadResources(); extern void LoadResources();
extern SDL_Texture *GetDiceImage(enum Dice_Die die); extern SDL_Texture *GetDiceImage(enum Die_Dice die);
#endif // !RESOURCES_H #endif // !RESOURCES_H

View file

@ -45,7 +45,7 @@ Clay_ElementDeclaration WindowStyle() {
}; };
} }
Clay_Color DieColor(enum Dice_Die die) { Clay_Color DieColor(enum Die_Dice die) {
switch(die) { switch(die) {
case COIN: return dieColors[0]; case COIN: return dieColors[0];
case D4: return dieColors[1]; case D4: return dieColors[1];
@ -59,7 +59,7 @@ Clay_Color DieColor(enum Dice_Die die) {
} }
} }
Clay_Color DieButtonColor(enum Dice_Die die, bool selected) { Clay_Color DieButtonColor(enum Die_Dice die, bool selected) {
return selected ? ToHoveredColor(DieColor(die)) : DieColor(die); return selected ? ToHoveredColor(DieColor(die)) : DieColor(die);
} }

View file

@ -2,7 +2,7 @@
#define STYLE_H #define STYLE_H
#include "defs.h" #include "defs.h"
#include "resources.h" // needed for macros #include "resources.h"
#include <clay/clay.h> #include <clay/clay.h>
#include <stdint.h> #include <stdint.h>
@ -70,12 +70,9 @@ fontId = FONT_BOLD,\
// BUTTONS // BUTTONS
//////////////////////////////////// ////////////////////////////////////
constexpr Clay_Color warningButton = { constexpr Clay_Color buttonBackground = {
177, 56, 52, 255 177, 56, 52, 255
}; };
constexpr Clay_Color proceedButton = {
49, 181, 99, 255
};
constexpr Clay_Padding buttonPadding = { constexpr Clay_Padding buttonPadding = {
24, 24, 24, 24,
4, 4, 4, 4,
@ -115,8 +112,8 @@ extern Clay_Color PanelBackground(size_t idx);
extern Clay_Color TextColors(size_t idx); extern Clay_Color TextColors(size_t idx);
extern Clay_Color WindowBackground(); extern Clay_Color WindowBackground();
extern Clay_ElementDeclaration WindowStyle(); extern Clay_ElementDeclaration WindowStyle();
extern Clay_Color DieColor(enum Dice_Die die); extern Clay_Color DieColor(enum Die_Dice die);
extern Clay_Color DieButtonColor(enum Dice_Die die, bool selected); extern Clay_Color DieButtonColor(enum Die_Dice die, bool selected);
extern Clay_Color ToHoveredColor(Clay_Color color); extern Clay_Color ToHoveredColor(Clay_Color color);
#endif // !STYLE_H #endif // !STYLE_H