NCBI C++ ToolKit
ind_progress_bar.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: ind_progress_bar.cpp 35341 2016-04-26 18:51:00Z katargir $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 
33 
36 
37 #include <wx/dcmemory.h>
38 #include <wx/dcclient.h>
39 
41 
42 ///////////////////////////////////////////////////////////////////////////////
43 /// CMessageSlot
44 
45 BEGIN_EVENT_TABLE(CIndProgressBar, wxControl)
46  EVT_PAINT(CIndProgressBar::OnPaint)
47  EVT_TIMER(-1, CIndProgressBar::OnTimer)
49 
50 
51 CIndProgressBar::CIndProgressBar(wxWindow* parent, wxWindowID id, const wxPoint& pos, int width)
52 : m_Timer(this), m_CurPos(0), m_BmWidth(100)
53 {
54  Create(parent, id, pos, width);
55 }
56 
57 void CIndProgressBar::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, int width)
58 {
59  static bool bitmap_registered = false;
60  if (! bitmap_registered) {
62  wxT("progress_bar::barberpole"),
63  wxT("barberpole.png"));
64  bitmap_registered = true;
65  }
66 
67  m_Bitmap = wxArtProvider::GetBitmap(wxT("progress_bar::barberpole"));
68 
69  int height = 9;
70  if (m_Bitmap.IsOk()) {
71  height = m_Bitmap.GetHeight();
72  m_BmWidth = m_Bitmap.GetWidth();
73  }
74 
75  wxControl::Create(parent, id, pos, wxSize(width, height + 4), wxBORDER_NONE, wxDefaultValidator, wxT("ind_progress_bar"));
76 
77  SetBackgroundStyle(wxBG_STYLE_CUSTOM);
78 
79  Enable(false);
80 
81  m_Timer.Start(50);
82 }
83 
84 
85 void CIndProgressBar::OnPaint(wxPaintEvent& WXUNUSED(event))
86 {
87  wxSize size = GetClientSize();
88  wxCoord width = size.GetWidth(), height = size.GetHeight();
89 
90  wxColour bkgColor = GetParent()->GetBackgroundColour();
91 
92  wxBitmap bitmap(width, height);
93 
94  wxMemoryDC memdc;
95  memdc.SelectObject( bitmap );
96  memdc.SetPen(bkgColor);
97  memdc.SetBrush(bkgColor);
98  memdc.DrawRectangle(0, 0, width, height);
99 
100  if (m_Bitmap.IsOk())
101  height = m_Bitmap.GetHeight() + 4;
102  wxCoord y = (size.GetHeight() - height) / 2;
103 
104  memdc.SetPen( *wxBLACK_PEN );
105  memdc.SetBrush( *wxWHITE_BRUSH );
106  memdc.DrawRectangle(0, y, width, height);
107 
108  if (m_Bitmap.IsOk()) {
109  memdc.SetClippingRegion( 2, y, width - 4, height);
110 
111  for (int pos = (m_CurPos - m_BmWidth + 1) + 2; pos < width - 2; pos += m_BmWidth) {
112  memdc.DrawBitmap(m_Bitmap, pos, y + 2);
113  }
114  }
115 
116  memdc.SelectObject( wxNullBitmap );
117 
118  wxPaintDC dc( this );
119  dc.DrawBitmap(bitmap, 0, 0);
120 }
121 
122 void CIndProgressBar::OnTimer(wxTimerEvent& WXUNUSED(event))
123 {
124  m_CurPos = (m_CurPos + 1) % m_BmWidth;
125  Refresh();
126 }
127 
void OnPaint(wxPaintEvent &event)
void Create(wxWindow *parent, wxWindowID id, const wxPoint &pos, int width)
void OnTimer(wxTimerEvent &event)
virtual void RegisterFileAlias(const wxArtID &anId, const wxArtClient &aClient, const wxSize &aSize, const wxString &aName, long aType=wxBITMAP_TYPE_ANY, int anIndex=-1)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
wxFileArtProvider * GetDefaultFileArtProvider()
Definition: wx_utils.cpp:334
#define const
Definition: zconf.h:232
Modified on Fri May 03 15:49:52 2024 by modify_doxy.py rev. 669887