Chapter 3, Listing 1

Listing 1: Backgroundscript

	-- Konstantenvereinbarung

	function xOffset
	  return 191
	end xOffset

	function xMax
	  return xOffset() + 300
	end xMax

	function yOffset
	  return 21
	end yOffset

	function yMax
	  return yOffset() + 300
	end yMax
	
	-- Initialisieren und wieder aufräumen
	
	on initGraph
	  -- Erst einmal Zeichenfläche löschen:
	  choose select tool
	  drag from 0, 0 to 1000, 1000
	  doMenu "clear picture"
	end initGraph

	on closeGraph
	  choose browse tool
	  -- alles wieder auf Default-Werte setzen
	  reset paint
	end closeGraph

	-- die verschiedenen "Achsenkreuze"

	on drawSideAxes
	  -- erst "Achsenkreuz" zeichnen
	  choose line tool
	  drag from xOffset(), yMax() to xOffset(), yOffset()
	  drag from xOffset(), yMax() to xMax(), yMax()
	  -- dann kleine Abschlußlinien (Tickmarks)
	  drag from xOffset() - 3, yOffset()¬
	  to xOffset() + 3, yOffset()
	  drag from xMax(), yMax() + 3 to¬
	  xMax(), yMax() - 3
	end drawSideAxes

	on drawBox
	  -- einen Kasten um die Zeichenfläche zeichnen
	  choose rectangle tool
	  drag from xOffset(), yOffset() to xMax(), yMax()
	end drawBox

	on drawLineAxes x1, y2
	  -- Achsenkreuz zeichnen
	  choose line tool
	  drag from xOffset(), yOrigin(y2)¬
	  to xMax(), yOrigin(y2)
	  drag from xOrigin(x1), yOffset()¬
	  to xOrigin(x1), yMax()
	end drawLineAxes

	-- Skalierung und Berechnung WC -> DC

	on scale x1,y1, x2,y2
	  global xFactor, yFactor
	  global xWMin, YWMin, xWMax, YWMax
	  put x1 into xWMin
	  put x2 into xWMax
	  put y1 into yWMin
	  put y2 into yWMax
	  put (xMax() - xOffset())/(xWMax - xWMin)¬
	  into xFactor
	  put (yMax() - yOffset())/(yWMax - yWMin)¬
	  into yFactor
	end scale

	on unConstrained x1,y1, x2,y2
	  global xFactor, yFactor
	  scale(x1,y1, x2,y2)
	  if xFactor > yFactor then
	    put yFactor into xFactor
	  else
	    put xFactor into yFactor
	  end if
	  end constrained
  
	function convertX xWelt
	  global xFactor, xWMin
	  put round(xFactor*(xWelt - xWMin)) into x
	  return xOffset() + x
	end convertX

	function convertY yWelt
	  global yFactor, yWMax
	  put round(yFactor*(yWMax - yWelt)) into y
	  return yOffset() + y
	end convertY

	function xOrigin xWelt
	  global xFactor
	  put round(xFactor*xWelt) into x
	  return xOffset() - x
	end xOrigin

	function yOrigin yWelt
	  global yFactor
	  put round(yFactor*yWelt) into y
	  return yOffset() + y
	end yOrigin

	-- Hilfsfunktionen für die Bg-Felder

	function maxLine feldName
	  repeat with i = 1 to the number of lines¬
	  in bg fld feldName
	    put word i of bg fld feldName into item i of it
	  end repeat
	  return max(it)
	end maxLine

	function minLine feldName
	  repeat with i = 1 to the number of lines¬
	  in bg fld feldName
	    put word i of bg fld feldName into item i of it
	  end repeat
	  return min(it)
	end minLine

	on EnterKey
	  click at 111, 316  -- the loc of "Default-Button"
	end EnterKey

	on ReturnKey
	  EnterKey
	end ReturnKey

© 1997 by Jörg Kantel
Zurück zum Inhaltsverzeichnis