-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui_msg_box.tbs
125 lines (108 loc) · 4.26 KB
/
ui_msg_box.tbs
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
'*********************************************************************************
' ON SCREEN MESSAGE BOX CONTROL
'
' This is a message box libaray. It popup a message box on the LCD screen, exit
' when one of the key(keys are defined by keycode_str) is pressed, if the keycode
' of the key matches on of the keycode that is defined in the keycode_str, the
' message box closes, and the function returns the keycode of the key that was
' pressed. In the case of timeout or error, 255 is returned.
'*********************************************************************************
include "global.tbh"
'--------------------------------------------------------------------------------
declare sub ui_msg_box_key_proc(key_event as pl_kp_event_codes, key_code as byte)
declare sub ui_msg_box_timer_proc
'--------------------------------------------------------------------------------
dim mb_timeout_ctr as byte
dim mb_keycode as byte
'================================================================================
public function ui_msg_box(
byref msg as string(MB_MSG_LEN), 'message to be displayed in the Message Box
x as word, 'x coordination
y as word, 'y coordination
w as word, 'width of the msgbox
h as word, 'height of the msgbox
align as pl_lcd_text_alignment, 'alignment of the text in the msgbox
byref keycode_str as string(20), 'this string contains the characters which ASCII is correspond to the keycode of keys on the keypad that msgbox responds to, chr(255) is the default key code, and cannot be used.
bolder as no_yes, 'if the msgbox is wrap with a visible bolder line
timeout as byte 'if no respond from the keypad within the time defined by "timeout", exit the msgbox and return to the previous screen. If timeout=0, no time out applies
) as byte
dim kp_event as pl_kp_event_codes
dim kp_code as byte
dim t as word
mb_timeout_ctr=timeout
if msg<>"" then
romfile.open(LCD_STD_FONT)
lcd.setfont(romfile.offset)
lcd.textverticalspacing=MSB_VER_SPACING
lcd.texthorizontalspacing=MSB_HOR_SPACING
lcd.linewidth=MSG_BOX_BOLDER
lcd.textalignment=align
LCD_LOCK
lcd_clear(x,y,w,h)
lcd.printaligned(msg,x+MSB_BOLDER_PADDING,y+MSB_BOLDER_PADDING,w-MSB_BOLDER_PADDING*2,h-MSB_BOLDER_PADDING*2)
if bolder=YES then lcd.rectangle(x+1,y+1,x+w-2,y+h-2)
device_msg_box_pre(msg,x,y,w,h,align,keycode_str,bolder,timeout)
LCD_UNLOCK
end if
if kp.enabled=NO or kp.genkpevent<>NO then
kp.enabled=NO
kp.genkpevent=NO
kp.enabled=YES
else
kp.clearbuffer
end if
wait:
mb_keycode=255 'mb_kycode is 255 by default, if a key is pressed, it will be changed to the key code of the pressed key
device_mb_interrupt() 'allow user to executes other procedures while inside the message box
if kp.enabled=NO then kp.enabled=YES
if kp.getkey(kp_event,kp_code)=OK then
if kp_event=PL_KP_EVENT_LOCKEDUP then
reset_keypad()
goto wait
end if
mb_timeout_ctr=timeout
ui_msg_box_key_proc(kp_event,kp_code)
end if
'key is pressed, the mb_keycode has changed, return pressed key code.
if mb_keycode<>255 then
goto key_pressed
end if
'making sure that ui_msg_box_timer_proc() is not excuted more than once per timer interval(500ms)
if t<>sys.timercount then
t=sys.timercount
ui_msg_box_timer_proc()
end if
if timeout=0 then
goto wait
else
if mb_timeout_ctr=0 then 'countdown timer reaches 0, exit message box.
ui_msg_box=255
goto exit_msgbox
key_pressed:
if mb_keycode<>255 then
if keycode_str<>"" AND instr(1,keycode_str,chr(mb_keycode),1)=0 then goto wait
ui_msg_box=mb_keycode
exit_msgbox:
device_msg_box_post(msg,x,y,w,h,align,keycode_str,bolder,timeout)
exit function
end if
end if
goto wait
end if
end function
'--------------------------------------------------------------------------------
sub ui_msg_box_key_proc(key_event as pl_kp_event_codes, key_code as byte)
'The keypad process for ui_msg_box module
device_mb_key_proc(key_event, key_code)
select case key_event
case PL_KP_EVENT_PRESSED:
mb_keycode=key_code
end select
end sub
'--------------------------------------------------------------------------------
sub ui_msg_box_timer_proc()
'The timer process for ui_msg_box module
if mb_timeout_ctr>0 then
mb_timeout_ctr=mb_timeout_ctr-1
end if
end sub