Commit 85652014 authored by twanvl's avatar twanvl

Card list for selecting cards; window using that list; print function using...

Card list for selecting cards; window using that list; print function using that window (actual printing todo)
parent a0390eff
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <gui/card_select_window.hpp>
#include <gui/control/select_card_list.hpp>
#include <util/window_id.hpp>
// ----------------------------------------------------------------------------- : CardSelectWindow
CardSelectWindow::CardSelectWindow(Window* parent, const SetP& set, const String& label)
: wxDialog(parent, wxID_ANY, _TITLE_("select cards"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
, set(set)
{
// init controls
list = new SelectCardList(this, wxID_ANY);
list->setSet(set);
wxButton* sel_all = new wxButton(this, ID_SELECT_ALL, _BUTTON_("select all"));
wxButton* sel_none = new wxButton(this, ID_SELECT_NONE, _BUTTON_("select none"));
// init sizers
wxSizer* s = new wxBoxSizer(wxVERTICAL);
s->Add(new wxStaticText(this, wxID_ANY, label), 0, wxALL & ~wxBOTTOM, 8);
s->Add(list, 1, wxEXPAND | wxALL, 8);
wxSizer* s2 = new wxBoxSizer(wxHORIZONTAL);
s2->Add(sel_all, 0, wxEXPAND | wxRIGHT, 8);
s2->Add(sel_none, 0, wxEXPAND | wxRIGHT, 8);
s2->Add(CreateButtonSizer(wxOK | wxCANCEL), 1, wxEXPAND, 8);
s->Add(s2, 0, wxEXPAND | wxALL & ~wxTOP, 8);
s->SetSizeHints(this);
SetSizer(s);
SetSize(500,500);
}
bool CardSelectWindow::isSelected(const CardP& card) const {
return list->isSelected(card);
}
void CardSelectWindow::onSelectAll(wxCommandEvent&) {
list->selectAll();
}
void CardSelectWindow::onSelectNone(wxCommandEvent&) {
list->selectNone();
}
BEGIN_EVENT_TABLE(CardSelectWindow,wxDialog)
EVT_BUTTON (ID_SELECT_ALL, CardSelectWindow::onSelectAll)
EVT_BUTTON (ID_SELECT_NONE, CardSelectWindow::onSelectNone)
END_EVENT_TABLE ()
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_GUI_CARD_SELECT_WINDOW
#define HEADER_GUI_CARD_SELECT_WINDOW
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
DECLARE_POINTER_TYPE(Set);
DECLARE_POINTER_TYPE(Card);
class SelectCardList;
// ----------------------------------------------------------------------------- : CardSelectWindow
/// A window for selecting a subset of the cards from a set.
/** this is used when printing or exporting
*/
class CardSelectWindow : public wxDialog {
public:
CardSelectWindow(Window* parent, const SetP& set, const String& label);
/// Is the given card selected?
bool isSelected(const CardP& card) const;
protected:
DECLARE_EVENT_TABLE();
SelectCardList* list;
SetP set;
void onSelectAll (wxCommandEvent&);
void onSelectNone(wxCommandEvent&);
};
// ----------------------------------------------------------------------------- : EOF
#endif
...@@ -7,7 +7,98 @@ ...@@ -7,7 +7,98 @@
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
#include <gui/control/select_card_list.hpp> #include <gui/control/select_card_list.hpp>
#include <gui/util.hpp>
DECLARE_TYPEOF_COLLECTION(CardP);
// ----------------------------------------------------------------------------- : SelectCardList // ----------------------------------------------------------------------------- : SelectCardList
// TODO SelectCardList::SelectCardList(Window* parent, int id, long additional_style)
: CardListBase(parent, id, additional_style)
{
// create image list
wxImageList* il = new wxImageList(15,15);
il->Add(Bitmap(_("SORT_ASC")), Color(255,0,255));
il->Add(Bitmap(_("SORT_DESC")), Color(255,0,255));
il->Add(load_resource_image(_("DESELECTED")));
il->Add(load_resource_image(_("SELECTED")));
AssignImageList(il, wxIMAGE_LIST_SMALL);
}
void SelectCardList::selectAll() {
FOR_EACH_CONST(c, getCards()) {
selected.insert(c);
}
Refresh(false);
}
void SelectCardList::selectNone() {
selected.clear();
Refresh(false);
}
bool SelectCardList::isSelected(const CardP& card) const {
return selected.find(card) != selected.end();
}
void SelectCardList::onChangeSet() {
CardListBase::onChangeSet();
// init selected list: select all
selected.clear();
selectAll();
}
int SelectCardList::OnGetItemImage(long pos) const {
return isSelected(getCard(pos)) ? 3 : 2;
}
// ----------------------------------------------------------------------------- : Events
void SelectCardList::toggle(const CardP& card) {
if (isSelected(card)) {
selected.erase(card);
} else {
selected.insert(card);
}
}
void SelectCardList::onKeyDown(wxKeyEvent& ev) {
if (selected_card_pos == -1 || !selected_card) {
// no selection
ev.Skip();
return;
}
switch (ev.GetKeyCode()) {
case WXK_SPACE: {
toggle(selected_card);
RefreshItem(selected_card_pos);
break;
}
case WXK_NUMPAD_ADD: case '+': {
selected.insert(selected_card);
RefreshItem(selected_card_pos);
break;
}
case WXK_NUMPAD_SUBTRACT: case '-': {
selected.erase(selected_card);
RefreshItem(selected_card_pos);
break;
}
default:
ev.Skip();
}
}
void SelectCardList::onLeftDown(wxMouseEvent& ev) {
int flags;
long item = HitTest(wxPoint(ev.GetX(), ev.GetY()), flags);
if (flags == wxLIST_HITTEST_ONITEMICON) {
// only clicking the icon toggles
toggle(getCard(item));
RefreshItem(item);
}
ev.Skip();
}
BEGIN_EVENT_TABLE(SelectCardList, CardListBase)
EVT_KEY_DOWN (SelectCardList::onKeyDown)
EVT_LEFT_DOWN (SelectCardList::onLeftDown)
END_EVENT_TABLE ()
...@@ -25,7 +25,8 @@ class SelectCardList : public CardListBase { ...@@ -25,7 +25,8 @@ class SelectCardList : public CardListBase {
/// Is the given card selected? /// Is the given card selected?
bool isSelected(const CardP& card) const; bool isSelected(const CardP& card) const;
protected: protected:
int OnGetItemImage(long pos) const; virtual int OnGetItemImage(long pos) const;
virtual void onChangeSet();
private: private:
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
......
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <gui/print_window.hpp>
#include <gui/card_select_window.hpp>
#include <gui/util.hpp>
#include <data/set.hpp>
DECLARE_TYPEOF_COLLECTION(CardP);
// ----------------------------------------------------------------------------- : Buffering DC
/// MemoryDC that buffers calls to write text
/** The printer device doesn't support alpha channels (at least not in wxMSW)
* This would result in black backgrounds where symbols should be transparent
* Our solution is:
* 1. Write all bitmaps to a buffer DC, initially white
* 2. When drawing with alpha: blend with the buffer
* 3. When drawing text: buffer the call
* 4. Draw the buffer image to the device
* 5. Replay the buffered text draw calls
* To simplify things this class itself is a fullblown DC, only text calls are buffered for later
* Actually buffering text separatly would not be necessary at all, but if we don't the text will be
* printed in a low resolution.
*/
class TextBufferDC : public wxMemoryDC {
public:
TextBufferDC(UInt width, UInt height);
virtual void DoDrawText(const String& str, int x, int y);
virtual void DoDrawRotatedText(const String& str, int x, int y, double angle);
/// Copy the contents of the DC to a target device, this DC becomes invalid
void drawToDevice(DC& dc, int x = 0, int y = 0);
private:
// A call to DrawText
struct TextDraw {
wxFont font;
Color color;
int x, y;
String text;
double angle;
TextDraw(wxFont font, Color color, int x, int y, String text, double angle = 0)
: font(font), color(color), x(x), y(y), text(text), angle(angle)
{}
};
public:
typedef shared_ptr<TextDraw> TextDrawP;
private:
vector<TextDrawP> text;
Bitmap buffer;
};
TextBufferDC::TextBufferDC(UInt width, UInt height)
: buffer(width, height, 32)
{
SelectObject(buffer);
// initialize to white
clearDC(*this,*wxWHITE_BRUSH);
}
void TextBufferDC::DoDrawText(const String& str, int x, int y) {
text.push_back( new_shared5<TextDraw>(GetFont(), GetTextForeground(), x, y, str) );
}
void TextBufferDC::DoDrawRotatedText(const String& str, int x, int y, double angle) {
text.push_back( new_shared6<TextDraw>(GetFont(), GetTextForeground(), x, y, str, angle) );
}
DECLARE_TYPEOF_COLLECTION(TextBufferDC::TextDrawP);
void TextBufferDC::drawToDevice(DC& dc, int x, int y) {
SelectObject(wxNullBitmap);
dc.DrawBitmap(buffer, x, y);
FOR_EACH(t, text) {
dc.SetFont (t->font);
dc.SetTextForeground(t->color);
if (t->angle) {
dc.DrawRotatedText(t->text, t->x + x, t->y + y, t->angle);
} else {
dc.DrawText(t->text, t->x + x, t->y + y);
}
}
}
// ----------------------------------------------------------------------------- : Printout
// ----------------------------------------------------------------------------- : PrintWindow
void print_preview(Window* parent, const SetP& set) {
// Let the user choose cards
CardSelectWindow wnd(parent, set, _LABEL_("select cards print"));
if (wnd.ShowModal() != wxID_OK) {
return; // cancel
}
vector<CardP> selected;
FOR_EACH(c, set->cards) {
if (wnd.isSelected(c)) selected.push_back(c);
}
/* // Show the print preview
wxPreviewFrame frame = new wxPreviewFrame(
new wxPrintPreview(
new CardsPrintout(set, selected),
new CardsPrintout(set, selected)
), parent, _TITLE_("print preview"));
frame->Initialize();
frame->Maximize(true);
frame->Show();
*/
}
void print_set(Window* parent, const SetP& set) {
// Let the user choose cards
CardSelectWindow wnd(parent, set, _LABEL_("select cards print"));
if (wnd.ShowModal() != wxID_OK) {
return; // cancel
}
vector<CardP> selected;
FOR_EACH(c, set->cards) {
if (wnd.isSelected(c)) selected.push_back(c);
}
/* // Print the cards
wxPrinter p;
CardsPrintout pout(set, selected);
p.Print(parent, &pout, true);
*/
}
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_GUI_PRINT_WINDOW
#define HEADER_GUI_PRINT_WINDOW
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
DECLARE_POINTER_TYPE(Set);
// ----------------------------------------------------------------------------- : Printing
/// Show a print preview for the given set
void print_preview(Window* parent, const SetP& set);
/// Print the given set
void print_set(Window* parent, const SetP& set);
// ----------------------------------------------------------------------------- : EOF
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment