///////////////////////////////////////////////////////////////////////////// // Name: tablepic.cpp // tag: this is a table shown in a room. // Author: David Roundy // Copyright: (c) 2002 David Roundy // Licence: GPL /* This program is free software; you can redistribute it 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 License, or (at your option) any later version. This program 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 this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes . #include #ifndef WX_PRECOMP #include #endif #include "tables.h" #include "tablepic.h" #include "colors.h" #include "seats.h" #include "globals.h" #include WX_DEFINE_LIST(TablePicList); //------------------------------------------------------------// // The TablePic class: a players name (and maybe later picture) // //------------------------------------------------------------// BEGIN_EVENT_TABLE(TablePic, wxPanel) EVT_SET_FOCUS(TablePic::SetTalkFocus) EVT_BUTTON(PUSH_BUTTON_ID,TablePic::ButtonPush) EVT_BUTTON(SIT_NORTH,TablePic::SitNorth) EVT_BUTTON(SIT_SOUTH,TablePic::SitSouth) EVT_BUTTON(SIT_WEST,TablePic::SitWest) EVT_BUTTON(SIT_EAST,TablePic::SitEast) END_EVENT_TABLE() TablePic::TablePic(wxWindow* parent, const wxString &name, int x, int y) : wxPanel(parent, -1, wxPoint(x, y), wxSize(400, 200)) { wxLayoutConstraints *c; m_name = name; wxColor grey = GetBackgroundColour(); wxFont normalFont = GetFont(); wxPanel *my_panel = new wxPanel(this, -1, wxPoint(120,50), wxSize(160,100)); m_button = new wxButton(my_panel,PUSH_BUTTON_ID, "Join Table",wxPoint(150,100)); my_panel->SetForegroundColour(*wxWHITE); my_panel->SetBackgroundColour(aBridgeTableBrownColour()); my_panel->SetFont(aBridgeFont()); m_name_label = new wxStaticText(my_panel, -1, m_name, wxPoint(0,0), wxSize(160,30), wxALIGN_CENTRE|wxST_NO_AUTORESIZE); c = new wxLayoutConstraints; c->centreX.SameAs(this, wxCentreX, 0); c->centreY.SameAs(this, wxCentreY, 5); c->height.AsIs(); c->width.AsIs(); my_panel->SetConstraints(c); c = new wxLayoutConstraints; c->centreX.SameAs(my_panel, wxCentreX, 0); c->top.SameAs(my_panel, wxTop, 5); c->height.AsIs(); c->right.SameAs(my_panel, wxRight, 0); m_name_label->SetConstraints(c); c = new wxLayoutConstraints; c->centreX.SameAs(my_panel, wxCentreX, 0); c->centreY.SameAs(my_panel, wxCentreY, 5); c->height.AsIs(); c->width.AsIs(); m_button->SetConstraints(c); m_sit_buttons[SOUTH] = new wxButton(this,SIT_SOUTH, "Sit South",wxPoint(150,160)); m_sit_buttons[EAST] = new wxButton(this,SIT_EAST, "Sit East",wxPoint(290,85)); m_sit_buttons[NORTH] = new wxButton(this,SIT_NORTH, "Sit North",wxPoint(150,15)); m_sit_buttons[WEST] = new wxButton(this,SIT_WEST, "Sit West",wxPoint(25,85)); c = new wxLayoutConstraints; c->centreY.SameAs(this, wxCentreY, 0); c->left.RightOf(my_panel, 10); c->height.AsIs(); c->width.AsIs(); m_sit_buttons[EAST]->SetConstraints(c); c = new wxLayoutConstraints; c->centreY.SameAs(this, wxCentreY, 0); c->right.LeftOf(my_panel, 10); c->height.AsIs(); c->width.AsIs(); m_sit_buttons[WEST]->SetConstraints(c); c = new wxLayoutConstraints; c->centreX.SameAs(this, wxCentreX, 0); c->bottom.Above(my_panel, -10); c->height.AsIs(); c->width.AsIs(); m_sit_buttons[NORTH]->SetConstraints(c); c = new wxLayoutConstraints; c->centreX.SameAs(this, wxCentreX, 0); c->top.Below(my_panel, 10); c->height.AsIs(); c->width.AsIs(); m_sit_buttons[SOUTH]->SetConstraints(c); SetFont(aBridgeFont()); m_name_label->SetBackgroundColour(aBridgeTableBrownColour()); SetForegroundColour(aBridgeTextColour()); SetBackgroundColour(aBridgeBackgroundColour()); m_players[SOUTH] = new wxStaticText(this, -1, "", wxPoint(0,170), wxSize(400,20), wxALIGN_CENTRE|wxST_NO_AUTORESIZE); m_players[WEST] = new wxStaticText(this, -1, "", wxPoint(5,100), wxSize(115,30), wxALIGN_RIGHT|wxST_NO_AUTORESIZE); m_players[NORTH] = new wxStaticText(this, -1, "", wxPoint(0,20), wxSize(400,20), wxALIGN_CENTRE|wxST_NO_AUTORESIZE); m_players[EAST] = new wxStaticText(this, -1, "", wxPoint(280,100), wxSize(115,30), wxALIGN_LEFT|wxST_NO_AUTORESIZE); int i; for (i=0;i<4;i++) { m_players[i]->Show(false); } c = new wxLayoutConstraints; c->centreY.SameAs(this, wxCentreY, 0); c->left.RightOf(my_panel, 10); c->height.AsIs(); c->right.SameAs(this, wxRight,0); m_players[EAST]->SetConstraints(c); c = new wxLayoutConstraints; c->centreY.SameAs(this, wxCentreY, 0); c->right.LeftOf(my_panel, 10); c->height.AsIs(); c->left.SameAs(this, wxLeft,0); m_players[WEST]->SetConstraints(c); c = new wxLayoutConstraints; c->centreX.SameAs(this, wxCentreX, 0); c->bottom.Above(my_panel, -10); c->height.AsIs(); c->width.AsIs(); m_players[NORTH]->SetConstraints(c); c = new wxLayoutConstraints; c->centreX.SameAs(this, wxCentreX, 0); c->top.Below(my_panel, 10); c->height.AsIs(); c->width.AsIs(); m_players[SOUTH]->SetConstraints(c); SetFont(normalFont); SetBackgroundColour(grey); SetBackgroundColour(aBridgeBackgroundColour()); SetFont(aBridgeFont()); Layout(); SetAutoLayout(true); } wxSize TablePic::GetBestSize() { return wxSize(400,200); } void TablePic::OnDraw(wxDC& dc) { wxColour bgColour = aBridgeBackgroundColour(); wxColour fgColour = aBridgeTextColour(); wxPen* pen = wxThePenList->FindOrCreatePen(bgColour, 1, wxSOLID); dc.SetTextBackground(bgColour); dc.SetTextForeground(aBridgeTextColour()); dc.SetBrush(aBridgeBackgroundBrush()); dc.SetPen(*pen); dc.DrawRectangle(0, 0, 400, 200); wxColor brown = aBridgeTableBrownColour(); dc.SetBrush(*wxTheBrushList->FindOrCreateBrush(brown, wxSOLID)); pen = wxThePenList->FindOrCreatePen(brown, 1, wxSOLID); dc.SetPen(*pen); dc.DrawRectangle(120, 50, 160, 100); } TablePic::~TablePic() { if (m_button) delete m_button; } void TablePic::SetTopic(const wxString &topic) { m_name_label->SetLabel(topic); } void TablePic::Sit(const wxString &seat, const wxString &player) { Seat i = String2Seat(seat); m_players[i]->SetLabel(player); if (player.IsSameAs("")) { // really I should fix host not to send empty sit strings! m_sit_buttons[i]->Show(true); m_players[i]->Show(false); } else { m_sit_buttons[i]->Show(false); m_players[i]->Show(true); } } void TablePic::Stand(const wxString &seat) { Seat i = String2Seat(seat); m_players[i]->SetLabel(""); m_sit_buttons[i]->Show(true); m_players[i]->Show(false); } void TablePic::JoinTable() { m_button->Show(false); } void TablePic::LeaveTable() { m_button->Show(true); } void TablePic::SendEvent(const wxString &type, const wxString &msg) { TablesEvent my_event( this, type, msg); if ( GetParent()->GetEventHandler()->ProcessEvent( my_event ) == FALSE ) wxLogWarning( "Tablepic: Could not process sent event!" ); } void TablePic::ButtonPush(wxCommandEvent& evt) { SendEvent("JOINTABLE", m_name); } void TablePic::SitNorth(wxCommandEvent& evt) { SendEvent("SITBUTTON", "North:" + m_name); } void TablePic::SitSouth(wxCommandEvent& evt) { SendEvent("SITBUTTON", "South:" + m_name); } void TablePic::SitEast(wxCommandEvent& evt) { SendEvent("SITBUTTON", "East:" + m_name); } void TablePic::SitWest(wxCommandEvent& evt) { SendEvent("SITBUTTON", "West:" + m_name); } void TablePic::SetTalkFocus(wxFocusEvent& evt) { GetParent()->GetEventHandler()->ProcessEvent(evt); }