File: progressbar.cc

package info (click to toggle)
performous 0.7.0%2Bgit20140715-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 7,900 kB
  • ctags: 3,470
  • sloc: cpp: 16,647; sh: 2,495; ansic: 2,015; python: 431; xml: 407; objc: 245; makefile: 12
file content (45 lines) | stat: -rw-r--r-- 1,373 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "progressbar.hh"

#include "util.hh"

#include <stdexcept>

ProgressBar::ProgressBar(fs::path const& bg, fs::path const& bar, Mode mode, float begin, float end, bool sliding):
  m_bg(bg), m_bar(bar), m_mode(mode), m_begin(begin), m_end(end), m_sliding(sliding), dimensions(m_bg.dimensions)
{}

void ProgressBar::draw(float value) {
	value = clamp(value);
	float scale = 1.0f - m_begin - m_end;
	float off = (1.0f - value) * scale;  // Offset for sliding mode
	m_bg.draw(dimensions);
	switch (m_mode) {
	  case HORIZONTAL:
		{
			Dimensions dim = dimensions;
			TexCoords tex;
			if (m_sliding) { dim.move(-off * dim.w(), 0.0f); tex.x1 = m_begin + off; }
			else { tex.x1 = m_begin; tex.x2 = tex.x1 + value * scale; }
			m_bar.drawCropped(dim, tex);
		}
		break;
	  case VERTICAL:
		{
			Dimensions dim = dimensions;
			TexCoords tex;
			if (m_sliding) { dim.move(0.0f, off * dim.h()); tex.y2 = 1.0f - m_begin - off; }
			else { tex.y2 = 1.0f - m_begin; tex.y1 = tex.y2 - value * scale; }
			m_bar.drawCropped(dim, tex);
		}
		break;
	  case CIRCULAR:
		{
			UseTexture texblock(m_bar);
			throw std::logic_error("ProgressBar::draw(): CIRCULAR not implemented yet");  // TODO: Implement
		}
		break;
	  default: throw std::logic_error("ProgressBar::draw(): unknown m_mode value");
	}
	// Reset dimensions due to async image loading
	dimensions = m_bg.dimensions;
}