Page 1 of 1

WinMeasure

Posted: Fri Sep 15, 2017 9:37 pm
by rbytes
This is a simple program to use your laptop or tablet as a measuring tool. There are some commented-out code lines that I hope to use once there is a #.hide() command for objects.

Code: Select all

''
WinMeasure by rbytes
September 2017
Uses graphic images of inch and metric rulers
You must set the width of the ruler images for
each device you use. Eg. a.width, b.width
and use an actual ruler to check the result.
''
' setup
#.angle(#.degrees)

' hide the side toolbar
#.scrview(#.normal) 
mx,my = #.scrsize()
'#.scrclear(.5,.5,.5)
'#.drawrotate(0,0,180)
shift = 40

' load the inch ruler
a = #.image                       ' ruler image
  a.source = "ruler.jpg"
  a.width = 1760
  a.x = -33
  a.y = 0
  '#.show(a)

' load and show the metric ruler
b = #.image                       ' ruler image
  b.source = "ruler2.jpg"
  b.width = 1760
  b.x = -33
  b.y = 0
  #.show(b)
  '#.scr()

' create a window for taking notes
c = #.textbox 'is a text box. Pressing "Enter" key if multi is 0 registers an action. Group elements are:
  c.edit = 1 'if 0 then text box is a non-editable text label (default), otherwise text box is an editable text field for text input;
  c.height = 400
  multi = 1 ' if 0 then text box is single-line (default), otherwise it is multi-line;
  c.text = "Notes: " 'text inside text box;
  c.width = mx 'text box width;
  c.x = 0 ' offset from left screen border;
  c.y = 70 'offset from top screen border.
  #.show(c)
  '#.scr()

' button to show the inch ruler
d = #.button
  d.height = 50
  d.text = "I N C H"
  d.width = 100
  d.x = 300 + shift
  d.y = 360

' button to show the metric ruler
e = #.button
  e.height = 50
  e.text = "C E N T"
  e.width = 100
  e.x = 450 + shift
  e.y = 360

' button to save notes
f = #.button
  f.height = 50
  f.text = "S A V E"
  f.width = 100
  f.x = 600 + shift
  f.y = 360

' button to quit
g = #.button
  g.height = 50
  g.text = "Q U I T"
  g.width = 100
  g.x = 750 + shift
  g.y = 360

  #.show(d,e,f,g)

' Main program loop
:loop

' if INCH button is pressed
  ? #.act(d)
    '#.show(a)  for future use
    b.x = -19
    b.source = "ruler.jpg"
  .
  
  ' if CENT button is pressed
  ? #.act(e) 
    '#.show(b)   ' for future use
    b.x = -33
    b.source = "ruler2.jpg"
  .
  
  ' If SAVE button is pressed
  ? #.act(f)
    k = "Notes.txt"
    #.writetext(k,c.text)
  .

If QUIT button is pressed
  ? #.act(g), #.end()

' Slow down the loop
#.delay(.1)

loop ->

Re: WinMeasure

Posted: Fri Sep 15, 2017 9:51 pm
by Mr. Kibernetik
In SPL the system UI object groups like #.button are a kind of templates to be copied to real buttons, but they are not read-only.
This means that if you need 5 buttons with, say, 120 points width, you can setup your system group like this:

Code: Select all

#.button.width = 120
and all subsequent assigns from system group #.button to other buttons will provide objects with width 120:

Code: Select all

b,c,d,e,f = #.button 'create all your buttons
Another similar approach if you don't want to modify system object #.button, can be:

setup your default button

Code: Select all

mybutton = #.button
mybutton.width = 120
and so on - setup all other necessary properties, and then do:

Code: Select all

b,c,d,e,f = mybutton
so all properties will be just copied from mybutton to b,c,d,e,f buttons.

SPL is very flexible in this regard.

Re: WinMeasure

Posted: Sat Sep 16, 2017 4:45 pm
by rbytes
Thanks for this information. :)