BWin - Mouse GUI with windows - move,scale,maximize,close,tab,animate

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
misol101
Posts: 475
Joined: 02 May 2016 18:20

BWin - Mouse GUI with windows - move,scale,maximize,close,tab,animate

#1 Post by misol101 » 08 Apr 2018 15:45

Image

What? For fun I wanted to make a Drag-n-Drop example with cmdgfx, but it turned out to be some kind of wannabe Windows GUI instead (thus named BWin). There is now both a Batch and a hybrid Batch/Jscript version. The second one is up to 10 times faster.

Where? http://www.mediafire.com/file/u3r0yx928 ... ndDrop.zip

So few? The Javascript version has 8 windows enabled by default, but the batch version only has 3 of 7 windows enabled in the script by default. If the script runs fine, try 7 windows by editing the line in BWin.bat that says: "set /a NOF_WIN=3" to "set /a NOF_WIN=7"

Controls? Select a window by clicking on it. Move a window by dragging it with the mouse. Most windows can also be resized by dragging from the bottom-right of the window. Likewise, most windows can be maximized or closed by pressing the top-right icon(s).

You can also switch between windows by pressing TAB or Shift-TAB. This is useful if a window has been maximized and you want to reach other windows. If the title of a window is white(=focus) it can also be moved with the cursor keys.

Resize focused window by pressing Alt+cursor keys. Resize the *actual* cmd window by pressing Ctrl+cursor keys. Switch between fullscreen and window mode by pressing RETURN or Ctrl+RETURN. In text windows, scroll by pressing PgUp/PgDown.

Exit by pressing ESCAPE or closing the window.

Adding windows during runtime? Drop any file on BWin.bat while it is running to add it to the "desktop" (gxy and pcx files are treated as scaleable images, obj and plg and ply files are shown as 3d objects, met files are meta files which can run animations etc (see more info below), cfg files are used to change overall colors, size, background etc, and all other files are treated as text files).

You can also start BWin.bat by dropping one or more files on it.

How? Below is for Batch version, the JScript version obviously looks a bit different.
For Batch version, each window is defined similar to:

Code: Select all

set W5_NAME="Doom"
set /a W5_W=50, W5_H=40
set /a W5_X=29, W5_Y=12
set /a W5_ACTIVE=1, W5_CLOSE=1, W5_SIZE=1, W5_CLEAR=1, W5_SCROLL=0, W5_MAXED=0
set W5_INIT="set /a IMGI2=0"
set W5_UPDATE="set /a IMGI2=(IMGI2+1) %% 20, REPL1=IMGI2/10"
set W5_CONTENT="image img\uglyREPL1.pcx 0 0 # 14 OFF_X,OFF_Y 0 0 OFF_W,OFF_H"
That is: window title, window width, height, initial x position, initial y position.
Whether or not it is active, whether or not is possible to close and/or resize and/or scroll.

The INIT part is run when the window is created and should use unique variable names. The UPDATE part is run each frame. It can use OFF_X, OFF_Y, OFF_W and OFF_H which represent the window's current position and dimensions. It can also expose up to three variables called REPL1,REPL2,REPL3 which can be used in the CONTENT. The CONTENT part is what is fed to cmdgfx to be drawn.

All in all, this makes is possible to run animations in a window with nothing more than these definitions (in this case a simple one which alternates between two images). Or, leave INIT and UPDATE empty and show static text, image or similar.

Why? No idea, just for fun. Perhaps it could be useful for something, but not sure what.

Image
Last edited by misol101 on 06 Jun 2018 02:36, edited 21 times in total.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Mouse GUI - move scale,maximize,close,tab,animate

#2 Post by misol101 » 08 Apr 2018 15:53

Oh, I guess I could have posted this in my cmdgfx thread, but I was interested in making it a separate thread to see if someone else would be able to make this into a similar thing using pure Batch (or perhaps a Batch/Powershell/JS hybrid). I wouldn't be able to pull this off myself but there are much better batch programmers here than me, so...

Basically what would be needed would be to replace the drawing code for cmdgfx (CONTENT definitions and line 140-152 in the script below), and also use another way to get the mouse and keyboard input.

Code: Select all

@echo off
cd "%~dp0"
rem if not "%~1"=="" if not defined __ mode 60,30 & tasklist /FI "IMAGENAME eq cmdgfx_gdi.exe" | find "cmdgfx_gdi.exe" >nul 2>nul
if not "%~1"=="" if not defined __ mode 60,30 & tasklist /FI "WINDOWTITLE eq misol GUI 101" | find "cmd.exe" >nul 2>nul
if "%errorlevel%"=="0" if not "%~1"=="" if not defined __ call :PROCESS_NEWDROP %* & goto :eof
set /a W=120, H=75, WPAGES=3, WWW=W*WPAGES, HH=H*2, FONT=2, MAXTW=256, MAXTH=256
cmdwiz setfont %FONT% & mode %W%,%H% & cls & cmdwiz showcursor 0
if defined __ goto :START
cmdwiz getquickedit
set /a QE=%errorlevel%
cmdwiz setquickedit 0
set __=.
cmdgfx_input zm0nxW30 | call %0 %* | cmdgfx_gdi "" Sf%FONT%:0,0,%WWW%,%HH%,%W%,%H%G%MAXTW%,%MAXTH%
set __=
cmdwiz setquickedit %QE%
set QE=&set W=&set H=&set WWW=&set HH=&set FONT=&set WPAGES=&set MAXTW=&set MAXTH=
cls & cmdwiz setfont 6 & cmdwiz showcursor 1 & mode 80,50
goto :eof

:START
setlocal ENABLEDELAYEDEXPANSION
title misol GUI 101
for /F "tokens=1 delims==" %%v in ('set') do if /I not "%%v"=="W" if /I not "%%v"=="WWW" if /I not "%%v"=="H" if /I not "%%v"=="HH" if /I not "%%v"=="WPAGES" if /I not "%%v"=="FONT" if /I not "%%v"=="MAXTW" if /I not "%%v"=="MAXTH" if /I not "%%v"=="PATH" set "%%v="
if exist centerwindow.bat call centerwindow.bat 0 -20

if exist NewDrop rd /S /Q NewDrop >nul 2>nul

set /a "MID_OFF_X=W+(WWW-W)/2"
set /a MID_OFF_Y=%H%, SEL_WIN=0, DRAG_MODE=0, WM=W-1, HM=H-1
set /a BORDER_TEXT_XP=5, BORDER_CLOSE_XP=5
set BKG=3 0 fa
set BORDER_COL=7 0
set TITLE_COL=7 0
set FOCUS_COL=f 0
set RESIZE_COL=f 0
set CLOSE_COL=7 0
set MAX_COL=7 0
set CLEAR_COL=0 0 20
set TEXT_COL=b 0
set SS0=skip& set SS1=

set /a NOF_WIN=3

if not "%~1"=="" set /a NOF_WIN=0 & call :PROCESS_NEWDROP %* & goto :SKIP_DEFINE_WINDOWS

:: WINDOW DEFINITIONS

set W1_NAME="Animation"
set /a W1_W=50, W1_H=40
set /a W1_X=7, W1_Y=28
set /a W1_XA=0, W1_YA=0
set /a W1_ACTIVE=1, W1_CLOSE=1, W1_SIZE=1, W1_CLEAR=1, W1_SCROLL=0, W1_MAXED=0
set W1_INIT="set /a IMGI=0"
set W1_UPDATE="set /a IMGI=(IMGI+1) %% 20, REPL1=IMGI/2"
set W1_CONTENT="image img\spiral\REPL1.txt 8 0 # -1 OFF_X,OFF_Y 0 0 OFF_W,OFF_H"

set W2_NAME="Test Image"
set /a W2_W=40, W2_H=30
set /a W2_X=71, W2_Y=6
set /a W2_XA=1, W2_YA=1
set /a W2_ACTIVE=1, W2_CLOSE=1, W2_SIZE=1, W2_CLEAR=1, W2_SCROLL=0
set W2_INIT=""
set W2_UPDATE=""
set W2_CONTENT="image img\apa.gxy 0 0 0 -1 OFF_X,OFF_Y 0 0 OFF_W,OFF_H"

set W3_NAME="centerwindow.bat"
set /a W3_W=52, W3_H=16
set /a W3_X=63, W3_Y=55
set /a W3_XA=1, W3_YA=1
set /a W3_ACTIVE=1, W3_CLOSE=1, W3_SIZE=0, W3_CLEAR=1, W3_SCROLL=1
set W3_INIT=""
set W3_UPDATE=""
set W3_CONTENT="image centerwindow.bat \b 0 0 -1 OFF_X,OFF_Y"

set W4_NAME="Plasma"
set /a W4_W=50, W4_H=35
set /a W4_X=10, W4_Y=4
set /a W4_XA=1, W4_YA=1
set /a W4_ACTIVE=1, W4_CLOSE=1, W4_SIZE=1, W4_CLEAR=1, W4_SCROLL=0
set W4_INIT="set /a A1=0, A2=0"
set W4_UPDATE="set /a A1+=(A1+1) %% 20, A2+=(A2+3) %% 50, REPL1=A1, REPL2=A2"
set STREAM="01??=00db,11??=6004,21??=60db,31??=e604,41??=e6db,51??=e6db,61??=ef04,71??=fe04,81??=fedb,91??=fe04,a1??=ef04,b1??=e6db,c1??=e604,d1??=60db,e1??=6004,f1??=00db,03??=00db,13??=2004,23??=20db,33??=a204,43??=a2db,53??=a2db,63??=af04,73??=af04,83??=fadb,98??=fadb,a8??=af04,b8??=a2db,c8??=a204,d8??=20db,e8??=2004,f8??=00db,0e??=00db,1e??=4004,2e??=40db,3e??=c404,4e??=c4db,5e??=c4db,6e??=cfb2,7e??=cf04,8e??=cf20,9e??=fdb2,ae??=df04,be??=d4db,ce??=d504,de??=50db,ee??=5004,fe??=00db,0???=00db,1???=1004,2???=10db,3???=9104,4???=91db,5???=9bb2,6???=9b04,7???=b9db,8???=bf04,9???=9bb0,a???=9bb2,b???=91db,c???=9104,d???=10db,e???=1004,f???=00db"
set W4_CONTENT="block 0 OFF_X,OFF_Y,OFF_W,OFF_H OFF_X,OFF_Y -1 0 0 !STREAM:~1,-1! random()*1.5+sin((x-REPL1/4)/80)*(y/2)+cos((y+REPL2/5)/35)*(x/3)"
set STREAM=

set W5_NAME="Doom"
set /a W5_W=50, W5_H=40
set /a W5_X=29, W5_Y=12
set /a W5_XA=0, W5_YA=-1
set /a W5_ACTIVE=1, W5_CLOSE=1, W5_SIZE=1, W5_CLEAR=1, W5_SCROLL=0
set W5_INIT="set /a IMGI2=0"
set W5_UPDATE="set /a IMGI2=(IMGI2+1) %% 20, REPL1=IMGI2/10"
set W5_CONTENT="image img\uglyREPL1.pcx 0 0 # 14 OFF_X,OFF_Y 0 0 OFF_W,OFF_H"

set W6_NAME="3d Ship"
set /a W6_W=50, W6_H=40
set /a W6_X=65, W6_Y=31
set /a W6_XA=0, W6_YA=0
set /a W6_ACTIVE=1, W6_CLOSE=1, W6_SIZE=1, W6_CLEAR=1, W6_SCROLL=0
set W6_INIT="set /a RY=0"
set W6_UPDATE="set /a RY+=24, REPL1=RY"
set W6_CONTENT="3d objects\spaceship.obj 1,0 700,REPL1,0 0,0,0 100,100,100,0,0,0 0,0,0,0 %MID_OFF_X%,%MID_OFF_Y%,4000,1 0 0 0 "

set W7_NAME="Scroll"
set /a W7_W=35, W7_H=3
set /a W7_X=11, W7_Y=69
set /a W7_XA=1, W7_YA=1
set /a W7_ACTIVE=1, W7_CLOSE=1, W7_SIZE=0, W7_CLEAR=1, W7_SCROLL=0
set W7_INIT="set /a SCROLLI=0"
set W7_UPDATE="set /a SCROLLI=(SCROLLI+1) %% 230, REPL1=OFF_X - SCROLLI / 3"
set W7_CONTENT="text a 0 0 ______________________________________Scrolling_without_\e0block\r_operation...____________________________________ REPL1,OFF_Y"

:: END WINDOW DEFINITIONS

:SKIP_DEFINE_WINDOWS

for /l %%a in (1,1,!NOF_WIN!) do if not "!W%%a_MAXED!"=="1" ( set /a W%%a_MAXED=0 ) else ( set /a W%%a_XO=!W%%a_X!,W%%a_YO=!W%%a_Y!,W%%a_WO=!W%%a_W!,W%%a_HO=!W%%a_H!,W%%a_X=0, W%%a_Y=0,W%%a_W=!W!,W%%a_H=!H!,W%%a_WM=!W!-1,W%%a_HM=!H!-1,W%%a_MAXED=1 )

for /l %%a in (1,1,!NOF_WIN!) do set /a W%%a_WM=!W%%a_W!-1, W%%a_HM=!W%%a_H!-1,LAY%%a=%%a & cmdwiz stringlen !W%%a_NAME! & set /a W%%a_WMIN = !errorlevel! + 16 & set DOCMD=!W%%a_INIT:~1,-1!& (if "!DOCMD!"=="" set DOCMD=rem) & !DOCMD!
set /a CLEANWIN=!NOF_WIN!+1
for /l %%a in (%CLEANWIN%,1,50) do set W%%a_NAME=&set W%%a_INIT=&set W%%a_UPDATE=&set W%%a_CONTENT=&set W%%a_X=&set W%%a_Y=&set W%%a_W=&set W%%a_H=&set W%%a_XA=&set W%%a_YA=&set W%%a_ACTIVE=&set W%%a_CLOSE=&set W%%a_SIZE=&set W%%a_CLEAR=&set W%%a_MAXED=&set W%%a_SCROLL=&set CLEANWIN=

:: Set window as topmost
rem cmdwiz setwindowpos k k topmost

:LOOP
for /L %%1 in (1,1,300) do if not defined STOP (
	set WINSTR=""
	for /l %%z in (1,1,!NOF_WIN!) do (
		for %%a in (!LAY%%z!) do (
			if !W%%a_ACTIVE! == 1 (
				if !W%%a_MAXED!==1 set /a W%%a_W=!W!,W%%a_H=!H!,W%%a_WM=!W!-1,W%%a_HM=!H!-1

				set /a REPL1=0, REPL2=0, REPL3=0
				set /a "DRAW_X=!MID_OFF_X!-!W%%a_W!/2, DRAW_Y=!MID_OFF_Y!-!W%%a_H!/2"
				set /a OFF_X=!DRAW_X!+!W%%a_XA!, OFF_Y=!DRAW_Y!+!W%%a_YA!, OFF_W=!W%%a_W!, OFF_H=!W%%a_H!
				set DOCMD=!W%%a_UPDATE:~1,-1!& (if "!DOCMD!"=="" set DOCMD=rem) & !DOCMD!
				set /a SIZE=!W%%a_SIZE! & if !W%%a_MAXED!==1 set /a SIZE=0
				for %%x in (!DRAW_X!) do for %%y in (!DRAW_Y!) do for %%w in (!W%%a_W!) do for %%h in (!W%%a_H!) do for %%r in (!REPL1!) do for %%s in (!REPL2!) do for %%t in (!REPL3!) do for %%_ in (!SIZE!) do for %%- in (!W%%a_SIZE!) do for %%q in (!W%%a_CLOSE!) do for %%c in (!W%%a_CLEAR!) do (
					set CONTENT=!W%%a_CONTENT!
					for %%i in (!OFF_X!) do set CONTENT=!CONTENT:OFF_X=%%i!
					for %%i in (!OFF_Y!) do set CONTENT=!CONTENT:OFF_Y=%%i!
					set CONTENT=!CONTENT:OFF_W=%%w!
					set CONTENT=!CONTENT:OFF_H=%%h!
					set CONTENT=!CONTENT:REPL1=%%r!
					set CONTENT=!CONTENT:REPL2=%%s!
					set CONTENT=!CONTENT:REPL3=%%t!
					set /a TEXTPOS=%%x + !BORDER_TEXT_XP!, CLOSEPOS=%%x + !W%%a_WM! - !BORDER_CLOSE_XP!, BORDER_RIGHT_X=%%x + !W%%a_WM!, BORDER_BOTTOM_Y=%%y + !W%%a_HM!, MAXPOS=CLOSEPOS-2
					set NAME=!W%%a_NAME: =_!
					set TCOL=!TITLE_COL! & if %%z == !NOF_WIN! set TCOL=!FOCUS_COL!
					set BOX="box !BORDER_COL! cd %%x,%%y,!W%%a_WM!,!W%%a_HM! & box !BORDER_COL! ba %%x,%%y,0,!W%%a_HM! & box !BORDER_COL! ba !BORDER_RIGHT_X!,%%y,0,!W%%a_HM! & text !TCOL! 0 _!NAME:~1,-1!_ !TEXTPOS!,%%y & !SS%%q! text !CLOSE_COL! 0 _X_ !CLOSEPOS!,%%y & !SS%%-! text !MAX_COL! 0 _\gf2_ !MAXPOS!,%%y  & pixel !BORDER_COL! c9 %%x,%%y & pixel !BORDER_COL! bb !BORDER_RIGHT_X!,%%y & pixel !BORDER_COL! c8 %%x,!BORDER_BOTTOM_Y! & pixel !BORDER_COL! bc !BORDER_RIGHT_X!,!BORDER_BOTTOM_Y! & !SS%%_! pixel !RESIZE_COL! fe !BORDER_RIGHT_X!,!BORDER_BOTTOM_Y!"
					set WINSTR="!WINSTR:~1,-1! & !SS%%c! fbox !CLEAR_COL! !DRAW_X!,!DRAW_Y!,%%w,%%h & !CONTENT:~1,-1! & !BOX:~1,-1! & block 0 %%x,%%y,!W%%a_W!,!W%%a_H! !W%%a_X!,!W%%a_Y!"
				)
			)
		)
	)

	for %%i in (!W!) do set TBKG=!BKG:OFF_W=%%i!
	for %%i in (!H!) do set TBKG=!TBKG:OFF_H=%%i!
	echo "cmdgfx: fbox !TBKG! & !WINSTR:~1,-1!" F
	set WINSTR=&set TBKG=
	
	set /p INPUT=
	for /f "tokens=1,2,4,6, 8,10,12,14,16,18,20,22" %%A in ("!INPUT!") do ( set EV_BASE=%%A & set /a K_EVENT=%%B, K_DOWN=%%C, KEY=%%D,  M_EVENT=%%E, M_X=%%F, M_Y=%%G, M_LB=%%H, M_RB=%%I, M_DBL_LB=%%J, M_DBL_RB=%%K, M_WHEEL=%%L 2>nul ) 
	set INPUT=
	
	if !M_EVENT!==1 (
		if !M_LB!==1 (
			if !SEL_WIN! == 0 (
				set /a SEL_WIN=-1, SEL_INDEX=-1, CLOSE_WIN=-1, MAX_WIN=-1
				for /l %%z in (1,1,!NOF_WIN!) do (
					for %%a in (!LAY%%z!) do (
						if !W%%a_ACTIVE! == 1 (
							set /a BORDER_RIGHT_X=!W%%a_X!+!W%%a_WM!, BORDER_BOTTOM_Y=!W%%a_Y!+!W%%a_HM!
							set /a CLOSEPOS=!W%%a_X!+!W%%a_WM!-!BORDER_CLOSE_XP!+1, MAXPOS=CLOSEPOS-2
							if !M_X! geq !W%%a_X! if !M_Y! geq !W%%a_Y! if !M_X! leq !BORDER_RIGHT_X! if !M_Y! leq !BORDER_BOTTOM_Y! set /a SEL_WIN=%%a, SEL_INDEX=%%z & set /a DRAG_MODE=1-!W%%a_MAXED!
							if !W%%a_CLOSE! == 1 if !M_X! == !CLOSEPOS! if !M_Y! == !W%%a_Y! set /a SEL_WIN=-1, CLOSE_WIN=%%a
							if !W%%a_SIZE! == 1 if !W%%a_MAXED!==0 if !M_X! == !BORDER_RIGHT_X! if !M_Y! == !BORDER_BOTTOM_Y! set /a SEL_WIN=%%a, SEL_INDEX=%%z & set /a DRAG_MODE=0 & if !W%%a_MAXED!==0 set /a DRAG_MODE=2
							if !W%%a_SIZE! == 1 if !M_X! == !MAXPOS! if !M_Y! == !W%%a_Y! set /a SEL_WIN=%%a, SEL_INDEX=%%z, DRAG_MODE=0, MAX_WIN=%%a
						)
					)
				)
				if !SEL_WIN! gtr 0 for %%a in (!SEL_WIN!) do (
					set /a ORGMX=M_X, ORGMY=M_Y, ORGWX=!W%%a_X!, ORGWY=!W%%a_Y!, ORGWW=!W%%a_W!, ORGWH=!W%%a_H!
					if not !SEL_INDEX! == !NOF_WIN! (
						set /a STARTI=!SEL_INDEX!+1
						for /l %%i in ( !STARTI!,1,!NOF_WIN! ) do set /a CI=%%i-1 & for %%j in (!CI!) do set /a LAY%%j=!LAY%%i!
						set /a LAY!NOF_WIN!=!SEL_WIN!
					)
				)
				if !CLOSE_WIN! gtr 0 for %%a in (!CLOSE_WIN!) do set /a W%%a_ACTIVE=0 & for %%b in (!NOF_WIN!) do if %%a==!LAY%%b! call :TAB 1

				if !MAX_WIN! gtr 0 for %%a in (!MAX_WIN!) do if !W%%a_MAXED!==0 ( set /a W%%a_XO=!W%%a_X!,W%%a_YO=!W%%a_Y!,W%%a_WO=!W%%a_W!,W%%a_HO=!W%%a_H!,W%%a_X=0, W%%a_Y=0,W%%a_W=!W!,W%%a_H=!H!,W%%a_WM=!W!-1,W%%a_HM=!H!-1,W%%a_MAXED=1) else (set /a W%%a_X=!W%%a_XO!,W%%a_Y=!W%%a_YO!,W%%a_W=!W%%a_WO!,W%%a_H=!W%%a_HO!,W%%a_WM=!W%%a_WO!-1,W%%a_HM=!W%%a_HO!-1,W%%a_MAXED=0 & set W%%a_XO=&set W%%a_YO=&set W%%a_WO=&set W%%a_HO=)
				
			) else if !SEL_WIN! gtr 0 (
				if !DRAG_MODE! == 1 for %%a in (!SEL_WIN!) do set /a W%%a_X=ORGWX + M_X-ORGMX, W%%a_Y=ORGWY + M_Y-ORGMY
				if !DRAG_MODE! == 2 for %%a in (!SEL_WIN!) do set /a W%%a_W=ORGWW + M_X-ORGMX, W%%a_H=ORGWH + M_Y-ORGMY, W%%a_WM=ORGWW + M_X-ORGMX-1, W%%a_HM=ORGWH + M_Y-ORGMY-1 & (if !W%%a_H! lss 4 set /a W%%a_H=4, W%%a_HM=3) & (if !W%%a_W! lss !W%%a_WMIN! set /a W%%a_W=!W%%a_WMIN!, W%%a_WM=!W%%a_WMIN!-1) & (if !W%%a_H! gtr !H! set /a W%%a_H=H, W%%a_HM=H-1) & (if !W%%a_W! gtr !W! set /a W%%a_W=W, W%%a_WM=W-1) 
			)
		) else (
			set /a SEL_WIN=0, DRAG_MODE=0
		)
		
		if !M_WHEEL! neq 0 for %%a in (!NOF_WIN!) do for %%i in (!LAY%%a!) do if !W%%i_SCROLL!==1 set /a W%%i_YA-=!M_WHEEL!*2 & if !W%%i_YA! geq 1 set /a W%%i_YA=1
	)
	
	if !KEY! == 9 cmdwiz getkeystate shift > nul & call :TAB !errorlevel!
	if !KEY! == 328 for %%a in (!NOF_WIN!) do for %%i in (!LAY%%a!) do if !W%%i_MAXED!==0 set /a W%%i_Y-=1, LIM=-!W%%i_H!+1 & if !W%%i_Y! leq !LIM! set /a W%%i_Y=!LIM!
	if !KEY! == 336 for %%a in (!NOF_WIN!) do for %%i in (!LAY%%a!) do if !W%%i_MAXED!==0 set /a W%%i_Y+=1 & if !W%%i_Y! geq !HM! set /a W%%i_Y=!HM!
	if !KEY! == 331 for %%a in (!NOF_WIN!) do for %%i in (!LAY%%a!) do if !W%%i_MAXED!==0 set /a W%%i_X-=1, LIM=-!W%%i_W!+1 & if !W%%i_X! leq !LIM! set /a W%%i_X=!LIM!
	if !KEY! == 333 for %%a in (!NOF_WIN!) do for %%i in (!LAY%%a!) do if !W%%i_MAXED!==0 set /a W%%i_X+=1 & if !W%%i_X! geq !WM! set /a W%%i_X=!WM!
	
	if !KEY! == 329 for %%a in (!NOF_WIN!) do for %%i in (!LAY%%a!) do if !W%%i_SCROLL!==1 set /a W%%i_YA+=1 & if !W%%i_YA! geq 1 set /a W%%i_YA=1
	if !KEY! == 337 for %%a in (!NOF_WIN!) do for %%i in (!LAY%%a!) do if !W%%i_SCROLL!==1 set /a W%%i_YA-=1
	for %%a in (!NOF_WIN!) do for %%i in (!LAY%%a!) do if !W%%i_SCROLL!==1 set /a TMP=-%MAXTH%+!W%%i_H! & if !W%%i_YA! lss !TMP! set /a W%%i_YA=!TMP!

	rem if !KEY! == 327 for %%a in (!NOF_WIN!) do for %%i in (!LAY%%a!) do if !W%%i_SCROLL!==1 set /a W%%i_XA+=1 & if !W%%i_XA! geq 1 set /a W%%i_XA=1
	rem if !KEY! == 335 for %%a in (!NOF_WIN!) do for %%i in (!LAY%%a!) do if !W%%i_SCROLL!==1 set /a W%%i_XA-=1
	rem for %%a in (!NOF_WIN!) do for %%i in (!LAY%%a!) do if !W%%i_SCROLL!==1 set /a TMP=-%MAXTW%+!W%%i_W! & if !W%%i_XA! lss !TMP! set /a W%%i_XA=!TMP!
	
	if !KEY! == 27 set STOP=1
	if !KEY! == 112 cmdwiz getch
	
	if !KEY! == 411 for %%a in (!NOF_WIN!) do for %%i in (!LAY%%a!) do if !W%%i_MAXED!==0 if !W%%i_SIZE!==1 set /a W%%i_W-=1 & (if !W%%i_W! lss !W%%a_WMIN! set /a W%%i_W=!W%%a_WMIN!) & set /a W%%i_WM=!W%%i_W!-1
	if !KEY! == 413 for %%a in (!NOF_WIN!) do for %%i in (!LAY%%a!) do if !W%%i_MAXED!==0 if !W%%i_SIZE!==1 set /a W%%i_W+=1 & (if !W%%i_W! gtr !W! set /a W%%i_W=W) & set /a W%%i_WM=!W%%i_W!-1
	if !KEY! == 408 for %%a in (!NOF_WIN!) do for %%i in (!LAY%%a!) do if !W%%i_MAXED!==0 if !W%%i_SIZE!==1 set /a W%%i_H-=1 & (if !W%%i_H! lss 4 set /a W%%i_H=4) & set /a W%%i_HM=!W%%i_H!-1
	if !KEY! == 416 for %%a in (!NOF_WIN!) do for %%i in (!LAY%%a!) do if !W%%i_MAXED!==0 if !W%%i_SIZE!==1 set /a W%%i_H+=1 & (if !W%%i_H! gtr !H! set /a W%%i_H=H) & set /a W%%i_HM=!W%%i_H!-1
	
	if !KEY! == 13 (
		if "!OLDW!"=="" ( cmdwiz fullscreen 1 & set /a OLDW=W, OLDH=H & cmdwiz getconsoledim sw & set /a W=!errorlevel! + 1 & cmdwiz getconsoledim sh & set /a H=!errorlevel!+3 & set /a WWW=W*WPAGES, HH=H*2, WM=W-1, HM=H-1 & echo "cmdgfx: " f%FONT%:0,0,!WWW!,!HH!,!W!,!H!
		) else ( cmdwiz fullscreen 0 & set /a W=!OLDW!, H=!OLDH! & set /a WWW=W*WPAGES, HH=H*2, WM=W-1, HM=H-1 & mode !W!,!H! & echo "cmdgfx: " f%FONT%:0,0,!WWW!,!HH!,!W!,!H! & set OLDW=&set OLDH= )
		set /a "MID_OFF_X=W+(WWW-W)/2"
	)

	if !KEY! == 371 if "!OLDW!"=="" set /a W-=3 & (if !W! lss 60 set /a W=60) & set /a "WWW=W*WPAGES, WM=W-1, MID_OFF_X=W+(WWW-W)/2" & mode !W!,!H! & echo "cmdgfx: " f%FONT%:0,0,!WWW!,!HH!,!W!,!H!
	if !KEY! == 372 if "!OLDW!"=="" set /a "W+=3, WWW=W*WPAGES, WM=W-1, MID_OFF_X=W+(WWW-W)/2" & mode !W!,!H! & echo "cmdgfx: " f%FONT%:0,0,!WWW!,!HH!,!W!,!H!
	if !KEY! == 397 if "!OLDW!"=="" set /a H-=3 & (if !H! lss 40 set /a H=40) & set /a HH=H*2, HM=H-1, MID_OFF_Y=!H! & mode !W!,!H! & echo "cmdgfx: " f%FONT%:0,0,!WWW!,!HH!,!W!,!H!
	if !KEY! == 401 if "!OLDW!"=="" set /a H+=3, HH=H*2, HM=H-1, MID_OFF_Y=!H! & mode !W!,!H! & echo "cmdgfx: " f%FONT%:0,0,!WWW!,!HH!,!W!,!H!

	set /a KEY=0
	
	if exist NewDrop\Done.txt call :NEWDROP
)
if not defined STOP goto LOOP

endlocal
cmdwiz delay 100
rd /S /Q _processed >nul 2>nul
echo "cmdgfx: quit"
title input:Q
goto :eof

:TAB
for /l %%n in (1,1,!NOF_WIN!) do (
	if %1 == 0 (
		set /a SEL_INDEX=1, SEL_WIN=!LAY1!
		for /l %%i in ( 2,1,!NOF_WIN! ) do set /a CI=%%i-1 & for %%j in (!CI!) do set /a LAY%%j=!LAY%%i!
		set /a LAY!NOF_WIN!=!SEL_WIN!, SEL_WIN=0
	) else (
		for %%i in (!NOF_WIN!) do set /a SEL_WIN=!LAY%%i!, STARTI=!NOF_WIN!-1
		for /l %%i in ( !STARTI!,-1,1 ) do set /a CI=%%i+1 & for %%j in (!CI!) do set /a LAY%%j=!LAY%%i!
		set /a LAY1=!SEL_WIN!, SEL_WIN=0
	)
	for %%i in (!NOF_WIN!) do for %%j in (!LAY%%i!) do if !W%%j_ACTIVE!==1 goto :eof
)
goto :eof

:NEWDROP
if not exist _processed mkdir _processed >nul 2>nul
set /a NEW_X=6, NEW_Y=6
for %%a in (NewDrop\*) do (
	set /a OW=W, OH=H
	set FULLSCREEN=
	set /a FS=1	& if "!OLDW!"=="" set /a FS=0
	if not "%%~nxa" == "Done.txt" (
		copy /Y %%a _processed\%%~nxa >nul 2>nul
		
		if "%%~xa"==".cfg" (
			for /f "tokens=* delims=" %%i in (%%a) do set line="%%i"& set DOCMD=!line:~1,-1!& !DOCMD!
		) else ( 
		
			set /a USEPOS=-1, INCW=0
			for /l %%b in (1,1,!NOF_WIN!) do if !W%%b_ACTIVE!==0 set /a USEPOS=%%b
			if !USEPOS!==-1 set /a NOF_WIN+=1, USEPOS=NOF_WIN, INCW=1
			
			for %%b in (!USEPOS!) do (
				set /a W%%b_W=50, W%%b_H=40, W%%b_X=!NEW_X!, W%%b_Y=!NEW_Y!, NEW_X+=2, NEW_Y+=2, W%%b_XA=1, W%%b_YA=1, W%%b_ACTIVE=1, W%%b_CLOSE=1, W%%b_SIZE=1, W%%b_CLEAR=1
				set W%%b_INIT=""&set W%%b_UPDATE=""
				set SCALE=&set NOCODE=\&set /a W%%b_SCROLL=1
				(if "%%~xa"==".gxy" set SCALE=OFF_W,OFF_H)&(if "%%~xa"==".pcx" set SCALE=OFF_W,OFF_H)& if not "!SCALE!"=="" set /a W%%b_XA=0, W%%b_YA=0,W%%b_SCROLL=0&set NOCODE=
				set W%%b_NAME="%%~nxa"& set W%%b_CONTENT="image _processed\%%~nxa !NOCODE!!TEXT_COL! 0 -1 OFF_X,OFF_Y 0 0 !SCALE!"
				set /a W%%b_MAXED=0
				
				if "%%~xa"==".met" for /f "tokens=* delims=" %%i in (%%a) do set line="%%i"&set line=!line:[]=%%b!& set DOCMD=!line:~1,-1!& !DOCMD!
				if not !W%%b_INIT!=="" set DOCMD=!W%%b_INIT:~1,-1!& !DOCMD!

				if "!W%%b_MAXED!"=="1" set /a W%%b_XO=!W%%b_X!,W%%b_YO=!W%%b_Y!,W%%b_WO=!W%%b_W!,W%%b_HO=!W%%b_H!,W%%b_X=0, W%%b_Y=0,W%%b_W=!W!,W%%b_H=!H!,W%%b_WM=!W!-1,W%%b_HM=!H!-1,W%%b_MAXED=1
				
				set /a W%%b_WM=!W%%b_W!-1, W%%b_HM=!W%%b_H!-1 & (if !INCW! == 1 set /a LAY%%b=%%b) & cmdwiz stringlen !W%%b_NAME! & set /a W%%b_WMIN = !errorlevel! + 16
			)
			
			set /a LAYCNT=1
			for /l %%i in (1,1,!NOF_WIN!) do (
				for %%j in (!LAY%%i!) do for %%k in (!LAYCNT!) do (
					if !W%%j_ACTIVE! == 1 if not %%j == !USEPOS! set /a LAY%%k=%%j, LAYCNT+=1
				)
			)
			set /a NOF_WIN=!LAYCNT! & set /a LAY!NOF_WIN!=!USEPOS!
			rem echo NW UP: !NOF_WIN! !USEPOS! & (for /l %%i in (1,1,!NOF_WIN!) do echo !LAY%%i!) & cmdwiz getch
		)
	)
	
	set /a OR=0 & (if not !W!==!OW! set /a OR=1) & (if not !H!==!OH! set /a OR=1) 
	if !OR!==1 set /a "WWW=W*WPAGES, WM=W-1, MID_OFF_X=W+(WWW-W)/2, HH=H*2, HM=H-1, MID_OFF_Y=!H!" & mode !W!,!H! & echo "cmdgfx: " f%FONT%:0,0,!WWW!,!HH!,!W!,!H! & if exist centerwindow.bat call centerwindow.bat 0 -20

	cmdwiz setwindowpos k k
	
	if not "!FULLSCREEN!" == "" (
		if "!FULLSCREEN!"=="1" ( if !FS!==0 cmdwiz fullscreen 1 & set /a OLDW=W, OLDH=H & cmdwiz getconsoledim sw & set /a W=!errorlevel! + 1 & cmdwiz getconsoledim sh & set /a H=!errorlevel!+3 & set /a WWW=W*WPAGES, HH=H*2, WM=W-1, HM=H-1 & echo "cmdgfx: " f%FONT%:0,0,!WWW!,!HH!,!W!,!H!
		) else ( if !FS!==1 cmdwiz fullscreen 0 & set /a W=!OLDW!, H=!OLDH! & set /a WWW=W*WPAGES, HH=H*2, WM=W-1, HM=H-1 & mode !W!,!H! & echo "cmdgfx: " f%FONT%:0,0,!WWW!,!HH!,!W!,!H! & set OLDW=&set OLDH= )
		set /a "MID_OFF_X=W+(WWW-W)/2" & set FULLSCREEN=
	)
)

rd /S /Q NewDrop >nul 2>nul
goto :eof

:PROCESS_NEWDROP
if "%~1" == "" goto :eof
mkdir NewDrop >nul 2>nul
:REP
copy /y "%~1" NewDrop> nul 2>nul
shift
if not "%~1" == "" goto :REP
echo Done>NewDrop\Done.txt
Last edited by misol101 on 01 May 2018 19:19, edited 8 times in total.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Mouse GUI with windows - move scale,maximize,close,tab,animate

#3 Post by misol101 » 11 Apr 2018 16:28

Related to this: is there any way to detect if one or more files has been dropped on a cmd window which is currently running your batch script? (from e.g. Windows Explorer)

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Mouse GUI with windows - move scale,maximize,close,tab,animate

#4 Post by ShadowThief » 11 Apr 2018 16:31

misol101 wrote:
11 Apr 2018 16:28
Related to this: is there any way to detect if one or more files has been dropped on a cmd window which is currently running your batch script? (from e.g. Windows Explorer)
When you drop multiple files onto a script, they get processed as arguments, so they will all be accessible via %*. To see if more than one was provided, you can see if

Code: Select all

if not "%~2"=="" echo Multiple files provided

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Mouse GUI with windows - move scale,maximize,close,tab,animate

#5 Post by misol101 » 12 Apr 2018 01:19

Thanks ShadowThief, I'm aware of that but probably phrased my question wrong.

What I mean is: can I detect if file(s) are dropped on an already *running* script? That is, dropped on top of the actual cmd *window* that is running the script?

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Mouse GUI with windows - move scale,maximize,close,tab,animate

#6 Post by misol101 » 18 Apr 2018 13:34

The above archive was updated.

Now, it's possible to:
1) Drop any number of files or folders on the drag-drop.bat script (to start it), and the files will pop up in their own window(s)
2) While running drag-drop.bat, drop files or folders onto the accompanying script in the same folder called DROP_FILES_HERE.bat. This will cause these files to pop up as new windows in the already running GUI.

Other changes:
1) For text windows (i.e. not gxy or pcx), it's possible to scroll up and down with PgDown/PgUp, or the scroll wheel.
Last edited by misol101 on 18 Apr 2018 17:06, edited 1 time in total.

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Mouse GUI with windows - move scale,maximize,close,tab,animate

#7 Post by ShadowThief » 18 Apr 2018 16:26

misol101 wrote:
12 Apr 2018 01:19
Thanks ShadowThief, I'm aware of that but probably phrased my question wrong.

What I mean is: can I detect if file(s) are dropped on an already *running* script? That is, dropped on top of the actual cmd *window* that is running the script?
Only if the script is looking for user input, in which case the script will act like the user just typed the full path of the file that was dropped onto the window.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Mouse GUI with windows - move scale,maximize,close,tab,animate

#8 Post by misol101 » 19 Apr 2018 15:50

ShadowThief wrote:
18 Apr 2018 16:26
Only if the script is looking for user input, in which case the script will act like the user just typed the full path of the file that was dropped onto the window.
Ah, ok, I didn't know that. Cmdgfx_input blocks normal input to the window in this case, but I could have a smaller cmd window next to the main one, waiting for input.

But will a newline automatically be added at the end if you drop files this way? (Sorry can't test this myself for a few days)

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Mouse GUI with windows - move scale,maximize,close,tab,animate

#9 Post by misol101 » 25 Apr 2018 01:39

misol101 wrote:
19 Apr 2018 15:50
but will a newline automatically be added at the end if you drop files this way?
To answer myself: no, it won't (tested), so this is of limited use in this case.

Archive updated:

1. Press RETURN to switch between normal and FULLSCREEN mode
2. Press Ctrl+cursor keys to resize window (if not Fullscreen)
3. No longer possible to move a maximized window with cursor keys

Just going to add some kind of meta files as well so it will be possible to create windows with animations by dropping a meta file. Then it's done.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Mouse GUI with windows - move,scale,maximize,close,tab,animate

#10 Post by misol101 » 27 Apr 2018 14:59

Archive update. I guess it is pretty much done now.

Changes:
1. The script(s) now accept meta files (.met), which allows to create animated and otherwise specialized windows (specific position, dimension etc).
2. The scripts(s) also accept config files (.cfg), which allows setting the colors used for the windows, setting the dimension of the actual (not text) window,changing the background look etc
3. Use ALT+cursor keys to resize the currently focused text window (CTRL+cursor keys are as before used to resize the *actual* window)
4. Windows may now be maximized directly on creation (set W[]_MAXED to 1)
5. Maximized windows are now updated if changing the size of the *actual* window or going Fullscreen by pressing ENTER.

.met files look very much like little bat files, such as:

Code: Select all

set W[]_NAME="Met Animation"
set /a W[]_W=50, W[]_H=40
set /a W[]_X=7, W[]_Y=28
set /a W[]_XA=0, W[]_YA=0
set /a W[]_ACTIVE=1, W[]_CLOSE=1, W[]_SIZE=1, W[]_CLEAR=1, W[]_SCROLL=0, W[]_MAXED=0
set W[]_INIT="set /a IMG[]=0"
set W[]_UPDATE="set /a IMG[]=(IMG[]+1) % 20, REPL1=IMG[]/2"
set W[]_CONTENT="image img\spiral\REPL1.txt 8 0 # -1 OFF_X,OFF_Y 0 0 OFF_W,OFF_H"
The difference is the inclusion of [], which will be replaced by the index number of whatever index is free when the .met file is dropped on the script(s). [] should also be used for any variables in INIT or UPDATE, as this ensures unique variables even if the same .met file is used twice or more for the same running script.


Here, drag-drop.bat was started by dropping colors.cfg on it, which sets an image as background and changes the windows to red colors. Then plasma.met, anim.met, drag-drop.bat, and centerwindow.bat were dropped simultaneously on DROP_FILES_HERE.bat.
Image
Last edited by misol101 on 27 Apr 2018 17:05, edited 1 time in total.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Mouse GUI with windows - move,scale,maximize,close,tab,animate

#11 Post by misol101 » 27 Apr 2018 16:50

Ideally, I would like to remove the extra DROP_FILES_HERE.bat script and just be able to drop files on drag-drop.bat while it is running (it would have to recognize that an instance of itself (drag-drop.bat) is already running, copy the files the same way DROP_FILES_HERE.bat does, and then exit silently). Unfortunately I was not successful with this so far.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Mouse GUI with windows - move,scale,maximize,close,tab,animate

#12 Post by misol101 » 29 Apr 2018 09:14

Hehe, good old Batch... I had all kinds of strange problems trying to merge the two scripts into one... then I finally saw I had two labels with the same name (:LOOP)... :oops:

Final (?) version, archive updated:

1. Now one script instead of two (DROP_FILES_HERE.bat was removed). Drop files on drag-drop.bat to start it, and drop files on it while running to add them to the screen.
2. The variable FULLSCREEN can now be set to 0 or 1 in a cfg file to enter or exit fullscreen.

I would like the "desktop" to always become top window after dropping new files on drag-drop.bat, but this only works sometimes. One way of dealing with this is to make the cmd window a TOPMOST window (always-on-top). To enable this functionality, uncomment line 124 which says: cmdwiz setwindowpos k k topmost

I may also rewrite this whole thing in Javascript to make it handle many more windows without lag, but that's for another day... :mrgreen:

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Mouse GUI with windows - move,scale,maximize,close,tab,animate

#13 Post by misol101 » 01 May 2018 18:42

Archive updated

There was a blantant bug related to closing windows and then opening new windows (easily reproduced by 1: double-click drag-drop.bat 2. Close centerwindow.bat 3. Drop any file on drag-drop.bat 4. Observe how the new window appears, but another window disappears )

Should work better now.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Mouse GUI with windows - move,scale,maximize,close,tab,animate

#14 Post by misol101 » 05 May 2018 19:00

I decided that I wanted the script to handle 3d files dropped on it as well, so I added support for that (obj, ply and plg files). Archive updated.

To try it, you can drop the entire "objects" folder on drag-drop.bat to start it (some machines will most likely get slow running 6 windows at the same time though (due to Batch being slow, not cmdgfx))

It looks something like:
Image


By the way, I just remembered that on Windows 10, it is possible to resize a cmd window with the mouse without using the mode command. Is there any notification or efficient way to detect that the window has been resized?

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Mouse GUI with windows - move,scale,maximize,close,tab,animate

#15 Post by misol101 » 13 May 2018 17:18

Image

Well, I guess there had to be one more run :D Archive updated.

What's new:
1. Interactive GUI content within windows (that's right, play a game within the text window or press some buttons)
2. Delayed expansion in windows (to show, for example, the time)
3. Wav files dropped on drag-drop.bat will play automatically.

Try starting drag-drop.bat by dropping game.met on it, press SPACE and play by moving the mouse. Too difficult? Resize the game window :mrgreen:

Other new met files to drop on drag-drop.bat:
1. time.met (show current date and time)
2. bounce.met (simple example of delayed expansion and if checks)
3. button[1-4].met (window must be focused to interact with button: button1:space to play. button2:Right mouse. button3:RMB over button. button4: hovering and RMB. )

Unfortunately the update function for each window has to be written on a single line, which makes making stuff like a game a bit... tricky :lol:

Post Reply