Properly canvas attach to bottom of window

BlitzMax Forums/MaxGUI Module/Properly canvas attach to bottom of window

ima747(Posted 2010) [#1]
I need to attach 2 gadgets to the bottom of a window.

a scroll bar running along the entire bottom of the window, and a canvas just above that.

using
SetGadgetLayout(scrollBar, EDGE_ALIGNED, EDGE_ALIGNED, Null, EDGE_ALIGNED)
works fine for the scroll bar, it stays anchored to the bottom of the window. but the same layout for the canvas above it causes it to float away from the bottom.

If I use say a listbox instead of a canvas (just to test the layout) it stays anchored properly.

I know canvases can't be resized (I free the canvas and then re-create it in position after the EVENT_WINDOWSIZE fires to handle then new size) but is there any way to prevent it floating away, I think it's using relative size for all sides and not respecting the layout...


matibee(Posted 2010) [#2]
I know canvases can't be resized


Really? I'm calling SetGadgetShape and resetting the viewport without problems.


ima747(Posted 2010) [#3]
intersting, if they can be resized then why don't they resize with the window? are you using the default driver on windows by any chance? I'm currently testing on mac, but I plan on this project being cross platform and will be forcing openGL driver on windows as well...


matibee(Posted 2010) [#4]
Yes I'm using the default Windows stuff and I've not tested on Mac yet. My canvas is embedded in a tab view with SetGadgetLayout(1,1,1,1) and they resize automatically just fine. I was calling SetGadgetShape manually but I've just checked and it was actually redundant.


ima747(Posted 2010) [#5]
My suspicion is that it works in directX, but not openGL... could you do me a favor and throw
SetGraphicsDriver GLMax2DDriver()
at the top of your window create code to see what happens?

also, what happens if you don't attach one side to the window frame, so it resizes width but not height for example? specifically detach the top so it should follow the bottom of the window during resize...


matibee(Posted 2010) [#6]
My suspicion is that it works in directX, but not openGL... could you do me a favor and throw
SetGraphicsDriver GLMax2DDriver()
at the top of your window create code to see what happens?


Tried that. Everything worked fine, no change.

also, what happens if you don't attach one side to the window frame, so it resizes width but not height for example? specifically detach the top so it should follow the bottom of the window during resize...


That was strange. I make my gadgets "any old size" at creation time, and a use a function that works out all their positions and re-shapes them. The same function is used when the window is resized.

By setting the layout to 1,1,0,1 the canvas actually appeared to have the top pixel aligned to the bottom of the parent client area. There was just one row of pixels visible. I tried lots of canvas sizes and when making a canvas any smaller than the parent gadget the behaviour is very confusing.

Do have some simple test code? My canvas management is wrapped into a specialised canvas type.


ima747(Posted 2010) [#7]
Found a couple of typos in my code that seem to be responsible for the glitching... kind of strange to me still, but I'll get over it.

However the auto resize does not properly resize the graphics context. I get corruption in the graphics area outside of the bounds it was initially created with. SetGadgetShape is not properly resizing the context either. My solution is to continue to use the freegadget and re-create it after the resize. The graphics area seems to vanish while the window is resizing anyway so it's not that big a deal.


ima747(Posted 2010) [#8]
edit: fixed this post content


matibee(Posted 2010) [#9]
To avoid the glitching when you resize the graphics context you have to reset the viewport, so I just set the viewport on every draw message;

SetGraphics CanvasGraphics( canvas )
SetViewport( 0, 0, canvas.ClientWidth(), canvas.ClientHeight() )


I'm not sure what you're trying to do here or I could be of more help. If you want to limit the position of the canvas inside the client of its parent control, why not do it manually? Along the lines of...

SetGadgetShape( canvas, GadgetX( parent ) + 10, GadgetY( parent ) + 10, GadgetWidth( parent ) - 20, GadgetHeight( parent ) - 20 )



ima747(Posted 2010) [#10]
Not at the right computer right now, but I think the viewport thing is the last bit I need to get this smoothed out... I assumed the viewport would get scaled along with the context.

Thanks for all the responses, it's been most helpful!