"Set window" function

For finished programs
Post Reply
User avatar
Dutchman
Posts: 148
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

"Set window" function

Post by Dutchman » Mon Sep 23, 2019 7:08 pm

Sometimes the minimum dimensions of the screen may not be sufficient, for example, to place the required interface objects.
In fact, it should be possible to set the screen size in advance. ;)
If that is not possible, as the status is now, then the user will have to be asked to adjust the size.
That is what the "SetWindow(w,h)" function does in the following code.
The function should be called at the beginning of the program if the screen size is too small.

Code: Select all

'Set window
'by Ton Nillesen, September 2019
'set Mac-window to desired size
'developed before "SCR SIZE w,h" was added
'
'==== User Settings ====
wmin = 600 ' minimum width
hmin = 450 ' minimum heigth
SetWindow.b=1 ' optional color setting of r,g,b
SetWindow.sign=1 ' optional setting of 'sign' object index
'
'--- Run ---
CALL SetWindow(wmin,hmin)
END
'
'==== Function ====
DEF SetWindow(wmin,hmin)
'set Mac-window to desired minimum size
' r,g,b, and 'sign' object index can be set on forehand
' sign color will be complementary
GOSUB Initiate
DRAW MANUAL
DO IF w<wmin OR h<hmin
  oldw=w : oldh=h
  DRAWCLEAR r,g,b
  DO 
    w,h=SCRSIZE|2
    GOSUB SetSign
  REDO IF w=oldw AND h=oldh
  DRAW UPDATE
REDO
DRAW AUTO
INSIGN HIDE sign
INSIGN DELETE sign
RETURN ' from function
'---- local subroutines ------
SetSign: ' set text panel
  txt$=txt0$+"width="+STRTEXT w "?????"
  txt$+=", height="+STRTEXT h "?????"
  INSIGN TEXT sign txt$
RETURN ' from local subroutine
Initiate: '------------------
  font$="Menlo bold" : fsize=12 ' font
  DRAWFONT font$,fsize
  w,h=SCRSIZE|2
  txt0$="Adjust window size to"+CR$
  sw=1.5*STRWIDTH txt0$ 
  txt0$+="width>="+STRTEXT wmin "????"
  txt0$+=", height>="+STRTEXT hmin "????"
  txt0$+=CR$
  sh=5*fsize: sx=w/2-sw/2: sy=h/2-sh/2
  INSIGN SET sign,txt0$,sx,sy,sw,sh
  INSIGN FONT sign,font$,fsize
  INSIGN BCOLOR sign 1-r,1-g,1-b
  INSIGN ALIGN sign 3 ' center text
  GOSUB SetSign
RETURN ' from local subroutine
END DEF
.
Screenshot.JPG
Screenshot.JPG (24.63 KiB) Viewed 220 times
Last edited by Dutchman on Tue Sep 24, 2019 7:52 am, edited 1 time in total.
It is still a long way to go

User avatar
kibernetik
Site Admin
Posts: 131
Joined: Tue Aug 06, 2019 3:03 pm

Re: "Set window" function

Post by kibernetik » Mon Sep 23, 2019 10:53 pm

This is the best inspiration for improvement.

viewtopic.php?f=8&t=26&p=286#p286

User avatar
Dutchman
Posts: 148
Joined: Tue Aug 06, 2019 4:47 pm
Location: Netherlands

Re: "Set window" function

Post by Dutchman » Tue Sep 24, 2019 7:45 am

Great, but my solution was first :!: :lol:
I added remark in the code:
developed before "SCR SIZE w,h" was added
It is still a long way to go

Post Reply