mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Implemented ImageValueViewer, and more of the related classes
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@54 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -32,6 +32,7 @@ String Card::identification() const {
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION(Card) {
|
||||
REFLECT(stylesheet);
|
||||
REFLECT(notes);
|
||||
REFLECT_NAMELESS(data);
|
||||
}
|
||||
|
||||
@@ -79,6 +79,10 @@ class Style {
|
||||
Scriptable<double> width, height; ///< Position of this field
|
||||
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
|
||||
/** thisP is a smart pointer to this */
|
||||
virtual ValueViewerP makeViewer(DataViewer& parent, const StyleP& thisP) = 0;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
// ----------------------------------------------------------------------------- : BooleanField
|
||||
|
||||
DECLARE_POINTER_TYPE(BooleanField);
|
||||
DECLARE_POINTER_TYPE(BooleanStyle);
|
||||
DECLARE_POINTER_TYPE(BooleanValue);
|
||||
|
||||
/// A field whos value is either true or false
|
||||
class BooleanField : public ChoiceField {
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
// ----------------------------------------------------------------------------- : ChoiceField
|
||||
|
||||
DECLARE_POINTER_TYPE(ChoiceField);
|
||||
DECLARE_POINTER_TYPE(ChoiceStyle);
|
||||
DECLARE_POINTER_TYPE(ChoiceValue);
|
||||
|
||||
/// A field that contains a list of choices
|
||||
class ChoiceField : public Field {
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
// ----------------------------------------------------------------------------- : 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
|
||||
class ColorField : public Field {
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
// ----------------------------------------------------------------------------- : ImageField
|
||||
|
||||
DECLARE_POINTER_TYPE(ImageField);
|
||||
DECLARE_POINTER_TYPE(ImageStyle);
|
||||
DECLARE_POINTER_TYPE(ImageValue);
|
||||
|
||||
/// A field for image values
|
||||
class ImageField : public Field {
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
// ----------------------------------------------------------------------------- : MultipleChoiceField
|
||||
|
||||
DECLARE_POINTER_TYPE(MultipleChoiceField);
|
||||
DECLARE_POINTER_TYPE(MultipleChoiceStyle);
|
||||
DECLARE_POINTER_TYPE(MultipleChoiceValue);
|
||||
|
||||
/// A ChoiceField where multiple choices can be selected simultaniously
|
||||
class MultipleChoiceField : public ChoiceField {
|
||||
|
||||
@@ -18,6 +18,8 @@ DECLARE_POINTER_TYPE(SymbolFilter);
|
||||
// ----------------------------------------------------------------------------- : SymbolField
|
||||
|
||||
DECLARE_POINTER_TYPE(SymbolField);
|
||||
DECLARE_POINTER_TYPE(SymbolStyle);
|
||||
DECLARE_POINTER_TYPE(SymbolValue);
|
||||
|
||||
/// A field for image values
|
||||
class SymbolField : public Field {
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
// ----------------------------------------------------------------------------- : TextField
|
||||
|
||||
DECLARE_POINTER_TYPE(TextField);
|
||||
DECLARE_POINTER_TYPE(TextStyle);
|
||||
DECLARE_POINTER_TYPE(TextValue);
|
||||
|
||||
/// A field for values containing tagged text
|
||||
class TextField : public Field {
|
||||
|
||||
@@ -56,14 +56,14 @@ void CardListBase::onAction(const Action& action, bool undone) {
|
||||
selectCardPos((long)sorted_card_list.size() - 1, true);
|
||||
} else {
|
||||
// select the new card
|
||||
selectCard(action.card, false /*list will be refreshed anyway*/);
|
||||
selectCard(action.card, false /*list will be refreshed anyway*/, true);
|
||||
refreshList();
|
||||
}
|
||||
}
|
||||
TYPE_CASE(action, RemoveCardAction) {
|
||||
if (undone) {
|
||||
// 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();
|
||||
} else {
|
||||
long pos = selected_card_pos;
|
||||
@@ -116,10 +116,12 @@ void CardListBase::selectNext() {
|
||||
|
||||
// ----------------------------------------------------------------------------- : CardListBase : Selection (private)
|
||||
|
||||
void CardListBase::selectCard(const CardP& card, bool focus) {
|
||||
void CardListBase::selectCard(const CardP& card, bool focus, bool event) {
|
||||
selected_card = card;
|
||||
CardSelectEvent ev(card);
|
||||
ProcessEvent(ev);
|
||||
if (event) {
|
||||
CardSelectEvent ev(card);
|
||||
ProcessEvent(ev);
|
||||
}
|
||||
if (focus) {
|
||||
findSelectedCardPos();
|
||||
selectCurrentCard();
|
||||
@@ -130,9 +132,9 @@ void CardListBase::selectCardPos(long pos, bool focus) {
|
||||
if (selected_card_pos == pos && !focus) return; // this card is already selected
|
||||
if ((size_t)pos < sorted_card_list.size()) {
|
||||
// only if there is something to select
|
||||
selectCard(sorted_card_list[pos], false);
|
||||
selectCard(sorted_card_list[pos], false, true);
|
||||
} else {
|
||||
selectCard(CardP(), false);
|
||||
selectCard(CardP(), false, true);
|
||||
}
|
||||
selected_card_pos = pos;
|
||||
if (focus) selectCurrentCard();
|
||||
|
||||
@@ -20,7 +20,10 @@ DECLARE_POINTER_TYPE(Field);
|
||||
|
||||
DECLARE_EVENT_TYPE(EVENT_CARD_SELECT, <not used>)
|
||||
/// 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
|
||||
struct CardSelectEvent : public wxCommandEvent {
|
||||
@@ -50,7 +53,7 @@ class CardListBase : public wxListView, public SetView {
|
||||
// --------------------------------------------------- : Selection
|
||||
|
||||
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?
|
||||
bool canSelectPrevious() const;
|
||||
@@ -113,7 +116,7 @@ class CardListBase : public wxListView, public SetView {
|
||||
/** 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).
|
||||
*/
|
||||
void selectCard(const CardP& card, bool focus);
|
||||
void selectCard(const CardP& card, bool focus, bool event);
|
||||
/// Select a card at the specified position
|
||||
void selectCardPos(long pos, bool focus);
|
||||
/// Find the position for the selected_card
|
||||
|
||||
@@ -211,4 +211,4 @@ CardP CardsPanel::selectedCard() const {
|
||||
void CardsPanel::selectCard(const CardP& card) {
|
||||
card_list->setCard(card);
|
||||
editor->setCard(*card);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class SetWindowPanel : public wxPanel, public SetView {
|
||||
|
||||
// --------------------------------------------------- : Selection
|
||||
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:
|
||||
// --------------------------------------------------- : Helper functions for UI
|
||||
|
||||
+4
-11
@@ -246,11 +246,10 @@ void SetWindow::onAction(const Action& action, bool undone) {
|
||||
}
|
||||
|
||||
|
||||
void SetWindow::onCardSelect(wxCommandEvent& ev) {
|
||||
// CardP card = static_cast<CardSelectEvent&>(ev).card;
|
||||
// FOR_EACH(p, panels) {
|
||||
// p->selectCard(card);
|
||||
// }
|
||||
void SetWindow::onCardSelect(CardSelectEvent& ev) {
|
||||
FOR_EACH(p, panels) {
|
||||
p->selectCard(ev.card);
|
||||
}
|
||||
fixMinWindowSize();
|
||||
}
|
||||
|
||||
@@ -547,12 +546,6 @@ void SetWindow::onChildMenu(wxCommandEvent& ev) {
|
||||
current_panel->onCommand(ev.GetId());
|
||||
}
|
||||
|
||||
void SetWindow::onCardSelect(CardSelectEvent& ev) {
|
||||
FOR_EACH(p, panels) {
|
||||
p->selectCard(ev.card);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Event table
|
||||
|
||||
BEGIN_EVENT_TABLE(SetWindow, wxFrame)
|
||||
|
||||
@@ -85,7 +85,7 @@ class SetWindow : public wxFrame, public SetView {
|
||||
|
||||
private:
|
||||
/// A different card has been selected
|
||||
void onCardSelect(wxCommandEvent&);
|
||||
void onCardSelect(CardSelectEvent&);
|
||||
|
||||
/// Render settings have changed (because of editing of preferences)
|
||||
void onRenderSettingsChange();
|
||||
@@ -154,8 +154,6 @@ class SetWindow : public wxFrame, public SetView {
|
||||
// --------------------------------------------------- : Window events - other
|
||||
|
||||
void onChildMenu (wxCommandEvent&);
|
||||
|
||||
void onCardSelect (CardSelectEvent&);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <gui/util.hpp>
|
||||
#include <util/error.hpp>
|
||||
#include <util/rotation.hpp>
|
||||
#include <wx/mstream.h>
|
||||
|
||||
// ----------------------------------------------------------------------------- : DC related
|
||||
@@ -20,6 +21,26 @@ void clearDC(DC& dc, const wxBrush& brush) {
|
||||
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 load_resource_image(String name) {
|
||||
|
||||
@@ -15,11 +15,17 @@
|
||||
|
||||
#include <util/prec.hpp>
|
||||
|
||||
class RotatedDC;
|
||||
class RealRect;
|
||||
|
||||
// ----------------------------------------------------------------------------- : DC related
|
||||
|
||||
/// Fill a DC with a single color
|
||||
void clearDC(DC& dc, const wxBrush& brush = *wxBLACK_BRUSH);
|
||||
|
||||
/// Draw a checkerboard pattern
|
||||
void draw_checker(RotatedDC& dc, const RealRect&);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Resource related
|
||||
|
||||
/// Load an image from a resource
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <data/field.hpp>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(ValueViewerP);
|
||||
typedef IndexMap<FieldP,StyleP> IndexMap_FieldP_StyleP;
|
||||
DECLARE_TYPEOF_NO_REV(IndexMap_FieldP_StyleP);
|
||||
|
||||
// ----------------------------------------------------------------------------- : DataViewer
|
||||
|
||||
@@ -21,16 +23,31 @@ DECLARE_TYPEOF_COLLECTION(ValueViewerP);
|
||||
// ----------------------------------------------------------------------------- : Drawing
|
||||
|
||||
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) {
|
||||
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
|
||||
|
||||
bool DataViewer::nativeLook() const { return false; }
|
||||
bool DataViewer::drawBorders() const { return false; }
|
||||
bool DataViewer::drawEditing() const { return false; }
|
||||
wxPen DataViewer::borderPen(bool) const { return wxPen(); }
|
||||
Value* DataViewer::focusedValue() const { return nullptr; }
|
||||
ValueViewer* DataViewer::focusedViewer() const { return nullptr; }
|
||||
|
||||
// ----------------------------------------------------------------------------- : Setting data
|
||||
|
||||
@@ -42,7 +59,29 @@ void DataViewer::setCard(Card& card) {
|
||||
|
||||
// ----------------------------------------------------------------------------- : 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) {
|
||||
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) {
|
||||
|
||||
@@ -39,11 +39,14 @@ class DataViewer : public SetView {
|
||||
/// Should field borders be drawn?
|
||||
/** false by default, can be overloaded */
|
||||
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())
|
||||
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 */
|
||||
virtual Value* focusedValue() const;
|
||||
virtual ValueViewer* focusedViewer() const;
|
||||
|
||||
// --------------------------------------------------- : Setting data
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
@@ -0,0 +1,18 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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
|
||||
@@ -0,0 +1,11 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
@@ -0,0 +1,18 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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
|
||||
@@ -0,0 +1,11 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
@@ -0,0 +1,18 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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
|
||||
@@ -0,0 +1,104 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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
|
||||
@@ -0,0 +1,11 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
@@ -0,0 +1,18 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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
|
||||
@@ -0,0 +1,11 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
@@ -0,0 +1,18 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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
|
||||
@@ -0,0 +1,11 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
@@ -0,0 +1,18 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| 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 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#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(DataViewer& parent, const StyleP& style)
|
||||
: viewer(parent), styleP(style)
|
||||
{}
|
||||
|
||||
Set& ValueViewer::getSet() const { return *viewer.getSet(); }
|
||||
|
||||
void ValueViewer::setValue(const ValueP& value) {
|
||||
assert(value->fieldP == styleP->fieldP); // matching field
|
||||
valueP = value;
|
||||
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
|
||||
|
||||
#ifdef _DEBUG
|
||||
@@ -31,11 +63,18 @@ void ValueViewer::setValue(const ValueP& value) {
|
||||
#include <data/field/symbol.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 BooleanStyle ::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 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 TextStyle ::makeViewer(DataViewer& parent, const StyleP& thisP) { return ValueViewerP(); }
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <util/real_point.hpp>
|
||||
#include <data/field.hpp>
|
||||
|
||||
class Set;
|
||||
class DataViewer;
|
||||
class ValueAction;
|
||||
DECLARE_POINTER_TYPE(Style);
|
||||
@@ -33,6 +34,8 @@ class ValueViewer {
|
||||
void setValue(const ValueP&);
|
||||
/// Return the associated field
|
||||
inline const FieldP& getField() const { return styleP->fieldP; }
|
||||
/// Return the associated style
|
||||
inline const StyleP& getStyle() const { return styleP; }
|
||||
|
||||
// Draw this value
|
||||
virtual void draw(RotatedDC& dc) = 0;
|
||||
@@ -65,17 +68,19 @@ class ValueViewer {
|
||||
|
||||
/// Draws a border around the field
|
||||
void drawFieldBorder(RotatedDC& dc);
|
||||
|
||||
Set& getSet() const;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : Utility
|
||||
|
||||
#define VALUE_VIEWER(Base, Type) \
|
||||
public: \
|
||||
Type(DataViewer& parent, const Type ## StyleP& style) \
|
||||
private: \
|
||||
inline Type##Style& style() const { return *styleP; } \
|
||||
inline Type##Value& value() const { return *valueP; } \
|
||||
inline Type##Field& field() const { return styleP->field(); }
|
||||
#define DECLARE_VALUE_VIEWER(Type) \
|
||||
private: \
|
||||
inline const Type##Style& style() const { return static_cast<const Type##Style&>(*styleP); } \
|
||||
inline const Type##Value& value() const { return static_cast<const Type##Value&>(*valueP); } \
|
||||
inline const Type##Field& field() const { return style().field(); } \
|
||||
public: \
|
||||
Type##ValueViewer(DataViewer& parent, const Type ## StyleP& style)
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
Reference in New Issue
Block a user