forked from yuryfdr/pbtk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselector.cxx
More file actions
130 lines (125 loc) · 3.33 KB
/
selector.cxx
File metadata and controls
130 lines (125 loc) · 3.33 KB
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
/* Copyright (C) 2011-2012 Yury P. Fedorchenko (yuryfdr at users.sf.net) */
/*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "selector.h"
static const char* grid[][3]={
{"<<","x",">>"},
{"1","2","3"},
{"4","5","6"},
{"7","8","9"},
{"<-","0","ok"},
};
void PBNumericSelector::draw_cell(int y0,int i,int j){
int cx=x()+i*elw;
int cy=y0+j*elw;
if(cbx==i && cby==j){
SetFont(getFont(),WHITE);
FillArea(cx,cy,elw,elw,BLACK);
}else{
SetFont(getFont(),BLACK);
}
DrawTextRect(cx,cy,elw,elw,grid[j][i],ALIGN_CENTER|VALIGN_MIDDLE);
}
void PBNumericSelector::draw(){
PBWidget::draw();
SetFont(captionFont,WHITE);
DrawLine(x()+elw,y(),x()+elw,y()+h()-2,BLACK);
DrawLine(x()+2*elw,y(),x()+2*elw,y()+h()-2,BLACK);
FillArea(x(),y(),w(),1.2*captionFont->height,BLACK);
char buff[128];
sprintf(buff,"%s %d",getText().c_str(),_select);
DrawTextRect(x(),y(),w(),1.2*captionFont->height,buff,ALIGN_LEFT|VALIGN_MIDDLE);
SetFont(getFont(),BLACK);
int cy=y()+1.2*captionFont->height;
DrawLine(x()+2,cy+1*elw,x()+w()-4,cy+1*elw,BLACK);
DrawLine(x()+2,cy+2*elw,x()+w()-4,cy+2*elw,BLACK);
DrawLine(x()+2,cy+3*elw,x()+w()-4,cy+3*elw,BLACK);
DrawLine(x()+2,cy+4*elw,x()+w()-4,cy+4*elw,BLACK);
SetFont(getFont(),BLACK);
for(int i=0;i<3;++i)
for(int j=0;j<5;++j)
draw_cell(cy,i,j);
}
void PBNumericSelector::hit_cell(){
if(cby==0){
if(cbx==1){
quit(false);
onSelect.emit(this,false);
}else if(cbx==0){
_select=0;
quit(true);
onSelect.emit(this,true);
}else if(cbx==2){
_select=-1;
quit(true);
onSelect.emit(this,true);
}
return;
}
if(cby==4 && cbx==2){
quit(true);
onSelect.emit(this,true);
return;
}
if(cby==4 && cbx==1){
_select*=10;
} else if(cby==4 && cbx==0){
_select/=10;
}else{
int nmb=1+cbx+3*(cby-1);
_select*=10;
_select+=nmb;
}
update();
}
int PBNumericSelector::handle(int type,int par1,int par2){
if(EVT_KEYUP == type){
switch(par1){
case KEY_OK:
hit_cell();
return 1;
case KEY_LEFT:
--cbx;if(cbx<0)cbx=2;
update();
return 1;
case KEY_RIGHT:
++cbx;if(cbx>2)cbx=0;
update();
return 1;
case KEY_UP:
--cby;if(cby<0)cby=4;
update();
return 1;
case KEY_DOWN:
++cby;if(cby>4)cby=0;
update();
return 1;
}
}
if(EVT_POINTERUP == type){
int cx=(par1-x())/elw;
if(cx>=0 && cx<3){
int cy=(par2-y()-1.2*captionFont->height)/elw;
if(cy>=0&& cy<5){
cbx=cx;cby=cy;
hit_cell();
update();
return 1;
}
}
}
return 0;
}