[Apps/Calcplus] Code refactoring, localization to Spanish, add copyright info
Some checks failed
Build system / Check kernel codestyle (pull_request) Successful in 39s
Build system / Build (pull_request) Failing after 2m35s

This commit is contained in:
2025-04-05 10:12:24 +03:00
parent c9b00a71b9
commit 029cb0ea31

View File

@@ -1,18 +1,54 @@
; VERSION equ "v1.0" ; SPDX-License-Identifier: GPL-2.0-only
;
; Calc+ - Multifunctional calculator
; Copyright (C) 2014-2025 KolibriOS team
;
; Contributor eAndrew - Main code
; Contributor Leency - Code refactoring and UX/UI update
; Contributor Burer - Code refactoring and UI update
; ================================================================
use32 use32
org 0 org 0
db 'MENUET01' db 'MENUET01'
dd 1, main, dataend, memory, stacktop, 0, 0 dd 1
dd START
dd I_END
dd MEM
dd STACKTOP
dd 0, 0
; ====================================================================
include "../../proc32.inc" include "../../proc32.inc"
include "../../macros.inc" include "../../macros.inc"
include "../../KOSfuncs.inc"
include "../../encoding.inc"
include "../../dll.inc" include "../../dll.inc"
include "../../develop/libraries/box_lib/trunk/box_lib.mac" include "../../develop/libraries/box_lib/trunk/box_lib.mac"
; include "../../debug.inc"
include "parser.inc" include "parser.inc"
;=============================== ; ====================================================================
if lang eq ru_RU
engineering_str db "Engineering calc"
engineering_len = 16
else if lang eq es_ES
engineering_str db " Modo ingeniero "
engineering_len = 16
else
engineering_str cp866 "Инженерный режим"
engineering_len = 16
endf
; ====================================================================
LIST_X = 5 LIST_X = 5
LIST_Y = 43 LIST_Y = 43
@@ -29,18 +65,20 @@
KEYBOARD_X = LIST_ITEM_W + 20 KEYBOARD_X = LIST_ITEM_W + 20
KEYBOARD_Y = LIST_Y KEYBOARD_Y = LIST_Y
KEYBOARD_W = 190 KEYBOARD_W = 190
WIN_W = LIST_ITEM_W + 16 + KEYBOARD_W
WIN_H = LIST_H + 58
LIST_ITEM_TEXT1 equ dword [sc.work_text] LIST_ITEM_TEXT1 equ dword [sc.work_text]
LIST_ITEM_TEXT2 equ dword [sc.work_text] LIST_ITEM_TEXT2 equ dword [sc.work_text]
WIN_X = 200
WIN_Y = 200
WIN_W = LIST_ITEM_W + 16 + KEYBOARD_W
WIN_H = LIST_H + 58
sz_head db "Calc+", 0 sz_head db "Calc+", 0
btn_clr db "" btn_clr db ""
buttons db "|%^*/-+)(=7894561230" buttons db "|%^*/-+)(=7894561230"
edb1 edit_box 0, 8, 12, 0xffffff,0x94AECE,0xffc90E,0xCACACA, 0x10000000, 480, \ edb1 edit_box 0, 8, 12, 0xffffff, 0x94AECE, 0xFFC90E,0xCACACA, 0x10000000, \
exp, group, ed_always_focus + ed_focus, 0, 0 480, exp, group, ed_always_focus + ed_focus, 0, 0
imports: imports:
library gui, "box_lib.obj" library gui, "box_lib.obj"
@@ -48,53 +86,53 @@
editbox.key, "edit_box_key", \ editbox.key, "edit_box_key", \
editbox.mouse, "edit_box_mouse" editbox.mouse, "edit_box_mouse"
;=============================== ; ====================================================================
main: START:
mov [ans.buffer], dword "= 0" mov [ans.buffer], dword "= 0"
mov [ans.size], 3 * 8 + 9 mov [ans.size], 3 * 8 + 9
mcall 40, EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE mcall SF_SET_EVENTS_MASK, EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE
m2m [edb1.color], [scn.gui_face] m2m [edb1.color], [scn.gui_face]
;m2m [edb1.shift_color], [scn.gui_select]
;m2m [edb1.focus_border_color], [scn.gui_face]
;m2m [edb1.text_color], [scn.gui_text]
mcall 68, 11 mcall SF_SYS_MISC, SSF_HEAP_INIT
stdcall dll.Load, imports stdcall dll.Load, imports
;---------------------- ; ====================================================================
update: update:
mcall 23, 5 mcall SF_WAIT_EVENT_TIMEOUT, 5
cmp eax, EV_REDRAW cmp eax, EV_REDRAW
je ev_redraw je ev_redraw
cmp eax, EV_KEY cmp eax, EV_KEY
je ev_key je ev_key
cmp eax, EV_BUTTON cmp eax, EV_BUTTON
je ev_button je ev_button
cmp eax, EV_MOUSE cmp eax, EV_MOUSE
je ev_mouse je ev_mouse
jmp update jmp update
;---------------------- ; ====================================================================
ev_redraw: ev_redraw:
mcall 12, 1 mcall SF_REDRAW, SSF_BEGIN_DRAW
mcall 48, 3, sc, sizeof.system_colors mcall SF_STYLE_SETTINGS, SSF_GET_COLORS, sc, sizeof.system_colors
; WINDOW ; WINDOW
mov edx, [sc.work] mov edx, [sc.work]
or edx, 0x34 shl 24 or edx, 0x34 shl 24
mcall 48, 4 ;get skin_h mcall SF_STYLE_SETTINGS, SSF_GET_SKIN_HEIGHT
mov ecx, 200 shl 16 + WIN_H mov ecx, WIN_Y shl 16 + WIN_H
add ecx, eax ; add skin_h to WIN_H add ecx, eax
mcall 14 ; get screen size mcall SF_GET_SCREEN_SIZE
shr eax, 16 shr eax, 16
mov ebx, eax mov ebx, eax
sub ebx, WIN_W sub ebx, WIN_W
@@ -107,25 +145,29 @@
call draw_keyb call draw_keyb
call draw_list call draw_list
mcall 12, 2 mcall SF_REDRAW, SSF_END_DRAW
jmp update jmp update
;---------------------- ; ====================================================================
ev_key: ev_key:
mcall 2 mcall SF_GET_KEY
cmp ah, 27 cmp ah, 27
je exit je exit
cmp ah, 13 cmp ah, 13
je calc je calc
invoke editbox.key, edb1 invoke editbox.key, edb1
jmp update jmp update
;---------------------- ; ====================================================================
ev_button: ev_button:
mcall 17 mcall SF_GET_BUTTON
; EXIT ; EXIT
cmp ah, 1 cmp ah, 1
@@ -133,12 +175,14 @@
cmp ah, 250 cmp ah, 250
jne @f jne @f
mcall 70, f70_calc mcall SF_FILE, f70_calc
jmp update jmp update
; DELETE ; DELETE
@@: @@:
cmp ah, 4 cmp ah, 4
jne .not_del jne .not_del
cmp [edb1.pos], 0 cmp [edb1.pos], 0
je update je update
mov eax, exp mov eax, exp
@@ -147,6 +191,7 @@
mov ebx, exp mov ebx, exp
add ebx, [edb1.size] add ebx, [edb1.size]
inc ebx inc ebx
@@: @@:
cmp eax, ebx cmp eax, ebx
je @f je @f
@@ -154,11 +199,14 @@
mov [eax], cl mov [eax], cl
inc eax inc eax
jmp @b jmp @b
@@: @@:
dec [edb1.pos] dec [edb1.pos]
dec [edb1.size] dec [edb1.size]
m2m [edb1.shift], [edb1.pos] m2m [edb1.shift], [edb1.pos]
jmp .redraw jmp .redraw
.not_del: .not_del:
; CALCULATE ; CALCULATE
@@ -181,6 +229,7 @@
add edx, eax add edx, eax
mov edi, exp mov edi, exp
add edi, [edb1.pos] add edi, [edb1.pos]
@@: @@:
cmp edx, edi cmp edx, edi
je @f je @f
@@ -192,6 +241,7 @@
pop eax pop eax
dec edx dec edx
jmp @b jmp @b
@@: @@:
add [edb1.size], eax add [edb1.size], eax
@@ -205,9 +255,10 @@
dec eax dec eax
inc [edb1.pos] inc [edb1.pos]
jmp @b jmp @b
@@:
@@:
jmp .redraw jmp .redraw
.not_list: .not_list:
; KEYBOARD ; KEYBOARD
@@ -224,6 +275,7 @@
cmp dh, 30 cmp dh, 30
jl @f jl @f
add ebx, 2 add ebx, 2
@@: @@:
cmp ebx, ecx cmp ebx, ecx
je @f je @f
@@ -231,8 +283,8 @@
mov [ebx], dl mov [ebx], dl
dec ebx dec ebx
jmp @b jmp @b
@@:
@@:
movzx eax, dh movzx eax, dh
add eax, buttons add eax, buttons
sub eax, 10 sub eax, 10
@@ -245,25 +297,26 @@
jl @f jl @f
add [edb1.size], 2 add [edb1.size], 2
add [edb1.pos], 2 add [edb1.pos], 2
@@: @@:
.redraw: .redraw:
call draw_textbox call draw_textbox
jmp update jmp update
;---------------------- ; ====================================================================
ev_mouse: ev_mouse:
mcall 2 mcall SF_GET_KEY
invoke editbox.mouse, edb1 invoke editbox.mouse, edb1
jmp update jmp update
;---------------------- ; ====================================================================
exit: exit:
mcall -1 mcall SF_TERMINATE_PROCESS
;---------------------- ; ====================================================================
calc: calc:
stdcall parse stdcall parse
@@ -283,6 +336,7 @@
mov ecx, LIST_ITEM_COUNT - 1 mov ecx, LIST_ITEM_COUNT - 1
mov eax, history mov eax, history
add eax, (LIST_ITEM_COUNT - 1) * 512 add eax, (LIST_ITEM_COUNT - 1) * 512
@@: @@:
mov ebx, eax mov ebx, eax
sub ebx, 512 sub ebx, 512
@@ -337,6 +391,7 @@
je .err_3 je .err_3
cmp [error_n], 5 cmp [error_n], 5
je .err_5 je .err_5
.err_1: .err_1:
mov [ans.buffer + 0], dword "Div." mov [ans.buffer + 0], dword "Div."
mov [ans.buffer + 4], dword " by " mov [ans.buffer + 4], dword " by "
@@ -344,6 +399,7 @@
mov [ans.buffer + 9], byte 0 mov [ans.buffer + 9], byte 0
mov [ans.size], 81 mov [ans.size], 81
jmp .redraw jmp .redraw
.err_4: .err_4:
mov [ans.buffer + 0], dword "Inpu" mov [ans.buffer + 0], dword "Inpu"
mov [ans.buffer + 4], dword "t er" mov [ans.buffer + 4], dword "t er"
@@ -351,31 +407,36 @@
mov [ans.buffer + 12], byte 0 mov [ans.buffer + 12], byte 0
mov [ans.size], 105 mov [ans.size], 105
jmp .redraw jmp .redraw
.err_3: .err_3:
mov [ans.buffer + 10], byte "(" mov [ans.buffer + 10], byte "("
jmp .redraw jmp .redraw
.err_5: .err_5:
mov [ans.buffer + 10], byte "|" mov [ans.buffer + 10], byte "|"
jmp .redraw jmp .redraw
.redraw: .redraw:
call draw_textbox call draw_textbox
call draw_list call draw_list
jmp update jmp update
;---------------------- ; ====================================================================
proc draw_textbox proc draw_textbox
; border ; border
mcall 13, <LIST_X, LIST_ITEM_W>, < 8, 30>, [sc.work_graph] mcall SF_DRAW_RECT, <LIST_X, LIST_ITEM_W>, < 8, 30>, [sc.work_graph]
; background ; background
mov edx, [scn.gui_face] mov edx, [scn.gui_face]
cmp [error_n], 0 cmp [error_n], 0
je @f je @f
mov edx, 0xFFAAAA mov edx, 0xFFAAAA
@@: @@:
mcall 13, < LIST_X+1, LIST_ITEM_W - 2>, < 9, 28> mcall SF_DRAW_RECT, <LIST_X + 1, LIST_ITEM_W - 2>, < 9, 28>
mcall , <LIST_X + 1, LIST_ITEM_W - 2>, < 9, 1>, [scn.text_box_inner_shadow] mcall , <LIST_X + 1, LIST_ITEM_W - 2>, < 9, 1>, [scn.text_box_inner_shadow]
mcall , <LIST_X + 1, 1 >, < 10, 27> mcall , <LIST_X + 1, 1 >, < 10, 27>
mcall , <LIST_X , LIST_ITEM_W - 1>, < 38, 1>, [sc.work_light] mcall , <LIST_X , LIST_ITEM_W - 1>, < 38, 1>, [sc.work_light]
@@ -387,79 +448,67 @@
mov ecx, [scn.gui_intext] mov ecx, [scn.gui_intext]
add ecx, 0x10000000 add ecx, 0x10000000
or ecx, 1 shl 31 or ecx, 1 shl 31
mcall 4, , , ans.buffer mcall SF_DRAW_TEXT, , , ans.buffer
mcall , <LIST_ITEM_W - 8, 19>, [scn.gui_intext], btn_clr, 1 mcall , <LIST_ITEM_W - 8, 19>, [scn.gui_intext], btn_clr, 1
add ebx, 1 shl 16 add ebx, 1 shl 16
mcall mcall
mcall 8, <LIST_ITEM_W - 14, 17>, <9, 27>, 4 + BT_HIDE mcall SF_DEFINE_BUTTON, <LIST_ITEM_W - 14, 17>, <9, 27>, 4 + BT_HIDE
; dots to fake border radius
; mcall 1, 4, 8, [sc.work]
; mcall , LIST_ITEM_W + 3
; mcall , , 37, [sc.work_light]
; mcall , 4
mov ebx, LIST_ITEM_W - 18 mov ebx, LIST_ITEM_W - 18
sub ebx, [ans.size] sub ebx, [ans.size]
cmp ebx, 24 cmp ebx, 24
jg @f jg @f
mov ebx, 24 mov ebx, 24
@@: @@:
mov [edb1.width], ebx mov [edb1.width], ebx
m2m [edb1.color] , [scn.gui_face] m2m [edb1.color] , [scn.gui_face]
m2m [edb1.focus_border_color], [scn.gui_face] m2m [edb1.focus_border_color], [scn.gui_face]
cmp [error_n], 0 cmp [error_n], 0
je @f je @f
mov [edb1.color], 0xFFAAAA mov [edb1.color] , 0x00FFAAAA
mov [edb1.focus_border_color], 0xFFAAAA mov [edb1.focus_border_color], 0x00FFAAAA
@@: @@:
invoke editbox.draw, edb1 invoke editbox.draw, edb1
ret ret
endp endp
;---------------------- ; ====================================================================
proc draw_button, x, y proc draw_button, x, y
mcall 8, <[x], KEYB_BTN_W>, <[y], KEYB_BTN_H>, [but_id], [but_c]
mcall SF_DEFINE_BUTTON, <[x], KEYB_BTN_W>, <[y], KEYB_BTN_H>, [but_id], [but_c]
mov ebx, [x] mov ebx, [x]
add ebx, KEYB_BTN_W/2-4 add ebx, KEYB_BTN_W/2-4
;mov esi, [txt_size] ;the text potentially could have valiable len
;imul esi, 4
;mov edi, 16
;add ebx, edi
shl ebx, 16 shl ebx, 16
add ebx, [y] add ebx, [y]
add ebx, KEYB_BTN_H/2 - 6 add ebx, KEYB_BTN_H/2 - 6
or [but_tc], 0x01000000 ;use bigger font or [but_tc], 0x01000000 ;use bigger font
mcall 4, , [but_tc], [txt_id], [txt_size] mcall SF_DRAW_TEXT, , [but_tc], [txt_id], [txt_size]
mov eax, [txt_size] mov eax, [txt_size]
add [txt_id], eax add [txt_id], eax
inc dword [but_id] inc dword [but_id]
ret ret
endp endp
;---------------------- ; ====================================================================
if lang eq ru_RU
engineering_str db "Engineering calc"
engineering_len = 16
else
engineering_str db "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <><E0A5A6>"
engineering_len = 16
endf
proc draw_keyb proc draw_keyb
mcall 8, <KEYBOARD_X, (KEYB_BTN_W + GAP)*4 - GAP>, <8, 29>, 250, [sc.work_light] mcall SF_DEFINE_BUTTON, <KEYBOARD_X, (KEYB_BTN_W + GAP)*4 - GAP>, <8, 29>, 250, [sc.work_light]
mov ecx, [sc.work_text] mov ecx, [sc.work_text]
or ecx, 0x10000000 or ecx, 0x10000000
mcall 4, <(KEYB_BTN_W + GAP - engineering_len*2)*2 - GAP/2 + KEYBOARD_X, KEYB_BTN_H / 2 - 10 + 8>, , engineering_str, engineering_len mcall SF_DRAW_TEXT, <(KEYB_BTN_W + GAP - engineering_len*2)*2 - GAP/2 + KEYBOARD_X, KEYB_BTN_H / 2 - 10 + 8>, , engineering_str, engineering_len
mov [txt_size], 1 mov [txt_size], 1
mov [but_id], 0x0000000A mov [but_id], 0x0000000A
@@ -477,8 +526,8 @@ endf
stdcall draw_button, KEYBOARD_X + (KEYB_BTN_W + GAP)*2, KEYBOARD_Y + (KEYB_BTN_H + GAP)*4 stdcall draw_button, KEYBOARD_X + (KEYB_BTN_W + GAP)*2, KEYBOARD_Y + (KEYB_BTN_H + GAP)*4
stdcall draw_button, KEYBOARD_X + (KEYB_BTN_W + GAP)*1, KEYBOARD_Y + (KEYB_BTN_H + GAP)*4 stdcall draw_button, KEYBOARD_X + (KEYB_BTN_W + GAP)*1, KEYBOARD_Y + (KEYB_BTN_H + GAP)*4
mov [but_c], 0xF0969D mov [but_c] , 0x00F0969D
mov [but_tc], 0x00FFFfff mov [but_tc], 0x00FFFFFF
stdcall draw_button, KEYBOARD_X + (KEYB_BTN_W + GAP)*3, KEYBOARD_Y +(KEYB_BTN_H + GAP)*4 stdcall draw_button, KEYBOARD_X + (KEYB_BTN_W + GAP)*3, KEYBOARD_Y +(KEYB_BTN_H + GAP)*4
m2m [but_c] , [sc.work_button] m2m [but_c] , [sc.work_button]
@@ -495,17 +544,20 @@ endf
stdcall draw_button, KEYBOARD_X + (KEYB_BTN_W + GAP)*0, KEYBOARD_Y + (KEYB_BTN_H + GAP)*4 stdcall draw_button, KEYBOARD_X + (KEYB_BTN_W + GAP)*0, KEYBOARD_Y + (KEYB_BTN_H + GAP)*4
ret ret
endp endp
;---------------------- ; ====================================================================
proc draw_list proc draw_list
; === BACKGROUND ===
mov edi, LIST_ITEM_COUNT ; BACKGROUND
mov eax, 13 mov eax, SF_DRAW_RECT
mov ebx, LIST_X shl 16 + LIST_ITEM_W mov ebx, LIST_X shl 16 + LIST_ITEM_W
mov ecx, LIST_Y shl 16 + LIST_ITEM_H mov ecx, LIST_Y shl 16 + LIST_ITEM_H
mov edx, [sc.work_light] mov edx, [sc.work_light]
mov edi, LIST_ITEM_COUNT
@@: @@:
mcall mcall
; draw separator { ; draw separator {
@@ -516,17 +568,19 @@ endf
; } ; }
pop edx ecx pop edx ecx
add ecx, LIST_ITEM_H shl 16 add ecx, LIST_ITEM_H shl 16
.next: .next:
dec edi dec edi
cmp edi, 0 cmp edi, 0
jne @b jne @b
; === BUTTONS === ; BUTTONS
mov edi, LIST_ITEM_COUNT mov eax, SF_DEFINE_BUTTON
mov eax, 8
mov ebx, LIST_X shl 16 + LIST_ITEM_W mov ebx, LIST_X shl 16 + LIST_ITEM_W
mov ecx, 43 shl 16 + LIST_ITEM_H mov ecx, 43 shl 16 + LIST_ITEM_H
mov edx, 60 + BT_HIDE mov edx, 60 + BT_HIDE
mov edi, LIST_ITEM_COUNT
@@: @@:
mcall mcall
add ecx, LIST_ITEM_H shl 16 add ecx, LIST_ITEM_H shl 16
@@ -535,14 +589,16 @@ endf
cmp edi, 0 cmp edi, 0
jne @b jne @b
; === TEXT === ; TEXT
mov edi, LIST_ITEM_COUNT mov eax, SF_DRAW_TEXT
mov eax, 4
mov ebx, (LIST_X + LIST_X) shl 16 + LIST_Y + LIST_TEXT_Y + 1 mov ebx, (LIST_X + LIST_X) shl 16 + LIST_Y + LIST_TEXT_Y + 1
mov ecx, [sc.work_text] mov ecx, [sc.work_text]
mov edi, LIST_ITEM_COUNT
@@: @@:
or ecx, 1 shl 31 or ecx, 1 shl 31
mov edx, history mov edx, history
@@: @@:
add ecx, 0x10000000 add ecx, 0x10000000
mcall mcall
@@ -564,8 +620,10 @@ endf
je .set_color_to_2_txt je .set_color_to_2_txt
mov ecx, LIST_ITEM_TEXT2 mov ecx, LIST_ITEM_TEXT2
jmp .next_txt jmp .next_txt
.set_color_to_2_txt: .set_color_to_2_txt:
mov ecx, LIST_ITEM_TEXT1 mov ecx, LIST_ITEM_TEXT1
.next_txt: .next_txt:
or ecx, 1 shl 31 or ecx, 1 shl 31
@@ -574,29 +632,36 @@ endf
jne @b jne @b
ret ret
endp endp
;---------------------- ; ====================================================================
proc str_len uses ebx, str proc str_len uses ebx, str
xor eax, eax xor eax, eax
mov ebx, [str] mov ebx, [str]
@@: @@:
cmp [ebx], byte 0 cmp [ebx], byte 0
je @f je @f
inc eax inc eax
inc ebx inc ebx
jmp @b jmp @b
@@: @@:
ret ret
endp endp
;---------------------- ; ====================================================================
proc str_cpy uses eax ebx ecx, from, to proc str_cpy uses eax ebx ecx, from, to
mov eax, [from] mov eax, [from]
mov ebx, [to] mov ebx, [to]
@@: @@:
cmp [eax], byte 0 cmp [eax], byte 0
je @f je @f
@@ -605,19 +670,20 @@ endf
inc eax inc eax
inc ebx inc ebx
jmp @b jmp @b
@@: @@:
mov [ebx], byte 0 mov [ebx], byte 0
ret ret
endp endp
;---------------------- ; ====================================================================
dataend: I_END:
;===============================
rb 2048 rb 2048
stacktop:
STACKTOP:
exp rb 480 exp rb 480
exp_pos rd 1 exp_pos rd 1
@@ -640,11 +706,11 @@ endf
rb 512 rb 512
struc system_colors_internal { struc system_colors_internal {
.text_box_inner_shadow dd 0xCED0D0 .gui_tb_in_shd dd 0x00CED0D0
.gui_face dd 0xFAF8FA .gui_face dd 0x00FAF8FA
.gui_text dd 0x10373C42 .gui_text dd 0x10373C42
.gui_intext dd 0x5F5F5F .gui_intext dd 0x005F5F5F
.gui_select dd 0xC7C9C9 .gui_select dd 0x00C7C9C9
} }
scn system_colors_internal scn system_colors_internal
@@ -658,4 +724,4 @@ struc system_colors_internal {
dd 0 dd 0
db '/sys/calc', 0 db '/sys/calc', 0
memory: MEM: