[Gcblue-commits] gcb_wx/src/graphics tcMessageCenter.cpp,NONE,1.1 tcMessageChannel.cpp,NONE,1.1 tcMe
Status: Alpha
Brought to you by:
ddcforge
Update of /cvsroot/gcblue/gcb_wx/src/graphics In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22147/src/graphics Modified Files: tc3DWindow.cpp tcMapView.cpp tcScenarioSelectView.cpp Added Files: tcMessageCenter.cpp tcMessageChannel.cpp tcMessageInterface.cpp tcPopupMessage.cpp Log Message: Text message "message center" GUI screen --- NEW FILE: tcMessageCenter.cpp --- /** ** @file tcMessageCenter.cpp */ /* Copyright (C) 2004 Dewitt Colclough (de...@tw...) ** 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" #include "tcMessageCenter.h" #include "tcMessageChannel.h" #include <stdio.h> #include <iostream> #include "tcTime.h" #ifdef _DEBUG #define new DEBUG_NEW #endif /** * */ void tcMessageCenter::AddMessage(const std::string& channelName, const std::string& msg) { tcMessageChannel* channel = GetOrCreateChannel(channelName); channel->AddMessage(msg); } /** * Removes and deletes all channels */ void tcMessageCenter::Clear() { std::map<std::string, tcMessageChannel*>::iterator iter; for (iter = channelMap.begin(); iter != channelMap.end(); ++iter) { tcMessageChannel* channel = iter->second; delete channel; } channelMap.clear(); channelTab.Set(10, 80, 10, 30); } /** * */ void tcMessageCenter::Draw() { std::map<std::string, tcMessageChannel*>::iterator iter; for (iter = channelMap.begin(); iter != channelMap.end(); ++iter) { tcMessageChannel* channel = iter->second; channel->Draw(this); } FinishDraw(); } /** * */ tcMessageChannel* tcMessageCenter::GetChannel(const std::string& channelName) { std::map<std::string, tcMessageChannel*>::iterator iter; iter = channelMap.find(channelName); if (iter == channelMap.end()) { return 0; } else { return iter->second; } } /** * */ tcMessageChannel* tcMessageCenter::GetOrCreateChannel(const std::string& channelName) { tcMessageChannel* channel; if (channel = GetChannel(channelName)) { return channel; } else // create { channel = new tcMessageChannel(channelName); channel->SetActivationRect(channelTab); channel->SetTextRect(defaultTextRect); // move channelTab to next position channelTab.Offset(channelTab.Width() + 2.0, 0); channelMap[channelName] = channel; return channelMap[channelName]; } } /** * */ void tcMessageCenter::OnLButtonDown(wxMouseEvent& event) { wxPoint pos = event.GetPosition(); tcMessageChannel* clickedChannel = 0; tcMessageChannel* activeChannel = GetChannel(activeChannelName); std::map<std::string, tcMessageChannel*>::iterator iter; for (iter = channelMap.begin(); iter != channelMap.end(); ++iter) { tcMessageChannel* channel = iter->second; if (channel->IsPointInActivationRect(pos)) { clickedChannel = channel; } } if (clickedChannel == 0) return; // none of the activation buttons were clicked if (clickedChannel == activeChannel) return; clickedChannel->SetActive(true); if (activeChannel) { activeChannel->SetActive(false); } activeChannelName = clickedChannel->GetName(); } /** * */ void tcMessageCenter::OnMouseMove(wxMouseEvent& event) { wxPoint pos = event.GetPosition(); std::map<std::string, tcMessageChannel*>::iterator iter; for (iter = channelMap.begin(); iter != channelMap.end(); ++iter) { tcMessageChannel* channel = iter->second; if (channel->IsPointInActivationRect(pos)) { channel->SetMouseOver(true); } else { channel->SetMouseOver(false); } } } /** * */ tcMessageCenter::tcMessageCenter(wxWindow* parent, const wxPoint& pos, const wxSize& size, const wxString& name) : tc3DWindow(parent, pos, size, name, 0), activeChannelName("") { channelTab.Set(10, 140, 10, 30); defaultTextRect.Set(10, size.GetWidth()-100, 50, size.GetHeight()-50); LoadBackgroundImage("background.jpg"); } tcMessageCenter::~tcMessageCenter() { } --- NEW FILE: tcMessageChannel.cpp --- /** ** @file tcMessageChannel.cpp */ /* Copyright (C) 2004 Dewitt Colclough (de...@tw...) ** 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" #include "tcMessageChannel.h" #include "tc3DWindow.h" #include <stdio.h> #include <iostream> #include "tcTime.h" #ifdef _DEBUG #define new DEBUG_NEW #endif /** * */ void tcMessageChannel::AddMessage(const std::string& msg) { messages.push_back(msg); } /** * */ void tcMessageChannel::Draw(tc3DWindow* graphics) { wxASSERT(graphics); DrawActivationButton(graphics); if (!isActive) return; DrawMessageText(graphics); } /** * */ void tcMessageChannel::DrawActivationButton(tc3DWindow* graphics) { wxASSERT(graphics); // draw title button osg::Vec4 buttonColor(0, 0, 0.2, 1); osg::Vec4 buttonTextColor(1, 1, 1, 1); osgText::Font* font = graphics->GetDefaultFont(); if (isActive) { buttonColor.set(1, 1, 1, 1); buttonTextColor.set(0, 0, 0, 1); } else if (isMouseOver) { buttonColor.set(0.05, 0.05, 0.3, 1); buttonTextColor.set(1, 1, 1, 1); } tcRect borderRect = activationRect; borderRect.Expand(1.0, 1.0); graphics->DrawRectangleR(borderRect, buttonTextColor, tc3DWindow::FILL_OFF); graphics->DrawRectangleR(activationRect, buttonColor, tc3DWindow::FILL_ON); graphics->DrawTextR(channelName.c_str(), activationRect.XCenter(), activationRect.YCenter(), font, buttonTextColor, buttonFontSize, CENTER_CENTER); } /** * */ void tcMessageChannel::DrawMessageText(tc3DWindow* graphics) { wxASSERT(graphics); osg::Vec4 color(1, 1, 1, 1); osgText::Font* font = graphics->GetDefaultFont(); std::deque<std::string>::reverse_iterator iter; float x = textRect.left + 10.0; float y = textRect.top; wxSize size; graphics->MeasureText(font, fontSize, "Tg", size); float lineSpacing = float(size.GetHeight()) + 2.0; for (iter = messages.rbegin(); iter != messages.rend(); ++iter) { y -= lineSpacing; if (y >= textRect.bottom + 10) { graphics->DrawTextR(iter->c_str(), x, y, font, color, fontSize, LEFT_BASE_LINE); } } graphics->DrawRectangleR(textRect, color, tc3DWindow::FILL_OFF); } /** * */ std::string tcMessageChannel::GetName() { return channelName; } /** * */ bool tcMessageChannel::IsActive() const { return isActive; } /** * */ bool tcMessageChannel::IsPointInActivationRect(const wxPoint& p) const { return activationRect.ContainsPoint(float(p.x), float(p.y)); } /** * */ void tcMessageChannel::SetActivationRect(tcRect r) { activationRect = r; } /** * */ void tcMessageChannel::SetActive(bool state) { isActive = state; } /** * */ void tcMessageChannel::SetMouseOver(bool state) { isMouseOver = state; } /** * */ void tcMessageChannel::SetTextRect(tcRect r) { textRect = r; } /** * */ tcMessageChannel::tcMessageChannel(std::string name) : channelName(name), isActive(false), isMouseOver(false), fontSize(16), buttonFontSize(12), activationRect(20, 80, 20, 40), textRect(50, 700, 50, 500) { } /** * */ tcMessageChannel::~tcMessageChannel() { } --- NEW FILE: tcMessageInterface.cpp --- /** ** @file tcMessageInterface.cpp */ /* Copyright (C) 2004 Dewitt Colclough (de...@tw...) ** 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" #include "tcMessageInterface.h" #include "tcMessageCenter.h" #include <stdio.h> #include <iostream> #ifdef _DEBUG #define new DEBUG_NEW #endif tcMessageCenter* tcMessageInterface::messageCenter = 0; /** * */ void tcMessageInterface::ChannelMessage(const std::string& channelName, const std::string& msg) { wxASSERT(messageCenter); messageCenter->AddMessage(channelName, msg); } tcMessageInterface* tcMessageInterface::Get() { static tcMessageInterface instance; return &instance; } /** * Must be called before using DisplayChannelMessage */ void tcMessageInterface::SetMessageCenter(tcMessageCenter* mc) { messageCenter = mc; } /** * */ tcMessageInterface::tcMessageInterface() { } tcMessageInterface::~tcMessageInterface() { } Index: tcScenarioSelectView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcScenarioSelectView.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** tcScenarioSelectView.cpp 6 Nov 2004 15:13:41 -0000 1.7 --- tcScenarioSelectView.cpp 14 Nov 2004 22:52:21 -0000 1.8 *************** *** 213,216 **** --- 213,217 ---- else { + mpSimState->mpPythonInterface->LoadScenario("", ""); // to clear director mpSimState->RandInit(); } Index: tcMapView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcMapView.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** tcMapView.cpp 6 Nov 2004 15:13:41 -0000 1.7 --- tcMapView.cpp 14 Nov 2004 22:52:21 -0000 1.8 *************** *** 720,723 **** --- 720,725 ---- DrawBorder(); + DrawChildren(); + FinishDraw(); } --- NEW FILE: tcPopupMessage.cpp --- /** ** @file tcPopupMessage.cpp */ /* Copyright (C) 2004 Dewitt Colclough (de...@tw...) ** 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" #include "tcPopupMessage.h" #include <stdio.h> #include <iostream> #include "tcTime.h" #ifdef _DEBUG #define new DEBUG_NEW #endif tc3DWindow* tcPopupMessage::parent = 0; /** * */ void tcPopupMessage::SetParent(tc3DWindow* par) { parent = par; } /** * Clears the text buffer */ void tcPopupMessage::Clear() { messageText = ""; } /** * */ void tcPopupMessage::Draw() { unsigned currentCount = tcTime::Get()->Get30HzCount(); unsigned age = currentCount - birthCount; if (age < 20) { bool blinkOn = age % 8 < 4; if (blinkOn) { redraw = true; } else { HideUnusedObjects(); redraw = true; return; } } else if (age > 150) { ClearDrawObjects(); Destroy(); return; } if (!redraw) return; osg::Vec4 color(1, 1, 1, 1); float x = 0.5f * float(mnWidth); float y = 0.5f * float(mnHeight); DrawRectangleR(0, 0, float(mnWidth), float(mnHeight), osg::Vec4(0, 0, 0, 0.5f), FILL_ON); DrawTextR(messageText.c_str(), x, y, defaultFont.get(), color, fontSize, CENTER_CENTER); DrawBorder(); HideUnusedObjects(); redraw = false; } void tcPopupMessage::OnLButtonDown(wxMouseEvent& event) { ClearDrawObjects(); this->Destroy(); } /** * */ tcPopupMessage::tcPopupMessage(std::string text, const wxPoint& pos, int width) : tc3DWindow(parent, pos, wxSize(width, 25), "PopupMessage", parent), messageText(text), redraw(true) { SetBaseRenderBin(parent->GetBaseRenderBin() + 10); birthCount = tcTime::Get()->Get30HzCount(); } tcPopupMessage::~tcPopupMessage() { } Index: tc3DWindow.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tc3DWindow.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** tc3DWindow.cpp 7 Nov 2004 03:40:44 -0000 1.10 --- tc3DWindow.cpp 14 Nov 2004 22:52:21 -0000 1.11 *************** *** 72,75 **** --- 72,76 ---- EVT_SET_FOCUS(tc3DWindow::OnSetFocus) EVT_KILL_FOCUS(tc3DWindow::OnKillFocus) + EVT_CLOSE(tc3DWindow::OnClose) END_EVENT_TABLE() *************** *** 101,104 **** --- 102,110 ---- } + void tc3DWindow::OnClose(wxCloseEvent& event) + { + event.Skip(); + } + void tc3DWindow::OnEnterWindow(wxMouseEvent& event) { *************** *** 236,239 **** --- 242,287 ---- + + /** + * Removes child window from children vector by adding + * to childrenToRemove queue for safe removal at the + * start of the next DrawChildren. + */ + void tc3DWindow::RemoveChild(tc3DWindow* child) + { + wxASSERT(child); + if (child == NULL) return; + + childrenToRemove.push(child); + } + + /** + * Removes pending children for removal from children vector. + */ + void tc3DWindow::UpdateChildren() + { + /* for each child in the childrenToRemove queue + ** iterate through children vector and remove if + ** found */ + while (!childrenToRemove.empty()) + { + tc3DWindow* child = childrenToRemove.front(); + childrenToRemove.pop(); + + wxASSERT(child); + if (child == NULL) return; + std::vector<tc3DWindow*>::iterator iter = children.begin(); + for (iter = children.begin(); iter != children.end(); ++iter) + { + if ((*iter) == child) + { + children.erase(iter); + return; + } + } + } + + } + /** * Creates new drawing projection and adds it to the root node of *************** *** 584,587 **** --- 632,637 ---- void tc3DWindow::DrawChildren() { + UpdateChildren(); + size_t nChildren = children.size(); *************** *** 1108,1112 **** } ! --- 1158,1168 ---- } ! /** ! * ! */ ! int tc3DWindow::GetBaseRenderBin() const ! { ! return baseRenderBin; ! } *************** *** 1500,1503 **** --- 1556,1573 ---- } + /** + * + */ + void tc3DWindow::ClearDrawObjects() + { + textIdx = 0; + imageQuadIdx = 0; + lineIdx = 0; + rectIdx = 0; + transformIdx = 0; + + HideUnusedObjects(); + } + /** *************** *** 1718,1722 **** fontSize(12.0), fontSizeLarge(18.0), ! fontSizeSmall(9.0) { --- 1788,1793 ---- fontSize(12.0), fontSizeLarge(18.0), ! fontSizeSmall(9.0), ! hostParent(graphicsHost) { *************** *** 1876,1879 **** --- 1947,1954 ---- linePool.size(), rectPool.size(), transformPool.size()); #endif + if (hostParent) + { + hostParent->RemoveChild(this); // watch out for destruction order problems here + } } |