carl 53 posts since
Oct 17, 2007
5.
Re: How to make a Canvas control's border looks like two border-styles ? Jul 4, 2008 1:19 AM

in response to:
Mirror
Option borders are singular for a Graphic. BorderSpec just controls each side's border width and margin width separately.
You could certainly override the draw method to add any such decoration, or anything else for that matter, though you'll want to ensure that you leave space for that decoration -- shouldn't be difficult with a Canvas. As a simple, but somewhat garish, example:
{import * from CURL.GUI.CONTROL-HELPERS}
{define-class public open BorderedCanvas {inherits Canvas}
{constructor public {default ...}
{construct-super ...}
}
{method public open {draw renderer2d:Renderer2d}:void
{super.draw renderer2d}
{self.overdraw-border renderer2d}
}
{method public open {overdraw-border renderer2d:Renderer2d}:void
def bounds = {self.get-bounds}
def left = -bounds.lextent
def right = bounds.rextent
def top = -bounds.ascent
def bottom = bounds.descent
def psize = renderer2d.pixel-size
def psize2 = psize * 2
{draw-standard-bevel-edges
left, top, right, bottom,
"black", "black", "red", "red",
renderer2d
}
{draw-standard-bevel-edges
left + psize2, top + psize2, right - psize2, bottom - psize2,
"green", "green", "blue", "blue",
renderer2d
}
}
}
{BorderedCanvas background = "pink"}
I would certainly prefer using a Canvas inside a Frame (or even, if you are using styled controls, a SkinnableFrame, for more options).