[Gcblue-commits] gcb_wx/src/graphics tcButton.cpp,NONE,1.1 tcButtonConsole.cpp,NONE,1.1 tc2DGraphics
Status: Alpha
Brought to you by:
ddcforge
From: <ddc...@us...> - 2004-01-03 00:45:18
|
Update of /cvsroot/gcblue/gcb_wx/src/graphics In directory sc8-pr-cvs1:/tmp/cvs-serv548/src/graphics Modified Files: tc2DGraphicsSurface.cpp tcwindow.cpp Added Files: tcButton.cpp tcButtonConsole.cpp Log Message: briefing camera features --- NEW FILE: tcButton.cpp --- /** * Copyright (C) 2003 Dewitt "Cole" 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 */ /** @file tcButton.cpp */ #include "stdwx.h" // precompiled header file #ifndef WX_PRECOMP #include "wx/wx.h" #ifdef WIN32 #include "wx/msw/private.h" // for MS Windows specific definitions #endif #endif #include "tcButton.h" #include "wxcommands.h" #include <iostream> using namespace Gdiplus; int tcButton::Draw() { Graphics *graphics; if (!mbActive) return 1; if (!GetGraphics(graphics)) { std::cerr << "Failed to get Graphics in DHookInfo::Draw()\n"; return 0; } UINT32 backgroundColor; UINT32 textColor; if (isMouseOver) { backgroundColor = 0xFFFFFFFF; textColor = 0xFE000000; } else { backgroundColor = 0xFF000000; textColor = 0xFEFFFFFF; } brush->SetColor(backgroundColor); RectF buttonRect(mrectWindow.left,mrectWindow.top,mrectWindow.right-mrectWindow.left, mrectWindow.bottom-mrectWindow.top); graphics->FillRectangle(brush,buttonRect); brush->SetColor(textColor); tcWindow::DrawTextInRect(graphics, font, brush, caption.c_str(), buttonRect); ReleaseGraphics(graphics); return 1; } void tcButton::OnEnterWindow(wxMouseEvent& event) { isMouseOver = true; // switch back to start view if no buttons clicked (for now) // send ID_BUTTONREDRAW message to force parent redraw wxCommandEvent cmd(wxEVT_COMMAND_BUTTON_CLICKED, ID_BUTTONREDRAW) ; cmd.SetEventObject(this); AddPendingEvent(cmd); } void tcButton::OnLButtonDown(wxMouseEvent& event) { // send command event wxCommandEvent cmd(wxEVT_COMMAND_BUTTON_CLICKED, command) ; cmd.SetEventObject(this); AddPendingEvent(cmd); } void tcButton::OnLButtonUp(wxMouseEvent& event) { event.Skip(); } void tcButton::OnLeaveWindow(wxMouseEvent& event) { isMouseOver = false; // send ID_BUTTONREDRAW message to force parent redraw wxCommandEvent cmd(wxEVT_COMMAND_BUTTON_CLICKED, ID_BUTTONREDRAW) ; cmd.SetEventObject(this); AddPendingEvent(cmd); } tcButton::tcButton(tcWindow *parent, const wxPoint& pos, const wxSize& size, const wxString& name) : tcWindow(parent, pos, size, name) { tc2DGraphicsSurface *sharedSurface = parent->GetSurface(); mbCloned = true; mp2DSurface = sharedSurface; // parent's CreateSurfaces must be called before using this constructor wxASSERT(sharedSurface); caption = "NULL"; command = -1; isMouseOver = false; sound = NULL; soundEffect = -1; fontSize = 16.0f; // init Gdiplus objects pen = new Pen(Color(255,100,255,100),2); if (pen == NULL) throw "tcObjectControl - mpPen creation failed\n"; FontFamily ff(L"Arial"); font = new Font(&ff,10,FontStyleBold,UnitPixel); if (font == NULL) throw "tcObjectControl - mpFont creation failed\n"; brush = new SolidBrush(Color(254,100,255,100)); if (brush == NULL) throw "tcObjectControl - mpBrush creation failed\n"; } tcButton::~tcButton() { if (pen) delete pen; if (brush) delete brush; if (font) delete font; } --- NEW FILE: tcButtonConsole.cpp --- /** @file tcButtonConsole.cpp */ /* ** Copyright (C) 2003 Dewitt "Cole" 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" // precompiled header file #ifndef WX_PRECOMP #include "wx/wx.h" #ifdef WIN32 #include "wx/msw/private.h" // for MS Windows specific definitions #endif #endif #include "tcButtonConsole.h" #include "tcButton.h" #include "wxcommands.h" #ifdef _DEBUG #define new DEBUG_NEW #endif BEGIN_EVENT_TABLE(tcButtonConsole, wxWindow) EVT_COMMAND(ID_BUTTONREDRAW, wxEVT_COMMAND_BUTTON_CLICKED, tcButtonConsole::ButtonRequestedRedraw) END_EVENT_TABLE() void tcButtonConsole::AddButton(wxRect bounds, long command, std::string caption) { wxSize buttonSize = bounds.GetSize(); wxPoint buttonPosition = bounds.GetPosition(); tcButton *buttonToAdd = new tcButton(this, buttonPosition, buttonSize); buttonToAdd->SetCaption(caption); buttonToAdd->SetCommand(command); buttons.push_back(buttonToAdd); } void tcButtonConsole::ButtonRequestedRedraw(wxCommandEvent& event) { tcConsole::ForceRedraw(); } int tcButtonConsole::Draw() { if (tcSoundConsole::Draw()) { size_t nButtons = buttons.size(); for(size_t n=0;n<nButtons;n++) { buttons[n]->Draw(); } return 1; } else { return 0; } } /** * Override to call SetActive of child button windows */ void tcButtonConsole::SetActive(bool abActive) { tcWindow::SetActive(abActive); size_t nButtons = buttons.size(); for(size_t n=0;n<nButtons;n++) { buttons[n]->SetActive(abActive); } } /********************************************************************/ tcButtonConsole::tcButtonConsole(wxWindow *parent, const wxPoint& pos, const wxSize& size, const wxString& name) : tcSoundConsole(parent, pos, size, name) { buttons.clear(); nyzero = mnHeight - 50; // margin for buttons at bottom } /********************************************************************/ tcButtonConsole::~tcButtonConsole() { } Index: tc2DGraphicsSurface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tc2DGraphicsSurface.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** tc2DGraphicsSurface.cpp 22 Dec 2003 02:32:37 -0000 1.6 --- tc2DGraphicsSurface.cpp 3 Jan 2004 00:45:12 -0000 1.7 *************** *** 187,191 **** } ! void tc2DGraphicsSurface::DrawBorder() { UINT32 nColor; --- 187,195 ---- } ! void tc2DGraphicsSurface::DrawBorder() ! { ! bool drawExtraRows = (mnHeight > 500); // hacks to fix strange cutoff border problem ! bool drawExtraCols = (mnWidth > 500); ! UINT32 nColor; *************** *** 193,200 **** memset(maBits,nColor,mnWidth*sizeof(UINT32)); memset(maBits+(mnHeight-1)*mnWidth,nColor,mnWidth*sizeof(UINT32)); ! for(int nRow=0;nRow<mnHeight;nRow++) { *(maBits + (nRow*mnWidth)) = nColor; *(maBits + (nRow*mnWidth) + mnWidth - 1) = nColor; } } --- 197,223 ---- memset(maBits,nColor,mnWidth*sizeof(UINT32)); memset(maBits+(mnHeight-1)*mnWidth,nColor,mnWidth*sizeof(UINT32)); ! ! for(int nRow=0;nRow<mnHeight;nRow++) ! { *(maBits + (nRow*mnWidth)) = nColor; *(maBits + (nRow*mnWidth) + mnWidth - 1) = nColor; } + + if (drawExtraRows) + { + memset(maBits+(1)*mnWidth,nColor,mnWidth*sizeof(UINT32)); + //memset(maBits+(2)*mnWidth,nColor,mnWidth*sizeof(UINT32)); + memset(maBits+(mnHeight-3)*mnWidth,nColor,mnWidth*sizeof(UINT32)); + memset(maBits+(mnHeight-2)*mnWidth,nColor,mnWidth*sizeof(UINT32)); + } + if (drawExtraCols) + { + for(int nRow=0;nRow<mnHeight;nRow++) + { + *(maBits + (nRow*mnWidth) + mnWidth - 2) = nColor; + *(maBits + (nRow*mnWidth) + mnWidth - 3) = nColor; + } + } + } Index: tcwindow.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcwindow.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** tcwindow.cpp 22 Dec 2003 02:32:37 -0000 1.13 --- tcwindow.cpp 3 Jan 2004 00:45:12 -0000 1.14 *************** *** 287,290 **** --- 287,292 ---- int tcWindow::CreateSurfaces(tcGraphicsEngine* apGraphicsEngine) { + wxASSERT(!mbCloned); // error, parent will create surface + // check if surface has already been created if (mp2DSurface) *************** *** 314,317 **** --- 316,320 ---- int tcWindow::DeleteSurfaces(tcGraphicsEngine* apGraphicsEngine) { + wxASSERT(!mbCloned); // error, parent window will delete surface if (apGraphicsEngine->Delete2DSurface(mp2DSurface) == false) {return false;} mp2DSurface = NULL; *************** *** 331,334 **** --- 334,340 ---- } + /** + * @return 1 if Draw was performed, 0 otherwise. + */ int tcWindow::Draw() { |