If you have a cool piece of software to share, but you are not hosting it officially yet, please dump it in here. If you have code snippets that are useful, please donate!
It is truth universally acknowledged, that background images in wxWindows need to be painted in the erase event handler.
Rather than deriving individually from all those classes that may be suitable to display a background image, to setup the event table etc., it is far simpler to create one event handler class once and for all, which can be used with any wxWindow derived class.
But to make it usable in more situations, it'd definitely need a tile- and stretchmode for cases when the client-area is bigger than the bitmap. Both should be trivial, tiling is simple and could be taken from htmlwin.cpp, stretching should be possible with wxDC::SetUserScale()
Personally i think it would be even better if it was part of the wxWindow class, like:
wxWindow::SetBackgroundBitmap(wxBitmap &bitmap, ...)
doublemax wrote:Personally i think it would be even better if it was part of the wxWindow class, like:
wxWindow::SetBackgroundBitmap(wxBitmap &bitmap, ...)
Though that would either require patching wxWidgets or require deriving new wxWindow classes for every type of wxWindow you want to use it with. I don't honestly think it would ever be applied in CVS, the devs are already annoyed with the number of existing wxWindow methods. Also, this encourages all sorts of human interface guideline violations and falls under the category of skinning which is heavily discouraged by wxWidgets. Paulsen's version is probably the best way it could/should of been implemented.
public class wxBackgroundBitmap : wx.EvtHandler
{
protected wx.Bitmap bitmap;
public wxBackgroundBitmap(wx.Bitmap bitmap)
{
this.bitmap = bitmap;
}
public new bool ProcessEvent(wx.Event e){
if(e.EventType == wx.Event.wxEVT_ERASE_BACKGROUND){
wx.EraseEvent eraseEvent = (wx.EraseEvent)e;
eraseEvent.DC.DrawBitmap(bitmap,0,0,false);
return true;
}
else return base.ProcessEvent(e);
}
}
There is however one problem, which should perhaps be resolved by the developpers of wx.NET
The EvtHandler class has an internal constructor. in the c++ version it's a public constructor, so I think this might have been an error.
// wxIdleOnceEvtHandler by Troels K 2006
// Thanks to Volker Bartheld and Belgabor.
// define a new handler type that will deal with the wxEVT_IDLE event when it arrives in the queue for the *FIRST* time
extern const wxEventType wxEVT_IDLE_ONCE;
#define EVT_IDLE_ONCE(func) wx__DECLARE_EVT0(wxEVT_IDLE_ONCE, wxIdleEventHandler(func))
class wxIdleOnceEvtHandler : public wxEvtHandler
{
public:
wxEvtHandler* m_target;
wxWindow * m_target_wnd;
wxIdleOnceEvtHandler(wxEvtHandler* target);
wxIdleOnceEvtHandler(wxWindow * target);
virtual ~wxIdleOnceEvtHandler();
virtual bool ProcessEvent(wxEvent&);
bool IsFired() const { return !GetEvtHandlerEnabled(); }
void Stop(void);
};
Yes, this is typical. I also try to set a background image in a wxFrame.
But it does not work. I noticed, that when I make the background image much more greater in size, then, the image will blink for a short time (less then 1second). But then disappeared for ever.
I used code direct from the example, which works on my machine. Sample: "sample\dragimag".
What I use to do is to close all the unnecessary panels of the debugger, i.e. Visual Studio then resize it to take the first vertical half of the screen, and then resize the application to take the other half of the screen. This way, when a break point is reached in the debugger the application screen will not be overlapped and when you come out of the debugger, a paint event will not be fired by the application. I think this should be clear to understand, though my English is not that good.
Yes, but I dont have and I dont use VisualC/Debugger.
Anyway, the Problem is solved now. What I did is draw the background, then a panel, on this panel are buttons. So, the background was removed / not seen on the window because of the panel.
The idea was, to have a full-screen-panel for wxFrame or wxWindows just to draw a background (can also use setBackgroundColour.)
priyank_bolia wrote:
* How to debug such things (GUI)?
What I use to do is to close all the unnecessary panels of the debugger, i.e. Visual Studio then resize it to take the first vertical half of the screen, and then resize the application to take the other half of the screen. This way, when a break point is reached in the debugger the application screen will not be overlapped and when you come out of the debugger, a paint event will not be fired by the application. I think this should be clear to understand, though my English is not that good.
After a long time of meaning to implement this code I have finally tried it and I also had problems with the dynamic cast. I found that the following code works for me.
Because this gives you one class that can easily be plugged into standard wxWindow derived classes such as wxPanel with two lines of code rather than rewriting a new function or deriving a new class every time.
I have revisited the code above to implement stretching