-
Notifications
You must be signed in to change notification settings - Fork 0
/
testwindow.cpp
101 lines (84 loc) · 2.32 KB
/
testwindow.cpp
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
#include "testwindow.hpp"
#include <iostream>
#include <time.h>
#include "nookfont.hpp"
bool WeatherIcon::draw()
{
return true ;
}
void WeatherIcon::initialise()
{
std::cout << "Initialising Weather Icon\n" ;
canvas.loadJPG("weather.jpg",8) ;
//set_window_merge(true) ;
set_white_transparency(true) ;
}
TestNookWnd::TestNookWnd()
{
NookWindow() ;
m_x = 0;
m_y = 0;
m_last = 0 ;
m_full = 0 ;
}
void TestNookWnd::initialise()
{
iconwnd.create(50,50,256,256) ;
add_window(iconwnd) ;
m_fnt.load_font("/usr/share/fonts/ttf/LiberationSans-Regular.ttf") ;
m_btn.create(100,600,70,30) ;
m_btn.add_text(L"Test") ;
add_window(m_btn) ;
m_msgbox.create(200,300,300, 200) ;
m_msgbox.set_text(L"Message to the world", 8) ;
add_window(m_msgbox) ;
}
bool TestNookWnd::draw()
{
//canvas.setFGCol(0,0,0,0);
//canvas.setBGCol(255,255,255,255) ;
canvas.setFGGrey(0) ;
canvas.setBGGrey(255) ;
canvas.eraseBackground();
if (!canvas.drawLine(m_width/2,m_height/2, m_x, m_y))
std::cerr << "Failed to draw line onto canvas\n" ;
if (!canvas.drawRect(10,10,m_width-20, m_height-20))
std::cerr << "Failed to draw rectangle onto canvas\n" ;
//DisplayImage fntstr = m_fnt.write_string(m_fnt.get_family_name(), 16) ;
DisplayImage fntstr = m_fnt.write_string(L"glyph justify", 16) ;
canvas.copy(fntstr, 2, 10, 400) ;
return true ;
}
void TestNookWnd::key_event(KeyEvent &keys)
{
std::string strState = "up";
if (keys.key_down) strState = "down" ;
std::cout << "Key " << strState << ", ID: " << (int)keys.code << std::endl;
}
void TestNookWnd::touch_event(TouchEvent &touch, unsigned int x_offset, unsigned int y_offset)
{
if (!m_msgbox.is_hidden()){
// Message box is modal so just send touch messages there
m_msgbox.touch_event(touch,x_offset+m_msgbox.get_x_pos(), y_offset + m_msgbox.get_y_pos()) ;
return ;
}
NookWindow::touch_event(touch, x_offset, y_offset) ;
}
bool TestNookWnd::tick()
{
time_t now = time(NULL) ;
bool full = false ;
if (now - m_last > 1){
if (now - m_full > 20){
full = true ;
m_full = now ;
}
invalidate_window(full);
m_last = now ;
}
if(m_x < m_width && m_y == 0) m_x++ ;
else if (m_x == m_width && m_y < m_height) m_y++;
else if (m_y == m_height && m_x > 0) m_x-- ;
else if (m_x == 0 && m_y > 0) m_y-- ;
return true ;
}