summaryrefslogtreecommitdiff
path: root/src/scenes/resultView.c
blob: 9985319e4b767077d04e879a02ffa15c9ad24155 (plain)
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
#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 = 10;
static const int BORDER = 2;

typedef struct {
    char *value;
    int scroll;
} ResultViewData;

Rectangle GetResultViewBodyRect() {
    int HeaderOffset = PADDING * 2;
    Rectangle outp = {
        .x = PADDING,
        .y = HeaderOffset,
        .width = GetScreenWidth() - PADDING * 2,
        .height = GetScreenHeight() - HeaderOffset - PADDING * 3,
    };
    return outp;
}

bool updateResultView(void *self) {
    if (IsKeyDown(KEY_ESCAPE)) {
        DeleteSceneFromStack();
        return true;
    }
    return true;
}

bool drawResultView(void *self) {
    ResultViewData *data = ((Scene *)self)->data;
    DrawBackground();
    Rectangle body = GetResultViewBodyRect();
    DrawRecBordered(body, WHITE, COLORSCHEME_ORANGE, BORDER);
    DrawTextInRec(body, data->value,
            GetMainFont(), 20, COLORSCHEME_BROWN, 3, &data->scroll);
    return true;
}

void deinitResultView(void *self) {
    TraceLog(LOG_INFO, "Deleting a result view");
    free((Scene *)self);
}

Scene *CreateResultView(char *result) {
    TraceLog(LOG_INFO, "Creating a main menu");
    Scene *outp = malloc(sizeof(Scene));
    outp->Draw = drawResultView;
    outp->Update = updateResultView;
    outp->Deint = deinitResultView;

    ResultViewData *data = malloc(sizeof(ResultViewData));
    if (data == NULL) {
        free(outp);
        return NULL;
    }
    data->value = result;
    data->scroll = 0;
    outp->data = data;

    return outp;
}