barber pole type progress bar

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
bobmanc
Experienced Solver
Experienced Solver
Posts: 69
Joined: Mon Oct 04, 2004 9:27 pm

barber pole type progress bar

Post by bobmanc » Fri Sep 02, 2005 1:05 pm

Anyone have code to create a progress dialog that shows a barber pole (or similar animated graphic) for when you dont know how long and operation might take?

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

Post by priyank_bolia » Fri Sep 02, 2005 1:24 pm

Just derive a class from wxGauge add a timer and move/increment the progress bar, when its reached the last value, sets again the value to 0.

AkiraDev
Knows some wx things
Knows some wx things
Posts: 48
Joined: Tue May 24, 2005 9:13 am

Re: barber pole type progress bar

Post by AkiraDev » Fri Sep 02, 2005 2:19 pm

bobmanc wrote:Anyone have code to create a progress dialog that shows a barber pole (or similar animated graphic) for when you dont know how long and operation might take?
Sure enough, someone already implement just what you ask... Just check under the Code Dump section:

http://forums.wxwidgets.org/viewtopic.php?t=3655

Regards
Back, just not as often

Windows Vista SP1, Ubuntu 8.04
MinGW 3.4.5, GCC 4.2.1
Code::Blocks
wxWidgets 2.8.9

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

Post by priyank_bolia » Fri Sep 02, 2005 2:41 pm

I had also quickly written one, its very poor, but shows you how to write your own custom one:

wxProgressBar.h

Code: Select all

#pragma once
#include "stdwx.h" 

class wxProgressBar : public wxControl
{
private:
	//Start of Enum
	enum
	{
		//GUI Enum Control ID Start
		ID_CALL_TIMER = 1234,
		//GUI Enum Control ID End
		ID_DUMMY_VALUE_ //Dont Delete this DummyValue
	}; 
	//End of Enum
	wxBitmap m_bitmap;
    wxTimer* m_pCallTimer;
	int nPos;
	bool m_bAdd;
public:
	wxProgressBar( wxWindow* parent, wxWindowID id, const wxBitmap& bitmap, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = "Progress Bar");
	virtual ~wxProgressBar(void);
private:
    void OnPaint(wxPaintEvent & event);
	void OnCallTimer(wxTimerEvent& WXUNUSED(event));
private:
	DECLARE_EVENT_TABLE()
};
wxProgressBar.cpp

Code: Select all

#include "wxprogressbar.h"

BEGIN_EVENT_TABLE(wxProgressBar, wxControl)
	EVT_PAINT(wxProgressBar::OnPaint)
	EVT_TIMER(ID_CALL_TIMER, wxProgressBar::OnCallTimer)
END_EVENT_TABLE()

wxProgressBar::wxProgressBar( wxWindow* parent, wxWindowID id, const wxBitmap& bitmap, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name)
{
	wxControl::Create(parent, id, pos, size, style, validator, name);
	m_bitmap = bitmap;
	nPos = 0;
	m_bAdd = true;
	m_pCallTimer = new wxTimer(this, ID_CALL_TIMER);
	m_pCallTimer->Start(350);
}

wxProgressBar::~wxProgressBar(void)
{
	m_pCallTimer->Stop();
	delete m_pCallTimer;
}

void wxProgressBar::OnCallTimer(wxTimerEvent& WXUNUSED(event))
{
    wxSize appSize = this->GetSize();
	if((nPos+m_bitmap.GetWidth()) > appSize.GetWidth())
		m_bAdd = false;
	else if((nPos-m_bitmap.GetWidth()) < 0)
		m_bAdd = true;
	if(m_bAdd)
		nPos += m_bitmap.GetWidth();
	else
		nPos -= m_bitmap.GetWidth();
	Refresh();
}

void wxProgressBar::OnPaint(wxPaintEvent & event)
{
        wxPaintDC dc(this);
		dc.DrawBitmap(m_bitmap, nPos, 0);
}
To use it:
Put this in the .h file:

Code: Select all

	wxProgressBar *m_pProgressBar;
	enum
	{
		//GUI Enum Control ID Start
		ID_WXPROGRESSBAR = 1000,
	}; 
Put this in the .cpp file:

Code: Select all

	m_pProgressBar = new wxProgressBar(this, ID_WXPROGRESSBAR, wxBitmap("res\\progressbar.png", wxBITMAP_TYPE_PNG), wxPoint(20, 40), wxSize(100, 22));
Image

Post Reply