sliding menu 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
phlow
In need of some credit
In need of some credit
Posts: 8
Joined: Tue Jul 15, 2008 9:05 pm

sliding menu

Post by phlow » Mon Jul 28, 2008 9:54 pm

hi all

Ive been trying to figure out the best way how to create a sliding bit map. when i press button the menu should slide from the right hand side as shown in the picture.

Im really looking for suggestion on how to improver

this is my tempt so far

Code: Select all


class Panel : public wxPanel
{
    
	public:
    	Panel(Frame *parent);
    	void OnPaint(wxPaintEvent& evt);
    	void OnTimer(wxTimerEvent& event);
    private:
    	int x;
    	wxBitmap background;
    	wxTimer *timer;
    	DECLARE_EVENT_TABLE();
};

BEGIN_EVENT_TABLE(Panel, wxPanel)
	EVT_TIMER(ID_Timer,Panel::OnTimer)
	EVT_PAINT(Panel::OnPaint)
END_EVENT_TABLE()

IMPLEMENT_APP(Converter)

bool Converter::OnInit()
{
	wxInitAllImageHandlers();
	
	Frame *frame = new Frame(wxT("Converter"));
	Panel *panel =  new Panel(frame);
	frame->Show(true);
	
	return true;
}

Frame::Frame(const wxString& title)
	:wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(485, 510))
{
    //Panel *panel =  new Panel (this);
    //panel->SetFocus();
	Center();	
}

Panel::Panel(Frame *parent)
	:wxPanel(parent, wxID_ANY)
{
	x = 486;
	background = wxBitmap(wxT("slide.png"), wxBITMAP_TYPE_PNG);
	timer = new wxTimer(this, ID_Timer);
	timer->Start(2);
}

void Panel::OnPaint(wxPaintEvent& WXUNUSED(event))
{
	wxAutoBufferedPaintDC dc (this);
	//dc.DrawBitmap(background, x, 0, true);
	//dc.DrawText(wxT("PHLOW"),x+40,460);
}

void Panel::OnTimer(wxTimerEvent& event)
{
	wxClientDC dc (this);
	if(x > 1)
	{
		x -= 5;
		dc.DrawBitmap(background, x, 0, true);
		//RefreshRect(wxRect(0,0,485,4482));
		
	}
	else
	{
		x = 0;
		//Refresh();
		//RefreshRect(wxRect(0,0,485,4482));
		dc.DrawBitmap(background, x, 0, true);
		timer->Stop();
	}
}
Attachments
slide.png

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: sliding menu

Post by Auria » Mon Jul 28, 2008 11:56 pm

you say you want it to improve, but what is currently wrong?

phlow
In need of some credit
In need of some credit
Posts: 8
Joined: Tue Jul 15, 2008 9:05 pm

Post by phlow » Tue Jul 29, 2008 12:34 am

sorry for not being clear
Problems
-When i use Refresh() on windows there are some lines all over the window, and Im not sure how to slide the windows back(after sliding it forward) without using refresh();

is there anyway to make a panel fully transparent i wanted to avoid cutting the the portion of the image the panel will be covering and painting it back to the panel

priyank_bolia
wxWorld Domination!
wxWorld Domination!
Posts: 1339
Joined: Wed Aug 03, 2005 8:10 am
Location: BANGALORE, INDIA
Contact:

Post by priyank_bolia » Tue Jul 29, 2008 4:50 am

regarding transparency just make the frame non-rectangular, just look at the wxWidgets sample "shaped" or at my sample:
http://forums.wxwidgets.org/viewtopic.php?t=10824

Regarding refresh try with wxBufferedDC and see if it helps.

eranif
Moderator
Moderator
Posts: 607
Joined: Tue Nov 29, 2005 7:10 pm
Location: Israel

Post by eranif » Tue Jul 29, 2008 5:08 am

Hi,
Some comments:
1. I would avoid drawing outside the OnPaint, so: in the OnTimer simply call Refresh() - to trigger OnPaint event

2.Use wxAutoBufferedPaintDC in the OnPaint - like you are using it now, it will provide you with smooth - non flicker drawing

3. You must also handle the EVT_ERASE_BACKGROUND like this:

Try this:

Code: Select all

EVT_ERASE_BACKGROUND(Panel::OnEraseBg)
...
void Panel::OnEraseBg(wxEraseEvent &e) { wxUnusedVar(e);}
Eran
IDE: CodeLite + wxCrafter
OS: All
https://wxcrafter.codelite.org
https://codelite.org

phlow
In need of some credit
In need of some credit
Posts: 8
Joined: Tue Jul 15, 2008 9:05 pm

Post by phlow » Tue Jul 29, 2008 9:55 pm

priyank_bolia thanks for the reply but i already have a non-rectangular frame and the panel is not transparent, however im sure ill be able get the results i want even it i don't get the panel transparent.

eranif thanks very much i had already done step 1 and 2 earlier bun not 2 and yes it did fix the line problem thanks

Post Reply