From 49451e1184a33c57db795ab3618a3eb36960e8e3 Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Wed, 23 Oct 2013 23:11:18 +0000 Subject: [PATCH] listboxes are rendered with dark background. listboxes can be "leftControlled" --- source/glest_game/facilities/components.cpp | 60 ++++++++++++++++++--- source/glest_game/facilities/components.h | 3 ++ source/glest_game/graphics/renderer.cpp | 31 +++++++++-- 3 files changed, 84 insertions(+), 10 deletions(-) diff --git a/source/glest_game/facilities/components.cpp b/source/glest_game/facilities/components.cpp index 4882cb78..b201db80 100644 --- a/source/glest_game/facilities/components.cpp +++ b/source/glest_game/facilities/components.cpp @@ -363,6 +363,7 @@ GraphicListBox::GraphicListBox(std::string containerName, std::string objName) : GraphicComponent(containerName, objName), graphButton1(), graphButton2() { selectedItemIndex = 0; lighted = false; + leftControlled = false; } void GraphicListBox::init(int x, int y, int w, int h, Vec3f textColor){ @@ -418,10 +419,55 @@ void GraphicListBox::setSelectedItemIndex(int index, bool errorOnMissing){ setText(getSelectedItem()); } +void GraphicListBox::setLeftControlled(bool leftControlled) { + if(this->leftControlled!=leftControlled){ + this->leftControlled= leftControlled; + if(leftControlled==true) { + graphButton2.setX(x+graphButton1.getW()-4); + graphButton2.setH(graphButton2.getH()-4); + graphButton2.setW(graphButton2.getW()-4); + graphButton1.setH(graphButton1.getH()-4); + graphButton1.setW(graphButton1.getW()-4); + graphButton2.setY(graphButton2.getY()+2); + graphButton1.setY(graphButton1.getY()+2); + +// graphButton2.setX(x); +// graphButton2.setH(graphButton2.getH()/2); +// graphButton2.setW(graphButton2.getW()/2); +// graphButton1.setH(graphButton1.getH()/2); +// graphButton1.setW(graphButton1.getW()/2); +// graphButton2.setY(graphButton2.getY()+graphButton1.getH()); + + } + else { + graphButton2.setX(x+w-graphButton2.getW()+4); + graphButton2.setH(graphButton2.getH()+4); + graphButton2.setW(graphButton2.getW()+4); + graphButton1.setH(graphButton1.getH()+4); + graphButton1.setW(graphButton1.getW()+4); + graphButton2.setY(graphButton2.getY()-2); + graphButton1.setY(graphButton1.getY()-2); + + +// graphButton2.setY(graphButton2.getY()-graphButton1.getH()); +// graphButton2.setH(graphButton2.getH()*2); +// graphButton2.setW(graphButton2.getW()*2); +// graphButton1.setH(graphButton1.getH()*2); +// graphButton1.setW(graphButton1.getW()*2); +// graphButton2.setX(x+w-graphButton2.getW()); + } + } +} + void GraphicListBox::setX(int x) { this->x= x; graphButton1.setX(x); - graphButton2.setX(x+w-22); + if(leftControlled==true) { + graphButton2.setX(x+graphButton1.getW()); + } + else { + graphButton2.setX(x+w-graphButton2.getW()); + } } void GraphicListBox::setY(int y) { @@ -491,7 +537,7 @@ bool GraphicListBox::mouseClick(int x, int y,string advanceToItemStartingWith) { bool bFound = false; if(advanceToItemStartingWith != "") { for(int i = selectedItemIndex - 1; i >= 0; --i) { - string item = items[i]; + string item = translated_items[i]; if(StartsWith(toLower(item),toLower(advanceToItemStartingWith)) == true) { bFound = true; selectedItemIndex = i; @@ -499,8 +545,8 @@ bool GraphicListBox::mouseClick(int x, int y,string advanceToItemStartingWith) { } } if(bFound == false) { - for(int i = items.size() - 1; i >= selectedItemIndex; --i) { - string item = items[i]; + for(int i = translated_items.size() - 1; i >= selectedItemIndex; --i) { + string item = translated_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; @@ -520,8 +566,8 @@ bool GraphicListBox::mouseClick(int x, int y,string advanceToItemStartingWith) { else if(b2) { bool bFound = false; if(advanceToItemStartingWith != "") { - for(int i = selectedItemIndex + 1; i < items.size(); ++i) { - string item = items[i]; + for(int i = selectedItemIndex + 1; i < translated_items.size(); ++i) { + string item = translated_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; @@ -531,7 +577,7 @@ bool GraphicListBox::mouseClick(int x, int y,string advanceToItemStartingWith) { } if(bFound == false) { for(int i = 0; i <= selectedItemIndex; ++i) { - string item = items[i]; + string item = translated_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; diff --git a/source/glest_game/facilities/components.h b/source/glest_game/facilities/components.h index c01b02c2..64ea46f4 100644 --- a/source/glest_game/facilities/components.h +++ b/source/glest_game/facilities/components.h @@ -238,6 +238,7 @@ private: int selectedItemIndex; bool lighted; Vec3f textColor; + bool leftControlled; public: GraphicListBox(std::string containerName="", std::string objName=""); @@ -251,6 +252,8 @@ public: GraphicButton *getButton2() {return &graphButton2;} bool getLighted() const {return lighted;} void setLighted(bool lighted) {this->lighted= lighted;} + bool getLeftControlled() const {return leftControlled;} + void setLeftControlled(bool leftControlled); Vec3f getTextColor() const {return textColor;} void setTextColor(Vec3f color) {this->textColor= color;} diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 387fbda2..312fd568 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -2087,8 +2087,6 @@ void Renderer::renderConsole(const Console *console,const bool showFullConsole, glEnable(GL_BLEND); if(showFullConsole) { - CoreData &coreData= CoreData::getInstance(); - int x= console->getXPos()-5; int y= console->getYPos()-5; int h= console->getLineHeight()*console->getStoredLineCount(); @@ -2106,6 +2104,7 @@ void Renderer::renderConsole(const Console *console,const bool showFullConsole, glVertex2i(x+w, y); glVertex2i(x+w, y+h); glEnd(); + glPopAttrib(); } for(int i = 0; i < console->getStoredLineCount(); ++i) { const ConsoleLineInfo &lineInfo = console->getStoredLineItem(i); @@ -3390,7 +3389,28 @@ void Renderer::renderListBox(GraphicListBox *listBox) { if(listBox->getVisible() == false) { return; } + //if(listBox->getLeftControlled()==true) + { + int x= listBox->getX(); + int y= listBox->getY(); + int h= listBox->getH(); + int w= listBox->getW(); + if(h>0){ + //background + glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT); + glEnable(GL_BLEND); + glColor4f(0.0f, 0.0f, 0.0f, 0.6f*listBox->getFade()) ; + + glBegin(GL_TRIANGLE_STRIP); + glVertex2i(x, y); + glVertex2i(x, y+h); + glVertex2i(x+w, y); + glVertex2i(x+w, y+h); + glEnd(); + glPopAttrib(); + } + } renderButton(listBox->getButton1()); renderButton(listBox->getButton2()); @@ -3398,7 +3418,12 @@ void Renderer::renderListBox(GraphicListBox *listBox) { glEnable(GL_BLEND); GraphicLabel label; - label.init(listBox->getX(), listBox->getY(), listBox->getW(), listBox->getH(), true,listBox->getTextColor()); + if(listBox->getLeftControlled()==true){ + label.init(listBox->getX()+listBox->getButton1()->getW()+listBox->getButton2()->getW()+2, listBox->getY(), listBox->getW(), listBox->getH(), false,listBox->getTextColor()); + } + else { + label.init(listBox->getX(), listBox->getY(), listBox->getW(), listBox->getH(), true,listBox->getTextColor()); + } label.setText(listBox->getText()); label.setTextNativeTranslation(listBox->getTextNativeTranslation()); label.setFont(listBox->getFont());