mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Removed the need for a separate multiple choice thumbnail request. This does no longer rely on any evil unsafe casts.
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@511 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+20
-22
@@ -29,38 +29,40 @@ class ChoiceThumbnailRequest : public ThumbnailRequest {
|
||||
private:
|
||||
StyleSheetP stylesheet;
|
||||
int id;
|
||||
|
||||
inline ChoiceStyle& style() { return *static_cast<ChoiceStyle*>(viewer().getStyle().get()); }
|
||||
inline ValueViewer& viewer() { return *static_cast<ValueViewer*>(owner); }
|
||||
};
|
||||
|
||||
ChoiceThumbnailRequest::ChoiceThumbnailRequest(ValueViewer* cve, int id, bool from_disk)
|
||||
ChoiceThumbnailRequest::ChoiceThumbnailRequest(ValueViewer* viewer, int id, bool from_disk)
|
||||
: ThumbnailRequest(
|
||||
reinterpret_cast<void *> (cve),
|
||||
cve->viewer.stylesheet->name() + _("/") + cve->getField()->name + _("/") << id,
|
||||
from_disk ? cve->viewer.stylesheet->lastModified()
|
||||
static_cast<void*>(viewer),
|
||||
viewer->viewer.stylesheet->name() + _("/") + viewer->getField()->name + _("/") << id,
|
||||
from_disk ? viewer->viewer.stylesheet->lastModified()
|
||||
: wxDateTime::Now()
|
||||
)
|
||||
, stylesheet(cve->viewer.stylesheet)
|
||||
, stylesheet(viewer->viewer.stylesheet)
|
||||
, id(id)
|
||||
{
|
||||
ChoiceValueEditor* e = dynamic_cast<ChoiceValueEditor*> (cve);
|
||||
if (!e)
|
||||
throw InternalError(_("Non-editor passed to ChoiceThumbnailRequest"));
|
||||
String name = cannocial_name_form(e->field().choices->choiceName(id));
|
||||
ScriptableImage img = e->style().choice_images[name];
|
||||
assert(dynamic_pointer_cast<ChoiceStyle>(viewer->getStyle())); // only works on choice styles
|
||||
ChoiceStyle& s = style();
|
||||
String name = cannocial_name_form(s.field().choices->choiceName(id));
|
||||
ScriptableImage img = s.choice_images[name];
|
||||
isThreadSafe = img.threadSafe();
|
||||
}
|
||||
|
||||
Image ChoiceThumbnailRequest::generate() {
|
||||
ChoiceValueEditor* cve = reinterpret_cast<ChoiceValueEditor*> (owner);
|
||||
String name = cannocial_name_form(cve->field().choices->choiceName(id));
|
||||
ScriptableImage& img = cve->style().choice_images[name];
|
||||
ChoiceStyle& s = style();
|
||||
String name = cannocial_name_form(s.field().choices->choiceName(id));
|
||||
ScriptableImage& img = s.choice_images[name];
|
||||
return img.isReady()
|
||||
? img.generate(GeneratedImage::Options(16,16, stylesheet.get(), &cve->getSet(), ASPECT_BORDER, true), false)
|
||||
? img.generate(GeneratedImage::Options(16,16, stylesheet.get(), viewer().viewer.getSet().get(), ASPECT_BORDER, true), false)
|
||||
: wxImage();
|
||||
}
|
||||
|
||||
void ChoiceThumbnailRequest::store(const Image& img) {
|
||||
ChoiceValueEditor* cve = reinterpret_cast<ChoiceValueEditor*> (owner);
|
||||
wxImageList* il = cve->style().thumbnails;
|
||||
ChoiceStyle& s = style();
|
||||
wxImageList* il = s.thumbnails;
|
||||
while (id > il->GetImageCount()) {
|
||||
il->Add(wxBitmap(16,16),*wxBLACK);
|
||||
}
|
||||
@@ -91,7 +93,7 @@ void ChoiceThumbnailRequest::store(const Image& img) {
|
||||
} else {
|
||||
il->Replace(id, img);
|
||||
}
|
||||
cve->style().thumbnails_status[id] = THUMB_OK;
|
||||
s.thumbnails_status[id] = THUMB_OK;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +203,7 @@ void DropDownChoiceListBase::generateThumbnailImages() {
|
||||
ThumbnailStatus status = style().thumbnails_status[i];
|
||||
if (i >= image_count || status != THUMB_OK) {
|
||||
// request this thumbnail
|
||||
thumbnail_thread.request( createThumbnailRequest(&cve, i, status == THUMB_NOT_MADE));
|
||||
thumbnail_thread.request( new_intrusive3<ChoiceThumbnailRequest>(&cve, i, status == THUMB_NOT_MADE) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -270,10 +272,6 @@ DropDownList* DropDownChoiceList::createSubMenu(ChoiceField::ChoiceP group) cons
|
||||
return new DropDownChoiceList(const_cast<DropDownChoiceList*>(this), true, cve, group);
|
||||
}
|
||||
|
||||
ThumbnailRequestP DropDownChoiceList::createThumbnailRequest(ValueViewer * e, int index, bool from_disk) const {
|
||||
return new_intrusive3<ChoiceThumbnailRequest>(e, index, from_disk);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : ChoiceValueEditor
|
||||
|
||||
IMPLEMENT_VALUE_EDITOR(Choice)
|
||||
|
||||
@@ -60,7 +60,6 @@ class DropDownChoiceListBase : public DropDownList {
|
||||
|
||||
protected:
|
||||
virtual DropDownList* createSubMenu(ChoiceField::ChoiceP group) const = 0;
|
||||
virtual ThumbnailRequestP createThumbnailRequest(ValueViewer * e, int index, bool from_disk) const = 0;
|
||||
|
||||
private:
|
||||
DECLARE_EVENT_TABLE();
|
||||
@@ -100,7 +99,6 @@ class DropDownChoiceList : public DropDownChoiceListBase {
|
||||
virtual bool select(size_t item);
|
||||
virtual size_t selection() const;
|
||||
virtual DropDownList* createSubMenu(ChoiceField::ChoiceP group) const;
|
||||
virtual ThumbnailRequestP createThumbnailRequest(ValueViewer * e, int index, bool from_disk) const;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
@@ -10,87 +10,6 @@
|
||||
#include <gui/thumbnail_thread.hpp>
|
||||
#include <gui/util.hpp>
|
||||
#include <data/action/value.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <wx/imaglist.h>
|
||||
|
||||
// ----------------------------------------------------------------------------- : ChoiceThumbnailRequest
|
||||
|
||||
class MultipleChoiceThumbnailRequest : public ThumbnailRequest {
|
||||
public:
|
||||
MultipleChoiceThumbnailRequest(ValueViewer* cve, int id, bool from_disk);
|
||||
virtual Image generate();
|
||||
virtual void store(const Image&);
|
||||
|
||||
bool isThreadSafe;
|
||||
virtual bool threadSafe() const {return isThreadSafe;}
|
||||
private:
|
||||
StyleSheetP stylesheet;
|
||||
int id;
|
||||
};
|
||||
|
||||
MultipleChoiceThumbnailRequest::MultipleChoiceThumbnailRequest(ValueViewer* cve, int id, bool from_disk)
|
||||
: ThumbnailRequest(
|
||||
reinterpret_cast<void *> (cve),
|
||||
cve->viewer.stylesheet->name() + _("/") + cve->getField()->name + _("/") << id,
|
||||
from_disk ? cve->viewer.stylesheet->lastModified()
|
||||
: wxDateTime::Now()
|
||||
)
|
||||
, stylesheet(cve->viewer.stylesheet)
|
||||
, id(id)
|
||||
{
|
||||
MultipleChoiceValueEditor* e = dynamic_cast<MultipleChoiceValueEditor*> (cve);
|
||||
if (!e)
|
||||
throw InternalError(_("Non-editor passed to MultipleChoiceThumbnailRequest"));
|
||||
String name = cannocial_name_form(e->field().choices->choiceName(id));
|
||||
ScriptableImage img = e->style().choice_images[name];
|
||||
isThreadSafe = img.threadSafe();
|
||||
}
|
||||
|
||||
Image MultipleChoiceThumbnailRequest::generate() {
|
||||
MultipleChoiceValueEditor* cve = reinterpret_cast<MultipleChoiceValueEditor*> (owner);
|
||||
String name = cannocial_name_form(cve->field().choices->choiceName(id));
|
||||
ScriptableImage& img = cve->style().choice_images[name];
|
||||
return img.isReady()
|
||||
? img.generate(GeneratedImage::Options(16,16, stylesheet.get(), &cve->getSet(), ASPECT_BORDER, true), false)
|
||||
: wxImage();
|
||||
}
|
||||
|
||||
void MultipleChoiceThumbnailRequest::store(const Image& img) {
|
||||
MultipleChoiceValueEditor* cve = reinterpret_cast<MultipleChoiceValueEditor*> (owner);
|
||||
wxImageList* il = cve->style().thumbnails;
|
||||
while (id > il->GetImageCount()) {
|
||||
il->Add(wxBitmap(16,16),*wxBLACK);
|
||||
}
|
||||
if (img.Ok()) {
|
||||
#ifdef __WXMSW__
|
||||
// for some reason windows doesn't like completely transparent images if they do not have a mask
|
||||
// HACK:
|
||||
if (img.HasAlpha() && img.GetWidth() == 16 && img.GetHeight() == 16) {
|
||||
// is the image empty?
|
||||
bool empty = true;
|
||||
int* b = (int*)img.GetAlpha();
|
||||
int* e = b + 16*16/sizeof(int);
|
||||
while (b != e) {
|
||||
if (*b++) {
|
||||
empty = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if so, use a mask instead
|
||||
if (empty) {
|
||||
const_cast<Image&>(img).ConvertAlphaToMask();
|
||||
}
|
||||
}
|
||||
// Hack ends here
|
||||
#endif
|
||||
if (id == il->GetImageCount()) {
|
||||
il->Add(img);
|
||||
} else {
|
||||
il->Replace(id, img);
|
||||
}
|
||||
cve->style().thumbnails_status[id] = THUMB_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : DropDownMultipleChoiceList
|
||||
|
||||
@@ -104,7 +23,6 @@ class DropDownMultipleChoiceList : public DropDownChoiceListBase {
|
||||
virtual bool select(size_t item);
|
||||
virtual size_t selection() const;
|
||||
virtual DropDownList* createSubMenu(ChoiceField::ChoiceP group) const;
|
||||
virtual ThumbnailRequestP createThumbnailRequest(ValueViewer * e, int index, bool from_disk) const;
|
||||
virtual void drawIcon(DC& dc, int x, int y, size_t item, bool selected) const;
|
||||
|
||||
virtual void onMotion(wxMouseEvent&);
|
||||
@@ -174,10 +92,6 @@ DropDownList* DropDownMultipleChoiceList::createSubMenu(ChoiceField::ChoiceP gro
|
||||
return new DropDownMultipleChoiceList(const_cast<DropDownMultipleChoiceList*>(this), true, cve, group);
|
||||
}
|
||||
|
||||
ThumbnailRequestP DropDownMultipleChoiceList::createThumbnailRequest(ValueViewer * e, int index, bool from_disk) const {
|
||||
return new_intrusive3<MultipleChoiceThumbnailRequest>(e, index, from_disk);
|
||||
}
|
||||
|
||||
void DropDownMultipleChoiceList::onMotion(wxMouseEvent& ev) {
|
||||
if (kept_open) {
|
||||
wxSize cs = GetClientSize();
|
||||
|
||||
@@ -34,7 +34,6 @@ class MultipleChoiceValueEditor : public MultipleChoiceValueViewer, public Value
|
||||
DropDownListP drop_down;
|
||||
vector<int> active; ///< Which choices are active? (note: vector<bool> is evil)
|
||||
friend class DropDownMultipleChoiceList;
|
||||
friend class MultipleChoiceThumbnailRequest;
|
||||
/// Initialize the drop down list
|
||||
DropDownList& initDropDown();
|
||||
/// Toggle a choice or on or off
|
||||
|
||||
Reference in New Issue
Block a user