summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/eve/screen/view.c
blob: a1290f0a35943acc4c40bb0c2e8c227d18f4437b (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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <stdlib.h>
#include <string.h>

#include "eve.h"
#include "eve_kbd.h"
#include "eve_font.h"

#include "window.h"

void eve_view_init(EVEView *view, EVEWindow *window, eve_view_draw_t draw, eve_view_touch_t touch, eve_view_uievt_t uievt, void *param) {
    view->draw = draw;
    view->touch = touch;
    view->uievt = uievt;
    view->param = param;
    view->window = window;
    view->color_bg = 0x000000;
    view->color_fg = 0xffffff;
}

void eve_view_attach(EVEView *view, EVEWindow *window, void *view_id) {
    view->window = window;
    eve_window_attach_view(window, view, view_id);
}

void eve_view_detach(EVEView *view) {
    eve_window_detach_view(view->window);
}

void eve_view_set_param(EVEView *view, void *param) {
    view->param = param;
}

void eve_view_set_color_bg(EVEView *view, uint8_t r, uint8_t g, uint8_t b) {
    view->color_bg = (r << 16) | (g << 8) | b;
}

void eve_view_set_color_fg(EVEView *view, uint8_t r, uint8_t g, uint8_t b) {
    view->color_fg = (r << 16) | (g << 8) | b;
}

uint8_t eve_view_clear(EVEView *view, uint8_t tag0, uint8_t tag_opt) {
    EVEWindow *win_scroll = NULL;
    EVEWindow *window = view->window;
    uint8_t scroll_tag;

    win_scroll = eve_window_scroll(window, &scroll_tag);
    eve_cmd_dl(CLEAR_COLOR_RGBC(view->color_bg));
    eve_cmd_dl(COLOR_RGBC(view->color_fg));
    if (win_scroll == window) {
        view->tag = scroll_tag;
    } else if (win_scroll) {
        view->tag = EVE_NOTAG;
    } else {
        view->tag = tag0;
        if (tag0 != EVE_NOTAG) {
            eve_tag_set_opt(tag0, tag_opt);
            tag0++;
        }
    }
    eve_cmd_dl(CLEAR_TAG(view->tag));
    eve_cmd_dl(CLEAR(1,1,1));
    return tag0;
}

uint8_t eve_view_tag(EVEView *view, uint8_t tag, uint8_t tag_opt) {
    if (tag != EVE_NOTAG) {
        eve_tag_set_opt(tag, tag_opt);
        eve_cmd_dl(TAG(tag));
        tag++;
    }
    return tag;
}

void eve_view_uievt_push(EVEView *view, uint16_t evt, void *param) {
    if (view->uievt) view->uievt(view, evt, param);
}

void eve_view_uievt_push_gest(EVEView *view, uint16_t evt, EVETouch *touch, uint16_t t_evt) {
    EVEUIEvtTouch param;

    if (view->uievt == NULL) return;

    param.touch = touch;
    param.evt = t_evt;
    view->uievt(view, evt, &param);
}

void eve_vstack_init(EVEVStack *stack) {
    memset(stack, 0, sizeof(EVEVStack));
}

int eve_vstack_push(EVEVStack *stack, eve_view_constructor_t constructor) {
    if (stack->level == EVE_VIEW_SIZE_STACK) return EVE_ERR_FULL;

    stack->constructor[stack->level] = constructor;
    stack->level++;

    return EVE_OK;
}

eve_view_constructor_t eve_vstack_pull(EVEVStack *stack) {
    eve_view_constructor_t constructor;

    constructor = eve_vstack_get(stack);
    if (stack->level) {
        stack->level--;
        stack->constructor[stack->level] = NULL;
    }
    return constructor;
}

eve_view_constructor_t eve_vstack_get(EVEVStack *stack) {
    if (stack->level) return stack->constructor[stack->level - 1];
    return NULL;
}

int eve_vstack_empty(EVEVStack *stack) {
    return (stack->level == 0);
}

int eve_vstack_full(EVEVStack *stack) {
    return (stack->level == EVE_VIEW_SIZE_STACK);
}

int eve_vstack_level(EVEVStack *stack) {
    return stack->level;
}

int eve_vstack_create_view(EVEVStack *stack, EVEWindow *window, eve_view_constructor_t constructor) {
    EVEView *view;
    int rv;

    rv = eve_vstack_push(stack, constructor);
    if (rv) return rv;

    view = constructor(window, stack);
    if (view == NULL) {
        eve_vstack_pull(stack);
        return EVE_ERR;
    }

    eve_view_attach(view, window, constructor);

    return EVE_OK;
}

int eve_vstack_back(EVEVStack *stack, EVEWindow *window) {
    EVEView *view;
    eve_view_constructor_t constructor;

    eve_vstack_pull(stack);
    constructor = eve_vstack_get(stack);
    if (constructor == NULL) return EVE_ERR_EMPTY;

    view = constructor(window, stack);
    if (view == NULL) return EVE_ERR;

    eve_view_attach(view, window, constructor);

    return EVE_OK;
}