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
94
95
96
97
98
99
100
|
#include <raylib.h>
#include <stdlib.h>
#include "scenes.h"
#include "../resources/resources.h"
#include "../ui_elements/UI.h"
typedef struct {
Puzzle *PuzzlePtr;
} puzzleSceneData;
bool updatePuzzleScene(void *self) {
return true;
}
const int HEADER_FONT_SIZE = 50;
const int PADDING = 10;
const int BORDER = 2;
const int FOOTER_HEIGHT = 40;
void DrawPuzzleName(char *name) {
Vector2 width = MeasureTextEx(*GetMainFont(), name, 50, 1);
int screen_width = GetScreenWidth();
Vector2 pos = { .y = 20, .x = (screen_width - width.x) / 2, };
DrawTextEx(*GetMainFont(), name, pos, HEADER_FONT_SIZE, 1, COLORSCHEME_BROWN);
}
Rectangle GetBodyRect() {
int HeaderOffset = PADDING * 2 + HEADER_FONT_SIZE;
Rectangle outp = {
.x = PADDING,
.y = HeaderOffset,
.width = GetScreenWidth() - PADDING * 2,
.height = GetScreenHeight() - HeaderOffset - PADDING * 3 - FOOTER_HEIGHT,
};
return outp;
}
void GetPanesSplit(Rectangle *pane1, Rectangle *pane2, Rectangle body, float proportion_h, float proportion_v) {
if (body.height >= body.width) {
// vertical split
pane1->x = body.x;
pane1->y = body.y;
pane1->width = body.width;
pane1->height = (body.height - PADDING) * proportion_v;
pane2->x = body.x;
pane2->y = body.y + pane1->height + PADDING;
pane2->width = body.width;
pane2->height = (body.height - PADDING) * (1 - proportion_v);
return;
}
// horizontal split
pane1->x = body.x;
pane1->y = body.y;
pane1->height = body.height;
pane1->width = (body.width - PADDING) * proportion_h;
pane2->y = body.y;
pane2->x = body.x + pane1->width + PADDING;
pane2->height = body.height;
pane2->width = (body.width - PADDING) * (1 - proportion_h);
}
bool drawPuzzleScene(void *self) {
puzzleSceneData *data = ((Scene *)self)->data;
ClearBackground(COLORSCHEME_WHITE);
DrawPuzzleName(data->PuzzlePtr->Name);
Rectangle body = GetBodyRect();
Rectangle pane1, pane2;
GetPanesSplit(&pane1, &pane2, body, 0.5, 0.4);
DrawRecBordered(pane1, WHITE, COLORSCHEME_ORANGE, BORDER);
DrawRecBordered(pane2, WHITE, COLORSCHEME_ORANGE, BORDER);
// DrawRecBordered(body, COLORSCHEME_WHITE, COLORSCHEME_ORANGE, BORDER);
return true;
}
void deinitPuzzleScene(void *self) {
TraceLog(LOG_INFO, "Deleting a puzzle scene");
free((puzzleSceneData *)((Scene *)self)->data);
free((Scene *)self);
}
Scene *CreatePuzzleScene(Puzzle *puzzle) {
Scene *outp = malloc(sizeof(Scene));
outp->Update = updatePuzzleScene;
outp->Draw = drawPuzzleScene;
outp->Deint = deinitPuzzleScene;
puzzleSceneData *data = malloc(sizeof(puzzleSceneData));
data->PuzzlePtr = puzzle;
outp->data = data;
return outp;
}
|