Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
a335b3f6
Commit
a335b3f6
authored
Jun 25, 2007
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented export functions;
Choice viewer uses font when rendering text.
parent
eed5eab8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
25 deletions
+83
-25
src/data/export_template.hpp
src/data/export_template.hpp
+2
-0
src/data/field/choice.cpp
src/data/field/choice.cpp
+1
-0
src/gui/html_export_window.cpp
src/gui/html_export_window.cpp
+2
-0
src/render/value/choice.cpp
src/render/value/choice.cpp
+9
-3
src/script/functions/export.cpp
src/script/functions/export.cpp
+69
-22
No files found.
src/data/export_template.hpp
View file @
a335b3f6
...
@@ -14,6 +14,7 @@
...
@@ -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 {
...
@@ -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
...
...
src/data/field/choice.cpp
View file @
a335b3f6
...
@@ -212,6 +212,7 @@ void ChoiceStyle::initImage() {
...
@@ -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
...
...
src/gui/html_export_window.cpp
View file @
a335b3f6
...
@@ -51,9 +51,11 @@ void HtmlExportWindow::onOk(wxCommandEvent&) {
...
@@ -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
)
{
...
...
src/render/value/choice.cpp
View file @
a335b3f6
...
@@ -57,9 +57,15 @@ void ChoiceValueViewer::draw(RotatedDC& dc) {
...
@@ -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
);
}
}
}
}
...
...
src/script/functions/export.cpp
View file @
a335b3f6
...
@@ -8,9 +8,17 @@
...
@@ -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) {
...
@@ -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
)
{
SCRIPT_FUNCTION
(
copy_file
)
{
if
(
!
export_info
())
{
throw
InternalError
(
_
(
"TODO: copy_file"
));
// TODO
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"
));
}
}
}
// write a file to the destination package.
// copy from source package -> destination directory, return new filename (relative)
// if 'filename' is not set, writes to the 'main' output file.
SCRIPT_FUNCTION
(
copy_file
)
{
SCRIPT_FUNCTION
(
write_file
)
{
guard_export_info
(
_
(
"copy_file"
));
throw
InternalError
(
_
(
"TODO: write_file"
));
// TODO
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 an ImageValue to a new file, return the filename
// write a file to the destination directory
// if the image was not written, return nil
SCRIPT_FUNCTION
(
write_text_file
)
{
// TODO: write a ScriptImage?
guard_export_info
(
_
(
"write_text_file"
));
SCRIPT_FUNCTION
(
image_to_file
)
{
SCRIPT_PARAM
(
String
,
input
);
// text to write
throw
InternalError
(
_
(
"TODO: image_to_file"
));
// TODO
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
());
}
}
// render a card, and write the image to a file
SCRIPT_FUNCTION
(
write_image_file
)
{
SCRIPT_FUNCTION
(
render_to_file
)
{
guard_export_info
(
_
(
"write_image_file"
));
throw
InternalError
(
_
(
"TODO: render_to_file"
));
// TODO
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
// ----------------------------------------------------------------------------- : 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
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment