mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04: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>
|
||||
|
||||
DECLARE_POINTER_TYPE(Game);
|
||||
DECLARE_POINTER_TYPE(Set);
|
||||
DECLARE_POINTER_TYPE(Field);
|
||||
DECLARE_POINTER_TYPE(Style);
|
||||
DECLARE_POINTER_TYPE(ExportTemplate);
|
||||
@@ -42,6 +43,7 @@ class ExportTemplate : public Packaged {
|
||||
|
||||
/// Information that can be used by export functions
|
||||
struct ExportInfo {
|
||||
SetP set; ///< The set that is being exported
|
||||
ExportTemplateP export_template; ///< The export template used
|
||||
String directory_relative; ///< The directory for storing extra files (or "" if !export->create_directory)
|
||||
/// This is just the directory name
|
||||
|
||||
@@ -212,6 +212,7 @@ void ChoiceStyle::initImage() {
|
||||
bool ChoiceStyle::update(Context& ctx) {
|
||||
// Don't update the choice images, leave that to invalidate()
|
||||
bool change = Style ::update(ctx)
|
||||
| font .update(ctx)
|
||||
| mask_filename.update(ctx);
|
||||
if (!choice_images_initialized) {
|
||||
// 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
|
||||
String name = wxFileSelector(_TITLE_("save html"),_(""),_(""),_(""),exp->file_type, wxSAVE | wxOVERWRITE_PROMPT);
|
||||
if (name.empty()) return;
|
||||
wxBusyCursor wait;
|
||||
// export info for script
|
||||
ExportInfo info;
|
||||
info.export_template = exp;
|
||||
info.set = set;
|
||||
WITH_DYNAMIC_ARG(export_info, &info);
|
||||
// create directory?
|
||||
if (exp->create_directory) {
|
||||
|
||||
@@ -57,9 +57,15 @@ void ChoiceValueViewer::draw(RotatedDC& dc) {
|
||||
}
|
||||
if (style().render_style & RENDER_TEXT) {
|
||||
// draw text
|
||||
dc.DrawText(tr(*viewer.stylesheet, value().value(), capitalize(value().value())),
|
||||
align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), style().getRect()) + RealSize(margin, 0)
|
||||
);
|
||||
dc.SetFont(style().font, 1.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/util.hpp>
|
||||
#include <script/image.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 <gfx/generated_image.hpp>
|
||||
#include <util/error.hpp>
|
||||
#include <wx/wfstream.h>
|
||||
#include <wx/filename.h>
|
||||
|
||||
// ----------------------------------------------------------------------------- : HTML
|
||||
|
||||
@@ -200,37 +208,76 @@ SCRIPT_FUNCTION(to_text) {
|
||||
|
||||
// ----------------------------------------------------------------------------- : 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) {
|
||||
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.
|
||||
// if 'filename' is not set, writes to the 'main' output file.
|
||||
SCRIPT_FUNCTION(write_file) {
|
||||
throw InternalError(_("TODO: write_file")); // TODO
|
||||
// write a file to the destination directory
|
||||
SCRIPT_FUNCTION(write_text_file) {
|
||||
guard_export_info(_("write_text_file"));
|
||||
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
|
||||
// if the image was not written, return nil
|
||||
// TODO: write a ScriptImage?
|
||||
SCRIPT_FUNCTION(image_to_file) {
|
||||
throw InternalError(_("TODO: image_to_file")); // TODO
|
||||
}
|
||||
|
||||
// render a card, and write the image to a file
|
||||
SCRIPT_FUNCTION(render_to_file) {
|
||||
throw InternalError(_("TODO: render_to_file")); // TODO
|
||||
SCRIPT_FUNCTION(write_image_file) {
|
||||
guard_export_info(_("write_image_file"));
|
||||
ExportInfo& ei = *export_info();
|
||||
// get image
|
||||
SCRIPT_PARAM(ScriptValueP, input);
|
||||
ScriptObject<CardP>* card = dynamic_cast<ScriptObject<CardP>*>(input.get()); // is it a card?
|
||||
Image image;
|
||||
if (card) {
|
||||
image = export_bitmap(ei.set, card->getValue()).ConvertToImage();
|
||||
} 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
|
||||
|
||||
void init_script_export_functions(Context& ctx) {
|
||||
ctx.setVariable(_("to html"), script_to_html);
|
||||
ctx.setVariable(_("to text"), script_to_text);
|
||||
ctx.setVariable(_("copy file"), script_copy_file);
|
||||
ctx.setVariable(_("write file"), script_write_file);
|
||||
ctx.setVariable(_("image to file"), script_image_to_file);
|
||||
ctx.setVariable(_("write image"), script_image_to_file);
|
||||
ctx.setVariable(_("render to file"), script_render_to_file);
|
||||
ctx.setVariable(_("to html"), script_to_html);
|
||||
ctx.setVariable(_("to text"), script_to_text);
|
||||
ctx.setVariable(_("copy file"), script_copy_file);
|
||||
ctx.setVariable(_("write text file"), script_write_text_file);
|
||||
ctx.setVariable(_("write image file"), script_write_image_file);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user