2010-04-01 09:53:07 +02:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
//
|
2011-12-14 08:40:48 +01:00
|
|
|
// Copyright (C) 2001-2008 Martiño Figueroa
|
2010-04-01 09:53:07 +02:00
|
|
|
//
|
2010-12-21 06:07:10 +01:00
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
2010-04-01 09:53:07 +02:00
|
|
|
// License, or (at your option) any later version
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
#include "components.h"
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "metrics.h"
|
|
|
|
#include "core_data.h"
|
|
|
|
#include "platform_util.h"
|
2010-05-31 21:57:10 +02:00
|
|
|
#include "util.h"
|
2010-09-09 00:37:24 +02:00
|
|
|
#include "conversion.h"
|
2011-04-05 22:19:25 +02:00
|
|
|
#include "lang.h"
|
2010-04-01 09:53:07 +02:00
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
|
|
|
using namespace std;
|
2010-05-31 21:57:10 +02:00
|
|
|
using namespace Shared::Util;
|
2010-04-01 09:53:07 +02:00
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class GraphicComponent
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
float GraphicComponent::anim= 0.f;
|
|
|
|
float GraphicComponent::fade= 0.f;
|
|
|
|
const float GraphicComponent::animSpeed= 0.02f;
|
|
|
|
const float GraphicComponent::fadeSpeed= 0.01f;
|
2012-06-01 07:26:01 +02:00
|
|
|
// WHITE
|
|
|
|
Vec3f GraphicComponent::customTextColor = Vec3f(1.0,1.0,1.0);
|
2010-04-01 09:53:07 +02:00
|
|
|
|
2010-09-09 00:37:24 +02:00
|
|
|
std::map<std::string, std::map<std::string, GraphicComponent *> > GraphicComponent::registeredGraphicComponentList;
|
|
|
|
|
|
|
|
GraphicComponent::GraphicComponent(std::string containerName, std::string objName) {
|
|
|
|
instanceName = "";
|
|
|
|
if(objName != "") {
|
|
|
|
registerGraphicComponent(containerName,objName);
|
|
|
|
}
|
2010-09-11 08:08:50 +02:00
|
|
|
enabled = true;
|
|
|
|
editable = true;
|
|
|
|
visible = true;
|
2011-03-23 06:49:38 +01:00
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
w = 0;
|
|
|
|
h = 0;
|
|
|
|
text = "";
|
|
|
|
font = NULL;
|
2011-06-10 05:09:19 +02:00
|
|
|
font3D = NULL;
|
2010-04-01 09:53:07 +02:00
|
|
|
}
|
|
|
|
|
2010-09-09 23:07:39 +02:00
|
|
|
void GraphicComponent::clearRegisteredComponents(std::string containerName) {
|
|
|
|
if(containerName == "") {
|
|
|
|
GraphicComponent::registeredGraphicComponentList.clear();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GraphicComponent::registeredGraphicComponentList[containerName].clear();
|
|
|
|
}
|
2010-09-09 02:05:12 +02:00
|
|
|
}
|
|
|
|
|
2010-10-10 08:35:50 +02:00
|
|
|
void GraphicComponent::clearRegisterGraphicComponent(std::string containerName, std::string objName) {
|
|
|
|
GraphicComponent *obj = findRegisteredComponent(containerName, objName);
|
|
|
|
if(obj) {
|
|
|
|
GraphicComponent::registeredGraphicComponentList[containerName].erase(objName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicComponent::clearRegisterGraphicComponent(std::string containerName, std::vector<std::string> objNameList) {
|
|
|
|
for(int idx = 0; idx < objNameList.size(); ++idx) {
|
|
|
|
GraphicComponent::clearRegisterGraphicComponent(containerName, objNameList[idx]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-09 00:37:24 +02:00
|
|
|
void GraphicComponent::registerGraphicComponent(std::string containerName, std::string objName) {
|
|
|
|
instanceName = objName;
|
|
|
|
registeredGraphicComponentList[containerName][objName] = this;
|
2010-09-09 23:07:39 +02:00
|
|
|
|
2010-12-21 06:07:10 +01:00
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] registered [%s] [%s] count = %d\n",__FILE__,__FUNCTION__,__LINE__,containerName.c_str(),instanceName.c_str(),registeredGraphicComponentList[containerName].size());
|
2010-09-09 00:37:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GraphicComponent * GraphicComponent::findRegisteredComponent(std::string containerName, std::string objName) {
|
|
|
|
GraphicComponent *result = NULL;
|
|
|
|
|
|
|
|
std::map<std::string, std::map<std::string, GraphicComponent *> >::iterator iterFind1 = GraphicComponent::registeredGraphicComponentList.find(containerName);
|
|
|
|
if(iterFind1 != GraphicComponent::registeredGraphicComponentList.end()) {
|
|
|
|
std::map<std::string, GraphicComponent *>::iterator iterFind2 = iterFind1->second.find(objName);
|
|
|
|
if(iterFind2 != iterFind1->second.end()) {
|
|
|
|
result = iterFind2->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicComponent::applyAllCustomProperties(std::string containerName) {
|
|
|
|
std::map<std::string, std::map<std::string, GraphicComponent *> >::iterator iterFind1 = GraphicComponent::registeredGraphicComponentList.find(containerName);
|
|
|
|
if(iterFind1 != GraphicComponent::registeredGraphicComponentList.end()) {
|
|
|
|
for(std::map<std::string, GraphicComponent *>::iterator iterFind2 = iterFind1->second.begin();
|
2011-09-01 01:10:43 +02:00
|
|
|
iterFind2 != iterFind1->second.end(); ++iterFind2) {
|
2010-09-09 00:37:24 +02:00
|
|
|
iterFind2->second->applyCustomProperties(containerName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicComponent::applyCustomProperties(std::string containerName) {
|
|
|
|
if(instanceName != "") {
|
|
|
|
std::map<std::string, std::map<std::string, GraphicComponent *> >::iterator iterFind1 = GraphicComponent::registeredGraphicComponentList.find(containerName);
|
|
|
|
if(iterFind1 != GraphicComponent::registeredGraphicComponentList.end()) {
|
|
|
|
std::map<std::string, GraphicComponent *>::iterator iterFind2 = iterFind1->second.find(instanceName);
|
|
|
|
if(iterFind2 != iterFind1->second.end()) {
|
|
|
|
Config &config = Config::getInstance();
|
|
|
|
|
2011-04-05 22:19:25 +02:00
|
|
|
//string languageToken = config.getString("Lang");
|
|
|
|
string languageToken = Lang::getInstance().getLanguage();
|
2010-09-09 08:42:39 +02:00
|
|
|
|
2010-09-09 00:37:24 +02:00
|
|
|
//if(dynamic_cast<GraphicButton *>(iterFind2->second) != NULL) {
|
|
|
|
GraphicComponent *ctl = dynamic_cast<GraphicComponent *>(iterFind2->second);
|
2010-09-09 08:42:39 +02:00
|
|
|
|
|
|
|
// First check default overrides
|
2010-09-09 00:37:24 +02:00
|
|
|
ctl->x = config.getInt(containerName + "_" + iterFind2->first + "_x",intToStr(ctl->x).c_str());
|
|
|
|
ctl->y = config.getInt(containerName + "_" + iterFind2->first + "_y",intToStr(ctl->y).c_str());
|
|
|
|
ctl->w = config.getInt(containerName + "_" + iterFind2->first + "_w",intToStr(ctl->w).c_str());
|
|
|
|
ctl->h = config.getInt(containerName + "_" + iterFind2->first + "_h",intToStr(ctl->h).c_str());
|
2011-10-04 22:18:57 +02:00
|
|
|
ctl->visible = config.getBool(containerName + "_" + iterFind2->first + "_visible",boolToStr(ctl->visible).c_str());
|
2010-09-09 08:42:39 +02:00
|
|
|
|
|
|
|
// Now check language specific overrides
|
|
|
|
ctl->x = config.getInt(containerName + "_" + iterFind2->first + "_x_" + languageToken, intToStr(ctl->x).c_str());
|
|
|
|
ctl->y = config.getInt(containerName + "_" + iterFind2->first + "_y_" + languageToken, intToStr(ctl->y).c_str());
|
|
|
|
ctl->w = config.getInt(containerName + "_" + iterFind2->first + "_w_" + languageToken, intToStr(ctl->w).c_str());
|
|
|
|
ctl->h = config.getInt(containerName + "_" + iterFind2->first + "_h_" + languageToken, intToStr(ctl->h).c_str());
|
2011-10-04 22:18:57 +02:00
|
|
|
ctl->visible = config.getBool(containerName + "_" + iterFind2->first + "_visible_" + languageToken,boolToStr(ctl->visible).c_str());
|
2010-09-09 08:42:39 +02:00
|
|
|
|
2010-09-09 00:37:24 +02:00
|
|
|
//}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-09 23:07:39 +02:00
|
|
|
bool GraphicComponent::saveAllCustomProperties(std::string containerName) {
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] registered [%s] count = %d\n",__FILE__,__FUNCTION__,__LINE__,containerName.c_str(),registeredGraphicComponentList[containerName].size());
|
|
|
|
|
|
|
|
bool foundPropertiesToSave = false;
|
|
|
|
std::map<std::string, std::map<std::string, GraphicComponent *> >::iterator iterFind1 = GraphicComponent::registeredGraphicComponentList.find(containerName);
|
|
|
|
if(iterFind1 != GraphicComponent::registeredGraphicComponentList.end()) {
|
|
|
|
for(std::map<std::string, GraphicComponent *>::iterator iterFind2 = iterFind1->second.begin();
|
2011-09-01 01:10:43 +02:00
|
|
|
iterFind2 != iterFind1->second.end(); ++iterFind2) {
|
2010-09-09 23:07:39 +02:00
|
|
|
bool saved = iterFind2->second->saveCustomProperties(containerName);
|
|
|
|
foundPropertiesToSave = (saved || foundPropertiesToSave);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(foundPropertiesToSave == true) {
|
|
|
|
Config &config = Config::getInstance();
|
|
|
|
config.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
return foundPropertiesToSave;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicComponent::saveCustomProperties(std::string containerName) {
|
|
|
|
bool savedChange = false;
|
|
|
|
if(instanceName != "") {
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] looking for [%s] [%s]\n",__FILE__,__FUNCTION__,__LINE__,containerName.c_str(),instanceName.c_str());
|
|
|
|
|
|
|
|
std::map<std::string, std::map<std::string, GraphicComponent *> >::iterator iterFind1 = GraphicComponent::registeredGraphicComponentList.find(containerName);
|
|
|
|
if(iterFind1 != GraphicComponent::registeredGraphicComponentList.end()) {
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] looking for [%s]\n",__FILE__,__FUNCTION__,__LINE__,instanceName.c_str());
|
|
|
|
|
|
|
|
std::map<std::string, GraphicComponent *>::iterator iterFind2 = iterFind1->second.find(instanceName);
|
|
|
|
if(iterFind2 != iterFind1->second.end()) {
|
|
|
|
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] FOUND [%s]\n",__FILE__,__FUNCTION__,__LINE__,instanceName.c_str());
|
|
|
|
|
|
|
|
Config &config = Config::getInstance();
|
|
|
|
|
|
|
|
//string languageToken = config.getString("Lang");
|
|
|
|
|
|
|
|
//if(dynamic_cast<GraphicButton *>(iterFind2->second) != NULL) {
|
|
|
|
GraphicComponent *ctl = dynamic_cast<GraphicComponent *>(iterFind2->second);
|
|
|
|
|
|
|
|
// First check default overrides
|
|
|
|
config.setInt(containerName + "_" + iterFind2->first + "_x",ctl->x);
|
|
|
|
config.setInt(containerName + "_" + iterFind2->first + "_y",ctl->y);
|
|
|
|
config.setInt(containerName + "_" + iterFind2->first + "_w",ctl->w);
|
|
|
|
config.setInt(containerName + "_" + iterFind2->first + "_h",ctl->h);
|
|
|
|
|
|
|
|
savedChange = true;
|
|
|
|
// Now check language specific overrides
|
|
|
|
//ctl->x = config.getInt(containerName + "_" + iterFind2->first + "_x_" + languageToken, intToStr(ctl->x).c_str());
|
|
|
|
//ctl->y = config.getInt(containerName + "_" + iterFind2->first + "_y_" + languageToken, intToStr(ctl->y).c_str());
|
|
|
|
//ctl->w = config.getInt(containerName + "_" + iterFind2->first + "_w_" + languageToken, intToStr(ctl->w).c_str());
|
|
|
|
//ctl->h = config.getInt(containerName + "_" + iterFind2->first + "_h_" + languageToken, intToStr(ctl->h).c_str());
|
|
|
|
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return savedChange;
|
|
|
|
}
|
|
|
|
|
2011-10-25 20:39:11 +02:00
|
|
|
void GraphicComponent::reloadFonts() {
|
|
|
|
font= CoreData::getInstance().getMenuFontNormal();
|
|
|
|
font3D= CoreData::getInstance().getMenuFontNormal3D();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicComponent::reloadFontsForRegisterGraphicComponents(std::string containerName) {
|
|
|
|
std::map<std::string, std::map<std::string, GraphicComponent *> >::iterator iterFind1 = GraphicComponent::registeredGraphicComponentList.find(containerName);
|
|
|
|
if(iterFind1 != GraphicComponent::registeredGraphicComponentList.end()) {
|
|
|
|
for(std::map<std::string, GraphicComponent *>::iterator iterFind2 = iterFind1->second.begin();
|
|
|
|
iterFind2 != iterFind1->second.end(); ++iterFind2) {
|
|
|
|
GraphicComponent *ctl = dynamic_cast<GraphicComponent *>(iterFind2->second);
|
|
|
|
if(ctl) {
|
|
|
|
ctl->reloadFonts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-09 08:42:39 +02:00
|
|
|
void GraphicComponent::init(int x, int y, int w, int h) {
|
2010-04-01 09:53:07 +02:00
|
|
|
this->x= x;
|
|
|
|
this->y= y;
|
|
|
|
this->w= w;
|
|
|
|
this->h= h;
|
2011-10-25 20:39:11 +02:00
|
|
|
reloadFonts();
|
2010-04-01 09:53:07 +02:00
|
|
|
enabled= true;
|
|
|
|
}
|
|
|
|
|
2010-09-11 08:08:50 +02:00
|
|
|
bool GraphicComponent::mouseMove(int x, int y) {
|
|
|
|
if(this->getVisible() == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-12-21 06:07:10 +01:00
|
|
|
return
|
2010-04-01 09:53:07 +02:00
|
|
|
x > this->x &&
|
|
|
|
y > this->y &&
|
|
|
|
x < this->x + w &&
|
|
|
|
y < this->y + h;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicComponent::mouseClick(int x, int y){
|
2010-09-11 08:08:50 +02:00
|
|
|
if(getVisible() && getEnabled() && getEditable())
|
2010-05-20 01:23:42 +02:00
|
|
|
return mouseMove(x, y);
|
|
|
|
else
|
|
|
|
return false;
|
2010-04-01 09:53:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicComponent::update(){
|
|
|
|
fade+= fadeSpeed;
|
|
|
|
anim+= animSpeed;
|
|
|
|
if(fade>1.f) fade= 1.f;
|
|
|
|
if(anim>1.f) anim= 0.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicComponent::resetFade(){
|
|
|
|
fade= 0.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class GraphicLabel
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
const int GraphicLabel::defH= 20;
|
|
|
|
const int GraphicLabel::defW= 70;
|
|
|
|
|
2011-10-02 04:14:05 +02:00
|
|
|
GraphicLabel::GraphicLabel() {
|
|
|
|
centered = false;
|
|
|
|
wordWrap = false;
|
|
|
|
centeredW = -1;
|
|
|
|
centeredH = 1;
|
2012-07-26 08:27:00 +02:00
|
|
|
editModeEnabled = false;
|
|
|
|
maxEditWidth = -1;
|
2012-07-26 17:26:59 +02:00
|
|
|
maxEditRenderWidth = -1;
|
2012-10-22 21:38:28 +02:00
|
|
|
isPassword = false;
|
2011-10-02 04:14:05 +02:00
|
|
|
}
|
|
|
|
|
2011-04-16 20:53:57 +02:00
|
|
|
void GraphicLabel::init(int x, int y, int w, int h, bool centered, Vec3f textColor, bool wordWrap) {
|
2010-04-01 09:53:07 +02:00
|
|
|
GraphicComponent::init(x, y, w, h);
|
|
|
|
this->centered= centered;
|
2011-03-26 14:40:22 +01:00
|
|
|
this->textColor=textColor;
|
2011-04-16 20:53:57 +02:00
|
|
|
this->wordWrap = wordWrap;
|
2010-04-01 09:53:07 +02:00
|
|
|
}
|
|
|
|
|
2012-07-26 09:06:12 +02:00
|
|
|
bool GraphicLabel::mouseMove(int x, int y) {
|
|
|
|
if(this->getVisible() == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int useWidth = w;
|
|
|
|
if(text.length() > 0 && font3D != NULL) {
|
2012-09-22 22:13:57 +02:00
|
|
|
float lineWidth = (font3D->getTextHandler()->Advance(text.c_str()) * Shared::Graphics::Font::scaleFontValue);
|
2012-07-26 09:06:12 +02:00
|
|
|
useWidth = (int)lineWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
x > this->x &&
|
|
|
|
y > this->y &&
|
|
|
|
x < this->x + useWidth &&
|
|
|
|
y < this->y + h;
|
|
|
|
}
|
|
|
|
|
2011-10-02 04:14:05 +02:00
|
|
|
bool GraphicLabel::getCenteredW() const {
|
|
|
|
bool result = (centered || centeredW == 1);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
void GraphicLabel::setCenteredW(bool centered) {
|
|
|
|
centeredW = (centered ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicLabel::getCenteredH() const {
|
|
|
|
bool result = (centered || centeredH == 1);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
void GraphicLabel::setCenteredH(bool centered) {
|
|
|
|
centeredH = (centered ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2010-04-01 09:53:07 +02:00
|
|
|
// =====================================================
|
|
|
|
// class GraphicButton
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
const int GraphicButton::defH= 22;
|
|
|
|
const int GraphicButton::defW= 90;
|
|
|
|
|
2011-03-25 11:11:16 +01:00
|
|
|
GraphicButton::GraphicButton(std::string containerName, std::string objName) : GraphicComponent(containerName,objName) {
|
|
|
|
lighted = false;
|
2011-04-16 20:53:57 +02:00
|
|
|
useCustomTexture = false;
|
2011-03-25 11:11:16 +01:00
|
|
|
customTexture = NULL;
|
|
|
|
}
|
|
|
|
|
2010-04-01 09:53:07 +02:00
|
|
|
void GraphicButton::init(int x, int y, int w, int h){
|
|
|
|
GraphicComponent::init(x, y, w, h);
|
|
|
|
lighted= false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicButton::mouseMove(int x, int y){
|
2010-09-11 08:08:50 +02:00
|
|
|
if(this->getVisible() == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool b= GraphicComponent::mouseMove(x, y);
|
2010-04-01 09:53:07 +02:00
|
|
|
lighted= b;
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class GraphicListBox
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
const int GraphicListBox::defH= 22;
|
|
|
|
const int GraphicListBox::defW= 140;
|
|
|
|
|
2011-12-02 17:07:59 +01:00
|
|
|
GraphicListBox::GraphicListBox(std::string containerName, std::string objName)
|
2012-03-28 08:25:57 +02:00
|
|
|
: GraphicComponent(containerName, objName), graphButton1(), graphButton2() {
|
2011-12-02 17:07:59 +01:00
|
|
|
selectedItemIndex = 0;
|
|
|
|
lighted = false;
|
|
|
|
}
|
|
|
|
|
2011-04-13 00:20:41 +02:00
|
|
|
void GraphicListBox::init(int x, int y, int w, int h, Vec3f textColor){
|
2010-04-01 09:53:07 +02:00
|
|
|
GraphicComponent::init(x, y, w, h);
|
|
|
|
|
2011-04-13 00:20:41 +02:00
|
|
|
this->textColor=textColor;
|
2010-04-01 09:53:07 +02:00
|
|
|
graphButton1.init(x, y, 22, h);
|
|
|
|
graphButton2.init(x+w-22, y, 22, h);
|
|
|
|
graphButton1.setText("<");
|
|
|
|
graphButton2.setText(">");
|
|
|
|
selectedItemIndex=-1;
|
2011-04-13 00:20:41 +02:00
|
|
|
lighted=false;
|
2010-12-21 06:07:10 +01:00
|
|
|
}
|
2010-04-01 09:53:07 +02:00
|
|
|
|
|
|
|
//queryes
|
|
|
|
void GraphicListBox::pushBackItem(string item){
|
|
|
|
items.push_back(item);
|
|
|
|
setSelectedItemIndex(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicListBox::setItems(const vector<string> &items){
|
2010-12-21 06:07:10 +01:00
|
|
|
this->items= items;
|
2011-12-26 07:29:14 +01:00
|
|
|
if(items.empty() == false) {
|
|
|
|
setSelectedItemIndex(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
selectedItemIndex=-1;
|
|
|
|
setText("");
|
|
|
|
}
|
2010-04-01 09:53:07 +02:00
|
|
|
}
|
|
|
|
|
2010-04-29 09:59:44 +02:00
|
|
|
void GraphicListBox::setSelectedItemIndex(int index, bool errorOnMissing){
|
|
|
|
if(errorOnMissing == true) assert(index>=0 && index<items.size());
|
2010-04-01 09:53:07 +02:00
|
|
|
selectedItemIndex= index;
|
|
|
|
setText(getSelectedItem());
|
|
|
|
}
|
|
|
|
|
2010-12-27 01:59:57 +01:00
|
|
|
void GraphicListBox::setY(int y) {
|
|
|
|
this->y= y;
|
|
|
|
graphButton1.setY(y);
|
|
|
|
graphButton2.setY(y);
|
|
|
|
}
|
|
|
|
|
2010-04-22 01:13:39 +02:00
|
|
|
void GraphicListBox::setEditable(bool editable){
|
|
|
|
graphButton1.setEditable(editable);
|
|
|
|
graphButton2.setEditable(editable);
|
2010-04-29 01:59:37 +02:00
|
|
|
GraphicComponent::setEditable(editable);
|
2010-04-22 01:13:39 +02:00
|
|
|
}
|
|
|
|
|
2011-09-07 18:55:49 +02:00
|
|
|
bool GraphicListBox::hasItem(string item) const {
|
|
|
|
bool result = false;
|
|
|
|
vector<string>::const_iterator iter= find(items.begin(), items.end(), item);
|
|
|
|
if(iter != items.end()) {
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-04-29 09:59:44 +02:00
|
|
|
void GraphicListBox::setSelectedItem(string item, bool errorOnMissing){
|
2010-12-21 06:07:10 +01:00
|
|
|
vector<string>::iterator iter;
|
2010-04-01 09:53:07 +02:00
|
|
|
|
|
|
|
iter= find(items.begin(), items.end(), item);
|
|
|
|
|
2010-04-29 09:59:44 +02:00
|
|
|
if(iter==items.end()) {
|
|
|
|
if(errorOnMissing == true) {
|
2010-05-31 21:57:10 +02:00
|
|
|
for(int idx = 0; idx < items.size(); idx++) {
|
2011-12-28 05:46:36 +01:00
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\ninstanceName [%s] idx = %d items[idx] = [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,instanceName.c_str(),idx,items[idx].c_str());
|
2010-05-31 21:57:10 +02:00
|
|
|
}
|
2012-04-14 23:21:09 +02:00
|
|
|
throw megaglest_runtime_error("[" + instanceName +"] Value not found on list box: [" + item + "]");
|
2010-04-29 09:59:44 +02:00
|
|
|
}
|
2010-04-01 09:53:07 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
setSelectedItemIndex(iter-items.begin());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-12-21 06:07:10 +01:00
|
|
|
|
2010-04-01 09:53:07 +02:00
|
|
|
bool GraphicListBox::mouseMove(int x, int y){
|
2010-09-11 08:08:50 +02:00
|
|
|
if(this->getVisible() == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
2010-12-21 06:07:10 +01:00
|
|
|
graphButton1.mouseMove(x, y) ||
|
2010-04-01 09:53:07 +02:00
|
|
|
graphButton2.mouseMove(x, y);
|
|
|
|
}
|
|
|
|
|
2012-10-15 09:44:44 +02:00
|
|
|
bool GraphicListBox::mouseClick(int x, int y,string advanceToItemStartingWith) {
|
2010-09-11 08:08:50 +02:00
|
|
|
if(this->getVisible() == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-15 09:44:44 +02:00
|
|
|
if(!items.empty()) {
|
2010-04-01 09:53:07 +02:00
|
|
|
bool b1= graphButton1.mouseClick(x, y);
|
|
|
|
bool b2= graphButton2.mouseClick(x, y);
|
|
|
|
|
2012-10-15 09:44:44 +02:00
|
|
|
if(b1) {
|
|
|
|
bool bFound = false;
|
|
|
|
if(advanceToItemStartingWith != "") {
|
2012-10-16 00:56:49 +02:00
|
|
|
for(int i = selectedItemIndex - 1; i >= 0; --i) {
|
2012-10-15 09:44:44 +02:00
|
|
|
string item = items[i];
|
|
|
|
if(StartsWith(toLower(item),toLower(advanceToItemStartingWith)) == true) {
|
|
|
|
bFound = true;
|
|
|
|
selectedItemIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-10-15 10:28:00 +02:00
|
|
|
if(bFound == false) {
|
2012-10-16 00:56:49 +02:00
|
|
|
for(int i = items.size() - 1; i >= selectedItemIndex; --i) {
|
2012-10-15 10:28:00 +02:00
|
|
|
string item = items[i];
|
|
|
|
//printf("Trying to match [%s] with item [%s]\n",advanceToItemStartingWith.c_str(),item.c_str());
|
|
|
|
if(StartsWith(toLower(item),toLower(advanceToItemStartingWith)) == true) {
|
|
|
|
bFound = true;
|
|
|
|
selectedItemIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-15 09:44:44 +02:00
|
|
|
}
|
|
|
|
if(bFound == false) {
|
|
|
|
selectedItemIndex--;
|
|
|
|
}
|
2010-04-01 09:53:07 +02:00
|
|
|
if(selectedItemIndex<0){
|
|
|
|
selectedItemIndex=items.size()-1;
|
|
|
|
}
|
|
|
|
}
|
2012-10-15 09:44:44 +02:00
|
|
|
else if(b2) {
|
|
|
|
bool bFound = false;
|
|
|
|
if(advanceToItemStartingWith != "") {
|
2012-10-16 00:56:49 +02:00
|
|
|
for(int i = selectedItemIndex + 1; i < items.size(); ++i) {
|
2012-10-15 09:44:44 +02:00
|
|
|
string item = items[i];
|
|
|
|
//printf("Trying to match [%s] with item [%s]\n",advanceToItemStartingWith.c_str(),item.c_str());
|
|
|
|
if(StartsWith(toLower(item),toLower(advanceToItemStartingWith)) == true) {
|
|
|
|
bFound = true;
|
|
|
|
selectedItemIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-10-15 10:28:00 +02:00
|
|
|
if(bFound == false) {
|
2012-10-16 00:56:49 +02:00
|
|
|
for(int i = 0; i <= selectedItemIndex; ++i) {
|
2012-10-15 10:28:00 +02:00
|
|
|
string item = items[i];
|
|
|
|
//printf("Trying to match [%s] with item [%s]\n",advanceToItemStartingWith.c_str(),item.c_str());
|
|
|
|
if(StartsWith(toLower(item),toLower(advanceToItemStartingWith)) == true) {
|
|
|
|
bFound = true;
|
|
|
|
selectedItemIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-15 09:44:44 +02:00
|
|
|
}
|
|
|
|
if(bFound == false) {
|
|
|
|
selectedItemIndex++;
|
|
|
|
}
|
2010-04-01 09:53:07 +02:00
|
|
|
if(selectedItemIndex>=items.size()){
|
|
|
|
selectedItemIndex=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setText(getSelectedItem());
|
|
|
|
|
|
|
|
return b1 || b2;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class GraphicMessageBox
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
const int GraphicMessageBox::defH= 240;
|
|
|
|
const int GraphicMessageBox::defW= 350;
|
|
|
|
|
2012-02-19 18:37:53 +01:00
|
|
|
GraphicMessageBox::GraphicMessageBox(std::string containerName, std::string objName) :
|
|
|
|
GraphicComponent(containerName, objName){
|
|
|
|
header= "";
|
2012-11-09 00:54:43 +01:00
|
|
|
autoWordWrap=true;
|
2011-12-02 17:07:59 +01:00
|
|
|
}
|
|
|
|
|
2012-02-19 18:37:53 +01:00
|
|
|
GraphicMessageBox::~GraphicMessageBox(){
|
|
|
|
//remove buttons
|
2012-10-06 21:01:13 +02:00
|
|
|
removeButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicMessageBox::removeButtons(){
|
2012-02-19 18:37:53 +01:00
|
|
|
while(!buttons.empty()){
|
|
|
|
delete buttons.back();
|
|
|
|
buttons.pop_back();
|
|
|
|
}
|
2010-09-11 18:14:03 +02:00
|
|
|
}
|
|
|
|
|
2012-02-19 18:37:53 +01:00
|
|
|
void GraphicMessageBox::init(const string &button1Str, const string &button2Str, int newWidth, int newHeight){
|
|
|
|
init(button1Str, newWidth, newHeight);
|
2012-10-06 21:01:13 +02:00
|
|
|
addButton(button2Str);
|
2010-09-11 18:14:03 +02:00
|
|
|
}
|
|
|
|
|
2012-02-19 18:37:53 +01:00
|
|
|
void GraphicMessageBox::init(const string &button1Str, int newWidth, int newHeight){
|
2012-02-19 18:49:33 +01:00
|
|
|
init(newWidth,newHeight);
|
2012-10-06 21:01:13 +02:00
|
|
|
removeButtons();
|
|
|
|
addButton(button1Str);
|
2012-02-19 18:49:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicMessageBox::init(int newWidth, int newHeight){
|
2010-04-01 09:53:07 +02:00
|
|
|
font= CoreData::getInstance().getMenuFontNormal();
|
2011-06-10 05:09:19 +02:00
|
|
|
font3D= CoreData::getInstance().getMenuFontNormal3D();
|
2010-04-01 09:53:07 +02:00
|
|
|
|
2011-11-23 09:00:09 +01:00
|
|
|
h= (newHeight >= 0 ? newHeight : defH);
|
|
|
|
w= (newWidth >= 0 ? newWidth : defW);
|
2010-12-21 06:07:10 +01:00
|
|
|
|
2010-04-01 09:53:07 +02:00
|
|
|
const Metrics &metrics= Metrics::getInstance();
|
|
|
|
|
2012-02-19 18:37:53 +01:00
|
|
|
x= (metrics.getVirtualW() - w) / 2;
|
|
|
|
y= (metrics.getVirtualH() - h) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicMessageBox::addButton(const string &buttonStr, int width, int height){
|
|
|
|
GraphicButton *newButton= new GraphicButton();
|
|
|
|
newButton->init(0, 0);
|
|
|
|
newButton->setText(buttonStr);
|
|
|
|
if(width != -1){
|
|
|
|
newButton->setW(width);
|
|
|
|
}
|
|
|
|
if(height != -1){
|
|
|
|
newButton->setH(height);
|
|
|
|
}
|
|
|
|
buttons.push_back(newButton);
|
|
|
|
alignButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicMessageBox::alignButtons(){
|
|
|
|
int currXPos= 0;
|
|
|
|
int totalbuttonListLength=0;
|
|
|
|
int buttonOffset=5;
|
|
|
|
for(int i= 0; i < getButtonCount(); i++){
|
|
|
|
GraphicButton *button= getButton(i);
|
|
|
|
totalbuttonListLength+=button->getW();
|
|
|
|
}
|
|
|
|
totalbuttonListLength+=(getButtonCount()-1)*buttonOffset;
|
|
|
|
currXPos=x+w/2-totalbuttonListLength/2;
|
|
|
|
for(int i= 0; i < getButtonCount(); i++){
|
|
|
|
GraphicButton *button= getButton(i);
|
|
|
|
button->setY(y + 25);
|
|
|
|
button->setX(currXPos);
|
|
|
|
currXPos+=button->getW()+buttonOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicMessageBox::setX(int x){
|
|
|
|
this->x= x;
|
|
|
|
alignButtons();
|
|
|
|
}
|
2010-04-01 09:53:07 +02:00
|
|
|
|
2012-02-19 18:37:53 +01:00
|
|
|
void GraphicMessageBox::setY(int y){
|
|
|
|
this->y= y;
|
|
|
|
alignButtons();
|
2010-04-01 09:53:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicMessageBox::mouseMove(int x, int y){
|
2012-02-19 18:37:53 +01:00
|
|
|
if(this->getVisible() == false){
|
2010-09-11 08:08:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-02-19 18:37:53 +01:00
|
|
|
for(int i= 0; i < getButtonCount(); i++){
|
|
|
|
if(getButton(i)->mouseMove(x, y)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2010-04-01 09:53:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicMessageBox::mouseClick(int x, int y){
|
2012-02-19 18:37:53 +01:00
|
|
|
if(this->getVisible() == false){
|
2010-09-11 08:08:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-19 18:37:53 +01:00
|
|
|
for(int i= 0; i < getButtonCount(); i++){
|
|
|
|
if(getButton(i)->mouseClick(x, y)){
|
|
|
|
return true;
|
|
|
|
}
|
2010-04-01 09:53:07 +02:00
|
|
|
}
|
2012-02-19 18:37:53 +01:00
|
|
|
return false;
|
2010-04-01 09:53:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicMessageBox::mouseClick(int x, int y, int &clickedButton){
|
2012-02-19 18:37:53 +01:00
|
|
|
if(this->getVisible() == false){
|
2010-09-11 08:08:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-19 18:37:53 +01:00
|
|
|
for(int i= 0; i < getButtonCount(); i++){
|
|
|
|
if(getButton(i)->mouseClick(x, y)){
|
|
|
|
clickedButton=i;
|
2010-04-01 09:53:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-12-27 01:59:57 +01:00
|
|
|
// =====================================================
|
|
|
|
// class GraphicLine
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
const int GraphicLine::defH= 5;
|
|
|
|
const int GraphicLine::defW= 1000;
|
|
|
|
|
2011-12-02 17:07:59 +01:00
|
|
|
GraphicLine::GraphicLine(std::string containerName, std::string objName)
|
|
|
|
: GraphicComponent(containerName, objName) {
|
|
|
|
horizontal = false;
|
|
|
|
}
|
|
|
|
|
2010-12-27 01:59:57 +01:00
|
|
|
void GraphicLine::init(int x, int y, int w, int h){
|
|
|
|
GraphicComponent::init(x, y, w, h);
|
|
|
|
horizontal=true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class GraphicCheckBox
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
const int GraphicCheckBox::defH= 22;
|
|
|
|
const int GraphicCheckBox::defW= 22;
|
|
|
|
|
2011-12-02 17:07:59 +01:00
|
|
|
GraphicCheckBox::GraphicCheckBox(std::string containerName, std::string objName)
|
|
|
|
: GraphicComponent(containerName, objName) {
|
|
|
|
value = false;
|
|
|
|
lighted = false;
|
|
|
|
}
|
|
|
|
|
2010-12-27 01:59:57 +01:00
|
|
|
void GraphicCheckBox::init(int x, int y, int w, int h){
|
|
|
|
GraphicComponent::init(x, y, w, h);
|
|
|
|
value=true;
|
|
|
|
lighted= false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicCheckBox::mouseMove(int x, int y){
|
|
|
|
if(this->getVisible() == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool b= GraphicComponent::mouseMove(x, y);
|
|
|
|
lighted= b;
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicCheckBox::mouseClick(int x, int y){
|
|
|
|
bool result=GraphicComponent::mouseClick( x, y);
|
|
|
|
if(result)
|
|
|
|
if(value)
|
|
|
|
value=false;
|
|
|
|
else
|
|
|
|
value=true;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-12-31 18:16:49 +01:00
|
|
|
// =====================================================
|
|
|
|
// class GraphicScrollBar
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
const int GraphicScrollBar::defThickness=20;
|
|
|
|
const int GraphicScrollBar::defLength= 200;
|
|
|
|
|
2011-12-02 17:07:59 +01:00
|
|
|
GraphicScrollBar::GraphicScrollBar(std::string containerName, std::string objName)
|
|
|
|
: GraphicComponent(containerName, objName) {
|
|
|
|
lighted = false;
|
2012-11-02 21:07:50 +01:00
|
|
|
activated = false;
|
2011-12-02 17:07:59 +01:00
|
|
|
horizontal = false;
|
|
|
|
elementCount = 0;
|
|
|
|
visibleSize = 0;
|
|
|
|
visibleStart = 0;
|
|
|
|
|
|
|
|
// position on component for renderer
|
|
|
|
visibleCompPosStart = 0;
|
|
|
|
visibleCompPosEnd = 0;
|
|
|
|
}
|
|
|
|
|
2010-12-31 18:16:49 +01:00
|
|
|
void GraphicScrollBar::init(int x, int y, bool horizontal,int length, int thickness){
|
|
|
|
GraphicComponent::init(x, y, horizontal?length:thickness,horizontal?thickness:length );
|
|
|
|
this->horizontal=horizontal;
|
|
|
|
this->elementCount=1;
|
|
|
|
this->visibleSize=1;
|
|
|
|
this->visibleStart=0;
|
2011-09-01 01:10:43 +02:00
|
|
|
this->visibleCompPosStart=0;
|
|
|
|
this->visibleCompPosEnd=length;
|
2012-11-02 21:07:50 +01:00
|
|
|
activated = false;
|
|
|
|
lighted = false;
|
2010-12-31 18:16:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GraphicScrollBar::mouseDown(int x, int y) {
|
|
|
|
if(getVisible() && getEnabled() && getEditable())
|
|
|
|
{
|
2012-11-02 21:07:50 +01:00
|
|
|
if(activated)
|
2010-12-31 18:16:49 +01:00
|
|
|
{
|
|
|
|
if( elementCount>visibleSize) {
|
|
|
|
int pos;
|
|
|
|
if(horizontal){
|
|
|
|
pos=x-this->x;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// invert the clicked point ( y is from bottom to top normally )
|
|
|
|
pos=getLength()-(y-this->y);
|
|
|
|
}
|
|
|
|
float partSize=(float)getLength()/(float)elementCount;
|
|
|
|
float visiblePartSize=partSize*(float)visibleSize;
|
|
|
|
float startPos=((float)pos)-visiblePartSize/2;
|
|
|
|
|
|
|
|
visibleStart=startPos/partSize;
|
|
|
|
setVisibleStart(visibleStart);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-02 21:07:50 +01:00
|
|
|
void GraphicScrollBar::mouseUp(int x, int y) {
|
|
|
|
activated = false;
|
|
|
|
lighted = false;
|
|
|
|
}
|
|
|
|
|
2010-12-31 18:16:49 +01:00
|
|
|
void GraphicScrollBar::setVisibleStart(int vs){
|
|
|
|
visibleStart=vs;
|
|
|
|
|
|
|
|
if(visibleStart>elementCount-visibleSize) {
|
|
|
|
visibleStart=elementCount-visibleSize;
|
|
|
|
}
|
|
|
|
if(visibleStart<0) {
|
|
|
|
visibleStart=0;
|
|
|
|
}
|
|
|
|
float partSize=(float)getLength()/(float)elementCount;
|
|
|
|
visibleCompPosStart=visibleStart*partSize;
|
|
|
|
visibleCompPosEnd=visibleStart*partSize+visibleSize*partSize;
|
|
|
|
if(visibleCompPosEnd>getLength()) {
|
|
|
|
visibleCompPosEnd=getLength();
|
|
|
|
}
|
|
|
|
if(!horizontal) {
|
|
|
|
// invert the display ( y is from bottom to top normally )
|
|
|
|
visibleCompPosStart=getLength()-visibleCompPosStart;
|
|
|
|
visibleCompPosEnd=getLength()-visibleCompPosEnd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicScrollBar::setElementCount(int elementCount){
|
|
|
|
this->elementCount=elementCount;
|
|
|
|
setVisibleStart(getVisibleStart());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicScrollBar::setVisibleSize(int visibleSize){
|
|
|
|
this->visibleSize=visibleSize;
|
|
|
|
setVisibleStart(getVisibleStart());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GraphicScrollBar::mouseClick(int x, int y){
|
|
|
|
bool result=GraphicComponent::mouseClick( x, y);
|
2012-11-02 21:07:50 +01:00
|
|
|
if(result) {
|
|
|
|
activated = true;
|
|
|
|
lighted = true;
|
2010-12-31 18:16:49 +01:00
|
|
|
mouseDown( x, y);
|
2012-11-02 21:07:50 +01:00
|
|
|
}
|
|
|
|
return result;
|
2010-12-31 18:16:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GraphicScrollBar::mouseMove(int x, int y){
|
2012-11-06 01:20:48 +01:00
|
|
|
if(this->getVisible() == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-02 21:07:50 +01:00
|
|
|
bool inScrollBar = GraphicComponent::mouseMove(x, y);
|
|
|
|
if (activated) {
|
|
|
|
lighted = true;
|
|
|
|
} else {
|
|
|
|
lighted = inScrollBar;
|
2010-12-31 18:16:49 +01:00
|
|
|
}
|
2012-11-02 21:07:50 +01:00
|
|
|
return inScrollBar;
|
2010-12-31 18:16:49 +01:00
|
|
|
}
|
|
|
|
|
2011-09-01 01:10:43 +02:00
|
|
|
int GraphicScrollBar::getLength() const {
|
2010-12-31 18:16:49 +01:00
|
|
|
return horizontal?getW():getH();
|
|
|
|
}
|
|
|
|
|
2011-09-01 01:10:43 +02:00
|
|
|
int GraphicScrollBar::getThickness() const {
|
2010-12-31 18:16:49 +01:00
|
|
|
return horizontal?getH():getW();
|
|
|
|
}
|
|
|
|
|
2012-03-16 02:10:32 +01:00
|
|
|
void GraphicScrollBar::arrangeComponents(vector<GraphicComponent *> &gcs) {
|
|
|
|
if(getElementCount()!=0 ) {
|
|
|
|
for(int i = getVisibleStart(); i <= getVisibleEnd(); ++i) {
|
|
|
|
if(horizontal){
|
|
|
|
gcs[i]->setX(getX()+getLength()-gcs[i]->getW()-gcs[i]->getW()*(i-getVisibleStart()));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gcs[i]->setY(getY()+getLength()-gcs[i]->getH()-gcs[i]->getH()*(i-getVisibleStart()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-21 08:51:28 +02:00
|
|
|
// ===========================================================
|
|
|
|
// class PopupMenu
|
|
|
|
// ===========================================================
|
|
|
|
|
|
|
|
const int PopupMenu::defH= 240;
|
|
|
|
const int PopupMenu::defW= 350;
|
|
|
|
|
|
|
|
PopupMenu::PopupMenu() {
|
|
|
|
h= defH;
|
|
|
|
w= defW;
|
|
|
|
}
|
|
|
|
|
|
|
|
PopupMenu::~PopupMenu() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::init(string menuHeader,std::vector<string> menuItems) {
|
|
|
|
header = menuHeader;
|
|
|
|
|
|
|
|
font= CoreData::getInstance().getMenuFontNormal();
|
|
|
|
font3D= CoreData::getInstance().getMenuFontNormal3D();
|
|
|
|
|
|
|
|
buttons.clear();
|
|
|
|
|
|
|
|
const Metrics &metrics= Metrics::getInstance();
|
|
|
|
|
|
|
|
x= (metrics.getVirtualW()-w)/2;
|
|
|
|
y= (metrics.getVirtualH()-h)/2;
|
|
|
|
|
2011-10-04 02:50:43 +02:00
|
|
|
int textHeight = GraphicButton::defH;
|
|
|
|
int textHeightSpacing = 6;
|
|
|
|
|
2011-09-21 08:51:28 +02:00
|
|
|
int maxButtonWidth = -1;
|
|
|
|
for(unsigned int i = 0; i < menuItems.size(); ++i) {
|
|
|
|
int currentButtonWidth = -1;
|
2012-09-22 22:13:57 +02:00
|
|
|
if(font3D != NULL && Shared::Graphics::Font::forceLegacyFonts == false) {
|
2011-09-21 08:51:28 +02:00
|
|
|
FontMetrics *fontMetrics= font3D->getMetrics();
|
2011-09-27 07:29:57 +02:00
|
|
|
if(fontMetrics) {
|
|
|
|
currentButtonWidth = fontMetrics->getTextWidth(menuItems[i]);
|
|
|
|
}
|
2011-09-21 08:51:28 +02:00
|
|
|
}
|
2011-09-27 07:29:57 +02:00
|
|
|
else if(font) {
|
2011-09-21 08:51:28 +02:00
|
|
|
FontMetrics *fontMetrics= font->getMetrics();
|
2011-09-27 07:29:57 +02:00
|
|
|
if(fontMetrics) {
|
|
|
|
currentButtonWidth = fontMetrics->getTextWidth(menuItems[i]);
|
|
|
|
}
|
2011-09-21 08:51:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(maxButtonWidth < 0 || currentButtonWidth > maxButtonWidth) {
|
2011-10-04 02:50:43 +02:00
|
|
|
maxButtonWidth = currentButtonWidth + textHeightSpacing;
|
2011-09-21 08:51:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-04 02:50:43 +02:00
|
|
|
int yStartOffset = y + h - (textHeight * 2);
|
|
|
|
|
|
|
|
if(maxButtonWidth >= w) {
|
|
|
|
w = maxButtonWidth + textHeightSpacing;
|
|
|
|
x= (metrics.getVirtualW()-w)/2;
|
|
|
|
}
|
|
|
|
|
|
|
|
int offsetH = (yStartOffset - y);
|
|
|
|
int maxH = (offsetH + ((menuItems.size() -1 ) * (textHeight + textHeightSpacing)));
|
|
|
|
if(maxH >= h) {
|
|
|
|
h = maxH;
|
|
|
|
y= (metrics.getVirtualH()-h)/2;
|
|
|
|
yStartOffset = y + h - (textHeight * 2);
|
|
|
|
}
|
|
|
|
|
2011-09-21 08:51:28 +02:00
|
|
|
for(unsigned int i = 0; i < menuItems.size(); ++i) {
|
|
|
|
GraphicButton button;
|
2011-10-04 02:50:43 +02:00
|
|
|
button.init(x+(w-maxButtonWidth)/2, yStartOffset - (i*(textHeight + textHeightSpacing)));
|
2011-09-21 08:51:28 +02:00
|
|
|
button.setText(menuItems[i]);
|
|
|
|
button.setW(maxButtonWidth);
|
|
|
|
|
|
|
|
buttons.push_back(button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::setX(int x) {
|
|
|
|
this->x= x;
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < buttons.size(); ++i) {
|
|
|
|
GraphicButton &button = buttons[i];
|
|
|
|
button.init(x+(w-GraphicButton::defW)/4, y+25 + (i*25));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopupMenu::setY(int y) {
|
|
|
|
this->y= y;
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < buttons.size(); ++i) {
|
|
|
|
GraphicButton &button = buttons[i];
|
|
|
|
button.init(x+(w-GraphicButton::defW)/4, y+25 + (i*25));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PopupMenu::mouseMove(int x, int y){
|
|
|
|
if(this->getVisible() == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < buttons.size(); ++i) {
|
|
|
|
GraphicButton &button = buttons[i];
|
|
|
|
if(button.mouseMove(x, y)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PopupMenu::mouseClick(int x, int y) {
|
|
|
|
if(this->getVisible() == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < buttons.size(); ++i) {
|
|
|
|
GraphicButton &button = buttons[i];
|
|
|
|
if(button.mouseClick(x, y)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<int,string> PopupMenu::mouseClickedMenuItem(int x, int y) {
|
|
|
|
std::pair<int,string> result;
|
|
|
|
for(unsigned int i = 0; i < buttons.size(); ++i) {
|
|
|
|
GraphicButton &button = buttons[i];
|
|
|
|
if(button.mouseClick(x, y)) {
|
|
|
|
result.first = i;
|
|
|
|
result.second = buttons[i].getText();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2010-12-31 18:16:49 +01:00
|
|
|
|
2010-04-01 09:53:07 +02:00
|
|
|
}}//end namespace
|