summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/eve/widget/freew.c
blob: 11b8e5000de30afa6a4b33352ad024c02dbb574e (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 <stdlib.h>
#include <string.h>

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

#include "screen/window.h"
#include "screen/page.h"

#include "widget.h"

void eve_freew_init(EVEFreeWidget *widget, EVERect *g, EVEPage *page, eve_freew_draw_t draw, eve_freew_touch_t touch, eve_kbd_input_handler_t putc) {
    EVEWidget *_widget = &widget->w;

    memset(widget, 0, sizeof(EVEFreeWidget));
    eve_widget_init(_widget, EVE_WIDGET_TYPE_FREE, g, page, eve_freew_draw, eve_freew_touch, putc);
    widget->_draw = draw;
    widget->_touch = touch;
}

int eve_freew_create(EVEWidget *_widget, EVEWidgetSpec *spec, EVEPage *page) {
    EVEFreeWidget *widget = (EVEFreeWidget *)_widget;
    EVEFreeSpec *tspec = &spec->tspec.free;

    eve_freew_init(widget, &spec->g, page, tspec->draw, tspec->touch, tspec->putc);

    return EVE_OK;
}

uint8_t eve_freew_draw(EVEWidget *_widget, uint8_t tag0) {
    EVEFreeWidget *widget = (EVEFreeWidget *)_widget;

    _widget->tag0 = tag0;
    _widget->tagN = tag0;
    eve_cmd_dl(SAVE_CONTEXT());
    widget->_draw(widget);
    eve_cmd_dl(RESTORE_CONTEXT());

    return _widget->tagN;
}

int eve_freew_touch(EVEWidget *_widget, EVETouch *touch, uint16_t evt) {
    EVEFreeWidget *widget = (EVEFreeWidget *)_widget;
    int ret;

    ret = widget->_touch(widget, touch, evt);
    return ret;
}

uint8_t eve_freew_tag(EVEFreeWidget *widget) {
    EVEWidget *_widget = &widget->w;
    uint8_t ret = EVE_NOTAG;

    if (_widget->tagN != EVE_NOTAG) {
        ret = _widget->tagN;
        eve_cmd_dl(TAG(ret));
        _widget->tagN++;
    }

    return ret;
}

uint8_t eve_widget_tag_index(EVEFreeWidget *widget, uint8_t tag) {
    EVEWidget *_widget = &widget->w;

    return tag - _widget->tag0;
}