Commit 3a68ae3f authored by twanvl's avatar twanvl

Implemented ImageValueViewer, and more of the related classes

parent bca72bc6
...@@ -32,6 +32,7 @@ String Card::identification() const { ...@@ -32,6 +32,7 @@ String Card::identification() const {
} }
IMPLEMENT_REFLECTION(Card) { IMPLEMENT_REFLECTION(Card) {
REFLECT(stylesheet);
REFLECT(notes); REFLECT(notes);
REFLECT_NAMELESS(data); REFLECT_NAMELESS(data);
} }
......
...@@ -79,6 +79,10 @@ class Style { ...@@ -79,6 +79,10 @@ class Style {
Scriptable<double> width, height; ///< Position of this field Scriptable<double> width, height; ///< Position of this field
Scriptable<bool> visible; ///< Is this field visible? Scriptable<bool> visible; ///< Is this field visible?
inline RealPoint getPos() const { return RealPoint(left, top ); }
inline RealSize getSize() const { return RealSize ( width, height); }
inline RealRect getRect() const { return RealRect (left, top, width, height); }
/// Make a viewer object for values using this style /// Make a viewer object for values using this style
/** thisP is a smart pointer to this */ /** thisP is a smart pointer to this */
virtual ValueViewerP makeViewer(DataViewer& parent, const StyleP& thisP) = 0; virtual ValueViewerP makeViewer(DataViewer& parent, const StyleP& thisP) = 0;
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
// ----------------------------------------------------------------------------- : BooleanField // ----------------------------------------------------------------------------- : BooleanField
DECLARE_POINTER_TYPE(BooleanField); DECLARE_POINTER_TYPE(BooleanField);
DECLARE_POINTER_TYPE(BooleanStyle);
DECLARE_POINTER_TYPE(BooleanValue);
/// A field whos value is either true or false /// A field whos value is either true or false
class BooleanField : public ChoiceField { class BooleanField : public ChoiceField {
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
// ----------------------------------------------------------------------------- : ChoiceField // ----------------------------------------------------------------------------- : ChoiceField
DECLARE_POINTER_TYPE(ChoiceField); DECLARE_POINTER_TYPE(ChoiceField);
DECLARE_POINTER_TYPE(ChoiceStyle);
DECLARE_POINTER_TYPE(ChoiceValue);
/// A field that contains a list of choices /// A field that contains a list of choices
class ChoiceField : public Field { class ChoiceField : public Field {
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
// ----------------------------------------------------------------------------- : ColorField // ----------------------------------------------------------------------------- : ColorField
DECLARE_POINTER_TYPE(ColorField); DECLARE_POINTER_TYPE(ColorField);
DECLARE_POINTER_TYPE(ColorStyle);
DECLARE_POINTER_TYPE(ColorValue);
/// A field for color values, it contains a list of choices for colors /// A field for color values, it contains a list of choices for colors
class ColorField : public Field { class ColorField : public Field {
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
// ----------------------------------------------------------------------------- : ImageField // ----------------------------------------------------------------------------- : ImageField
DECLARE_POINTER_TYPE(ImageField); DECLARE_POINTER_TYPE(ImageField);
DECLARE_POINTER_TYPE(ImageStyle);
DECLARE_POINTER_TYPE(ImageValue);
/// A field for image values /// A field for image values
class ImageField : public Field { class ImageField : public Field {
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
// ----------------------------------------------------------------------------- : MultipleChoiceField // ----------------------------------------------------------------------------- : MultipleChoiceField
DECLARE_POINTER_TYPE(MultipleChoiceField); DECLARE_POINTER_TYPE(MultipleChoiceField);
DECLARE_POINTER_TYPE(MultipleChoiceStyle);
DECLARE_POINTER_TYPE(MultipleChoiceValue);
/// A ChoiceField where multiple choices can be selected simultaniously /// A ChoiceField where multiple choices can be selected simultaniously
class MultipleChoiceField : public ChoiceField { class MultipleChoiceField : public ChoiceField {
......
...@@ -18,6 +18,8 @@ DECLARE_POINTER_TYPE(SymbolFilter); ...@@ -18,6 +18,8 @@ DECLARE_POINTER_TYPE(SymbolFilter);
// ----------------------------------------------------------------------------- : SymbolField // ----------------------------------------------------------------------------- : SymbolField
DECLARE_POINTER_TYPE(SymbolField); DECLARE_POINTER_TYPE(SymbolField);
DECLARE_POINTER_TYPE(SymbolStyle);
DECLARE_POINTER_TYPE(SymbolValue);
/// A field for image values /// A field for image values
class SymbolField : public Field { class SymbolField : public Field {
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
// ----------------------------------------------------------------------------- : TextField // ----------------------------------------------------------------------------- : TextField
DECLARE_POINTER_TYPE(TextField); DECLARE_POINTER_TYPE(TextField);
DECLARE_POINTER_TYPE(TextStyle);
DECLARE_POINTER_TYPE(TextValue);
/// A field for values containing tagged text /// A field for values containing tagged text
class TextField : public Field { class TextField : public Field {
......
...@@ -56,14 +56,14 @@ void CardListBase::onAction(const Action& action, bool undone) { ...@@ -56,14 +56,14 @@ void CardListBase::onAction(const Action& action, bool undone) {
selectCardPos((long)sorted_card_list.size() - 1, true); selectCardPos((long)sorted_card_list.size() - 1, true);
} else { } else {
// select the new card // select the new card
selectCard(action.card, false /*list will be refreshed anyway*/); selectCard(action.card, false /*list will be refreshed anyway*/, true);
refreshList(); refreshList();
} }
} }
TYPE_CASE(action, RemoveCardAction) { TYPE_CASE(action, RemoveCardAction) {
if (undone) { if (undone) {
// select the re-added card // select the re-added card
selectCard(action.card, false /*list will be refreshed anyway*/); selectCard(action.card, false /*list will be refreshed anyway*/, true);
refreshList(); refreshList();
} else { } else {
long pos = selected_card_pos; long pos = selected_card_pos;
...@@ -116,10 +116,12 @@ void CardListBase::selectNext() { ...@@ -116,10 +116,12 @@ void CardListBase::selectNext() {
// ----------------------------------------------------------------------------- : CardListBase : Selection (private) // ----------------------------------------------------------------------------- : CardListBase : Selection (private)
void CardListBase::selectCard(const CardP& card, bool focus) { void CardListBase::selectCard(const CardP& card, bool focus, bool event) {
selected_card = card; selected_card = card;
if (event) {
CardSelectEvent ev(card); CardSelectEvent ev(card);
ProcessEvent(ev); ProcessEvent(ev);
}
if (focus) { if (focus) {
findSelectedCardPos(); findSelectedCardPos();
selectCurrentCard(); selectCurrentCard();
...@@ -130,9 +132,9 @@ void CardListBase::selectCardPos(long pos, bool focus) { ...@@ -130,9 +132,9 @@ void CardListBase::selectCardPos(long pos, bool focus) {
if (selected_card_pos == pos && !focus) return; // this card is already selected if (selected_card_pos == pos && !focus) return; // this card is already selected
if ((size_t)pos < sorted_card_list.size()) { if ((size_t)pos < sorted_card_list.size()) {
// only if there is something to select // only if there is something to select
selectCard(sorted_card_list[pos], false); selectCard(sorted_card_list[pos], false, true);
} else { } else {
selectCard(CardP(), false); selectCard(CardP(), false, true);
} }
selected_card_pos = pos; selected_card_pos = pos;
if (focus) selectCurrentCard(); if (focus) selectCurrentCard();
......
...@@ -20,7 +20,10 @@ DECLARE_POINTER_TYPE(Field); ...@@ -20,7 +20,10 @@ DECLARE_POINTER_TYPE(Field);
DECLARE_EVENT_TYPE(EVENT_CARD_SELECT, <not used>) DECLARE_EVENT_TYPE(EVENT_CARD_SELECT, <not used>)
/// Handle CardSelectEvents /// Handle CardSelectEvents
#define EVT_CARD_SELECT(id, handler) EVT_COMMAND(id, EVENT_CARD_SELECT, handler) #define EVT_CARD_SELECT(id, handler) \
DECLARE_EVENT_TABLE_ENTRY(EVENT_CARD_SELECT, id, -1, \
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) \
(void (wxEvtHandler::*)(CardSelectEvent&)) (&handler), (wxObject*) NULL),
/// The event of selecting a card /// The event of selecting a card
struct CardSelectEvent : public wxCommandEvent { struct CardSelectEvent : public wxCommandEvent {
...@@ -50,7 +53,7 @@ class CardListBase : public wxListView, public SetView { ...@@ -50,7 +53,7 @@ class CardListBase : public wxListView, public SetView {
// --------------------------------------------------- : Selection // --------------------------------------------------- : Selection
inline CardP getCard() const { return selected_card; } inline CardP getCard() const { return selected_card; }
inline void setCard(const CardP& card) { selectCard(card, true); } inline void setCard(const CardP& card) { selectCard(card, true, false); }
/// Is there a previous card to select? /// Is there a previous card to select?
bool canSelectPrevious() const; bool canSelectPrevious() const;
...@@ -113,7 +116,7 @@ class CardListBase : public wxListView, public SetView { ...@@ -113,7 +116,7 @@ class CardListBase : public wxListView, public SetView {
/** If focus then the card is also focused and selected in the actual control. /** If focus then the card is also focused and selected in the actual control.
* This should abviously not be done when the card is selected because it was selected (leading to a loop). * This should abviously not be done when the card is selected because it was selected (leading to a loop).
*/ */
void selectCard(const CardP& card, bool focus); void selectCard(const CardP& card, bool focus, bool event);
/// Select a card at the specified position /// Select a card at the specified position
void selectCardPos(long pos, bool focus); void selectCardPos(long pos, bool focus);
/// Find the position for the selected_card /// Find the position for the selected_card
......
...@@ -68,7 +68,7 @@ class SetWindowPanel : public wxPanel, public SetView { ...@@ -68,7 +68,7 @@ class SetWindowPanel : public wxPanel, public SetView {
// --------------------------------------------------- : Selection // --------------------------------------------------- : Selection
virtual CardP selectedCard() const { return CardP(); } ///< Return the currently selected card, or CardP() virtual CardP selectedCard() const { return CardP(); } ///< Return the currently selected card, or CardP()
virtual void selectCard(CardP card) {} ///< Switch the view to another card virtual void selectCard(const CardP& card) {} ///< Switch the view to another card
protected: protected:
// --------------------------------------------------- : Helper functions for UI // --------------------------------------------------- : Helper functions for UI
......
...@@ -246,11 +246,10 @@ void SetWindow::onAction(const Action& action, bool undone) { ...@@ -246,11 +246,10 @@ void SetWindow::onAction(const Action& action, bool undone) {
} }
void SetWindow::onCardSelect(wxCommandEvent& ev) { void SetWindow::onCardSelect(CardSelectEvent& ev) {
// CardP card = static_cast<CardSelectEvent&>(ev).card; FOR_EACH(p, panels) {
// FOR_EACH(p, panels) { p->selectCard(ev.card);
// p->selectCard(card); }
// }
fixMinWindowSize(); fixMinWindowSize();
} }
...@@ -547,12 +546,6 @@ void SetWindow::onChildMenu(wxCommandEvent& ev) { ...@@ -547,12 +546,6 @@ void SetWindow::onChildMenu(wxCommandEvent& ev) {
current_panel->onCommand(ev.GetId()); current_panel->onCommand(ev.GetId());
} }
void SetWindow::onCardSelect(CardSelectEvent& ev) {
FOR_EACH(p, panels) {
p->selectCard(ev.card);
}
}
// ----------------------------------------------------------------------------- : Event table // ----------------------------------------------------------------------------- : Event table
BEGIN_EVENT_TABLE(SetWindow, wxFrame) BEGIN_EVENT_TABLE(SetWindow, wxFrame)
......
...@@ -85,7 +85,7 @@ class SetWindow : public wxFrame, public SetView { ...@@ -85,7 +85,7 @@ class SetWindow : public wxFrame, public SetView {
private: private:
/// A different card has been selected /// A different card has been selected
void onCardSelect(wxCommandEvent&); void onCardSelect(CardSelectEvent&);
/// Render settings have changed (because of editing of preferences) /// Render settings have changed (because of editing of preferences)
void onRenderSettingsChange(); void onRenderSettingsChange();
...@@ -154,8 +154,6 @@ class SetWindow : public wxFrame, public SetView { ...@@ -154,8 +154,6 @@ class SetWindow : public wxFrame, public SetView {
// --------------------------------------------------- : Window events - other // --------------------------------------------------- : Window events - other
void onChildMenu (wxCommandEvent&); void onChildMenu (wxCommandEvent&);
void onCardSelect (CardSelectEvent&);
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <gui/util.hpp> #include <gui/util.hpp>
#include <util/error.hpp> #include <util/error.hpp>
#include <util/rotation.hpp>
#include <wx/mstream.h> #include <wx/mstream.h>
// ----------------------------------------------------------------------------- : DC related // ----------------------------------------------------------------------------- : DC related
...@@ -20,6 +21,26 @@ void clearDC(DC& dc, const wxBrush& brush) { ...@@ -20,6 +21,26 @@ void clearDC(DC& dc, const wxBrush& brush) {
dc.DrawRectangle(0, 0, size.GetWidth(), size.GetHeight()); dc.DrawRectangle(0, 0, size.GetWidth(), size.GetHeight());
} }
void draw_checker(RotatedDC& dc, const RealRect& rect) {
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(*wxWHITE_BRUSH);
dc.DrawRectangle(rect);
dc.SetBrush(Color(235,235,235));
const double checker_size = 10;
int odd = 0;
for (double y = 0 ; y < rect.size.height ; y += checker_size) {
for (double x = odd * checker_size ; x < rect.size.width ; x += checker_size * 2) {
dc.DrawRectangle(RealRect(
rect.position.x + x,
rect.position.y + y,
min(checker_size, rect.size.width - x),
min(checker_size, rect.size.height - y)
));
}
odd = 1 - odd;
}
}
// ----------------------------------------------------------------------------- : Image related // ----------------------------------------------------------------------------- : Image related
Image load_resource_image(String name) { Image load_resource_image(String name) {
......
...@@ -15,11 +15,17 @@ ...@@ -15,11 +15,17 @@
#include <util/prec.hpp> #include <util/prec.hpp>
class RotatedDC;
class RealRect;
// ----------------------------------------------------------------------------- : DC related // ----------------------------------------------------------------------------- : DC related
/// Fill a DC with a single color /// Fill a DC with a single color
void clearDC(DC& dc, const wxBrush& brush = *wxBLACK_BRUSH); void clearDC(DC& dc, const wxBrush& brush = *wxBLACK_BRUSH);
/// Draw a checkerboard pattern
void draw_checker(RotatedDC& dc, const RealRect&);
// ----------------------------------------------------------------------------- : Resource related // ----------------------------------------------------------------------------- : Resource related
/// Load an image from a resource /// Load an image from a resource
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include <data/field.hpp> #include <data/field.hpp>
DECLARE_TYPEOF_COLLECTION(ValueViewerP); DECLARE_TYPEOF_COLLECTION(ValueViewerP);
typedef IndexMap<FieldP,StyleP> IndexMap_FieldP_StyleP;
DECLARE_TYPEOF_NO_REV(IndexMap_FieldP_StyleP);
// ----------------------------------------------------------------------------- : DataViewer // ----------------------------------------------------------------------------- : DataViewer
...@@ -21,16 +23,31 @@ DECLARE_TYPEOF_COLLECTION(ValueViewerP); ...@@ -21,16 +23,31 @@ DECLARE_TYPEOF_COLLECTION(ValueViewerP);
// ----------------------------------------------------------------------------- : Drawing // ----------------------------------------------------------------------------- : Drawing
void DataViewer::draw(DC& dc) { void DataViewer::draw(DC& dc) {
// RotatedDC rdc(dc, rotation, settings.styleSettingsFor(*style).cardAntiAlias && !nativeLook())
RotatedDC rdc(dc, 0, RealRect(0,0,400,400), 1.0, false);
draw(rdc);
} }
void DataViewer::draw(RotatedDC& dc) { void DataViewer::draw(RotatedDC& dc) {
if (!set) return; // no set specified, don't draw anything
// fill with background color
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(set->stylesheet->card_background);
dc.DrawRectangle(dc.getInternalRect());
// draw values
FOR_EACH(v, viewers) { // draw low z index fields first
if (v->getStyle()->visible) {// visible
v->draw(dc);
}
}
} }
// ----------------------------------------------------------------------------- : Utility for ValueViewers // ----------------------------------------------------------------------------- : Utility for ValueViewers
bool DataViewer::nativeLook() const { return false; } bool DataViewer::nativeLook() const { return false; }
bool DataViewer::drawBorders() const { return false; } bool DataViewer::drawBorders() const { return false; }
bool DataViewer::drawEditing() const { return false; }
wxPen DataViewer::borderPen(bool) const { return wxPen(); } wxPen DataViewer::borderPen(bool) const { return wxPen(); }
Value* DataViewer::focusedValue() const { return nullptr; } ValueViewer* DataViewer::focusedViewer() const { return nullptr; }
// ----------------------------------------------------------------------------- : Setting data // ----------------------------------------------------------------------------- : Setting data
...@@ -42,7 +59,29 @@ void DataViewer::setCard(Card& card) { ...@@ -42,7 +59,29 @@ void DataViewer::setCard(Card& card) {
// ----------------------------------------------------------------------------- : Viewers // ----------------------------------------------------------------------------- : Viewers
struct CompareViewer {
bool operator() (const ValueViewerP& a, const ValueViewerP& b) {
return a->getStyle()->z_index < b->getStyle()->z_index;
}
};
void DataViewer::setStyles(IndexMap<FieldP,StyleP>& styles) { void DataViewer::setStyles(IndexMap<FieldP,StyleP>& styles) {
if (!viewers.empty() && styles.contains(viewers.front()->getStyle())) {
// already using these styles
return;
}
// create viewers
viewers.clear();
FOR_EACH(s, styles) {
if (s->visible || s->visible.isScripted()) {
// no need to make a viewer for things that are always invisible
viewers.push_back(makeViewer(s));
// REMOVEME //TODO //%%%
if (!viewers.back()) viewers.pop_back();
}
}
// sort viewers by z-index of style
stable_sort(viewers.begin(), viewers.end(), CompareViewer());
} }
void DataViewer::setData(IndexMap<FieldP,ValueP>& values) { void DataViewer::setData(IndexMap<FieldP,ValueP>& values) {
......
...@@ -39,11 +39,14 @@ class DataViewer : public SetView { ...@@ -39,11 +39,14 @@ class DataViewer : public SetView {
/// Should field borders be drawn? /// Should field borders be drawn?
/** false by default, can be overloaded */ /** false by default, can be overloaded */
virtual bool drawBorders() const; virtual bool drawBorders() const;
/// Should editing specific things be drawn?
/** false by default, can be overloaded */
virtual bool drawEditing() const;
/// Pens for drawing field borders (only called if drawBorders()) /// Pens for drawing field borders (only called if drawBorders())
virtual wxPen borderPen(bool active) const; virtual wxPen borderPen(bool active) const;
/// The value of the field that is currently focused, may be null /// The viewer that is currently focused, may be null
/** null by default, can be overloaded */ /** null by default, can be overloaded */
virtual Value* focusedValue() const; virtual ValueViewer* focusedViewer() const;
// --------------------------------------------------- : Setting data // --------------------------------------------------- : Setting data
......
//+----------------------------------------------------------------------------+
//| 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 <render/value/boolean.hpp>
// ----------------------------------------------------------------------------- :
//+----------------------------------------------------------------------------+
//| 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_RENDER_VALUE_BOOLEAN
#define HEADER_RENDER_VALUE_BOOLEAN
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
// ----------------------------------------------------------------------------- :
// ----------------------------------------------------------------------------- : EOF
#endif
//+----------------------------------------------------------------------------+
//| 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 <render/value/choice.hpp>
// ----------------------------------------------------------------------------- :
//+----------------------------------------------------------------------------+
//| 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_RENDER_VALUE_CHOICE
#define HEADER_RENDER_VALUE_CHOICE
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
// ----------------------------------------------------------------------------- :
// ----------------------------------------------------------------------------- : EOF
#endif
//+----------------------------------------------------------------------------+
//| 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 <render/value/color.hpp>
// ----------------------------------------------------------------------------- :
//+----------------------------------------------------------------------------+
//| 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_RENDER_VALUE_COLOR
#define HEADER_RENDER_VALUE_COLOR
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
// ----------------------------------------------------------------------------- :
// ----------------------------------------------------------------------------- : EOF
#endif
//+----------------------------------------------------------------------------+
//| 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 <render/value/image.hpp>
#include <render/card/viewer.hpp>
#include <data/set.hpp>
#include <gui/util.hpp>
// ----------------------------------------------------------------------------- : ImageValueViewer
void ImageValueViewer::draw(RotatedDC& dc) {
drawFieldBorder(dc);
// try to load image
if (!bitmap.Ok() && !value().filename.empty()) {
try {
InputStreamP image_file = getSet().openIn(value().filename);
Image image;
if (image.LoadFile(*image_file)) {
image.Rescale(dc.trS(style().width), dc.trS(style().height));
// apply mask to image
/* loadMask(dc);
if (alpha_mask) alpha_mask->setAlpha(image);
*/ bitmap = Bitmap(image);
}
} catch (Error e) {
handle_error(e, false, false); // don't handle now, we are in onPaint
}
}
// if there is no image, generate a placeholder, only if there is enough room for it
if (!bitmap.Ok() && style().width > 40) {
bitmap = imagePlaceholder(dc, dc.trS(style().width), dc.trS(style().height), viewer.drawEditing());
/* loadMask(dc);
if (alpha_mask) alpha_mask->setAlpha(bitmap);
/* if (alphaMask) {
// convert to image and apply alpha
Image image = bmp.ConvertToImage();
alpha_mask->setAlpha(image);
bitmap = image;
}
*/ }
// draw image, if any
if (bitmap.Ok()) {
dc.DrawBitmap(bitmap, style().getPos());
}
}
bool ImageValueViewer::containsPoint(const RealPoint& p) const {
int x = p.x - style().left;
int y = p.y - style().top;
if (x < 0 || y < 0 || x >= (int)style().width || y >= (int)style().height) {
return false; // outside rectangle
}
/* // check against mask
if (!style->maskFilename.value.empty()) {
RotatedObject rot(viewer.getRotation());
loadMask(rot);
return !alphaMask->isTransparent(x, y);
} else {
return true;
}*/
return true;
}
void ImageValueViewer::onValueChange() {
bitmap = Bitmap();
}
void ImageValueViewer::onStyleChange() {
bitmap = Bitmap();
// alpha_mask = AlphaMaskP();
}
Bitmap ImageValueViewer::imagePlaceholder(const Rotation& rot, UInt w, UInt h, bool editing) {
// Bitmap and memory dc
Bitmap bmp(w, h, 24);
wxMemoryDC mdc;
mdc.SelectObject(bmp);
RealRect rect(0,0,w,h);
RotatedDC dc(mdc, 0, rect, 1.0, true);
// Draw checker background
draw_checker(dc, rect);
// Draw text
if (editing) {
// only when in editor mode
for (UInt size = 12 ; size > 2 ; --size) {
dc.SetFont(wxFont(size, wxSWISS, wxNORMAL, wxNORMAL));
RealSize rs = dc.GetTextExtent(_("double click to load image"));
if (rs.width <= w - 10 && rs.height < h - 10) {
// text fits
dc.SetTextForeground(*wxBLACK);
dc.DrawText(_("double click to load image"), align_in_rect(ALIGN_MIDDLE_CENTER, rs, rect));
break;
}
}
}
// Done
mdc.SelectObject(wxNullBitmap);
return bmp;
}
//+----------------------------------------------------------------------------+
//| 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_RENDER_VALUE_IMAGE
#define HEADER_RENDER_VALUE_IMAGE
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <render/value/viewer.hpp>
#include <data/field/image.hpp>
// ----------------------------------------------------------------------------- : ImageValueViewer
/// Viewer that displays an image value
class ImageValueViewer : public ValueViewer {
public:
DECLARE_VALUE_VIEWER(Image) : ValueViewer(parent,style) {}
void draw(RotatedDC& dc);
bool containsPoint(const RealPoint& p) const;
void onValueChange();
void onStyleChange();
private:
Bitmap bitmap;
// mutable AlphaMaskP alpha_mask;
// void loadMask(const RotatedObject& rot) const;
/// Generate a placeholder image
static Bitmap imagePlaceholder(const Rotation& rot, UInt w, UInt h, bool editing);
};
// ----------------------------------------------------------------------------- : EOF
#endif
//+----------------------------------------------------------------------------+
//| 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 <render/value/multiple_choice.hpp>
// ----------------------------------------------------------------------------- :
//+----------------------------------------------------------------------------+
//| 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_RENDER_VALUE_MULTIPLE_CHOICE
#define HEADER_RENDER_VALUE_MULTIPLE_CHOICE
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
// ----------------------------------------------------------------------------- :
// ----------------------------------------------------------------------------- : EOF
#endif
//+----------------------------------------------------------------------------+
//| 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 <render/value/symbol.hpp>
// ----------------------------------------------------------------------------- :
//+----------------------------------------------------------------------------+
//| 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_RENDER_VALUE_SYMBOL
#define HEADER_RENDER_VALUE_SYMBOL
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
// ----------------------------------------------------------------------------- :
// ----------------------------------------------------------------------------- : EOF
#endif
//+----------------------------------------------------------------------------+
//| 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 <render/value/text.hpp>
// ----------------------------------------------------------------------------- :
//+----------------------------------------------------------------------------+
//| 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_RENDER_VALUE_TEXT
#define HEADER_RENDER_VALUE_TEXT
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
// ----------------------------------------------------------------------------- :
// ----------------------------------------------------------------------------- : EOF
#endif
...@@ -7,15 +7,47 @@ ...@@ -7,15 +7,47 @@
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
#include <render/value/viewer.hpp> #include <render/value/viewer.hpp>
#include <render/value/text.hpp>
#include <render/value/choice.hpp>
#include <render/value/multiple_choice.hpp>
#include <render/value/boolean.hpp>
#include <render/value/image.hpp>
#include <render/value/symbol.hpp>
#include <render/value/color.hpp>
#include <render/card/viewer.hpp>
// ----------------------------------------------------------------------------- : ValueViewer // ----------------------------------------------------------------------------- : ValueViewer
ValueViewer::ValueViewer(DataViewer& parent, const StyleP& style)
: viewer(parent), styleP(style)
{}
Set& ValueViewer::getSet() const { return *viewer.getSet(); }
void ValueViewer::setValue(const ValueP& value) { void ValueViewer::setValue(const ValueP& value) {
assert(value->fieldP == styleP->fieldP); // matching field assert(value->fieldP == styleP->fieldP); // matching field
valueP = value; valueP = value;
onValueChange(); onValueChange();
} }
bool ValueViewer::containsPoint(const RealPoint& p) const {
return p.x >= styleP->left
&& p.y >= styleP->top
&& p.x < styleP->left + (int)(styleP->width)
&& p.y < styleP->top + (int)(styleP->height);
}
RealRect ValueViewer::boundingBox() const {
return styleP->getRect().grow(1);
}
void ValueViewer::drawFieldBorder(RotatedDC& dc) {
if (viewer.drawBorders() && getField()->editable) {
dc.SetPen(viewer.borderPen(viewer.focusedViewer() == this));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(styleP->getRect().grow(dc.trInvS(1)));
}
}
// ----------------------------------------------------------------------------- : Development/debug // ----------------------------------------------------------------------------- : Development/debug
#ifdef _DEBUG #ifdef _DEBUG
...@@ -31,11 +63,18 @@ void ValueViewer::setValue(const ValueP& value) { ...@@ -31,11 +63,18 @@ void ValueViewer::setValue(const ValueP& value) {
#include <data/field/symbol.hpp> #include <data/field/symbol.hpp>
#include <data/field/text.hpp> #include <data/field/text.hpp>
#define IMPLEMENT_MAKE_VIEWER(Type) \
ValueViewerP Type##Style::makeViewer(DataViewer& parent, const StyleP& thisP) { \
assert(thisP.get() == this); \
return ValueViewerP(new Type##ValueViewer(parent, static_pointer_cast<Type##Style>(thisP))); \
}
ValueViewerP ChoiceStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } ValueViewerP ChoiceStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); }
ValueViewerP BooleanStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } ValueViewerP BooleanStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); }
ValueViewerP MultipleChoiceStyle::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } ValueViewerP MultipleChoiceStyle::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); }
ValueViewerP ColorStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } ValueViewerP ColorStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); }
ValueViewerP ImageStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } //ValueViewerP ImageStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); }
IMPLEMENT_MAKE_VIEWER(Image);
ValueViewerP SymbolStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } ValueViewerP SymbolStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); }
ValueViewerP TextStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); } ValueViewerP TextStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <util/real_point.hpp> #include <util/real_point.hpp>
#include <data/field.hpp> #include <data/field.hpp>
class Set;
class DataViewer; class DataViewer;
class ValueAction; class ValueAction;
DECLARE_POINTER_TYPE(Style); DECLARE_POINTER_TYPE(Style);
...@@ -33,6 +34,8 @@ class ValueViewer { ...@@ -33,6 +34,8 @@ class ValueViewer {
void setValue(const ValueP&); void setValue(const ValueP&);
/// Return the associated field /// Return the associated field
inline const FieldP& getField() const { return styleP->fieldP; } inline const FieldP& getField() const { return styleP->fieldP; }
/// Return the associated style
inline const StyleP& getStyle() const { return styleP; }
// Draw this value // Draw this value
virtual void draw(RotatedDC& dc) = 0; virtual void draw(RotatedDC& dc) = 0;
...@@ -65,17 +68,19 @@ class ValueViewer { ...@@ -65,17 +68,19 @@ class ValueViewer {
/// Draws a border around the field /// Draws a border around the field
void drawFieldBorder(RotatedDC& dc); void drawFieldBorder(RotatedDC& dc);
Set& getSet() const;
}; };
// ----------------------------------------------------------------------------- : Utility // ----------------------------------------------------------------------------- : Utility
#define VALUE_VIEWER(Base, Type) \ #define DECLARE_VALUE_VIEWER(Type) \
public: \
Type(DataViewer& parent, const Type ## StyleP& style) \
private: \ private: \
inline Type##Style& style() const { return *styleP; } \ inline const Type##Style& style() const { return static_cast<const Type##Style&>(*styleP); } \
inline Type##Value& value() const { return *valueP; } \ inline const Type##Value& value() const { return static_cast<const Type##Value&>(*valueP); } \
inline Type##Field& field() const { return styleP->field(); } inline const Type##Field& field() const { return style().field(); } \
public: \
Type##ValueViewer(DataViewer& parent, const Type ## StyleP& style)
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
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