mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-13 05:57:00 -04:00
Implemented export functions;
Choice viewer uses font when rendering text. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@433 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
#include <script/scriptable.hpp>
|
#include <script/scriptable.hpp>
|
||||||
|
|
||||||
DECLARE_POINTER_TYPE(Game);
|
DECLARE_POINTER_TYPE(Game);
|
||||||
|
DECLARE_POINTER_TYPE(Set);
|
||||||
DECLARE_POINTER_TYPE(Field);
|
DECLARE_POINTER_TYPE(Field);
|
||||||
DECLARE_POINTER_TYPE(Style);
|
DECLARE_POINTER_TYPE(Style);
|
||||||
DECLARE_POINTER_TYPE(ExportTemplate);
|
DECLARE_POINTER_TYPE(ExportTemplate);
|
||||||
@@ -42,6 +43,7 @@ class ExportTemplate : public Packaged {
|
|||||||
|
|
||||||
/// Information that can be used by export functions
|
/// Information that can be used by export functions
|
||||||
struct ExportInfo {
|
struct ExportInfo {
|
||||||
|
SetP set; ///< The set that is being exported
|
||||||
ExportTemplateP export_template; ///< The export template used
|
ExportTemplateP export_template; ///< The export template used
|
||||||
String directory_relative; ///< The directory for storing extra files (or "" if !export->create_directory)
|
String directory_relative; ///< The directory for storing extra files (or "" if !export->create_directory)
|
||||||
/// This is just the directory name
|
/// This is just the directory name
|
||||||
|
|||||||
@@ -212,6 +212,7 @@ void ChoiceStyle::initImage() {
|
|||||||
bool ChoiceStyle::update(Context& ctx) {
|
bool ChoiceStyle::update(Context& ctx) {
|
||||||
// Don't update the choice images, leave that to invalidate()
|
// Don't update the choice images, leave that to invalidate()
|
||||||
bool change = Style ::update(ctx)
|
bool change = Style ::update(ctx)
|
||||||
|
| font .update(ctx)
|
||||||
| mask_filename.update(ctx);
|
| mask_filename.update(ctx);
|
||||||
if (!choice_images_initialized) {
|
if (!choice_images_initialized) {
|
||||||
// we only want to do this once because it is rather slow, other updates are handled by dependencies
|
// we only want to do this once because it is rather slow, other updates are handled by dependencies
|
||||||
|
|||||||
@@ -51,9 +51,11 @@ void HtmlExportWindow::onOk(wxCommandEvent&) {
|
|||||||
// get filename
|
// get filename
|
||||||
String name = wxFileSelector(_TITLE_("save html"),_(""),_(""),_(""),exp->file_type, wxSAVE | wxOVERWRITE_PROMPT);
|
String name = wxFileSelector(_TITLE_("save html"),_(""),_(""),_(""),exp->file_type, wxSAVE | wxOVERWRITE_PROMPT);
|
||||||
if (name.empty()) return;
|
if (name.empty()) return;
|
||||||
|
wxBusyCursor wait;
|
||||||
// export info for script
|
// export info for script
|
||||||
ExportInfo info;
|
ExportInfo info;
|
||||||
info.export_template = exp;
|
info.export_template = exp;
|
||||||
|
info.set = set;
|
||||||
WITH_DYNAMIC_ARG(export_info, &info);
|
WITH_DYNAMIC_ARG(export_info, &info);
|
||||||
// create directory?
|
// create directory?
|
||||||
if (exp->create_directory) {
|
if (exp->create_directory) {
|
||||||
|
|||||||
@@ -57,9 +57,15 @@ void ChoiceValueViewer::draw(RotatedDC& dc) {
|
|||||||
}
|
}
|
||||||
if (style().render_style & RENDER_TEXT) {
|
if (style().render_style & RENDER_TEXT) {
|
||||||
// draw text
|
// draw text
|
||||||
dc.DrawText(tr(*viewer.stylesheet, value().value(), capitalize(value().value())),
|
dc.SetFont(style().font, 1.0);
|
||||||
align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), style().getRect()) + RealSize(margin, 0)
|
String text = tr(*viewer.stylesheet, value().value(), capitalize(value().value()));
|
||||||
);
|
RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), style().getRect()) + RealSize(margin, 0);
|
||||||
|
if (style().font.hasShadow()) {
|
||||||
|
dc.SetTextForeground(style().font.shadow_color);
|
||||||
|
dc.DrawText(text, pos + style().font.shadow_displacement);
|
||||||
|
}
|
||||||
|
dc.SetTextForeground(style().font.color());
|
||||||
|
dc.DrawText(text, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,17 @@
|
|||||||
|
|
||||||
#include <script/functions/functions.hpp>
|
#include <script/functions/functions.hpp>
|
||||||
#include <script/functions/util.hpp>
|
#include <script/functions/util.hpp>
|
||||||
|
#include <script/image.hpp>
|
||||||
#include <data/symbol_font.hpp>
|
#include <data/symbol_font.hpp>
|
||||||
|
#include <data/set.hpp>
|
||||||
|
#include <data/card.hpp>
|
||||||
|
#include <data/export_template.hpp>
|
||||||
|
#include <data/format/formats.hpp>
|
||||||
#include <util/tagged_string.hpp>
|
#include <util/tagged_string.hpp>
|
||||||
|
#include <gfx/generated_image.hpp>
|
||||||
#include <util/error.hpp>
|
#include <util/error.hpp>
|
||||||
|
#include <wx/wfstream.h>
|
||||||
|
#include <wx/filename.h>
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : HTML
|
// ----------------------------------------------------------------------------- : HTML
|
||||||
|
|
||||||
@@ -200,37 +208,76 @@ SCRIPT_FUNCTION(to_text) {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Files
|
// ----------------------------------------------------------------------------- : Files
|
||||||
|
|
||||||
// copy from source package -> destination package, return new filename (relative)
|
void guard_export_info(const String& fun) {
|
||||||
|
if (!export_info()) {
|
||||||
|
throw ScriptError(_("Can only use ") + fun + _(" from export templates"));
|
||||||
|
} else if (export_info()->directory_relative.empty()) {
|
||||||
|
throw ScriptError(_("Can only use ") + fun + _(" when 'create directory' is set to true"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy from source package -> destination directory, return new filename (relative)
|
||||||
SCRIPT_FUNCTION(copy_file) {
|
SCRIPT_FUNCTION(copy_file) {
|
||||||
throw InternalError(_("TODO: copy_file")); // TODO
|
guard_export_info(_("copy_file"));
|
||||||
|
SCRIPT_PARAM(String, input); // file to copy
|
||||||
|
ExportInfo& ei = *export_info();
|
||||||
|
wxFileName fn(input);
|
||||||
|
fn.SetPath(ei.directory_absolute);
|
||||||
|
// copy
|
||||||
|
InputStreamP in = ei.export_template->openIn(input);
|
||||||
|
wxFileOutputStream out(fn.GetFullPath());
|
||||||
|
if (!out.Ok()) throw Error(_("Unable to open file '") + fn.GetFullPath() + _("' for output"));
|
||||||
|
out.Write(*in);
|
||||||
|
SCRIPT_RETURN(fn.GetFullName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// write a file to the destination package.
|
// write a file to the destination directory
|
||||||
// if 'filename' is not set, writes to the 'main' output file.
|
SCRIPT_FUNCTION(write_text_file) {
|
||||||
SCRIPT_FUNCTION(write_file) {
|
guard_export_info(_("write_text_file"));
|
||||||
throw InternalError(_("TODO: write_file")); // TODO
|
SCRIPT_PARAM(String, input); // text to write
|
||||||
|
SCRIPT_PARAM(String, file); // file to write to
|
||||||
|
// filename
|
||||||
|
wxFileName fn;
|
||||||
|
fn.SetPath(export_info()->directory_absolute);
|
||||||
|
fn.SetFullName(file);
|
||||||
|
// write
|
||||||
|
wxFileOutputStream out(fn.GetFullPath());
|
||||||
|
if (!out.Ok()) throw Error(_("Unable to open file '") + fn.GetFullPath() + _("' for output"));
|
||||||
|
wxTextOutputStream tout(out);
|
||||||
|
tout.WriteString(BYTE_ORDER_MARK);
|
||||||
|
tout.WriteString(input);
|
||||||
|
SCRIPT_RETURN(fn.GetFullName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// write an ImageValue to a new file, return the filename
|
SCRIPT_FUNCTION(write_image_file) {
|
||||||
// if the image was not written, return nil
|
guard_export_info(_("write_image_file"));
|
||||||
// TODO: write a ScriptImage?
|
ExportInfo& ei = *export_info();
|
||||||
SCRIPT_FUNCTION(image_to_file) {
|
// get image
|
||||||
throw InternalError(_("TODO: image_to_file")); // TODO
|
SCRIPT_PARAM(ScriptValueP, input);
|
||||||
}
|
ScriptObject<CardP>* card = dynamic_cast<ScriptObject<CardP>*>(input.get()); // is it a card?
|
||||||
|
Image image;
|
||||||
// render a card, and write the image to a file
|
if (card) {
|
||||||
SCRIPT_FUNCTION(render_to_file) {
|
image = export_bitmap(ei.set, card->getValue()).ConvertToImage();
|
||||||
throw InternalError(_("TODO: render_to_file")); // TODO
|
} else {
|
||||||
|
image = image_from_script(input)->generate(GeneratedImage::Options(0,0,ei.export_template.get(),ei.set.get()));
|
||||||
|
}
|
||||||
|
if (!image.Ok()) throw Error(_("Unable to convert .. to image"));
|
||||||
|
// filename
|
||||||
|
SCRIPT_PARAM(String, file); // file to write to
|
||||||
|
wxFileName fn;
|
||||||
|
fn.SetPath(ei.directory_absolute);
|
||||||
|
fn.SetFullName(file);
|
||||||
|
// write
|
||||||
|
image.SaveFile(fn.GetFullPath());
|
||||||
|
SCRIPT_RETURN(fn.GetFullName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Init
|
// ----------------------------------------------------------------------------- : Init
|
||||||
|
|
||||||
void init_script_export_functions(Context& ctx) {
|
void init_script_export_functions(Context& ctx) {
|
||||||
ctx.setVariable(_("to html"), script_to_html);
|
ctx.setVariable(_("to html"), script_to_html);
|
||||||
ctx.setVariable(_("to text"), script_to_text);
|
ctx.setVariable(_("to text"), script_to_text);
|
||||||
ctx.setVariable(_("copy file"), script_copy_file);
|
ctx.setVariable(_("copy file"), script_copy_file);
|
||||||
ctx.setVariable(_("write file"), script_write_file);
|
ctx.setVariable(_("write text file"), script_write_text_file);
|
||||||
ctx.setVariable(_("image to file"), script_image_to_file);
|
ctx.setVariable(_("write image file"), script_write_image_file);
|
||||||
ctx.setVariable(_("write image"), script_image_to_file);
|
|
||||||
ctx.setVariable(_("render to file"), script_render_to_file);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user