///////////////////////////////////////////////////////////////////////////// // Name: bidwindow.cpp // tag: a window for bidding // Author: David Roundy // Modified by: // Created: 9/2001 // Copyright: (c) 2001 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 "bidwindow.h" #include "debug.h" #include "gameevent.h" #include "prefmacros.h" #include "nofocusbutton.h" wxPoint BidWindow::defpos = wxPoint(500,350); #ifdef __WXMSW__ static const wxSize bidwindowsize = wxSize(305,230); #else static const wxSize bidwindowsize = wxSize(305,225); #endif #define BID_BUTTON_ID 137 BEGIN_EVENT_TABLE(BidWindow, FloatWindow) EVT_COMMAND_RANGE(100, 1000, wxEVT_COMMAND_BUTTON_CLICKED, BidWindow::ButtonPushed) END_EVENT_TABLE() static int bidbits_initialized = 0; static wxBitmap *bidbits[6][8]; BidWindow::BidWindow(wxWindow* parent, int current_val, Suit current_suit, bool can_double, bool can_redouble) : FloatWindow(parent->GetParent(), -1, "Bid", GetRelativePosition(), bidwindowsize, wxDEFAULT_DIALOG_STYLE) { if (!bidbits_initialized) for (int s=0;s<6;s++) for (int b=0;b<8;b++) bidbits[s][b] = NULL; int bidval; m_game = parent; for (bidval=7;bidval>=1;bidval--) { m_bids[bidval][clubs] = BidButton(this,bidval, clubs, 0+5, 25*(bidval-1)+5); m_bids[bidval][diamonds] = BidButton(this,bidval, diamonds, 60+5, 25*(bidval-1)+5); m_bids[bidval][hearts] = BidButton(this,bidval, hearts, 120+5, 25*(bidval-1)+5); m_bids[bidval][spades] = BidButton(this,bidval, spades, 180+5, 25*(bidval-1)+5); m_bids[bidval][notrump] = BidButton(this,bidval, notrump, 240+5, 25*(bidval-1)+5); } m_pass = BidButton(this,0,clubs, 0+5,25*7+5,80); m_double = BidButton(this,-1,clubs, 100+5,25*7+5,90); m_redouble = BidButton(this,-2,clubs, 200+5,25*7+5,90); if (current_val) { Suit suit; for (bidval=1;bidvalEnable(FALSE); } } for (suit=clubs;suit<=current_suit; suit = (Suit)(suit + 1)) { m_bids[current_val][suit]->Enable(FALSE); } m_double->Enable(can_double); m_redouble->Enable(can_redouble); } else { m_double->Enable(FALSE); m_redouble->Enable(FALSE); } ParentMoved(); } BidWindow::~BidWindow() { defpos = GetPosition() - GetParent()->GetPosition(); SetBidWindowPosition(defpos); } void BidWindow::InitStaticVariables() { if (GetRememberWindowPositions()) { defpos = GetBidWindowPosition(); } else { defpos = wxPoint(500,350); } } static wxString BidString(int bid_val, Suit suit) { wxString bid_string; if (bid_val > 0) { bid_string = ""; bid_string << bid_val; bid_string << " " << Suit2Char(suit); } else if (bid_val == 0) { bid_string = "Pass"; } else if (bid_val == -1) { bid_string = "Double"; } else if (bid_val == -2) { bid_string = "Redouble"; } return bid_string; } void BidWindow::ButtonPushed(wxCommandEvent& event) { int my_id = event.GetId() - BID_BUTTON_ID; int bid_val = my_id % 13; Suit suit = (Suit) (my_id / 13); if (my_id < 0) bid_val = my_id; GameEvent my_event( this, "BID", BidString(bid_val, suit)); wxPostEvent(m_game->GetEventHandler(), my_event); //if ( m_game->GetEventHandler()->ProcessEvent( my_event ) == FALSE ) // wxLogWarning( "BidWindow: could not process buttonpushed event!" ); Destroy(); } static inline SuitColour suit_to_color(Suit suit) { switch (suit) { case clubs: case spades: return black; case diamonds: case hearts: return red; } } wxBitmapButton *BidWindow::BidButton(wxWindow* parent, int bid_val, Suit suit, int x, int y, int w, int h) { wxString bid_string = BidString(bid_val, suit); wxBitmap mybits(40,14); wxMemoryDC dc; dc.SelectObject(mybits); wxBrush back(parent->GetBackgroundColour(), wxSOLID); dc.SetBackground( back ); dc.Clear(); if (suit != notrump && bid_val >= 1) { if (!bidbits[suit][bid_val]) { wxString num = ""; num << bid_val; DrawNumber(dc, num, suit_to_color(suit) == red, false, 9, 0, 12, 12); DrawSuit(dc, suit, 0, 20,0,12,12); mybits.SetMask(new wxMask(mybits, parent->GetBackgroundColour())); bidbits[suit][bid_val] = new wxBitmap(mybits); } else { mybits = *bidbits[suit][bid_val]; } } else { if (suit == notrump) { if (!bidbits[suit][bid_val]) { wxString num = ""; num << bid_val << "NT"; DrawNumber(dc, num, false, false, 7, 0, 26, 12); mybits.SetMask(new wxMask(mybits, parent->GetBackgroundColour())); bidbits[suit][bid_val] = new wxBitmap(mybits); } else { mybits = *bidbits[suit][bid_val]; } } else if (bid_val == 0) { if (!bidbits[0][0]) { wxString b = "Pass"; DrawNumber(dc, b, false, false, 0, 0, 40, 12); mybits.SetMask(new wxMask(mybits, parent->GetBackgroundColour())); bidbits[0][0] = new wxBitmap(mybits); } else { mybits = *bidbits[0][0]; } } else if (bid_val == -1) { if (!bidbits[1][0]) { wxString b = "Double"; DrawNumber(dc, b, false, false, 0, 0, 40, 12); mybits.SetMask(new wxMask(mybits, parent->GetBackgroundColour())); bidbits[1][0] = new wxBitmap(mybits); } else { mybits = *bidbits[1][0]; } } else if (bid_val == -2) { if (!bidbits[2][0]) { wxString b = "Redouble"; DrawNumber(dc, b, false, false, 0, 0, 40, 12); mybits.SetMask(new wxMask(mybits, parent->GetBackgroundColour())); bidbits[2][0] = new wxBitmap(mybits); } else { mybits = *bidbits[2][0]; } } } return new NoFocusButton(parent, BID_BUTTON_ID+bid_val+13*suit, mybits, wxPoint(x,y), wxSize(w, h), wxBU_AUTODRAW, wxDefaultValidator, bid_string); } bool BidWindow::OnCloseWindow() { return false; // Never allow the window to be closed! } wxPoint BidWindow::GetRelativePosition() { return defpos; } void BidWindow::SetRelativePosition(wxPoint p) { defpos = p; }