Thread: [Gcblue-commits] gcb_wx/src/graphics tcDatabaseViewer.cpp,NONE,1.1 tc3DWindow.cpp,1.34,1.35 tcButton
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2006-03-27 01:08:24
|
Update of /cvsroot/gcblue/gcb_wx/src/graphics In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18363/src/graphics Modified Files: tc3DWindow.cpp tcButton.cpp tcDatabaseInfoWindow.cpp tcStartView.cpp tcXmlWindow.cpp Added Files: tcDatabaseViewer.cpp Log Message: Index: tcStartView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcStartView.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** tcStartView.cpp 23 Mar 2006 01:11:02 -0000 1.12 --- tcStartView.cpp 27 Mar 2006 01:08:17 -0000 1.13 *************** *** 65,69 **** maButton[0].mzCaption = "Select scenario."; maButton[1].mzCaption = "Configure game options."; ! maButton[2].mzCaption = "Browse database (not functional)."; maButton[3].mzCaption = "Show credits."; maButton[4].mzCaption = "Start game."; --- 65,69 ---- maButton[0].mzCaption = "Select scenario."; maButton[1].mzCaption = "Configure game options."; ! maButton[2].mzCaption = "Browse database."; maButton[3].mzCaption = "Show credits."; maButton[4].mzCaption = "Start game."; *************** *** 204,208 **** if ((i == nButton)&&(bButtonOver)) { ! bool bButtonEnabled = (i==4) ? mbPlayEnabled : (i!=2); if ((maButton[i].mnState == 0)&&(bButtonEnabled)) { --- 204,208 ---- if ((i == nButton)&&(bButtonOver)) { ! bool bButtonEnabled = (i==4) ? mbPlayEnabled : true; if ((maButton[i].mnState == 0)&&(bButtonEnabled)) { *************** *** 230,234 **** //TranslatePoint(point); // adjust for flipped up/down bButtonClicked = ButtonContainingPoint(event.GetPosition(), nButton); ! bool bButtonEnabled = (nButton==4) ? mbPlayEnabled : (nButton!=2); if (!bButtonEnabled) {bButtonClicked = false;} --- 230,234 ---- //TranslatePoint(point); // adjust for flipped up/down bButtonClicked = ButtonContainingPoint(event.GetPosition(), nButton); ! bool bButtonEnabled = (nButton==4) ? mbPlayEnabled : true; if (!bButtonEnabled) {bButtonClicked = false;} --- NEW FILE: tcDatabaseViewer.cpp --- /** ** @file tcDatabaseViewer.cpp */ /* Copyright (C) 2006 Dewitt Colclough (de...@gc...) ** All rights reserved. ** This file is part of the Global Conflict Blue (GCB) program. ** GCB is free software; you can redistribute it and/or modify ** it under the terms of version 2 of the GNU General Public License as ** published by the Free Software Foundation. ** GCB 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 GCB; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA **/ #include "stdwx.h" #ifndef WX_PRECOMP #include "wx/wx.h" #endif #include "tcDatabaseViewer.h" #include <osg/Texture2D> #include <osg/Vec4> #include "wxcommands.h" #include "common/tinyxml.h" #include "tcButton.h" #include "tcDatabaseObject.h" #include "tcDatabaseIterator.h" #include "tcDatabaseInfoWindow.h" #ifdef _DEBUG #define new DEBUG_NEW #endif BEGIN_EVENT_TABLE(tcDatabaseViewer, tcXmlWindow) EVT_COMMAND(101, wxEVT_COMMAND_BUTTON_CLICKED, tcDatabaseViewer::BrowseSurface) EVT_COMMAND(102, wxEVT_COMMAND_BUTTON_CLICKED, tcDatabaseViewer::BrowseSub) EVT_COMMAND(103, wxEVT_COMMAND_BUTTON_CLICKED, tcDatabaseViewer::BrowseAir) EVT_COMMAND(104, wxEVT_COMMAND_BUTTON_CLICKED, tcDatabaseViewer::BrowseHelo) EVT_COMMAND(105, wxEVT_COMMAND_BUTTON_CLICKED, tcDatabaseViewer::BrowseLand) EVT_COMMAND(106, wxEVT_COMMAND_BUTTON_CLICKED, tcDatabaseViewer::BrowseMissile) EVT_COMMAND(107, wxEVT_COMMAND_BUTTON_CLICKED, tcDatabaseViewer::BrowseTorpedo) EVT_COMMAND(108, wxEVT_COMMAND_BUTTON_CLICKED, tcDatabaseViewer::BrowseBallistic) END_EVENT_TABLE() void tcDatabaseViewer::BrowseSurface(wxCommandEvent& event) { SetClassificationMask(PTYPE_SURFACE); } void tcDatabaseViewer::BrowseSub(wxCommandEvent& event) { SetClassificationMask(PTYPE_SUBMARINE); } void tcDatabaseViewer::BrowseAir(wxCommandEvent& event) { SetClassificationMask(PTYPE_FIXEDWING); } void tcDatabaseViewer::BrowseHelo(wxCommandEvent& event) { SetClassificationMask(PTYPE_HELO); } void tcDatabaseViewer::BrowseLand(wxCommandEvent& event) { SetClassificationMask(PTYPE_FIXED); } void tcDatabaseViewer::BrowseMissile(wxCommandEvent& event) { SetClassificationMask(PTYPE_MISSILE); } void tcDatabaseViewer::BrowseTorpedo(wxCommandEvent& event) { SetClassificationMask(PTYPE_TORPEDO); } void tcDatabaseViewer::BrowseBallistic(wxCommandEvent& event) { SetClassificationMask(PTYPE_BALLISTIC); } /** * Updates browse info data based on classificationMask * Should be called after changing classificationMask */ void tcDatabaseViewer::BuildBrowseInfo() { browseInfo.clear(); database::tcDatabaseIterator iter(classificationMask); for (iter.First(); !iter.IsDone(); iter.Next()) { database::tcDatabaseObject* obj = iter.Get(); wxASSERT(obj); wxASSERT(obj->mnKey != -1); BrowseItem item; item.className = obj->mzClass.mz; browseInfo.push_back(item); } } /** * */ bool tcDatabaseViewer::ProcessMouseClick(std::vector<BrowseItem>& info, wxPoint pos) { for (size_t n=0; n < info.size(); ++n) { wxRect r(info[n].drawBox.x, info[n].drawBox.y, info[n].drawBox.width, info[n].drawBox.height); if (r.Inside(pos)) { return true; } } return false; } void tcDatabaseViewer::SetClassificationMask(unsigned int mask) { if (mask == classificationMask) return; classificationMask = mask; BuildBrowseInfo(); UpdateDrawInfo(browseInfo); } /** * Update drawing info of browseInfo vector */ void tcDatabaseViewer::UpdateDrawInfo(std::vector<BrowseItem>& info) { float x = 50.0f; float y = 150.0f; float xWidth = 100.0f; float yHeight = 15.0f; for (size_t n=0; n < info.size(); ++n) { BrowseItem& item = info[n]; item.drawBox.x = x; item.drawBox.y = y; item.drawBox.height = yHeight - 2; item.drawBox.width = xWidth; y += yHeight; wxRect r(item.drawBox.x, item.drawBox.y, item.drawBox.width, item.drawBox.height); int oldState = item.drawState; if (item.className == displayName) { item.drawState = BrowseItem::ON; item.color = osg::Vec4(1, 1, 1, 1); if (item.drawState != oldState) tcSound::Get()->PlayEffect("Beep2"); } else if (r.Inside(mousePosition)) { item.drawState = BrowseItem::OVER; item.color = osg::Vec4(0.6, 0.6, 1, 1); if (item.drawState != oldState) tcSound::Get()->PlayEffect("Thuck"); } else { item.drawState = BrowseItem::OFF; item.color = osg::Vec4(0.5, 0.5, 0.5, 1); } } } /** * */ void tcDatabaseViewer::Draw() { DrawChildren(); for (size_t n=0; n<browseInfo.size(); n++) { BrowseItem& item = browseInfo[n]; DrawTextR(item.className.c_str(), item.drawBox.x, item.drawBox.y + item.drawBox.height - 3, defaultFont.get(), item.color, 16.0f, LEFT_BASE_LINE); } DrawBorder(); HideUnusedObjects(); } void tcDatabaseViewer::InitializeButtons() { size_t nButtons = 8; float x = 50.0f; float y = 50.0f; float width = 64.0f; for (size_t n=0; n<nButtons; n++) { tcButton* button = new tcButton(this, wxPoint(x, y), wxSize(width, width)); button->LoadImages("test_button_off.png", "test_button_on.png", "test_button_on.png", "test_button_on.png"); button->SetActive(true); button->SetCommand(101 + n); x += width + 16.0f; } } void tcDatabaseViewer::InitializeDatabaseInfoWindow() { databaseInfoWindow = new tcDatabaseInfoWindow(wxPoint(300, 150), "xml/database_info.xml", "DBViewInfo", this); wxASSERT(databaseInfoWindow != 0); databaseInfoWindow->SetBackgroundColor(osg::Vec4(0.1f, 0.1f, 0.1f, 0.2f)); databaseInfoWindow->SetButtonDisable(86, true); // disable the close button databaseInfoWindow->SetDragable(false); } /** * */ void tcDatabaseViewer::OnMouseMove(wxMouseEvent& event) { mousePosition = event.GetPosition(); UpdateDrawInfo(browseInfo); } /** * */ void tcDatabaseViewer::OnLButtonDown(wxMouseEvent& event) { if (!mbActive) { event.Skip(); return; } mousePosition = event.GetPosition(); if (ProcessMouseClick(browseInfo, mousePosition)) { UpdateDrawInfo(browseInfo); return; } } /** * */ tcDatabaseViewer::tcDatabaseViewer(wxWindow *parent, const wxPoint& pos, const wxSize& size, const wxString& name) : tcXmlWindow(parent, pos, size, "xml/database_viewer.xml", name), basePosition(20, 50), classificationMask(0) { LoadBackgroundImage("start_background_plain.jpg"); if (!config) { fprintf(stderr, "tcDatabaseViewer::tcDatabaseViewer - NULL xml config node\n"); return; } TiXmlNode* root = config->FirstChild("Window"); if (!root) { fprintf(stderr, "tcDatabaseViewer::tcDatabaseViewer - " "Missing top level <Window> tag\n"); return; } SetClassificationMask(PTYPE_SURFACE); InitializeButtons(); InitializeDatabaseInfoWindow(); } tcDatabaseViewer::~tcDatabaseViewer() { } Index: tcDatabaseInfoWindow.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcDatabaseInfoWindow.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tcDatabaseInfoWindow.cpp 26 Mar 2006 00:32:14 -0000 1.2 --- tcDatabaseInfoWindow.cpp 27 Mar 2006 01:08:17 -0000 1.3 *************** *** 121,125 **** s.Printf("%s", databaseObj->mzDescription); DrawTextR(s.c_str(), textx, texty, ! defaultFont.get(), color, fontSize, LEFT_BASE_LINE, maxWidth, textBox); float imagex = 265.0; --- 121,125 ---- s.Printf("%s", databaseObj->mzDescription); DrawTextR(s.c_str(), textx, texty, ! defaultFont.get(), color, fontSize, LEFT_BASE_LINE, maxWidth - 150.0f, textBox); float imagex = 265.0; *************** *** 128,132 **** if (nImages > 0) { ! DrawImageR(imageList[currentImageIdx].get(), imagex, imagey, 128.0f, 128.0f, ALIGN_BOTTOM_LEFT); // cycle through images --- 128,133 ---- if (nImages > 0) { ! DrawImageR(imageList[currentImageIdx].get(), imagex, imagey, 128.0f, 100.0f, ALIGN_BOTTOM_LEFT); ! DrawRectangleR(imagex, imagey, 128.0f, 100.0f, osg::Vec4(1, 1, 1, 0.5)); // cycle through images *************** *** 227,231 **** isLButtonDown = true; ! if ((point.y <= 20) || (point.y >= mnHeight)) { windowDragOn = true; --- 228,232 ---- isLButtonDown = true; ! if (isDragable && ((point.y <= 20) || (point.y >= mnHeight))) { windowDragOn = true; *************** *** 282,285 **** --- 283,291 ---- } + void tcDatabaseInfoWindow::SetDragable(bool state) + { + isDragable = state; + } + void tcDatabaseInfoWindow::UpdateWindowDrag(const wxPoint& pos) *************** *** 302,313 **** /** ! * static method SetParent must be called first */ ! tcDatabaseInfoWindow::tcDatabaseInfoWindow(const wxPoint& pos, const wxString& configFile, const wxString& name) ! : tcXmlWindow(parent, pos, wxSize(10, 10), configFile, name, parent), destroy(false), drawCount(0), isLButtonDown(false), windowDragOn(false), objId(-1), databaseClassName(""), --- 308,320 ---- /** ! * if hostParent argument is not used then static method SetParent must be called first */ ! tcDatabaseInfoWindow::tcDatabaseInfoWindow(const wxPoint& pos, const wxString& configFile, const wxString& name, tc3DWindow* hostParent) ! : tcXmlWindow(hostParent, pos, wxSize(10, 10), configFile, name, hostParent), destroy(false), drawCount(0), isLButtonDown(false), windowDragOn(false), + isDragable(true), objId(-1), databaseClassName(""), *************** *** 317,324 **** { ! wxASSERT(parent != 0); // put gui window on top ! SetBaseRenderBin(parent->GetBaseRenderBin() + windowLayer*10); wxWindow::Raise(); --- 324,331 ---- { ! wxASSERT(hostParent != 0); // put gui window on top ! SetBaseRenderBin(hostParent->GetBaseRenderBin() + windowLayer*10); wxWindow::Raise(); Index: tcXmlWindow.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcXmlWindow.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** tcXmlWindow.cpp 23 Mar 2006 01:11:02 -0000 1.8 --- tcXmlWindow.cpp 27 Mar 2006 01:08:17 -0000 1.9 *************** *** 135,138 **** --- 135,155 ---- } + + void tcXmlWindow::SetButtonDisable(long command, bool state) + { + for (unsigned int n=0; n<children.size(); n++) + { + if (tcButton* button = dynamic_cast<tcButton*>(children[n])) + { + if (button->GetCommand() == command) + { + button->SetForceDisable(state); + return; + } + } + + } + } + /** * This allows a window to change the caption of a button based on game state Index: tcButton.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcButton.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** tcButton.cpp 23 Mar 2006 01:11:02 -0000 1.21 --- tcButton.cpp 27 Mar 2006 01:08:17 -0000 1.22 *************** *** 177,180 **** --- 177,192 ---- } + void tcButton::SetActive(bool abActive) + { + if (forceDisable) + { + tc3DWindow::SetActive(false); + } + else + { + tc3DWindow::SetActive(abActive); + } + } + /** * *************** *** 204,207 **** --- 216,223 ---- } + void tcButton::SetForceDisable(bool state) + { + forceDisable = state; + } /** *************** *** 220,224 **** fontSize(12.0f), sendRedraw(false), ! backgroundAlpha(1.0f) { --- 236,241 ---- fontSize(12.0f), sendRedraw(false), ! backgroundAlpha(1.0f), ! forceDisable(false) { *************** *** 338,353 **** offColor(0, 0, 0, 1), overColor(0.4, 1, 0.4, 1), ! onColor(1, 1, 1, 1) { - - caption = "NULL"; - command = -1; - isButtonOn = false; - isMouseOver = false; - soundEffect = ""; - fontSize = 16.0f; - sendRedraw = false; - backgroundAlpha = 1.0f; - ref_count++; --- 355,369 ---- offColor(0, 0, 0, 1), overColor(0.4, 1, 0.4, 1), ! onColor(1, 1, 1, 1), ! caption("NULL"), ! command(-1), ! isButtonOn(false), ! isMouseOver(false), ! soundEffect(""), ! fontSize(16.0f), ! sendRedraw(false), ! backgroundAlpha(1.0f), ! forceDisable(false) { ref_count++; Index: tc3DWindow.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tc3DWindow.cpp,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** tc3DWindow.cpp 26 Mar 2006 00:32:14 -0000 1.34 --- tc3DWindow.cpp 27 Mar 2006 01:08:17 -0000 1.35 *************** *** 722,725 **** --- 722,726 ---- { backgroundColor = color; + UpdateBackgroundQuad(); } |