src/gui/EnergyBar.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  *Energy bar.
00020  *****************************************************************************/
00021 
00022 #include <iostream>
00023 #include <sstream>
00024 #include "EnergyBar.h"
00025 #include "../tool/resource_manager.h"
00026 
00027 static const int energy_step[EnergyBar::NB_OF_ENERGY_COLOR] = { 16, 33, 50, 67, 84, 100 };
00028 
00029 EnergyBar::EnergyBar() : ProgressBar()
00030 {
00031   Profile *res = resource_manager.LoadXMLProfile("graphism.xml", false);
00032   for(int i = 0; i < NB_OF_ENERGY_COLOR ;i++) {
00033     std::ostringstream color_name;
00034     color_name << "energy_bar/energy_color_" << energy_step[i] << "_percent";
00035     colors_value[i] = resource_manager.LoadColor(res, color_name.str());
00036   }
00037 }
00038 
00039 Color EnergyBar::GetColorValue(long app_energy) const
00040 {
00041   for(int i = 0; i < NB_OF_ENERGY_COLOR - 1; ++i) {
00042     if(energy_step[i] > ((float)app_energy / GetMaxVal()) * 100)
00043       return colors_value[i];
00044   }
00045   return colors_value[NB_OF_ENERGY_COLOR - 1];
00046 }
00047 
00048 void EnergyBar::Actu (long real_energy){
00049   long app_energy;
00050 
00051   /* update progress bar position*/
00052   ProgressBar::UpdateValue(real_energy);
00053 
00054   /* get the real applied enargie value. It may be different from the
00055    * real_energy in case of under/over flow*/
00056   app_energy = ProgressBar::GetVal();
00057 
00058   SetValueColor(GetColorValue(app_energy));
00059 }

Generated on Mon Jan 1 13:10:57 2007 for Wormux by  doxygen 1.4.7