Button functions via VT100, and Mouse.exe

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
IcarusLives
Posts: 117
Joined: 17 Jan 2016 23:55

Button functions via VT100, and Mouse.exe

#1 Post by IcarusLives » 12 Aug 2019 08:50

Hello! I have been working on some functions that allow you to click the console with a 3rd party called Mouse.exe

MOUSE.EXE -> http://www.mediafire.com/file/96p9tqu4d500fli/bin.zip

Image

I thought this would be a fun project to limit user input. Overall I AM looking to improve this.

Any suggestions on making it faster, more appealing. Please let me know!

Hope you enjoy!

code

Code: Select all

@echo off & setlocal enableDelayedExpansion

call:importantStuff
call:extras
call:createToggle "RED  GRE  YEL  BLU  PUR" 1 2 5 12 3
call:createSlider 1 14 23 10 9 0 20
call:createButton 1 5 "Move Left "
call:createButton 15 5 "Move Right"
call:createButton 1 8 "Move  Up "
call:createButton 15 8 "Move Down"

:main
rem update the toggle box
call:updateToggleButtons
cls

rem draw our buttons, and slider
echo %esc%[11;1HValue: %slideValue%%esc%[0m%toggleDisplay%%sliderBar%%sliderPos%%button[0]%%button[1]%%button[2]%%button[3]%

rem draw a circle
set "circleColor=!color[%currentToggle%]!"
( for /l %%a in (0,10,360) do ( set /a "cx=slideValue * !cos:x=%%a! + bx", "cy=slideValue * !sin:x=%%a! + by"
	<nul set /p "=%esc%[!cy!;!cx!H%esc%[38;5;%circleColor%m#"
) ) & echo %esc%[0m

rem ask for a mouse click
%allowMouseClicks%

rem check if a button has been clicked
%ifUserClicksButton[0]% set /a "bx-=10"
%ifUserClicksButton[1]% set /a "bx+=10"
%ifUserClicksButton[2]% set /a "by-=10"
%ifUserClicksButton[3]% set /a "by+=10"

rem check/allow the slider to be moved
%sliderInput%

rem allow each toggle box to be toggled.
%allowToggle[0]%
%allowToggle[1]%
%allowToggle[2]%
%allowToggle[3]%
%allowToggle[4]%
goto :main


:createSlider
	for /l %%a in (1,1,%~3) do set "slider=!slider!-"
	set /a "spb=%~5","slider[Xmin]=%~1+1","slider[Xmax]=%~1 + %~3","sxp1=%~1+1","sym1=%~2-1","cscm=%~6","cscx=%~7"
	set "sliderBar=%esc%[%~2;%~1H%esc%[38;5;%~4m^|%slider%^|%esc%[0m"
	set "sliderPos=%esc%[%~2;%sxp1%H%esc%[38;5;%~5mÛ%esc%[0m"
	set "sliderInput=if ^!mouseY^! equ ^!sym1^! if ^!mouseX^! geq ^!slider[Xmin]^! if ^!mouseX^! leq ^!slider[Xmax]^! set /a "adaptSlide=adaptedY=mouseY + 1, slideValue=cscm+(cscx-cscm)*(mouseX-(slider[Xmin]+1))/((slider[Xmin]+slider[Xmax])-(slider[Xmin]+1))" ^& set "sliderPos=%esc%[^^!adaptedY^^!;^^!mouseX^^!H%esc%[38;5;%spb%mÛ%esc%[0m""
goto :eof

:createToggle
	if not defined toggleBoxTemplate set "toggleBoxTemplate=ÚÄÄÄ¿%esc%[B%esc%[5D³   ³%esc%[B%esc%[5DÀÄÄÄÙ%esc%[2A"
	set /a "toggleArray=%~4 - 1", "togX=%~2", "togY=%~3", "oX=togX + 1", "oY=togY + 1", "up1=togY - 1", "ov1=oX", "togCol=%~5"
	( if "%~6" neq "" ( set /a "defaultToggle=%~6" ) else ( set /a "defaultToggle=0" )) & set /a "currentToggle=defaultToggle"
	set "toggleBoxes=%esc%[%up1%;%ov1%H%~1%esc%[%togY%;%togX%H" & set "toggleOverlay=%esc%[%oY%;%oX%H"
	
	for /l %%a in (0,1,%toggleArray%) do (
		set "toggleBoxes=!toggleBoxes!%toggleBoxTemplate%"
		if %currentToggle% equ %%a ( set "toggle[%%a]=%esc%[38;5;%~5mÛÛÛ" ) else set "toggle[%%a]=%esc%[38;5;16mÛÛÛ"
		set "toggleOverlay=!toggleOverlay!!toggle[%%a]!%esc%[0m³³"
		set /a "toggleX[%%a]=(%%a + 1) * 5 + %~2 - 6"
	)
	set /a "toggleX[%~4]=(%~4 + 1) * 5 + %~2 - 6"
	
	for /l %%a in (0,1,%toggleArray%) do ( set /a "n=%%a + 1"
		for %%n in (!n!) do set "allowToggle[%%a]=if ^!mouseY^! geq ^!toggleY[min]^! if ^!mouseY^! leq ^!toggleY[max]^! if ^!mouseX^! geq ^!toggleX[%%a]^! if ^!mouseX^! lss ^!toggleX[%%n]^! set currentToggle=%%a"
	)

	set /a "toggleY[min]=%~3 - 1", "toggleY[max]=%~3 + 1"
	set "toggleOverlay=!toggleOverlay:~0,-1!"
	set "toggleDisplay=^!toggleBoxes^!%esc[0m%^!toggleOverlay^!%esc%[0m"
goto :eof


:updateToggleButtons
	set "toggleOverlay=%esc%[%oY%;%oX%H"
	for /l %%a in (0,1,%toggleArray%) do (
		if !currentToggle! equ %%a ( set "toggle[%%a]=%esc%[38;5;%togCol%mÛÛÛ" ) else set "toggle[%%a]=%esc%[38;5;16mÛÛÛ"
		set "toggleOverlay=!toggleOverlay!!toggle[%%a]!%esc%[0m³³"
	)
	set "toggleOverlay=%toggleOverlay:~0,-1%"
goto :eof

:createButton
	set /a "buttons+=1", "len=0", "buttons-=1"
	set /a "button[X][%buttons%]=%~1", "button[Y][%buttons%]=%~2"
	set "s=%~3#" & ( for %%P in (8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do ( if "!s:~%%P,1!" NEQ "" ( set /a "len+=%%P" & set "s=!s:~%%P!" ))) & set /a "len[%%e]=len" 2>nul
	set /a "e=len&1", "len+=(((~(0-e)>>31)&1)&((~(e-0)>>31)&1))+1", "len+=(((~(1-e)>>31)&1)&((~(e-1)>>31)&1))", "back=len + 2"
	set "buttonWidth=" & (for /l %%a in (1,1,%len%) do set "buttonWidth=!buttonWidth!Ä")
	set "button[%buttons%]=%esc%[!button[Y][%buttons%]!;!button[X][%buttons%]!HÚ%buttonWidth%¿%esc%[%back%D%esc%[B³ %~3 ³%esc%[%back%D%esc%[BÀ%buttonWidth%Ù"
	set /a "button[%buttons%][Xmin]=%~1-1","button[%buttons%][Xmax]=%~1 + len","button[%buttons%][Ymin]=%~2-1","button[%buttons%][Ymax]=%~2 + 1"
	set "ifUserClicksButton[!buttons!]=if ^!mouseY^! geq ^!button[%buttons%][Ymin]^! if ^!mouseY^! leq ^!button[%buttons%][Ymax]^! if ^!mouseX^! geq ^!button[%buttons%][Xmin]^! if ^!mouseX^! leq ^!button[%buttons%][Xmax]^!"
	set /a "buttons+=1"
goto :eof

:extras
set "_SIN=a-a*a/1920*a/312500+a*a/1920*a/15625*a/15625*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000"
set "sin=(a=((x) * 31416 / 180)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832)  +  (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a)  ), %_SIN%) / 10000"
set "cos=(a=(15708 - (x) * 31416 / 180)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832)  +  (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a)  ), %_SIN%) / 10000"

set "color[0]=9"
set "color[1]=10"
set "color[2]=11"
set "color[3]=12"
set "color[4]=13"

set /a "by=bx=50"
goto :eof

:importantStuff
( for /f %%a in ('echo prompt $E^| cmd') do set "esc=%%a" ) & <nul set /p "=!esc![?25l"
set "allowMouseClicks=for /f "tokens=1-3" %%W in ('"bin\Mouse.exe"') do set /a "mouseC=%%W,mouseX=%%Y,mouseY=%%X""
goto :eof
documentation

Code: Select all

:important stuff

	accepts no arguments

	creates %ESC% and %allowMouseClicks%
	
	%ESC% is a necessary character in VT100, which is how the buttons are drawn and displayed
		Please GOOGLE: VT100 escape sequences
	
	%allowMouseClicks% is a argument-less macro. It is a FOR loop that accepts the input of a mouse click. Do not ECHO.
		This is captured in...
			%mouseC% - int = Left or right click
			%mouseY% - int = Y coordinate
			%mouseX% - int = X coordinate
			
			These values can be ECHO'd, but are already implemented into the functions below.
				No need to use them unless they do not involve the buttons, toggles, or slider.
			

:createSlider

	USAGE:
		call :createSlider X Y sliderLength sliderColor positionColor minRange maxRange
		
		example:
			call:createSlider 1 14 23 10 9 0 10

	creates %sliderBar%, %sliderPos%, %sliderInput%, and %slideValue%
	
	%sliderBar% and %sliderPos% are the DISPLAY of the slider bar itself, and it's current slide position
		 Simply ECHO this to display. ( echo %sliderBar%%sliderPos% )
	
	%sliderInput% collects and moves the users slider input. Do not ECHO
	
	%slideValue% is the value indictive of the current position shown on the %sliderBar%. 
		This value can be ECHO'd or used in various ways.
	

:createToggle

	USAGE:
		call :createToggle "Text above toggle bar" X Y numOfToggles color defaultToggle {defaultToggle - can be empty}
		
		example:
			call:createToggle "RED  GRE  YEL  BLU  PUR" 1 2 5 12 3

	creates %toggleDisplay%, %allowToggle[0-n]%, :updateToggleButtons
	
	%toggleDisplay% is the DISPLAY of the toggle bar. Simply ECHO this to display. ( echo %toggleDisplay% )
	
	%allowToggle[0-n]% this is the line of code you will need to allow the toggle bar to be clicked in each position.
		
		example:
			
			%allowToggle[0]%
			%allowToggle[1]%
			%allowToggle[2]%

		%allowToggle[0-n]% accepts no arguments. Do not ECHO.
	
	:updateToggleButtons 
		must be called immediately at the beginning of the loop to "update" the display of the toggle bar.
		
		example:
			
			:main
				call:updateToggleButtons
			
				Do more things, but noticed we called :updateToggleButtons immediately
			goto :main
	
	This function accepts no arguments.
	

:createButton

	USAGE:
		call :createButton X Y "Button Text"
		
		example:
			call :createButton 10 25 "Say Hello"
			
	creates %button[0-n]%, and %ifUserClicksButton[0-n]%
	
	%button[0-n]% is the DISPLAY of the button. Simply ECHO this to display. ( echo %button[0-n]% )
	
	%ifUserClicksButton[0-n]% treat this exactly like an IF statement, only it already knows the comparison. Do not ECHO.
	
		example:
			%ifUserClicksButton[0]% (
				ECHO Hello World
			)

Post Reply