Subversion Repositories Kolibri OS

Rev

Rev 4865 | Rev 4882 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4875 eAndrew 1
VERSION equ "0.2Å"
4865 eAndrew 2
    use32
3
    org     0
4
    db	    'MENUET01'
5
    dd	    1, main, dataend, memory, stacktop, 0, 0
6
 
7
    include "../../proc32.inc"
8
    include "../../macros.inc"
9
    include "../../dll.inc"
10
    include "../../develop/libraries/box_lib/trunk/box_lib.mac"
11
    include "parser.inc"
4875 eAndrew 12
    ;include "../../debug.inc"
4865 eAndrew 13
 
14
 ;===============================
15
 
16
    sz_head db "Calc+ [v", VERSION, "]", 0
4875 eAndrew 17
    buttons db "123456789()%^-+/*0"
4865 eAndrew 18
    edb1    edit_box 184, 8, 12, 0, 0, 0, 0, 0, 500, \
19
		     exp, group, ed_always_focus + ed_focus, 0, 0
20
 
21
 imports:
22
    library gui, "box_lib.obj"
23
    import  gui, editbox.draw,	"edit_box",	\
24
		 editbox.key,	"edit_box_key", \
25
		 editbox.mouse, "edit_box_mouse"
26
 
27
 ;===============================
28
 
29
 main:
30
    mov     [ans.buffer], word "0"
31
    mov     [ans.size], 15
32
 
33
    mcall   40, 100111b
34
    mcall   48, 3, scn, 192
35
 
36
    m2m     [edb1.color],	       [scn.gui_face]
37
    m2m     [edb1.shift_color],        [scn.gui_select]
38
    m2m     [edb1.focus_border_color], [scn.gui_face]
39
    m2m     [edb1.text_color],	       [scn.gui_fctext]
40
 
41
    mcall   68, 11
42
    stdcall dll.Load, imports
43
 
44
 ;----------------------
45
 
46
 update:
4875 eAndrew 47
    mcall   23, 5
4865 eAndrew 48
 
49
    cmp     eax, EV_REDRAW
50
    je	    ev_redraw
51
    cmp     eax, EV_KEY
52
    je	    ev_key
53
    cmp     eax, EV_BUTTON
54
    je	    ev_button
55
    cmp     eax, EV_MOUSE
56
    je	    ev_mouse
57
 
58
    dec     [timer]
59
    cmp     [timer], 0
60
    je	    calc
61
 
62
    jmp     update
63
 
64
 ;----------------------
65
 
66
 ev_redraw:
67
    mov     edx, [scn.win_body]
68
    or	    edx, 0x34 shl 24
69
    mcall    0, <100, 236>, <100, 164>, , , sz_head
70
 
4875 eAndrew 71
    call    draw_textbox
4865 eAndrew 72
 
4875 eAndrew 73
    mov     [but_id], 0x4000000A
74
    mov     [txt_id], buttons
75
    mov     [txt_x], 16
76
    mov     [but_w], 38
77
    stdcall draw_button,   4,  42
78
    stdcall draw_button,  46,  42
79
    stdcall draw_button,  88,  42
80
    stdcall draw_button,   4,  66
81
    stdcall draw_button,  46,  66
82
    stdcall draw_button,  88,  66
83
    stdcall draw_button,   4,  90
84
    stdcall draw_button,  46,  90
85
    stdcall draw_button,  88,  90
86
    stdcall draw_button,  88, 114
4865 eAndrew 87
 
4875 eAndrew 88
    stdcall draw_button, 144,  42
89
    stdcall draw_button, 186,  42
90
    stdcall draw_button, 144,  66
91
    stdcall draw_button, 186,  66
92
    stdcall draw_button, 144,  90
93
    stdcall draw_button, 186,  90
94
    stdcall draw_button, 144, 114
95
    stdcall draw_button, 186, 114
4865 eAndrew 96
 
4875 eAndrew 97
    mov     [txt_x], 37
98
    mov     [but_w], 80
99
    stdcall draw_button,   4, 114
4865 eAndrew 100
 
101
    jmp     update
102
 
103
 ;----------------------
104
 
105
 ev_key:
4875 eAndrew 106
    mov     [timer], 10
4865 eAndrew 107
 
108
    mcall   2
109
    cmp     ah, 27
110
    je	    exit
111
    invoke  editbox.key, edb1
112
    jmp     update
113
 
114
 ;----------------------
115
 
116
 ev_button:
4875 eAndrew 117
    mov     [timer], 10
4865 eAndrew 118
 
119
    mcall   17
120
 
121
    cmp     ah, 1
122
    je	    exit
123
 
4875 eAndrew 124
    cmp     ah, 2
125
    jne     .not_copy
126
 
127
 .copy:
128
 
129
    mov     eax, exp
130
    mov     ebx, ans.buffer
131
    mov     ecx, 0
132
  @@:
133
    mov     dl, [ebx]
134
    mov     [eax], dl
135
    inc     eax
136
    inc     ebx
137
    inc     ecx
138
    cmp     [eax - 1], byte 0
139
    jne     @b
140
 
141
    dec     ecx
142
    mov     [edb1.size], ecx
143
    m2m     [edb1.pos], [edb1.size]
144
 
145
    jmp     .redraw
146
 
147
 .not_copy:
148
 
149
    cmp     ah, 19
4865 eAndrew 150
    jne     .not_del
151
 
4875 eAndrew 152
 .del:
153
 
4865 eAndrew 154
    cmp     [edb1.pos], 0
155
    je	    update
156
    mov     eax, exp
157
    add     eax, [edb1.pos]
158
    dec     eax
159
    mov     ebx, exp
160
    add     ebx, [edb1.size]
161
    inc     ebx
162
  @@:
163
    cmp     eax, ebx
164
    je	    @f
165
    mov     cl, [eax + 1]
166
    mov     [eax], cl
167
    inc     eax
168
    jmp     @b
169
  @@:
170
    dec     [edb1.pos]
171
    dec     [edb1.size]
172
    m2m     [edb1.shift], [edb1.pos]
4875 eAndrew 173
    jmp     .redraw
4865 eAndrew 174
 
175
 .not_del:
176
 
177
    cmp     ah, 10
178
    jl	    update
179
    cmp     ah, 50
180
    jg	    update
181
 
182
    movzx   eax, ah
183
    add     eax, buttons
184
    sub     eax, 10
185
    mov     al, [eax]
186
 
187
    mov     ebx, exp
188
    add     ebx, [edb1.size]
189
    mov     ecx, exp
190
    add     ecx, [edb1.pos]
191
  @@:
192
    cmp     ebx, ecx
193
    je	    @f
194
    mov     dl, [ebx - 1]
195
    mov     [ebx], dl
196
    dec     ebx
197
    jmp     @b
198
  @@:
199
 
200
    mov     [ebx], al
201
    inc     [edb1.size]
202
    inc     [edb1.pos]
203
 
4875 eAndrew 204
 .redraw:
205
    call    draw_textbox
206
    jmp     update
4865 eAndrew 207
 
208
 ;----------------------
209
 
210
 ev_mouse:
211
    mcall   2
212
 
213
    invoke  editbox.mouse, edb1
214
    jmp     update
215
 
216
 ;----------------------
217
 
218
 exit:
219
    mcall   -1
220
 
221
 ;----------------------
222
 
223
 calc:
224
    stdcall parse
225
    cmp     [error_n], 0
226
    jne     .error
227
 
228
    stdcall convert_to_str, eax, ans.buffer
229
    imul    eax, 6
230
    add     eax, 9
231
    mov     [ans.size], eax
4875 eAndrew 232
    jmp     .redraw
4865 eAndrew 233
 
234
 .error:
235
    cmp     [error_n], 1
236
    je	    .err_1
4875 eAndrew 237
    cmp     [error_n], 4
238
    je	    .err_4
239
 
240
    mov     [ans.buffer +  0], dword "Expe"
241
    mov     [ans.buffer +  4], dword "cted"
242
    mov     [ans.buffer +  8], dword " ')'"
243
    mov     [ans.buffer + 12], byte 0
244
    mov     [ans.size], 81
245
 
246
    cmp     [error_n], 2
247
    je	    .redraw
248
    cmp     [error_n], 3
249
    je	    .err_3
4865 eAndrew 250
 .err_1:
251
    mov     [ans.buffer +  0], dword "Div."
252
    mov     [ans.buffer +  4], dword " by "
4875 eAndrew 253
    mov     [ans.buffer +  8], byte  "0"
254
    mov     [ans.buffer +  9], byte 0
255
    mov     [ans.size], 63
256
    jmp     .redraw
257
 .err_4:
258
    mov     [ans.buffer +  0], dword "Inpu"
259
    mov     [ans.buffer +  4], dword "t er"
260
    mov     [ans.buffer +  8], dword "rror"
4865 eAndrew 261
    mov     [ans.buffer + 12], byte 0
262
    mov     [ans.size], 81
4875 eAndrew 263
    jmp     .redraw
264
 .err_3:
265
    mov     [ans.buffer + 10], byte "("
266
    jmp     .redraw
4865 eAndrew 267
 
4875 eAndrew 268
 .redraw:
269
    call    draw_textbox
270
    jmp     update
271
 
4865 eAndrew 272
 ;----------------------
273
 
4875 eAndrew 274
 proc draw_button, x, y
275
    mcall   13, <[x], [but_w]>, <[y], 20>, [scn.gui_frame]
4865 eAndrew 276
 
277
    add     ebx, 1 shl 16
278
    add     ecx, 1 shl 16
279
    sub     ebx, 2
280
    sub     ecx, 2
281
    mcall   , , , [scn.3d_light]
282
 
283
    add     ebx, 1 shl 16
284
    add     ecx, 1 shl 16
285
    dec     ebx
286
    dec     ecx
287
    mcall   , , , [scn.3d_dark]
288
 
289
    dec     ebx
290
    dec     ecx
291
    mcall   , , , [scn.win_face]
292
 
293
    mcall   1, [x], [y], [scn.win_body]
294
 
4875 eAndrew 295
    add     ebx, [but_w]
4865 eAndrew 296
    dec     ebx
297
    mcall
298
 
299
    add     ecx, 20
300
    dec     ecx
301
    mcall
302
 
4875 eAndrew 303
    sub     ebx, [but_w]
4865 eAndrew 304
    inc     ebx
305
    mcall
306
 
307
    mov     ebx, [x]
308
    inc     ebx
309
    shl     ebx, 16
4875 eAndrew 310
    add     ebx, [but_w]
4865 eAndrew 311
    sub     ebx, 3
312
    mov     ecx, [y]
313
    inc     ecx
314
    shl     ecx, 16
315
    add     ecx, 20
316
    sub     ecx, 3
317
    mov     edx, [but_id]
318
    mcall   8
319
 
320
    mov     ebx, [x]
4875 eAndrew 321
    add     ebx, [txt_x]
4865 eAndrew 322
    shl     ebx, 16
323
    add     ebx, [y]
324
    add     ebx, 7
4875 eAndrew 325
    mcall   4, , [scn.win_text], [txt_id], 1
4865 eAndrew 326
 
4875 eAndrew 327
    inc     dword [txt_id]
328
    inc     dword [but_id]
329
 
4865 eAndrew 330
    ret
331
 endp
332
 
333
 ;----------------------
334
 
4875 eAndrew 335
 proc draw_textbox
336
    mcall   13, <  4, 220>, <  8,  23>, [scn.gui_frame]
337
    mov     edx, [scn.gui_face]
338
    cmp     [error_n], 0
339
    je	    @f
340
    mov     edx, 0xFFAAAA
341
  @@:
342
    mcall   13, <  5, 218>, <  9, 21>
343
    mcall     , <  5, 218>, <  9,  1>, [scn.3d_face]
344
    mcall     , <  5,	1>, < 10, 20>
345
    mcall     , <  5, 218>, < 31,  1>, [scn.3d_light]
346
 
347
    mov     ebx, 224
348
    sub     ebx, [ans.size]
349
    shl     ebx, 16
350
    inc     ebx
351
    mcall     , 	  , < 9, 21>, [scn.gui_frame]
352
    add     ebx, [ans.size]
353
    add     ebx, 1 shl 16
354
    sub     ebx, 3
355
    mcall     , 	  ,	    , [scn.3d_light]
356
    cmp     [error_n], 0
357
    jne     .btn_not
358
    mcall   8, , , 0x40000002
359
 .btn_not:
360
    add     ebx, 1 shl 16
361
    add     ecx, 1 shl 16
362
    dec     ebx
363
    dec     ecx
364
    mcall   13, 	  ,	    , [scn.win_face]
365
    shr     ecx, 16
366
    mov     bx, cx
367
    add     ebx, 3 shl 16 + 6
368
    mov     ecx, [scn.win_text]
369
    or	    ecx, 1b shl 31
370
    mcall   4, , , ans.buffer
371
 
372
    mcall    1,   4,  8, [scn.win_body]
373
    mcall     , 223
374
    mcall     ,    , 30, [scn.3d_light]
375
    mcall     ,   4
376
 
377
    mov     ebx, 214
378
    sub     ebx, [ans.size]
379
    cmp     ebx, 24
380
    jg	    @f
381
    mov     ebx, 24
382
  @@:
383
    mov     [edb1.width], ebx
384
    m2m     [edb1.color],	       [scn.gui_face]
385
    m2m     [edb1.focus_border_color], [scn.gui_face]
386
    cmp     [error_n],	0
387
    je	    @f
388
    mov     [edb1.color],	       0xFFAAAA
389
    mov     [edb1.focus_border_color], 0xFFAAAA
390
  @@:
391
    invoke  editbox.draw, edb1
392
 
393
    ret
394
 endp
395
 
396
 ;----------------------
397
 
4865 eAndrew 398
 dataend:
399
 
400
 ;===============================
401
 
402
	    rb 2048
403
 stacktop:
404
 
405
 exp	    rb 512
406
 exp_pos    rd 1
407
 exp_lvl    rd 1
408
 group	    rd 1
409
 
410
 ans.buffer:rb 512
411
 ans.size   rd 1
412
 error_n    rd 1
413
 
414
 scn	    sys_colors_new
415
 timer	    rd 1
416
 but_id     rd 1
4875 eAndrew 417
 but_w	    rd 1
418
 txt_id     rd 1
419
 txt_x	    rd 1
4865 eAndrew 420
 
421
 memory: