I want to draw a box by drawing points, and I found a web site that suggested something like the following (under the upper button):
on mouseUp
choose brush tool
set the brush to 32
set the brushColor to brown
set the dragSpeed to 0
drag from 250,0 to 500,250 -- cuts off part at the right
drag from 0,250 to 250,0 --works
drag from 0,250 to 250,500 -- cuts off part at the bottom
drag from 250,500 to 500,250 -- shows nothing
-- draw tick marks to see how much is getting cut off
put 0 into K
repeat while K < 800
drag from 0,K to 10,K
put K+50 into K
end repeat
choose browse tool
end mouseUp
The result was a surprise - it clipped everything outside a magic boundary
It turns out that there's a magic clipping boundary from 0,0 to 399,399 and any would be drag fails (silently, I might add, no runtime errors) if outside this magic zone - I cannot find anything in a default stack that's that size, so what gives? It took me hours to discover this invisible limit.
Of course, what I really want is to make the graphic fit or exceed (and have optional scroll bars) the current screen size, or have a zoom function.
My question is how to draw a diamond and make it fit.
This stack had just two buttons (the lower button for "clear") and no other objects deliberately added.
on mouseUp
choose select tool
drag from 0,0 to 800,800 -- arbitrary number larger than the invisible drag limit frame
-- the inside 400x400 rectangle's outline flashes
cut
choose browse tool
end mouseUp
When the clear function runs, I can see it briefly select the 400x400 hidden rectangle and not an 800x800 one, so somewhere there's a hidden thing that I couldn't find.
There is no other code in the stack - this in a from-scratch new Mainstack.
When I rewrote the numbers to stay in the 400x400 rectangle, it looked fine.
Best way to draw lines on a card
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 10082
- Joined: Fri Feb 19, 2010 10:17 am
Re: Best way to draw lines on a card
Go to this menu item on the menuBar:
Object/New Control/Regular Polygon Graphic
you will end up with a diamond-shaped graphic object (120,120 pixels)
slap in the middle of your card: you can them resize it to whatever size
you need.
Object/New Control/Regular Polygon Graphic
you will end up with a diamond-shaped graphic object (120,120 pixels)
slap in the middle of your card: you can them resize it to whatever size
you need.
-
- Posts: 15
- Joined: Sat Jul 18, 2015 5:11 pm
Re: Best way to draw lines on a card
In Microsoft land, there is a "graphics" object that has Methods such as DrawRectangle and the like. A diamond to fit in a box in Microsoft looks like:
Sub DrawDiamond(p As Graphics, c As String, X As Integer, Y As Integer, W As Integer, H As Integer)
' p is the Microsoft defined graphics object.
Dim b As Drawing.Pen = getPen(c) ' c is a pen color
Dim tPoints(3) As Drawing.Point
tPoints(0).X = X
tPoints(0).Y = CInt(Y + H / 2)
tPoints(1).X = CInt(X + W / 2)
tPoints(1).Y = Y
tPoints(2).X = X + W
tPoints(2).Y = CInt(Y + H / 2)
tPoints(3).X = CInt(X + W / 2)
tPoints(3).Y = Y + H
p.DrawPolygon(b, tPoints)
End Sub
Sub DrawDiamond(p As Graphics, c As String, X As Integer, Y As Integer, W As Integer, H As Integer)
' p is the Microsoft defined graphics object.
Dim b As Drawing.Pen = getPen(c) ' c is a pen color
Dim tPoints(3) As Drawing.Point
tPoints(0).X = X
tPoints(0).Y = CInt(Y + H / 2)
tPoints(1).X = CInt(X + W / 2)
tPoints(1).Y = Y
tPoints(2).X = X + W
tPoints(2).Y = CInt(Y + H / 2)
tPoints(3).X = CInt(X + W / 2)
tPoints(3).Y = Y + H
p.DrawPolygon(b, tPoints)
End Sub
-
- Posts: 15
- Joined: Sat Jul 18, 2015 5:11 pm
Re: Best way to draw lines on a card
What is the script way to do that? And once made, can these controls be moved around in script?
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Best way to draw lines on a card
RedDeupree wrote:In Microsoft land, there is a "graphics" object that has Methods such as DrawRectangle and the like. A diamond to fit in a box in Microsoft looks like:
Sub DrawDiamond(p As Graphics, c As String, X As Integer, Y As Integer, W As Integer, H As Integer)
' p is the Microsoft defined graphics object.
Dim b As Drawing.Pen = getPen(c) ' c is a pen color
Dim tPoints(3) As Drawing.Point
tPoints(0).X = X
tPoints(0).Y = CInt(Y + H / 2)
tPoints(1).X = CInt(X + W / 2)
tPoints(1).Y = Y
tPoints(2).X = X + W
tPoints(2).Y = CInt(Y + H / 2)
tPoints(3).X = CInt(X + W / 2)
tPoints(3).Y = Y + H
p.DrawPolygon(b, tPoints)
End Sub
Code: Select all
on mouseUp
put 200 into tLocX
put 200 into tLocY
put 100 into tWidth
put 100 into tHeight
put DrawDiamond(tLocX, tLocY, tWidth, tHeight) into tObjectLongID
end mouseUp
function DrawDiamond pLocX, pLocY, pWidth, pHeight
-- Returns the long id of a new diamond-shaped polygon object,
-- created at the location pLocX, pLocY, with size specified
-- in pWidth and pHeight
--
put pLocX, (pLocY - pHeight div 2) &cr \
& (pLocX + pWidth div 2), pLocY &cr \
& pLocX, (pLocY + pHeight div 2) &cr \
& (pLocX - pWidth div 2), pLocY &cr \
& pLocX, (pLocY - pHeight div 2) into tPoints
set the points of the templateGraphic to tPoints
set the style of the templateGraphic to "polygon"
create graphic
return it
end DrawDiamond
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn