wxButton on top of wxDC Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

wxButton on top of wxDC

Post by mael15 »

hi,

is it possible to have a button on top of a device context?
i would like to have a button that only shows on top of a dc when the mouse is within the dc.

thanx!
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

A device context is not a visible object, it's more like a helper class to paint onto windows, printers or into bitmaps.

So the expression "button on top of a dc" doesn't make much sense.

You could just put a button onto a wxPanel, catch the xEVT_ENTER_WINDOW and wxEVT_LEAVE_WINDOW event on the panel and show/hide the button as you like.
Use the source, Luke!
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Post by mael15 »

ok, in other words, i would like to have a button on top of an area i painted with wxPaintDC. is that possible?

maybe by putting the painted stuff in the window background somehow?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

Sure, put a button onto a wxPanel and do your drawing in that panel's paint event handler. The button will be clipped automatically, you can't "overdraw" it, even if you wanted.
Use the source, Luke!
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Post by mael15 »

alright, this worked, thanx!
.... BUT .... :)

as soon as i have a sizer in the wxScrolledWindow, according to http://docs.wxwidgets.org/2.8.8/wx_wxsc ... lledwindow it overrides the possibility to set the pageSize via setScrollbars or SetScrollPageSize. i tried a couple of workarounds but none worked :(

the final aim is to have a bitmap that can be scrolled and a slider for zooming the bitmap plus a button for opening a config menue in another window. the zoom slider and config button should not scroll with the image, so the sizer size schould always stay the same.

any ideas?
thanx!
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

I don't see why you'd put the button and the slider onto the image panel (which is probably your wxScrolledWindow)

I'd do it like this:

Code: Select all

main panel
-vertical sizer
--wxScrolledWindow
--horizontal sizer
---slider
---button
I hope this is clear enough ;)

But then the button wouldn't be on top of the image, which was your initial question, so i'm not sure if this is what you want.
Use the source, Luke!
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Post by mael15 »

i was thinking about something like in google maps, where you have the zoomSlider and the buttons on top of the map. slider and buttons always stay in the same position, only the picture below is moved by scrollbars or dragging.

do you think this is possible with wxWidgets?
thank you for your input and time!
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

Possible, but will be some work if you want something that looks good ;)

Major downside when using standard controls for button and slider: The background can't shine through transparently or even with a mask. Especially the slider will look ugly when put above a custom background (your image).

Option 1:
use wxScrolledWindow for image display
don't use sizers
place controls at absolute position
when window scrolls, adjust controls' position so that they appear to be stationary

Disadvantage: Position of the controls will flicker (totally unacceptable IMO)

Option 2:
use normal wxPanel for image display
put separate wxScrollBars above and next to panel using sizer (if you really need them, Google maps doesn't have them)

Advantage: Position of the controls will not flicker
Disadvantage: You have to code everything yourself what usually wxScrolledWindow would do for you: Handling virtual area, scroll position, scrollbar handling etc.
Standard controls will still look ugly

Option 3 (What i'd do):
Like 2), but even code the controls (button, slider) yourself and render them yourself when you render the image

You might be tempted to use a wxScrolledWindow together with custom drawn controls, but there will be a problem:
When you scroll only one line in any direction, the OS will just copy the content of the window and send a redraw request only for the small stripe that actually changed. But when you have stationary content over a dynamic background you need to do a full redraw each time. If you manually force a full redraw on each scroll event, you'll get heavy flicker again.
Use the source, Luke!
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Post by mael15 »

that is exactly what i needed to know, thanx!

for now, i will avoid the slider, only zoom with plus and minus buttons in a sizer, and enable moving the image only by dragging it (no scrollbars).
maybe i will have time for a more perfect version later.
Post Reply