On 12/18/2012 05:35 PM, Vadim Zeitlin wrote:
> On Tue, 18 Dec 2012 17:29:25 -0800 Chris MacGregor wrote:
>
> CM> What I'm trying to accomplish (for an embedded device, using wxWidgets
> CM> 2.9.4 on Linux) is a full-screen app, with a bitmap (e.g. wxStaticBitmap
> CM> or similar) background behind everything (all controls).
>
> See
http://docs.wxwidgets.org/trunk/classwx_custom_background_window.html
>
> CM> What is the right solution here?
>
> Drawing the bitmap on the panel itself, as the class above does.
Hello again. Okay, wxCustomBackgroundWindow does seem to address this
(although I haven't tried it on Mac or Windows yet; apparently that's
not going to be pretty), although it's a bit finicky w.r.t. ordering of
operations and class hierarchy, such that in order to use it with
wxformbuilder-generated classes I had to use a gross hack involving
#define-ing wxPanel to wxPanelWithBackground and introducing "class
wxPanelWithBackground : public wxCustomBackgroundWindow <wxPanel>"...
However, there's a bit more to it. What I'm trying to build is a UI
wherein there is a constant top status bar (sorry, not a wxStatusBar,
just a little horizontal sizer with a clock and a battery icon and such)
and a constant bitmap background, and then various different pages
(sets, arrangements, etc.) of buttons and other controls. Imagine a
main menu page with a bunch of buttons, and when you click one the main
menu disappears and other buttons and controls appear, and so on across
many such pages. The only thing that is the same across all these pages
is the top status bar and the background.
I expected to be able to create a wxFrame with the top status bar and
the background, and then swap the various other pages in and out with
just one or two operations - hiding/showing or adding/removing a panel
or sizer or whatever. However, I've run into a few issues:
1. I can't put the background on the wxFrame (at least, not if I want to
use wxPanel for the pages), because the wxPanel's background covers up
the wxFrame's bitmap background. So apparently I would need to
separately put the background on each such wxPanel (each page in the
UI). Yuck. Do-able, yes, but yuck. I'm assuming I can at least share
the wxBitmap used for the purpose and the memory won't be consumed 30x
for 30 pages - if not, that's a big problem, because this is an embedded
device with limited RAM. It would be much better if I could just put
the background on one wxFrame and swap controls in and out of the frame
in groups (contained in a sizer would be fine, but then I think I'd run
into the issue in #3, below).
2. I tried using Hide() and Show() on the wxPanels containing the pages
of controls. There seems to be some kind of bug (or else I'm doing
something stupid, but this part is pretty straightforward, and I don't
see much I could be doing wrong), because when I hide one such panel and
show the other (both having been added to a sizer which also contains
the top status bar, or to a separate sizer added to the top level sizer
- it happens either way), showing the panel which was not originally
shown causes the top status bar to be hidden (as if I told it to hide
the whole sizer or something). OTOH, this is currently inside a
wxScrolledWindow ... hmmm. (Checking...) Well, okay, when I eliminate
the wxScrolledWindow (which is only used when simulating the device
target on a Linux desktop or Mac/Windows machine), that problem goes
away. So I guess this is related to the problem Hector noted - never mind.
3. I tried using Detach() and Add() to remove one panel (page of
controls) from the sizer and add another, but that seemed to just not
work. I'm guessing it's because I have a wxPanel that is a child of the
wxFrame but isn't included in the wxFrame's sizer, and as a result the
wxPanel that isn't in the sizer just gets displayed always, at (0,0).
So apparently this is not the right way to do things. (I'm a little
more accustomed to the GTK+ approach, wherein the VBoxes and HBoxes
(their sizers) are first-class controls, rather than completely
different objects.)
Overall, I'm getting the distinct impression that there should be - and
probably is - a "better" and easier way to accomplish what I'm trying to
do. Any clues would be appreciated.
Again, I just want an easy way to change out sets of controls in the
middle of the wxFrame en masse, ideally while maintaining a bitmap
background behind everything. The erase sample doesn't provide much
guidance for my problem, and it's the only sample that uses
wxCustomBackgroundWindow. The various BookCtrl flavors don't seem
suitable, because there shouldn't be an explicit page selector (tabs or
a listbox or anything of the sort). I don't see any other samples or
classes which seem to address the kind of thing I'm trying to do,
although it doesn't seem so unusual to me...but I may have overlooked a
relevant item, or overestimated the typical-ness of my application.
Happy holidays, and many thanks for any help,
Chris MacGregor (in Seattle, WA, USA)