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
|
#include <raylib.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include "scenes.h"
#include "../ui_elements/UI.h"
#include "../resources/resources.h"
static const int PADDING = 20;
static const int BORDER = 2;
static const int SCROLL_SPEED = 10;
typedef struct {
SubmitionResult *value;
int scroll;
/// For the fun popping up effect
float scroll_up;
bool isClosing;
} ResultViewData;
Rectangle GetResultViewBodyRect(float scroll_up) {
int HeaderOffset = PADDING * 2;
int height = GetScreenHeight();
Rectangle outp = {
.x = PADDING,
.y = HeaderOffset + (height * scroll_up),
.width = GetScreenWidth() - PADDING * 2,
.height = height - HeaderOffset - PADDING * 3,
};
return outp;
}
bool updateResultView(void *self) {
ResultViewData *data = ((Scene *)self)->data;
if (data->isClosing) {
data->scroll_up += SCROLL_SPEED * GetFrameTime();
if (data->scroll_up > 1) DeleteSceneFromStack();
return true;
}
if (data->scroll_up != 0) {
data->scroll_up -= SCROLL_SPEED * GetFrameTime();
if (data->scroll_up < 0) data->scroll_up = 0;
}
if (IsKeyPressed(KEY_ESCAPE)) {
data->isClosing = true;
}
return true;
}
bool drawResultView(void *self) {
ResultViewData *data = ((Scene *)self)->data;
// DrawBackground();
Rectangle body = GetResultViewBodyRect(data->scroll_up);
DrawRecBordered(body, WHITE, data->value->result == RESULT_OK ? COLORSCHEME_GREEN : COLORSCHEME_ORANGE, BORDER);
DrawTextInRec(body, data->value->stdout_sb,
GetMainFont(), 20, COLORSCHEME_BROWN, 3, &data->scroll);
return true;
}
void deinitResultView(void *self) {
TraceLog(LOG_INFO, "Deleting a result view");
ResultViewData *data = ((Scene *)self)->data;
if (data->value != NULL) FreeSunmitionResult(data->value);
free(data);
free((Scene *)self);
}
Scene *CreateResultView(SubmitionResult *result) {
TraceLog(LOG_INFO, "Creating a main menu");
Scene *outp = malloc(sizeof(Scene));
outp->Draw = drawResultView;
outp->Update = updateResultView;
outp->Deint = deinitResultView;
outp->IsTransparent = true;
ResultViewData *data = malloc(sizeof(ResultViewData));
if (data == NULL) {
free(outp);
return NULL;
}
data->value = result;
data->scroll = 0;
data->scroll_up = 1;
data->isClosing = false;
outp->data = data;
return outp;
}
|