summaryrefslogtreecommitdiff
path: root/src/progress.cxx
blob: 0b4713a360f8439ebbe17a13460b449318801944 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * This file is part of the planetblupi source code
 * Copyright (C) 1997, Daniel Roux & EPSITEC SA
 * Copyright (C) 2017-2018, Mathieu Schroeter
 * http://epsitec.ch; http://www.blupi.org; http://github.com/blupi-games
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://gnu.org/licenses
 */

#include <stdio.h>
#include <stdlib.h>

#include "decor.h"
#include "def.h"
#include "misc.h"
#include "pixmap.h"
#include "progress.h"
#include "sound.h"

CJauge::CJauge ()
{
  m_type    = 0;
  m_bHide   = true;
  m_pPixmap = nullptr;
  m_pDecor  = nullptr;
  m_pSound  = nullptr;
}

CJauge::~CJauge () {}

// Crée un nouveau bouton.

bool
CJauge::Create (CPixmap * pPixmap, CSound * pSound, Point pos, Sint32 type)
{
  m_pPixmap = pPixmap;
  m_pSound  = pSound;
  m_type    = type;
  m_bHide   = true;
  m_pos     = pos;
  m_dim.x   = DIMJAUGEX;
  m_dim.y   = DIMJAUGEY;
  m_level   = 0;

  return true;
}

// Dessine un bouton dans son état.

void
CJauge::Draw ()
{
  Sint32 part;
  Rect   rect;

  if (m_bHide) // bouton caché ?
  {
    rect.left   = m_pos.x;
    rect.right  = m_pos.x + m_dim.x;
    rect.top    = m_pos.y;
    rect.bottom = m_pos.y + m_dim.y;
    m_pPixmap->DrawPart (-1, CHBACK, m_pos, rect); // dessine le fond
    return;
  }

  part = (m_level * (DIMJAUGEX - 6 - 4)) / 100;

  rect.left   = 0;
  rect.right  = DIMJAUGEX;
  rect.top    = DIMJAUGEY * 0;
  rect.bottom = DIMJAUGEY * 1;
  m_pPixmap->DrawPart (-1, CHJAUGE, m_pos, rect); // partie noire

  if (part > 0)
  {
    rect.left   = 0;
    rect.right  = 6 + part;
    rect.top    = DIMJAUGEY * m_type;
    rect.bottom = DIMJAUGEY * (m_type + 1);
    m_pPixmap->DrawPart (-1, CHJAUGE, m_pos, rect); // partie colorée
  }
}

// Modifie le niveau.

void
CJauge::SetLevel (Sint32 level)
{
  if (level < 0)
    level = 0;
  if (level > 100)
    level = 100;

  m_level = level;
}

// Modifie le type.

void
CJauge::SetType (Sint32 type)
{
  m_type = type;
}

bool
CJauge::GetHide ()
{
  return m_bHide;
}

void
CJauge::SetHide (bool bHide)
{
  m_bHide = bHide;
}

Point
CJauge::GetPos ()
{
  return m_pos;
}