From 8a7de6d31dfd7312990c4e71d4b9a03db7a39854 Mon Sep 17 00:00:00 2001 From: spaceraven Date: Mon, 11 Sep 2023 17:29:39 +0000 Subject: [PATCH] New program - Screen Ruler, for measuring distance between 2 pixel on screen. git-svn-id: svn://kolibrios.org@9934 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/demos/ScreenRuler/BUILD_EN.BAT | 6 + programs/demos/ScreenRuler/BUILD_RU.BAT | 6 + programs/demos/ScreenRuler/ScreenRuler | Bin 0 -> 1052 bytes programs/demos/ScreenRuler/ScreenRuler.asm | 298 +++++++++++++++++++++ programs/demos/ScreenRuler/TUPFILE.LUA | 3 + 5 files changed, 313 insertions(+) create mode 100644 programs/demos/ScreenRuler/BUILD_EN.BAT create mode 100644 programs/demos/ScreenRuler/BUILD_RU.BAT create mode 100644 programs/demos/ScreenRuler/ScreenRuler create mode 100644 programs/demos/ScreenRuler/ScreenRuler.asm create mode 100644 programs/demos/ScreenRuler/TUPFILE.LUA diff --git a/programs/demos/ScreenRuler/BUILD_EN.BAT b/programs/demos/ScreenRuler/BUILD_EN.BAT new file mode 100644 index 0000000000..b5a9355be4 --- /dev/null +++ b/programs/demos/ScreenRuler/BUILD_EN.BAT @@ -0,0 +1,6 @@ +@erase lang.inc +@echo lang fix en >lang.inc +@fasm ScreenRuler.asm ScreenRuler +@kpack ScreenRuler +@erase lang.inc +@pause \ No newline at end of file diff --git a/programs/demos/ScreenRuler/BUILD_RU.BAT b/programs/demos/ScreenRuler/BUILD_RU.BAT new file mode 100644 index 0000000000..262b8b85f5 --- /dev/null +++ b/programs/demos/ScreenRuler/BUILD_RU.BAT @@ -0,0 +1,6 @@ +@erase lang.inc +@echo lang fix ru >lang.inc +@fasm ScreenRuler.asm ScreenRuler +@kpack ScreenRuler +@erase lang.inc +@pause \ No newline at end of file diff --git a/programs/demos/ScreenRuler/ScreenRuler b/programs/demos/ScreenRuler/ScreenRuler new file mode 100644 index 0000000000000000000000000000000000000000..aba629ea0428034a9e2f02715d8956a96a0a007b GIT binary patch literal 1052 zcmb7CL1+^}6rHpyROog?NN5!!OSPazFcELLY=vqs7Oi?nPemjr4<1rXp@pPN#370S zJqRKa>cvxALd|Al({2OO7#C(O2qhOKR8sAsg3w|M_5azVHSNiP`Sbt#@4x?dX0P=P z-0r*O4>$-Rr(v(Qf^pV29Jp!$k#Lx2$^gH zlNQix2lMlzy0mL5T053v8&jF~X9QEpm&jf6S_inMB4w9)skj5>M$M^AZlQEV>)|Y88uagvHPj;y1=LZTEM3W_K;KA89%9SC}`!}t}t?DHbS zs5-;6?DJwxe7lo$kjT0C_AxxWF?N#3ag5<~(Pe4Mi&BoVc8bq+W6;OD`8=pa%SP3e z5vXN+bIk~JQ4=|7DAXI|Q%Z?@Z~;kPaXH9GmJ%U=G`x)b7-=K94On^*!~!;IDr(WK zhXCLtJABX_K5GuAn#0n5m?uPtCHWodDKbn7(EBaUskG>Bj~LBsd(|Me+s(#r$e7oY-KN4mc3`QR*Y%Z1e;}f>oH-knZ|T0 zZijL}J|n|Ak48RwFnjSp_BjZ}L28=KSr5T~Do1SwR36Ta{+olE3@flXIAM&v%qxiB Y!H|4Fna#tj1vZ1jkyI)LZ}Q*kFWLoSUH||9 literal 0 HcmV?d00001 diff --git a/programs/demos/ScreenRuler/ScreenRuler.asm b/programs/demos/ScreenRuler/ScreenRuler.asm new file mode 100644 index 0000000000..18be240b0d --- /dev/null +++ b/programs/demos/ScreenRuler/ScreenRuler.asm @@ -0,0 +1,298 @@ +;--------------------------------------------------------------------- +; Screen Ruler v1.0 +; Version for KolibriOS 2005-2023 +;--------------------------------------------------------------------- +; last update: 11.09.2023 +; created by: Subbotin Anton aka Spaceraven +;--------------------------------------------------------------------- + use32 + org 0x0 + db 'MENUET01'; 8 byte id + dd 1 ; header version + dd START ; program start + dd I_END ; program image size + dd 0x1000 ; required amount of memory + dd 0x1000 ; esp + dd 0, 0 ; no parameters, no path +;--------------------------------------------------------------------- + include 'lang.inc' + include '..\..\macros.inc' + + delay = 20 + magnify_width = 48 + magnify_height = 30 + magnify_halfwidth = magnify_width / 2 + magnify_halfheight = magnify_height / 2 + aim0 = (magnify_halfheight - 1) * 65536 + magnify_halfwidth - 1 + aim1 = (magnify_halfheight - 1) * 65536 + magnify_halfwidth + 1 + aim2 = (magnify_halfheight + 1) * 65536 + magnify_halfwidth - 1 + aim3 = (magnify_halfheight + 1) * 65536 + magnify_halfwidth + 1 + +;------------------------- Main cycle +START: +redraw: + call draw_window +still: + call draw_magnify +wtevent: + mcall 23, delay ; wait here for event with timeout + dec eax + js still + jz redraw + dec eax + jnz button +; key in buffer + mov eax, 2 + mcall + cmp ah, 32 + jnz wtevent + mov eax, [mouse_x] + mov [pix1_x], eax + mov eax, [mouse_y] + mov [pix1_y], eax + + jmp wtevent +;--------------------------------------------------------------------- +button: +; we have only one button, close + + or eax, -1 + mcall +;------------------------- Window draw +draw_window: + mcall 12, 1 + + mov al, 48 ; function 48 : graphics parameters + mov bl, 4 ; subfunction 4 : get skin height + mcall + ; DRAW WINDOW + mov ebx, 100*65536 + 4*magnify_width + 9 + lea ecx, [eax + 100*65536 + 4*magnify_height + 128] + mov edx, 0x34000000 ; color of work area RRGGBB + mov edi, labelt ; header + xor eax, eax ; function 0 : define and draw window + mcall + + mov eax, 71 + mov ebx, 1 + mov ecx, labelt + + mcall 12,2 + ret +;------------------------- Magnify draw +draw_magnify: + mcall 9, procinfo, -1 + mov eax, [procinfo+70] ;status of window + test eax,100b + jne .end + + mcall 14 ; get screen size + movzx ecx, ax + inc ecx + mov [screen_size_y], ecx + shr eax, 16 + inc eax + mov [screen_size_x], eax + + xor ebx, ebx + mcall 37 ; get mouse coordinates + mov ecx, eax + shr ecx, 16 ; ecx = x + movzx edx, ax ; edx = y + mov [mouse_x], ecx + mov [mouse_y], edx + add ecx, magnify_halfwidth + add edx, magnify_halfheight + mov [magnify_area_end_x], ecx + mov [magnify_area_end_y], edx + sub ecx, magnify_width + sub edx, magnify_height + mov [magnify_area_start_x], ecx + mov [magnify_area_start_y], edx +.loop_y: +.loop_x: + xor eax, eax ; assume black color for invalid pixels + test ecx, ecx + js .nopix + cmp ecx, [screen_size_x] + jge .nopix + test edx, edx + js .nopix + cmp edx, [screen_size_y] + jge .nopix + mov ebx, edx + sub ebx, [magnify_area_start_y] + shl ebx, 16 + mov bx, cx + sub ebx, [magnify_area_start_x] + cmp ebx, aim0 + jz .nopix + cmp ebx, aim1 + jz .nopix + cmp ebx, aim2 + jz .nopix + cmp ebx, aim3 + jz .nopix + + mov ebx, edx + imul ebx, [screen_size_x] + add ebx, ecx + mcall 35 ; read pixel + +.nopix: + push ecx edx + sub ecx, [magnify_area_start_x] + sub edx, [magnify_area_start_y] + mov ebx, ecx + shl ebx, 2+16 + mov bl, 4 + mov ecx, edx + shl ecx, 2+16 + mov cl, 4 + mov edx, eax + mcall 13 ; draw rectangle 8x8 + pop edx ecx + + inc ecx + cmp ecx, [magnify_area_end_x] + jnz .loop_x + mov ecx, [magnify_area_start_x] + inc edx + cmp edx, [magnify_area_end_y] + jnz .loop_y + +;------------------------- Measure labels draw + mov eax, 4 + mov ebx, 8*65536 + 124 + mov ecx, 11110000111100001111000011110000b + mov edx, start_pix + xor edi, edi + mcall 4 + add ebx, 20 + mov edx, end_pix + mcall 4 + add ebx, 20 + mov edx, measure_x + mcall 4 + add ebx, 20 + mov edx, measure_y + mcall 4 + add ebx, 20 + mov edx, measure_d + mcall 4 + add ebx, 20 + mov edx, inf + mcall 4 + + mov ebx, 0x80040000 + mov ecx, [mouse_x] + mov edx, 12*8*65536 + 144 + mov esi, 0x50FFFFFF + xor edi, edi + mcall 47 + sub ecx, [pix1_x] + jns .sign1 + neg ecx +.sign1: + mov edx, 14*8*65536 + 164 + mov [dist_x], ecx + mcall 47 + mov ecx, [mouse_y] + mov edx, 18*8*65536 + 144 + mcall 47 + sub ecx, [pix1_y] + jns .sign2 + neg ecx +.sign2: + mov [dist_y], ecx + mov edx, 14*8*65536 + 184 + mcall 47 + mov ecx, [pix1_y] + mov edx, 18*8*65536 + 124 + mcall 47 + mov ecx, [pix1_x] + mov edx, 12*8*65536 + 124 + mcall 47 + + mov eax, [dist_x] + mov ebx, eax + mul bx + mov cx, dx + shl ecx, 16 + mov cx, ax + mov eax, [dist_y] + mov ebx, eax + mul bx + mov si, dx + shl esi, 16 + mov si, ax + add ecx, esi + mov [diag_l], ecx + finit + fild [diag_l] + fsqrt + fistp [diag_l] + + mov ebx, 0x80040000 + mov ecx, [diag_l] + mov edx, 12*8*65536 + 204 + mov esi, 0x50FFFFFF + xor edi, edi + mcall 47 + +.end: + ret + +;------------------------- Data area + if lang eq ru +labelt: + db 3, 'Измеритель', 0 +start_pix: + db 'Пиксель 1 ( , )', 0 +end_pix: + db 'Пиксель 2 ( , )', 0 +measure_x: + db 'Дистанция x ( )', 0 +measure_y: + db 'Дистанция y ( )', 0 +measure_d: + db 'Диагональ ( )', 0 +inf: + db 'Нажмите пробел', 0 + + else +labelt: + db 3, 'Ruler', 0 +start_pix: + db 'Pixel 1 ( , )', 0 +end_pix: + db 'Pixel 2 ( , )', 0 +measure_x: + db 'Distance x ( )', 0 +measure_y: + db 'Distance y ( )', 0 +measure_d: + db 'Diagonal ( )', 0 +inf: + db 'Press Space', 0 + + end if +I_END: + align 4 + magnify_area_start_x dd ? + magnify_area_start_y dd ? + magnify_area_end_x dd ? + magnify_area_end_y dd ? + screen_size_x dd ? + screen_size_y dd ? + mouse_x dd ? + mouse_y dd ? + pix1_x dd 0 + pix1_y dd 0 + dist_x dd 0 + dist_y dd 0 + diag_l dd 0 +;--------------------------------------------------------------------- +procinfo: + rb 1024 +;--------------------------------------------------------------------- \ No newline at end of file diff --git a/programs/demos/ScreenRuler/TUPFILE.LUA b/programs/demos/ScreenRuler/TUPFILE.LUA new file mode 100644 index 0000000000..6311fd8343 --- /dev/null +++ b/programs/demos/ScreenRuler/TUPFILE.LUA @@ -0,0 +1,3 @@ +if tup.getconfig("NO_FASM") ~= "" then return end +tup.rule("echo lang fix " .. ((tup.getconfig("LANG") == "") and "en" or tup.getconfig("LANG")) .. " > lang.inc", {"lang.inc"}) +tup.rule({"ScreenRuler.asm", extra_inputs = {"lang.inc"}}, "fasm %f %o " .. tup.getconfig("KPACK_CMD"), "ScreenRuler")