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

Go to the SVN repository for this file.

1 /* $Id: progress_panel.cpp 31681 2014-11-05 14:32:56Z falkrb $
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: Andrey Yazhuk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
35 
36 #include <gui/opengl/glhelpers.hpp>
37 
38 #include <math.h>
39 
41 
42 
43 ///////////////////////////////////////////////////////////////////////////////
44 /// CProgressPanel
46 : m_Font(CGlTextureFont::eFontFace_Helvetica, 12),
47  m_Progress(0)
48 {
49 }
50 
51 
53 {
54 }
55 
56 
57 void CProgressPanel::Update(float progress, const string& msg)
58 {
59  m_Progress = progress;
60  m_Message = msg;
61 }
62 
63 
64 const static double kAlpha = 0.9;
65 const static int kPrOff = 4; // progress bar offset
66 const static int kPrH = 10; // progress bar height
67 
69 {
70  CGlAttrGuard guard(GL_LINE_BIT | GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT );
71 
72  pane.OpenPixels();
73 
74  glEnable(GL_BLEND);
75  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
76 
77  glEnable(GL_LINE_SMOOTH);
78  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
79 
80  int x1 = m_VPRect.Left();
81  int y1 = m_VPRect.Bottom();
82  int x2 = m_VPRect.Right();
83  int y2 = m_VPRect.Top();
84 
85  glColor4d(0.9, 0.9, 0.9, kAlpha);
86  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
87  glRectd(x1, y1, x2, y2);
88 
89  glColor4d(0.5, 0.5, 0.5, kAlpha);
90  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
91  glRectd(x1, y1, x2, y2);
92 
93  TVPPoint pt = PreferredSize();
94  if(m_VPRect.Width() >= pt.X() && m_VPRect.Height() >= pt.Y()) {
95  ///draw progress bar
96  int pr_x1 = x1 + kPrOff;
97  int pr_x2 = x2 - kPrOff;
98  int pr_y1 = y1 + kPrOff;
99  int pr_y2 = pr_y1 + kPrH - 1;
100 
101  // background
102  glColor4d(0.8, 0.8, 1.0, kAlpha);
103  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
104  glRectd(pr_x1, pr_y1, pr_x2, pr_y2);
105 
106  // completed bar
107  glColor4d(0.5, 0.5, 1.0, kAlpha);
108  int w = int((x2 - x1 - 2 * kPrOff) * m_Progress);
109  glRectd(pr_x1, pr_y1, pr_x1 + w - 1, pr_y2);
110 
111  // countour
112  glColor4d(0.0, 0.0, 1.0, kAlpha);
113  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
114  glRectd(pr_x1, pr_y1, pr_x2, pr_y2);
115 
116  // text message
117  glColor4d(0.2, 0.2, 0.2, 1.0);
118  m_Font.TextOut(pr_x1, pr_y2 + kPrOff, pr_x2, y2 - kPrOff,
120  }
121 
122  pane.Close();
123 }
124 
125 
127 {
128  int w = kPrOff * 2 + 20;
129  int h = kPrOff * 3 + kPrH + int(ceil(m_Font.TextHeight()));
130  return TVPPoint(w, h);
131 }
132 
133 
CGlAttrGuard - guard class for restoring OpenGL attributes.
Definition: glutils.hpp:130
class CGlPane
Definition: glpane.hpp:62
virtual TVPPoint PreferredSize()
CGlTextureFont m_Font
virtual void Render(CGlPane &pane)
virtual void Update(float progress, const string &msg)
virtual ~CProgressPanel()
CProgressPanel()
CProgressPanel.
T X() const
Definition: glpoint.hpp:59
T Height() const
Definition: glrect.hpp:90
CGlPoint< TVPUnit > TVPPoint
Definition: gltypes.hpp:50
T Top() const
Definition: glrect.hpp:84
T Bottom() const
Definition: glrect.hpp:82
T Width() const
Definition: glrect.hpp:86
bool OpenPixels()
Definition: glpane.hpp:432
T Right() const
Definition: glrect.hpp:83
T Left() const
Definition: glrect.hpp:81
T Y() const
Definition: glpoint.hpp:60
void Close(void)
Definition: glpane.cpp:178
virtual TModelUnit TextHeight(void) const
virtual void TextOut(const char *text) const
TextOut interface Write the specified text and set up state and transformation as needed.
@ eAlign_Left
Definition: glfont.hpp:102
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
static const double kAlpha
static const int kPrOff
static const int kPrH
Modified on Sat Dec 02 09:21:35 2023 by modify_doxy.py rev. 669887