Notifications
Clear all
[Closed] Best way to Draw Boxes in Rollout?
Page 4 / 4
Prev
Mar 20, 2008 2:02 am
Well here is what I have now. Still just using scene cubes as a quick and dirty way to drive the BoxShapes array. It’ll be replaced with more specialized code in my script but this is a nice and easy interface method.
Now I threw in an ‘FPS’ o meter to check how fast the bitmap code was executing and it’s only dropping on my system to 60fps when I’m guessing some kind of gc is occuring. But it’s only seeming to redraw when the mouse stops moving. How do I make it update while the mouse is moving?
try(destroyDialog BoxDrawing)Catch()
global BoxDrawing,BoxShapes
selectionchangedvar = 0
fn boxzsort_ASC v1 v2 =
(
if v1.z < v2.z then (d = -1) else if v1.z > v2.z then (d = 1) else (d = 0)
case of
(
(d < 0.): -1
(d > 0.): 1
default: 0
)
)
fn getboxes =
(
ReturnArray = #()
struct BoxShape (pos,width,height,border,bordercolor,bgcolor,active,fg,nhandle,obj,z)
local Boxobjects = for o in objects collect o
for o in BoxObjects do
(
append ReturnArray (BoxShape pos:[(o.min.x + (255/2))as integer,(o.max.y*(-1) + (255/2)) as integer] width:((o.max.x-o.min.x) as integer) height:((o.max.y - o.min.y) as integer) border:1 bordercolor:black bgcolor:white active:0 fg:0 nhandle:o.inode.handle obj:o z:(o.max.z))
)
qsort returnarray boxzsort_ASC
return ReturnArray
)
fn updatepos boxarray =
(
for o in boxarray do
(
o.pos = [(o.obj.min.x + (255/2))as integer,(o.obj.max.y*(-1) + (255/2)) as integer]
)
qsort boxarray boxzsort_ASC
return boxarray
)
fn updateFGStatus boxarray =
(
s = selection as array
for o in boxarray do
(
if (finditem s o.obj) != 0 then
(
o.fg = 1
)
else
(
o.fg = 0
)
)
return boxarray
)
BoxShapes = getboxes()
(
local bitmapX = bitmapY = 255
local WhiteBitmap = (bitmap bitmapx Bitmapy color:white)
local BlankBitmap = (bitmap bitmapx bitmapy color:(color 0 0 0 0))
local BackgroundBitmap = (bitmap bitmapX bitmapY color:white)
local MidgroundBitmap = (bitmap bitmapx bitmapy color:(color 0 0 0 0))
local ForegroundBitmap = (bitmap bitmapx bitmapy color:(Color 0 0 0 0))
rollout BoxDrawing "DrawingBox"
(
BITMAP Canvas pos:[10,10] width: bitmapX height: bitmapY bitmap:WhiteBitmap
timer clock "maxscriptdemoclock" interval:17
label fpsLabel "FPS:" pos:[10,BitmapY +20]
label fpsNumber "0" pos:[45,BitmapY +20]
fn drawbox canvas: pos: width: height: border:1 bordercolor:black bgcolor:white =
(
rightcrop = (canvas.width-pos.x-width)
if rightcrop > 0 do (rightcrop = 0)
if pos.x < 0 then (leftoffset = abs(pos.x)+1; pos.x = 0) else (leftoffset = 1)
local theBorderLine = for i = leftoffset to (width+rightcrop) collect bordercolor
local theBodyLine = for i = leftoffset to (width+rightcrop) collect bgcolor
for i = 1 to border do
(
if i >= leftoffset and width > rightcrop do
(
theBodyLine[i] = bordercolor
)
if (i-1) <= rightcrop and leftoffset < width do
(
theBodyLine[width+2-i-leftoffset] = bordercolor
)
)
for y = border to height-border-1 do
setPixels canvas [pos.x,pos.y+y] theBodyLine
for y = 0 to border-1 do
(
setPixels canvas [pos.x,pos.y+y] theBorderLine
setPixels canvas [pos.x,pos.y+height-1-y] theBorderLine
)
)
fn CompositeCanvas bgcanvas fgcanvas =
(
pasteBitmap fgcanvas bgcanvas (box2 0 0 fgcanvas.width fgcanvas.height) [0,0] type:#blend
)
fn drawbg shapearray canvas =
(
for b in shapearray do
(
if b.fg == 0 then
(
drawbox canvas:canvas pos:b.pos width:b.width height:b.height bgcolor:red bordercolor:black
)
)
)
fn drawfg shapearray canvas =
(
for b in shapearray do
(
if b.fg == 1 then
(
drawbox canvas:canvas pos:b.pos width:b.width height:b.height bgcolor:blue bordercolor:green
)
)
)
fn updateFG =
(
BoxShapes = updatepos BoxShapes
copy BlankBitmap ForegroundBitmap
drawfg boxshapes foregroundBitmap
copy BackgroundBitmap MidgroundBitmap
compositeCanvas MidgroundBitmap ForegroundBitmap
Canvas.bitmap = MidGroundBitmap
)
fn updateBG =
(
BoxShapes = updatepos BoxShapes
copy WhiteBitmap BackgroundBitmap
drawbg boxshapes BackgroundBitmap
updateFG()
)
on clock tick do
(
startfps = timestamp()
(
if selectionchangedvar == 1 do
(
updateBG()
selectionchangedvar = 0
gc light:true
)
updateFG()
)
endfps = timestamp()
dif = ((endfps-startfps)+1)
fpsNumber.text = ((1000/dif) as string)
print $.center
)
on BoxDrawing open do
(
updateFGStatus boxshapes
callbacks.addscript #selectionsetchanged "BoxShapes = getboxes(); updateFGStatus boxshapes; selectionchangedvar = 1;" id:#FGChangeCallback
updateBG()
)
on BoxDrawing close do
(
callbacks.removescripts #selectionsetchanged id:#FGChangeCallback
)
)
createDialog BoxDrawing (bitmapX+22) (bitmapY+45)
)
Edit: Oh it is rendering fine… it’s a limitation of the $.pos call. I guess $.pos doesn’t get updated in RT very well. So it’s not in the render code but just a limitation of the temporary “use scene objects as interface drivers”.
Page 4 / 4
Prev