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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
#include "scenes.h"
#include <raylib.h>
#include <stdio.h>
#include "../ui_elements/UI.h"
#include "../resources/resources.h"
static const float BODY_PADDING = 0.05f;
static const int BORDER = 2;
static const int EDITOR_PADDING = 3;
typedef struct {
DistractionPuzzle *puzzle;
TextArea *EditorInfo;
void (*addTime_cb)(Scene *, size_t);
int scroll;
} distractionSceneData;
Rectangle getBodyRect() {
float screen_h = GetScreenHeight();
float screen_w = GetScreenWidth();
return (Rectangle) {
.x = screen_w * BODY_PADDING,
.y = screen_h * BODY_PADDING,
.height = screen_h * (1 - BODY_PADDING * 2),
.width = screen_w * (1 - BODY_PADDING * 2),
};
}
bool updateDisctractionScene(void *self) {
distractionSceneData *data = ((Scene *)self)->data;
Rectangle pane1, pane2;
GetPanesSplit(&pane1, &pane2, getBodyRect(), 0.35, 0.4);
UpdateTextArea(data->EditorInfo, pane2);
return true;
}
bool drawDisctractionScene(void *self) {
distractionSceneData *data = ((Scene *)self)->data;
DrawRectangle(0, 0,
GetScreenWidth(), GetScreenHeight(),
(Color) {0, 0, 0, 127 });
Rectangle body = getBodyRect();
Rectangle pane1, pane2;
GetPanesSplit(&pane1, &pane2, body, 0.35, 0.4);
DrawRecBordered(pane1, WHITE, COLORSCHEME_ORANGE, BORDER);
DrawRecBordered(pane2, WHITE, COLORSCHEME_ORANGE, BORDER);
if (data->puzzle == NULL) {
return true;
}
DrawTextInRec(pane1, data->puzzle->puzzle->Description,
GetMainFont(), 20, COLORSCHEME_BROWN, 3, &data->scroll);
Rectangle editor_rect = {
.x = pane2.x + EDITOR_PADDING,
.y = pane2.y + EDITOR_PADDING,
.width = pane2.width - EDITOR_PADDING * 2,
.height = pane2.height - EDITOR_PADDING * 2,
};
DrawTextArea(data->EditorInfo, editor_rect);
return true;
}
void deinitDisctractionScene(void *self) {
distractionSceneData *data = ((Scene *)self)->data;
if (data->puzzle != NULL) {
FreeDistrationPuzzle(data->puzzle);
}
}
Scene *CreateDistractionScene(DistractionPuzzle *puzzle, void (*addTime)(Scene *, size_t)) {
if (puzzle == NULL) {
TraceLog(LOG_ERROR, "Failed to create a distraction scene: puzzle struct is NULL");
return NULL;
}
Scene *outp = malloc(sizeof(Scene));
if (outp == NULL) {
TraceLog(LOG_ERROR, "Failed to create a distraction scene: scene allocation failed");
return NULL;
}
outp->Update = updateDisctractionScene;
outp->Draw = drawDisctractionScene;
outp->Deint = deinitDisctractionScene;
outp->IsTransparent = true;
distractionSceneData *data = malloc(sizeof(distractionSceneData));
if (data == NULL) {
free(outp);
TraceLog(LOG_ERROR, "Failed to create a distraction scene: data allocation failed");
return NULL;
}
data->puzzle = puzzle;
data->addTime_cb = addTime;
TextAreaDisplayParams *EditorDisplayParams = malloc(sizeof(TextAreaDisplayParams));
if (EditorDisplayParams != NULL) {
EditorDisplayParams->font = GetMonoFont();
EditorDisplayParams->spacing = 1;
EditorDisplayParams->font_size = 20; // this will change
EditorDisplayParams->scroll_h = 0;
EditorDisplayParams->scroll_v = 0;
}
if (puzzle->puzzle->InitialCode != NULL) {
data->EditorInfo = CreateTextAreaFromText(EditorDisplayParams, puzzle->puzzle->InitialCode);
} else {
data->EditorInfo = CreateTextArea(EditorDisplayParams);
}
outp->data = data;
return outp;
}
|