summaryrefslogtreecommitdiff
path: root/code/fe310/eos/eve/screen/screen.c
blob: 68b6fb8c679ec374415a2a0628fcabf09f88ae21 (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
#include <stdlib.h>
#include <string.h>

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

#include "screen.h"
#include "window.h"

int eve_screen_init(EVEScreen *screen, uint16_t w, uint16_t h) {
    memset(screen, 0, sizeof(EVEScreen));
    screen->w = w;
    screen->h = h;
}

void eve_screen_set_kbd(EVEScreen *screen, EVEKbd *kbd) {
    screen->kbd = kbd;
}

EVEKbd *eve_screen_get_kbd(EVEScreen *screen) {
    return screen->kbd;
}

void eve_screen_show_kbd(EVEScreen *screen) {
    if (screen->kbd && screen->kbd_win) screen->kbd_win->g.y = screen->h - screen->kbd->g.h;
}

void eve_screen_hide_kbd(EVEScreen *screen) {
    if (screen->kbd && screen->kbd_win) screen->kbd_win->g.y = screen->h;
}

int eve_screen_win_insert(EVEScreen *screen, EVEWindow *window, int idx) {
    if (idx) {
        int i;
        EVEWindow *h = screen->win_head;

        for (i=1; i<idx; i++) {
            h = h->next;
            if (h == NULL) return EVE_ERR;
        }
        window->next = h->next;
        h->next = window;
    } else {
        window->next = screen->win_head;
        screen->win_head = window;
    }
    if (window->next == NULL) screen->win_tail = window;
    return EVE_OK;
}

int eve_screen_win_remove(EVEScreen *screen, EVEWindow *window) {
    EVEWindow *h = screen->win_head;
    if (h == NULL) return EVE_ERR;
    if (h == window) {
        screen->win_head = window->next;
        if (screen->win_head == NULL) screen->win_tail = NULL;
    } else {
        while (h->next && (h->next != window)) h = h->next;
        if (h->next == NULL) return EVE_ERR;

        h->next = window->next;
        if (h->next == NULL) screen->win_tail = h;
    }
}

void eve_screen_win_append(EVEScreen *screen, EVEWindow *window) {
    screen->win_tail->next = window;
    screen->win_tail = window;
}

void eve_screen_handle_touch(EVEScreen *screen, uint8_t tag0, int touch_idx) {
    EVEWindow *w;
    int a;
    uint8_t tagN = 0x80;

    eve_touch_clear_opt();

    w = screen->win_head;
    while(w) {
        if (eve_window_visible(w)) a = w->view->touch(w->view, tag0, touch_idx);
        w = w->next;
    }

    eve_cmd_burst_start();
	eve_cmd_dl(CMD_DLSTART);
	eve_cmd_dl(CLEAR_COLOR_RGB(0,0,0));
	eve_cmd_dl(CLEAR(1,1,1));

    w = screen->win_head;
    while(w) {
        if (eve_window_visible(w)) tagN = w->view->draw(w->view, tagN);
        w = w->next;
    }

    eve_cmd_dl(DISPLAY());
	eve_cmd_dl(CMD_SWAP);
    eve_cmd_burst_end();
    eve_cmd_exec(1);
}