- new auxframes update scheme

- new auxframe : gfxresult
- need some modification in mainframe.[h|cc] to take care of the update
This commit is contained in:
Antoine Fraboulet 2005-12-26 18:14:46 +00:00
parent 504198b8ff
commit 8f605110b7
5 changed files with 716 additions and 171 deletions

View file

@ -27,6 +27,7 @@ AM_CPPFLAGS = @WX_CPPFLAGS@
eliot_SOURCES = \
configdb.cc configdb.h \
gfxboard.cc gfxboard.h \
gfxresult.cc gfxresult.h \
printout.cc printout.h \
confdimdlg.cc confdimdlg.h \
confsearch.cc confsearch.h \

View file

@ -1,13 +1,14 @@
/* Eliot */
/* Copyright (C) 1999 Antoine Fraboulet */
/* Antoine.Fraboulet@free.fr */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* This file is part of Eliot. */
/* */
/* Eliot 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, */
/* Eliot 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. */
@ -16,8 +17,15 @@
/* along with this program; if not, write to the Free Software */
/* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
/**
* \file auxframes.cc
* \brief Window Frames used in Eliot
* \author Antoine Fraboulet
* \date 2005
*/
#include <iostream>
using namespace std;
#include <sstream>
#include "wx/sizer.h"
#include "wx/button.h"
@ -31,6 +39,7 @@ using namespace std;
#include "dic.h"
#include "dic_search.h"
#include "training.h"
#include "player.h"
#include "game.h"
#include "configdb.h"
@ -69,6 +78,7 @@ AuxFrame::SwitchDisplay()
Show(TRUE);
Raise();
show = 1;
Reload();
}
else
{
@ -84,6 +94,8 @@ AuxFrame::Reload()
#define MINH 50
wxSize size;
//debug(" %s::Reload() - %s\n",(const char*)classname.mb_str(),(const char*)name.mb_str());
Move(config.getFramePos(classname));
size = config.getFrameSize(classname);
@ -109,7 +121,6 @@ BoardFrame::BoardFrame(wxFrame* parent, Game& iGame):
AuxFrame(parent, ID_Frame_Board, wxT("Grille"), FRAMEBOARD)
{
board = new GfxBoard(this, iGame);
wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
sizer->Add(board, 1, wxEXPAND, 0);
SetAutoLayout(TRUE);
@ -121,6 +132,7 @@ BoardFrame::BoardFrame(wxFrame* parent, Game& iGame):
void
BoardFrame::Refresh(refresh_t force)
{
//debug(" BoardFrame::Refresh\n");
if (force == REFRESH)
board->Refresh(GfxBoard::BOARD_REFRESH);
else
@ -137,9 +149,9 @@ BagFrame::BagFrame(wxFrame* parent, Game& iGame):
{
tiles = new wxListCtrl(this, -1);
tiles->SetSingleStyle(wxLC_LIST);
tiles->SetColumnWidth(0, wxLIST_AUTOSIZE);
tiles->SetFont(config.getFont(LISTFONT));
tiles->SetToolTip(wxT("Lettre, nombre restant"));
//tiles->SetColumnWidth(0, wxLIST_AUTOSIZE);
//tiles->SetFont(config.getFont(LISTFONT));
//tiles->SetToolTip(wxT("Lettre, nombre restant"));
wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
sizer->Add(tiles, 1, wxEXPAND | wxALL, 1);
@ -150,18 +162,28 @@ BagFrame::BagFrame(wxFrame* parent, Game& iGame):
void
BagFrame::Refresh(refresh_t force)
{
int index;
{
//debug(" BagFrame::Refresh\n");
int n,index;
wxString buf;
#ifdef DEBUG
wxChar format[] = wxT("%c:%2d[%2d]");
#else
wxChar format[] = wxT("%c:%2d");
#endif
tiles->ClearAll();
const list<Tile>& allTiles = Tile::getAllTiles();
list<Tile>::const_iterator it;
std::list<Tile>::const_iterator it;
const std::list<Tile>& allTiles = Tile::getAllTiles();
for (index = 0, it = allTiles.begin(); it != allTiles.end(); index++, it++)
{
buf.Printf(format, it->toChar(), m_game.getBag().in(*it));
n = m_game.getBag().in(*it);
#ifdef DEBUG
buf.Printf(format, it->toChar(), n, n - it->maxNumber());
#else
buf.Printf(format, it->toChar(), n);
#endif
tiles->InsertItem(index,buf);
}
}
@ -184,6 +206,7 @@ SearchFrame::SearchFrame(wxFrame *parent, Dictionary _dic):
void
SearchFrame::Refresh(refresh_t force)
{
//debug(" SearchFrame::Refresh\n");
}
/****************************************************************/
@ -244,16 +267,9 @@ VerifFrame::OnText(wxCommandEvent&)
void
VerifFrame::Refresh(refresh_t force)
{
//debug(" VerifFrame::Refresh\n");
}
/** *******************************************************************
**
**
**
**
**
** ********************************************************************/
/****************************************************************/
/* AUXFRAMELIST */
/****************************************************************/
@ -267,10 +283,13 @@ BEGIN_EVENT_TABLE(AuxFrameList, AuxFrame)
EVT_BUTTON (ButtonCopyID , AuxFrameList::OnCopy)
END_EVENT_TABLE()
AuxFrameList::AuxFrameList(wxFrame* parent, int _id, wxString _name, wxString _classname):
AuxFrameList::AuxFrameList(wxFrame* parent, int _id, wxString _name, wxString _classname, Game *g):
AuxFrame(parent, _id, _name, _classname)
{
game = g;
savedword = "";
wxBoxSizer *sizer_v = new wxBoxSizer(wxVERTICAL);
listbox = new wxListBox(this, ListBoxID);
listbox->SetFont(config.getFont(LISTFONT));
@ -314,82 +333,116 @@ AuxFrameList::Waiting()
listbox->Show(TRUE);
}
void
AuxFrameList::Refresh(refresh_t force)
{
//debug(" %s : Refresh start\n",(const char*)name.mb_str());
if (game == NULL)
{
listbox->Clear();
listbox->Append(wxT("Pas de partie en cours"));
//debug(" %s : Refresh end - no game\n",(const char*)name.mb_str());
return;
}
if (game->getDic() == NULL)
{
listbox->Clear();
listbox->Append(wxT("Pas de dictionnaire"));
//debug(" %s : Refresh end - no dictionnary\n",(const char*)name.mb_str());
return;
}
if (show == 0)
{
//debug(" %s : Refresh end - no window\n",(const char*)name.mb_str());
return;
}
noresult = true;
refresh();
if (noresult == true)
{
//debug(" %s : noresult == true\n",(const char*)name.mb_str());
listbox->Clear();
listbox->Append(wxT("Aucun resultat"));
}
//debug(" %s : Refresh end\n",(const char*)name.mb_str());
}
/****************************************************************/
/* PLUS1 FRAME */
/****************************************************************/
Plus1Frame::Plus1Frame(wxFrame* parent, Game& iGame):
AuxFrameList(parent, ID_Frame_Plus1, wxT("Tirage + 1"), FRAMEPLUS1),
m_game(iGame)
{
m_rack[0] = '\0';
}
void
Plus1Frame::Refresh(refresh_t force)
Plus1Frame::refresh()
{
int i, j;
string rack2;
std::string rack;
//debug(" Plus1Frame::refresh start\n");
rack = game->getCurrentPlayer().getCurrentRack().toString();
assert(0);
//debug(" CurrentPlayer -> rack : %s\n",rack.c_str());
if (savedword == rack)
{
noresult = false; // keep old results
//debug(" Plus1Frame::refresh end, no change\n");
return;
}
savedword = rack;
char buff[DIC_LETTERS][RES_7PL1_MAX][DIC_WORD_MAX];
Dic_search_7pl1(game->getDic(), rack.c_str(), buff, config.getJokerPlus1());
rack2 = m_game.getPlayerRack(0);
if (m_rack == rack2)
return;
m_rack = rack2;
Waiting();
Dic_search_7pl1(m_game.getDic(), m_rack.c_str(), buff, config.getJokerPlus1());
int resnum = 0;
listbox->Clear();
wxString res[DIC_LETTERS*(RES_7PL1_MAX+1)];
// wxString(wxT) added for clean compile with wx2.4
res[resnum++] = wxString(wxT("Tirage: ")) + wxString(wxU(m_rack.c_str()));
for (i = 0; i < DIC_LETTERS; i++)
int resnum = 0;
res[resnum++] = wxString(wxT("Tirage: ")) + wxString(wxU(rack.c_str()));
for (int i = 0; i < DIC_LETTERS; i++)
{
if (i && buff[i][0][0])
res[resnum++] = wxString(wxT("+")) + (wxChar)(i + 'A' - 1);
for (j = 0; j < RES_7PL1_MAX && buff[i][j][0]; j++)
res[resnum++] = wxString(wxT(" ")) + wxU(buff[i][j]);
{
res[resnum++] = wxString(wxT("+")) + (wxChar)(i + 'A' - 1);
noresult = false;
}
for (int j = 0; j < RES_7PL1_MAX && buff[i][j][0]; j++)
{
res[resnum++] = wxString(wxT(" ")) + wxU(buff[i][j]);
noresult = false;
}
}
listbox->Set(resnum, res);
//debug(" Plus1Frame::refresh end\n");
}
/****************************************************************/
/* BENJAMINS */
/****************************************************************/
BenjFrame::BenjFrame(wxFrame* parent, Game& iGame, wxListCtrl* _results):
AuxFrameList(parent, ID_Frame_Benj, wxT("benjamins"), FRAMEBENJ),
m_game(iGame)
{
results = _results;
}
void
BenjFrame::Refresh(refresh_t force)
BenjFrame::refresh()
{
int i;
std::string word;
if (game->getMode() != Game::kTRAINING)
return;
word = ((Training*)game)->getTestPlayWord();
if (savedword == word)
{
noresult = false; // keep old results
return;
}
savedword = word;
//debug(" BenjFrame::refresh : %s\n",word.c_str());
char wordlist[RES_BENJ_MAX][DIC_WORD_MAX];
long item = -1;
item = results->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
// item can be -1
Dic_search_Benj(game->getDic(), word.c_str(), wordlist);
if (item < 0)
{
listbox->Clear();
return;
}
Waiting();
Dic_search_Benj(m_game.getDic(),
((Training&)m_game).getSearchedWord(item).c_str(), wordlist);
int resnum = 0;
wxString res[RES_BENJ_MAX];
for (i = 0; (i < RES_BENJ_MAX) && (wordlist[i][0]); i++)
res[resnum++] = wxU(wordlist[i]);
int resnum = 0;
for (int i = 0; (i < RES_BENJ_MAX) && (wordlist[i][0]); i++)
{
res[resnum++] = wxU(wordlist[i]);
//debug(" BenjFrame : %s (%d)\n",wordlist[i],resnum);
noresult = false;
}
listbox->Set(resnum, res);
}
@ -398,41 +451,160 @@ BenjFrame::Refresh(refresh_t force)
/* RACC FRAME */
/****************************************************************/
RaccFrame::RaccFrame(wxFrame* parent, Game& iGame, wxListCtrl* _results):
AuxFrameList(parent, ID_Frame_Racc, wxT("raccords"), FRAMERACC),
m_game(iGame)
{
results = _results;
}
void
RaccFrame::Refresh(refresh_t force)
RaccFrame::refresh()
{
int i;
std::string word;
if (game->getMode() != Game::kTRAINING)
return;
word = ((Training*)game)->getTestPlayWord();
if (savedword == word)
{
noresult = false; // keep old results
return;
}
savedword = word;
//debug(" RaccFrame::refresh : %s\n",word.c_str());
char wordlist[RES_RACC_MAX][DIC_WORD_MAX];
long item = -1;
item = results->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
// item can be -1
Dic_search_Racc(game->getDic(), word.c_str(), wordlist);
if (item < 0)
{
listbox->Clear();
return;
}
Waiting();
Dic_search_Racc(m_game.getDic(),
((Training&)m_game).getSearchedWord(item).c_str(), wordlist);
int resnum = 0;
wxString res[RES_RACC_MAX];
for (i = 0; (i < RES_RACC_MAX) && (wordlist[i][0]); i++)
{
res[resnum++] = wxU(wordlist[i]);
}
int resnum = 0;
for (int i = 0; (i < RES_RACC_MAX) && (wordlist[i][0]); i++)
{
res[resnum++] = wxU(wordlist[i]);
//debug(" RaccFrame : %s (%d)\n",wordlist[i],resnum);
noresult = false;
}
listbox->Set(resnum, res);
}
/****************************************************************/
/* AUXFRAMETEXT */
/****************************************************************/
AuxFrameText::AuxFrameText(wxFrame* parent, int _id, wxString _name, wxString _classname, int _style):
AuxFrame(parent, _id, _name, _classname)
{
wxBoxSizer *sizer_v = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
wxFont font(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
wxFONTWEIGHT_NORMAL, false, wxString(wxT("Courier New")), wxFONTENCODING_SYSTEM);
textbox = new wxTextCtrl(this, -1, wxT(""), wxDefaultPosition, wxDefaultSize, _style);
textbox->SetFont(font);
sizer_v->Add(textbox, 1, wxEXPAND | wxALL, 1);
sizer->Add(sizer_v, 1, wxEXPAND, 0);
SetAutoLayout(TRUE);
SetSizer(sizer);
sizer->Fit(this);
sizer->SetSizeHints(this);
}
/****************************************************************/
/* GAME FRAME */
/****************************************************************/
GameFrame::GameFrame(wxFrame* parent, Game& iGame):
AuxFrameText(parent, ID_Frame_Game, wxT("partie"), FRAMEGAME, wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP),
m_game(iGame)
{
textbox->Clear();
textbox->AppendText(wxT(""));
}
void
GameFrame::Refresh(refresh_t force)
{
std::ostringstream mos;
m_game.save(mos);
#ifdef DEBUG
mos << std::string(30,'-') << std::endl;
mos << "Player History\n";
//FIXME1 mos << m_game.getPlayer(0).getHistory().toString();
mos << std::string(30,'-') << std::endl;
mos << "Game History\n";
//FIXME1 mos << m_game.getHistory().toString();
#endif
textbox->Clear();
textbox->AppendText( wxU( mos.str().c_str() ) );
}
/****************************************************************/
/* RESULT FRAME */
/****************************************************************/
BEGIN_EVENT_TABLE(ResultFrame, AuxFrame)
END_EVENT_TABLE()
ResultFrame::ResultFrame(wxFrame* parent, Game* iGame):
AuxFrame(parent, ID_Frame_Result, wxT("recherche"), FRAMERESULT)
{
reslist = new GfxResult(this, (MainFrame*)parent, iGame);
wxBoxSizer *sizer_v = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
sizer_v->Add(reslist, 1, wxEXPAND, 0);
sizer->Add (sizer_v, 1, wxEXPAND | wxALL, 2);
SetAutoLayout(TRUE);
SetSizer(sizer);
sizer->Fit(this);
sizer->SetSizeHints(this);
//debug("ResultFrame created\n");
}
void
ResultFrame::Refresh(refresh_t WXUNUSED(force))
{
if (reslist != NULL)
{
reslist->Show(false);
//debug("ResultFrame refresh\n");
reslist->Refresh();
reslist->Show(true);
}
}
void
ResultFrame::Search()
{
if (reslist != NULL)
{
reslist->Search();
}
}
int
ResultFrame::GetSelected()
{
if (reslist != NULL)
{
return reslist->GetSelected();
}
return -1;
}
void
ResultFrame::OnSize(wxSizeEvent& e)
{
int w,h;
GetClientSize(&w,&h);
//debug("ResultFrame::OnSize (%d,%d)\n",w,h);
}
/****************************************************************/
/****************************************************************/
/// Local Variables:
/// mode: c++
/// mode: hs-minor
/// c-basic-offset: 4
/// End:

View file

@ -1,13 +1,14 @@
/* Eliot */
/* Copyright (C) 1999 Antoine Fraboulet */
/* Antoine.Fraboulet@free.fr */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* This file is part of Eliot. */
/* */
/* Eliot 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, */
/* Eliot 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. */
@ -16,12 +17,16 @@
/* along with this program; if not, write to the Free Software */
/* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
// -*- C++ -*-
/**
* \file auxframes.h
* \brief Window Frames used in Eliot
* \author Antoine Fraboulet
* \date 2005
*/
#ifndef _AUXFRAMES_H
#define _AUXFRAMES_H
#include "searchpanel.h"
#include "gfxboard.h"
#include "wx/frame.h"
#include "wx/listctrl.h"
#include "wx/textctrl.h"
@ -29,13 +34,12 @@
#include "wx/listbox.h"
#include "wx/button.h"
#define MIN_FRAME_ID 0
#define MAX_FRAME_ID 7
#include "searchpanel.h"
#include "gfxboard.h"
#include "gfxresult.h"
typedef enum {
REFRESH,
FORCE_REFRESH
} refresh_t;
#define MIN_FRAME_ID 0
#define MAX_FRAME_ID 9
typedef enum {
ID_Frame_Verif = MIN_FRAME_ID + 0,
@ -44,46 +48,98 @@ typedef enum {
ID_Frame_Racc = MIN_FRAME_ID + 3,
ID_Frame_Benj = MIN_FRAME_ID + 4,
ID_Frame_Bag = MIN_FRAME_ID + 5,
ID_Frame_Board = MIN_FRAME_ID + 6
ID_Frame_Board = MIN_FRAME_ID + 6,
ID_Frame_Game = MIN_FRAME_ID + 7,
ID_Frame_Result = MIN_FRAME_ID + 8
} frames_id_t;
/** ******************************
/**
* Generic AuxFrame :
* - BoardFrame
* - BagFrame
* - SearchFrame
* - VerifFrame
* - ResultFrame
* derived to AuxFrameList :
* - Plus1Frame
* - BenjFrame
* - RaccFrame
* derived to AuxFrameText :
* - GameFrame
*
****************************** */
*/
class AuxFrame: public wxFrame
{
protected:
int show;
int show;
frames_id_t frameid;
wxString name, classname;
ConfigDB config;
wxString name, classname;
ConfigDB config;
public:
AuxFrame(wxFrame*, int, wxString, wxString);
AuxFrame (wxFrame*, int, wxString, wxString);
~AuxFrame();
typedef enum {
REFRESH,
FORCE_REFRESH
} refresh_t;
void SwitchDisplay();
void Reload();
virtual void Refresh(refresh_t force = REFRESH) {};
};
/** ******************************
*
****************************** */
/**
* Generic auxframe that includes a list and a """copy""" button
*/
class AuxFrameList: public AuxFrame
{
protected:
bool noresult;
string savedword;
Game *game;
wxButton *button;
wxListBox *listbox;
void Waiting();
virtual void refresh() = 0;
public:
AuxFrameList(wxFrame*, int, wxString, wxString, Game*);
void OnCopy(wxCommandEvent& event);
void Refresh(refresh_t force = REFRESH);
DECLARE_EVENT_TABLE()
};
/**
* Generic auxframe that includes a text area
*/
class AuxFrameText: public AuxFrame
{
protected:
wxTextCtrl *textbox;
public:
AuxFrameText(wxFrame*, int, wxString, wxString, int);
};
/**
* Frame to display the game board
*/
class BoardFrame: public AuxFrame
{
protected:
GfxBoard* board;
GfxBoard *board;
public:
BoardFrame(wxFrame*, Game&);
void Refresh(refresh_t force = REFRESH);
};
/** ******************************
*
****************************** */
/**
* Frame to display the tiles left in the bag
*/
class BagFrame: public AuxFrame
{
@ -95,9 +151,9 @@ public:
void Refresh(refresh_t force = REFRESH);
};
/** ******************************
*
****************************** */
/**
* Several research tool in a panel widget within the frame
*/
class SearchFrame: public AuxFrame
{
@ -108,13 +164,13 @@ public:
void Refresh(refresh_t force = REFRESH);
};
/** ******************************
*
****************************** */
/**
* Frame to verify if a word is in the dictionary
*/
class VerifFrame: public AuxFrame
{
private:
protected:
Dictionary dic;
wxTextCtrl *word;
wxStaticText *result;
@ -126,63 +182,76 @@ public:
DECLARE_EVENT_TABLE()
};
/** **********************************************************
**************************************************************
*********************************************************** */
class AuxFrameList: public AuxFrame
{
protected:
wxListBox *listbox;
wxButton *button;
public:
AuxFrameList(wxFrame*, int, wxString, wxString);
void OnCopy(wxCommandEvent& event);
void Waiting();
DECLARE_EVENT_TABLE()
};
/** ******************************
*
****************************** */
/**
* Displays the list of 7+1 for the current search
*/
class Plus1Frame: public AuxFrameList
{
protected:
Game& m_game;
string m_rack;
virtual void refresh();
public:
Plus1Frame(wxFrame*, Game&);
void Refresh(refresh_t force = REFRESH);
Plus1Frame(wxFrame* p, Game* g) : AuxFrameList(p, ID_Frame_Plus1, wxT("Tirage + 1"), FRAMEPLUS1, g) {};
};
/** ******************************
*
****************************** */
/**
* Displays the list of benjamins for the current selected word
*/
class BenjFrame: public AuxFrameList
{
protected:
Game& m_game;
wxListCtrl* results;
virtual void refresh();
public:
BenjFrame(wxFrame*, Game&, wxListCtrl*);
void Refresh(refresh_t force = REFRESH);
BenjFrame(wxFrame* p, Game* g) : AuxFrameList(p, ID_Frame_Benj, wxT("benjamins"), FRAMEBENJ, g) {};
};
/** ******************************
*
****************************** */
/**
* Displays the list of possible glue letter for the current selected word
*/
class RaccFrame: public AuxFrameList
{
protected:
Game& m_game;
wxListCtrl* results;
virtual void refresh();
public:
RaccFrame(wxFrame*, Game&, wxListCtrl*);
RaccFrame(wxFrame* p, Game* g) : AuxFrameList(p, ID_Frame_Racc, wxT("raccords"), FRAMERACC, g) {};
};
/**
* Displays the current game
*/
class GameFrame: public AuxFrameText
{
protected:
Game& m_game;
public:
GameFrame(wxFrame*, Game&);
void Refresh(refresh_t force = REFRESH);
};
/**
* Displays the list of possible words searched for the given rack and board
*/
class ResultFrame: public AuxFrame
{
protected:
GfxResult *reslist;
public:
ResultFrame(wxFrame*, Game*);
void Search();
int GetSelected();
void Refresh(refresh_t force = REFRESH);
void OnSize(wxSizeEvent& e);
DECLARE_EVENT_TABLE()
};
#endif
/// Local Variables:
/// mode: c++
/// mode: hs-minor
/// c-basic-offset: 4
/// End:

234
wxwin/gfxresult.cc Normal file
View file

@ -0,0 +1,234 @@
/* Eliot */
/* Copyright (C) 1999 Antoine Fraboulet */
/* */
/* This file is part of Eliot. */
/* */
/* Eliot 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. */
/* */
/* Eliot 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
/**
* \file reslist.cc
* \brief Search results list view
* \author Antoine Fraboulet
* \date 2005
*/
#include <wx/wx.h>
#include "ewx.h"
#include "dic.h"
#include "game.h"
#include "player.h"
#include "training.h"
#include "configdb.h"
#include "gfxresult.h"
#include "mainframe.h"
/* ************************************************** */
/* ************************************************** */
enum {
ListCtrl_ID = 11000
};
BEGIN_EVENT_TABLE(GfxResult, wxControl)
EVT_SIZE(GfxResult::OnSize)
EVT_LIST_ITEM_SELECTED (ListCtrl_ID, GfxResult::OnListCtrlSelected)
EVT_LIST_ITEM_ACTIVATED (ListCtrl_ID, GfxResult::OnListCtrlActivated)
END_EVENT_TABLE()
/* ************************************************** */
/* ************************************************** */
GfxResult::GfxResult(wxFrame *parent, MainFrame* _mf, Game* _game) :
wxControl(parent, wxWindowID(234), wxDefaultPosition, wxDefaultSize,
wxNO_BORDER | wxFULL_REPAINT_ON_RESIZE)
{
mf = _mf;
game = _game;
savedrack = std::string("");
results = new wxListCtrl(this, ListCtrl_ID);
#if defined(ENABLE_LC_NO_HEADER)
results->SetSingleStyle(wxLC_REPORT | wxLC_NO_HEADER | wxLC_SINGLE_SEL);
#else
results->SetSingleStyle(wxLC_REPORT | wxLC_SINGLE_SEL);
#endif
results->InsertColumn(0, wxT("Sol"));
results->InsertColumn(1, wxT("*"));
results->InsertColumn(2, wxT("Pos"));
results->InsertColumn(3, wxT("Pts"));
results->SetToolTip(wxT("Resultats de la recherche"));
wxBoxSizer *sizer_v = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *sizer_h = new wxBoxSizer(wxHORIZONTAL);
sizer_v->Add(results, 1, wxEXPAND, 0);
sizer_h->Add(sizer_v, 1, wxEXPAND, 0);
SetAutoLayout(TRUE);
SetSizer(sizer_h);
sizer_h->Fit(this);
sizer_h->SetSizeHints(this);
}
/* ************************************************** */
/* ************************************************** */
GfxResult::~GfxResult(void)
{
//debug(" GfxResult::~GfxResult\n");
Show(false);
Show(true);
}
/* ************************************************** */
/* ************************************************** */
void
GfxResult::SetGame(Game* g)
{
game = g;
savedrack = std::string("");
results->DeleteAllItems();
}
/* ************************************************** */
/* ************************************************** */
void
GfxResult::Refresh()
{
if (game == NULL)
return;
//debug(" GfxResult::Refresh : ");
std::string rack = game->getCurrentPlayer().getCurrentRack().toString();
if (savedrack != rack)
{
//debug("changed (%s -> %s)",savedrack.c_str(),rack.c_str());
savedrack = rack;
results->DeleteAllItems();
}
else
{
//debug("unchanged");
}
//debug("\n");
}
/* ************************************************** */
/* ************************************************** */
void
GfxResult::Search()
{
//debug("GfxResult::Search()\n");
if (game == NULL)
return;
((Training*)game)->search();
results->DeleteAllItems();
results->SetFont(config.getFont(LISTFONT));
const Results &res = ((Training*)game)->getResults();
//debug(" GfxResult::Search size = %d\n",res.size());
for (int i = 0; i < res.size(); i++)
{
Round r = res.get(i);
//debug(" adding %s\n",r.toString().c_str());
wxString pts;
wxString word = wxU(r.getWord().c_str());
wxString coords = wxU(r.getCoord().toString().c_str());
wxChar bonus = r.getBonus() ? wxT('*') : wxT(' ');
pts << r.getPoints();
long tmp = results->InsertItem(i, word);
results->SetItemData(tmp, i);
tmp = results->SetItem(i, 1, bonus);
tmp = results->SetItem(i, 2, coords);
tmp = results->SetItem(i, 3, pts);
}
for (int i = 0; i < 4; i++)
results->SetColumnWidth(i, wxLIST_AUTOSIZE);
// results->Show();
if (res.size() > 0)
{
results->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED | wxLIST_MASK_STATE);
((Training*)game)->testPlay(0);
}
}
/* ************************************************** */
/* ************************************************** */
int
GfxResult::GetSelected()
{
int item = -1;
item = results->GetNextItem(item,wxLIST_NEXT_ALL,wxLIST_STATE_SELECTED);
//debug("GfxResult::GetSelected = %d\n",item);
return item;
}
/* ************************************************** */
/* ************************************************** */
void
GfxResult::OnListCtrlSelected(wxListEvent& event)
{
//debug(" GfxResult::OnListCtrlSelected\n");
if (event.m_itemIndex > -1)
{
mf->TestPlay(event.m_itemIndex);
}
}
/* ************************************************** */
/* ************************************************** */
void
GfxResult::OnListCtrlActivated(wxListEvent& event)
{
//debug(" GfxResult::OnListCtrlActivated");
if (event.m_itemIndex > -1)
{
mf->Play(1);
results->DeleteAllItems();
}
}
/* ************************************************** */
/* ************************************************** */
void
GfxResult::OnSize(wxSizeEvent& e)
{
int w,h;
GetClientSize(&w,&h);
results->SetClientSize(w,h);
//debug(" GfxResult::OnSize (%d,%d)\n",w,h);
}
/* ************************************************** */
/* ************************************************** */
/// Local Variables:
/// mode: hs-minor
/// c-basic-offset: 4
/// End:

69
wxwin/gfxresult.h Normal file
View file

@ -0,0 +1,69 @@
/* Eliot */
/* Copyright (C) 2005 Antoine Fraboulet */
/* */
/* This file is part of Eliot. */
/* */
/* Eliot 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. */
/* */
/* Eliot 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
/**
* \file reslist.h
* \brief Search results list view
* \author Antoine Fraboulet
* \date 2005
*/
#ifndef _RESLIST_H
#define _RESLIST_H
/**
*
*/
#include <wx/listctrl.h>
class MainFrame;
class GfxResult : public wxControl
{
private:
MainFrame *mf;
std::string savedrack;
Game *game;
wxListCtrl *results;
ConfigDB config;
public:
GfxResult(wxFrame*, MainFrame*, Game*);
~GfxResult();
void SetGame(Game*);
void Search();
int GetSelected();
void Refresh();
void OnSize(wxSizeEvent& e);
void OnListCtrlSelected(wxListEvent& event);
void OnListCtrlActivated(wxListEvent& event);
DECLARE_EVENT_TABLE()
};
#endif
/// Local Variables:
/// mode: c++
/// mode: hs-minor
/// c-basic-offset: 4
/// End: