summaryrefslogtreecommitdiff
path: root/views/displaymenutabview.c
blob: f9e03f9522d9bcb98de3694a2f8f0fc93b005a08 (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
#include "displaymenutabview.h"


cDisplayMenuTabView::cDisplayMenuTabView(cTemplateViewTab *tmplTab) : cView(tmplTab) {
}

cDisplayMenuTabView::~cDisplayMenuTabView() {
    CancelSave();
}

void cDisplayMenuTabView::SetTokens(map < string, int > *intTokens, map < string, string > *stringTokens, map < string, vector< map< string, string > > > *loopTokens) {
    this->intTokens = intTokens;
    this->stringTokens = stringTokens;
    this->loopTokens = loopTokens;
}

void cDisplayMenuTabView::Clear(void) {
    Fill(0, clrTransparent);
}

void cDisplayMenuTabView::CreateTab(void) {
    //Create Pixmap
    if (!PixmapExists(0)) {
        cSize drawportSize;
        scrolling = tmplTab->CalculateDrawPortSize(drawportSize, loopTokens);
        if (scrolling) {
            CreateScrollingPixmap(0, tmplTab, drawportSize);
            scrollingPix = 0;
            scrollOrientation = orVertical; 
            scrollMode = smNone;
        } else {
            CreateViewPixmap(0, tmplTab);              
        }
    }    
}


void cDisplayMenuTabView::Render(void) {
    if (tmplTab->DoDebug()) {
        tmplTab->Debug();
    }
    //Draw Tab, flushing every loop
    DrawPixmap(0, tmplTab, loopTokens, true);
}

bool cDisplayMenuTabView::KeyUp(void) { 
    if (!scrolling)
        return false;
    int scrollStep = tmplTab->GetScrollStep();
    int aktHeight = DrawportY(0);
    if (aktHeight >= 0) {
        return false;
    }
    int newY = aktHeight + scrollStep;
    if (newY > 0)
        newY = 0;
    SetDrawPortPoint(0, cPoint(0, newY));
    return true;
}

bool cDisplayMenuTabView::KeyDown(void) {
    if (!scrolling)
        return false;

    int scrollStep = tmplTab->GetScrollStep();
    int aktHeight = DrawportY(0);
    int totalHeight = DrawportHeight(0);
    int screenHeight = Height(0);
    
    if (totalHeight - ((-1)*aktHeight) == screenHeight) {
        return false;
    } 
    int newY = aktHeight - scrollStep;
    if ((-1)*newY > totalHeight - screenHeight)
        newY = (-1)*(totalHeight - screenHeight);
    SetDrawPortPoint(0, cPoint(0, newY));
    return true;
}

bool cDisplayMenuTabView::KeyLeft(void) {
    if (!scrolling)
        return false;
    if (!PixmapExists(0))
        return false;
    int aktHeight = DrawportY(0);
    int screenHeight = Height(0);
    int newY = aktHeight + screenHeight;
    if (newY > 0)
        newY = 0;
    SetDrawPortPoint(0, cPoint(0, newY));
    return true;
}

bool cDisplayMenuTabView::KeyRight(void) {
    if (!scrolling)
        return false;
    if (!PixmapExists(0))
        return false;
    int aktHeight = DrawportY(0);
    int screenHeight = Height(0);
    int totalHeight = DrawportHeight(0);
    int newY = aktHeight - screenHeight;
    if ((-1)*newY > totalHeight - screenHeight)
        newY = (-1)*(totalHeight - screenHeight);
    SetDrawPortPoint(0, cPoint(0, newY));
    return true;
}

void cDisplayMenuTabView::GetScrollbarPosition(int &barTop, int &barHeight) {
    int y = (-1)*DrawportY(0);
    int totalHeight = DrawportHeight(0);
    int screenHeight = Height(0);
    if (totalHeight == 0)
        return;
    if (totalHeight <= screenHeight)
        barHeight = 1000;
    else {
        barHeight = (double)screenHeight / (double) totalHeight * 1000; 
    }
    barTop = (double)y / (double) totalHeight * 1000;
}

void cDisplayMenuTabView::Action(void) {
    Render();
    DoFlush();
}