Page 1 of 1
rectangle graphic on the fly
Posted: Mon Mar 30, 2009 11:27 pm
by magice
On my current project, I need for my end users to be able to draw a box within an image area, much like the rectangle tool does in runrev. Is there any way to create graphics on the fly? I have not seen any commands for doing so.
Posted: Tue Mar 31, 2009 8:26 am
by Mark
Sure, Magice, check the create command in the docs.
Best,
Mark
Posted: Tue Mar 31, 2009 9:25 am
by SparkOut
This thread has some basic info about how to set the points of a graphic and its style.
http://forums.runrev.com/phpBB2/viewtopic.php?t=1898
Posted: Tue Mar 31, 2009 2:25 pm
by bn
magice,
try
Code: Select all
local tStartLoc
on mouseDown pMouseBtnNum
if there is a graphic "myGraphic" then delete graphic "myGraphic"
reset templategraphic
set the style of the templategraphic to "rectangle" -- or "oval" or "roundrect"
set the linesize of the templategraphic to 1 -- adjust
-- set the foregroundpattern of the templategraphic to 208034 -- block to have straight line w/o pattern
set the opaque of the templategraphic to false
create invisible graphic
set the name of last graphic to "myGraphic"
put the clickloc into tStartLoc
send "makeMyGraphic" to me in 2 milliseconds
end mouseDown
on makeMyGraphic
if the mouse is up then exit makeMyGraphic
put the mouseloc into tLoc
if item 1 of tStartLoc < item 1 of tLoc then
put item 1 of tStartLoc into tLeft
put item 1 of tLoc into tRight
else
put item 1 of tStartLoc into tRight
put item 1 of tLoc into tLeft
end if
if item 2 of tStartloc > item 2 of tLoc then
put item 2 of tStartloc into tBottom
put item 2 of tLoc into tTop
else
put item 2 of tStartloc into tTop
put item 2 of tLoc into tBottom
end if
if not (tTop < the top of me or tLeft < the left of me or tBottom > the bottom of me or tRight > the right of me) then
put tLeft & "," & tTop & "," & tRight & "," & tBottom into myRect
set the rect of graphic "myGraphic" to myRect
set the visible of graphic "myGraphic" to true
end if
send "makeMyGraphic" to me in 10 milliseconds
end makeMyGraphic
When you put this code into the script of a card it will draw the rectangle anywhere on the card. If you put it into the script of an image it will only draw within the limits of that image.
If you put it into a card script you have to watch out for controls (e.g. buttons) that dont trap the mouseDown. They misbehave. Just add a "on mouseUp/end mouseUp to the script of those controls.
regards
Bernd
Posted: Tue Mar 31, 2009 5:45 pm
by magice
you are all awesome!!
Posted: Tue Jun 23, 2009 4:09 am
by Dondi
bn wrote:magice,
try
Code: Select all
local tStartLoc
on mouseDown pMouseBtnNum
if there is a graphic "myGraphic" then delete graphic "myGraphic"
reset templategraphic
set the style of the templategraphic to "rectangle" -- or "oval" or "roundrect"
set the linesize of the templategraphic to 1 -- adjust
-- set the foregroundpattern of the templategraphic to 208034 -- block to have straight line w/o pattern
set the opaque of the templategraphic to false
create invisible graphic
set the name of last graphic to "myGraphic"
put the clickloc into tStartLoc
send "makeMyGraphic" to me in 2 milliseconds
end mouseDown
on makeMyGraphic
if the mouse is up then exit makeMyGraphic
put the mouseloc into tLoc
if item 1 of tStartLoc < item 1 of tLoc then
put item 1 of tStartLoc into tLeft
put item 1 of tLoc into tRight
else
put item 1 of tStartLoc into tRight
put item 1 of tLoc into tLeft
end if
if item 2 of tStartloc > item 2 of tLoc then
put item 2 of tStartloc into tBottom
put item 2 of tLoc into tTop
else
put item 2 of tStartloc into tTop
put item 2 of tLoc into tBottom
end if
if not (tTop < the top of me or tLeft < the left of me or tBottom > the bottom of me or tRight > the right of me) then
put tLeft & "," & tTop & "," & tRight & "," & tBottom into myRect
set the rect of graphic "myGraphic" to myRect
set the visible of graphic "myGraphic" to true
end if
send "makeMyGraphic" to me in 10 milliseconds
end makeMyGraphic
When you put this code into the script of a card it will draw the rectangle anywhere on the card. If you put it into the script of an image it will only draw within the limits of that image.
If you put it into a card script you have to watch out for controls (e.g. buttons) that dont trap the mouseDown. They misbehave. Just add a "on mouseUp/end mouseUp to the script of those controls.
regards
Bernd
Brilliant! Thank you bn. This is exactly what I need for my "learning" app.
Dondi.
Re:
Posted: Mon Nov 09, 2020 5:18 pm
by marksmithhfx
bn wrote: ↑Tue Mar 31, 2009 2:25 pm
When you put this code into the script of a card it will draw the rectangle anywhere on the card. If you put it into the script of an image it will only draw within the limits of that image.
regards
Bernd
Thanks Bernd, I just used this example from Mar 2009 because I needed to add a background rectangle to a card that was already fully populated (header bar, nav bar, datagrid). I suppose I could have tried to place the rectangle image on top and then send to back (next time) but it was easier to just create the object in code than to move and rearrange the existing objects.
Cheers,
Mark