Committed a (broken) copy of ASSDraw3 source code by ai-chan

Originally committed to SVN as r1815.
This commit is contained in:
Rodrigo Braz Monteiro 2008-01-23 02:22:15 +00:00
parent ef55f55df0
commit 08274f0a0c
66 changed files with 8596 additions and 0 deletions

317
assdraw/assdraw.vcproj Normal file
View File

@ -0,0 +1,317 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Name="assdraw"
ProjectGUID="{3BC75951-691C-4703-A29A-D29E298248AC}"
RootNamespace="assdraw"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\src\agg_bcspline.cpp"
>
</File>
<File
RelativePath=".\src\agg_vcgen_bcspline.cpp"
>
</File>
<File
RelativePath=".\src\wxAGG\AGGWindow.cpp"
>
</File>
<File
RelativePath=".\src\assdraw.cpp"
>
</File>
<File
RelativePath=".\src\assdraw_settings.cpp"
>
</File>
<File
RelativePath=".\src\canvas.cpp"
>
</File>
<File
RelativePath=".\src\canvas_mouse.cpp"
>
</File>
<File
RelativePath=".\src\cmd.cpp"
>
</File>
<File
RelativePath=".\src\dlgctrl.cpp"
>
</File>
<File
RelativePath=".\src\engine.cpp"
>
</File>
<File
RelativePath=".\src\library.cpp"
>
</File>
<File
RelativePath=".\src\settings.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\src\_common.hpp"
>
</File>
<File
RelativePath=".\src\agg_bcspline.h"
>
</File>
<File
RelativePath=".\src\agg_conv_bcspline.h"
>
</File>
<File
RelativePath=".\src\agg_vcgen_bcspline.h"
>
</File>
<File
RelativePath=".\src\agghelper.hpp"
>
</File>
<File
RelativePath=".\src\wxAGG\AGGWindow.h"
>
</File>
<File
RelativePath=".\src\assdraw.hpp"
>
</File>
<File
RelativePath=".\src\canvas.hpp"
>
</File>
<File
RelativePath=".\src\canvas_mouse.hpp"
>
</File>
<File
RelativePath=".\src\cmd.hpp"
>
</File>
<File
RelativePath=".\src\dlgctrl.hpp"
>
</File>
<File
RelativePath=".\src\engine.hpp"
>
</File>
<File
RelativePath=".\src\enums.hpp"
>
</File>
<File
RelativePath=".\src\include_once.hpp"
>
</File>
<File
RelativePath=".\src\library.hpp"
>
</File>
<File
RelativePath=".\src\wxAGG\PixelFormatConvertor.h"
>
</File>
<File
RelativePath=".\src\resource.h"
>
</File>
<File
RelativePath=".\src\settings.hpp"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
<File
RelativePath=".\src\assdraw.rc"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

323
assdraw/src/ASSDraw3.dev Normal file
View File

@ -0,0 +1,323 @@
[Project]
FileName=ASSDraw3.dev
Name=ASSDraw
UnitCount=26
Type=0
Ver=3
IsCpp=1
Folders=AGG
CommandLine=
CompilerSettings=0000000001001000000100
PchHead=-1
PchSource=-1
ProfilesCount=1
ProfileIndex=0
[Unit1]
FileName=assdraw.cpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[VersionInfo]
Major=3
Minor=0
Release=0
Build=0
LanguageID=1033
CharsetID=1252
CompanyName=ai-chan
FileVersion=3.0.0.0
FileDescription=A tool for designing shapes to be used in ASS subtitle
InternalName=ASSDraw3
LegalCopyright=
LegalTrademarks=
OriginalFilename=ASSDraw3.exe
ProductName=ASSDraw
ProductVersion=3
AutoIncBuildNrOnRebuild=0
AutoIncBuildNrOnCompile=0
UnitCount=20
[Unit3]
FileName=cmd.hpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit4]
FileName=engine.hpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit5]
FileName=assdraw.rc
CompileCpp=1
Folder=Resources
Compile=1
Link=0
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit7]
FileName=engine.cpp
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
CompileCpp=1
[Unit9]
FileName=include_once.hpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit6]
FileName=assdraw.hpp
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
CompileCpp=1
[Unit2]
FileName=cmd.cpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Profile1]
ProfileName=Default Profile
Type=0
ObjFiles=
Includes=E:\DEV;E:\DEV\agg-2.5\include;E:\DEV\wxTreeMultiCtrl\include
Libs=E:\DEV\agg-2.5;E:\DEV\wxTreeMultiCtrl
PrivateResource=E:\DEV\_projects\ASSDraw 3\Default Profile\ASSDraw_private.rc
ResourceIncludes=
MakeIncludes=
Compiler=
CppCompiler=-D__WXMSW__ -DNO_GCC_PRAGMA -fno-rtti -fno-exceptions_@@_ -Wno-deprecated_@@_
Linker=-lwxmsw28_propgrid_@@_-mwindows_@@_-lwxmsw28_@@_-lwxmsw28_gl_@@_-lwxtiff_@@_-lwxjpeg_@@_-lwxpng_@@_-lwxzlib_@@_-lwxregex_@@_-lwxexpat_@@_-lkernel32_@@_-luser32_@@_-lgdi32_@@_-lcomdlg32_@@_-lwinspool_@@_-lwinmm_@@_-lshell32_@@_-lcomctl32_@@_-lole32_@@_-loleaut32_@@_-luuid_@@_-lrpcrt4_@@_-ladvapi32_@@_-lwsock32_@@_-lodbc32_@@_-lopengl32_@@_-lagg_@@_
PreprocDefines=
CompilerSettings=0000000001001000000100
Icon=
ExeOutput=E:\DEV\_projects\ASSDraw 3\Default Profile\
ObjectOutput=E:\DEV\_projects\ASSDraw 3\Default Profile\
OverrideOutput=1
OverrideOutputName=ASSDraw3.exe
HostApplication=
CommandLine=
UseCustomMakefile=0
CustomMakefile=
IncludeVersionInfo=1
SupportXPThemes=1
CompilerSet=0
compilerType=0
[Unit8]
FileName=dlgctrl.cpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit10]
FileName=resource.h
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit15]
FileName=agg_bcspline.cpp
CompileCpp=1
Folder=AGG
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit16]
FileName=enums.hpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit18]
FileName=library.cpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit17]
FileName=library.hpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit13]
FileName=wxAGG\AGGWindow.cpp
CompileCpp=1
Folder=AGG
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit14]
FileName=agg_vcgen_bcspline.cpp
CompileCpp=1
Folder=AGG
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit11]
FileName=canvas.cpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit12]
FileName=canvas.hpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit20]
FileName=dlgctrl.hpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit19]
FileName=_common.hpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit21]
FileName=settings.cpp
CompileCpp=1
Folder=ASSDraw
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit22]
FileName=settings.hpp
CompileCpp=1
Folder=ASSDraw
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit23]
FileName=assdraw_settings.cpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit24]
FileName=agghelper.hpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit25]
FileName=canvas_mouse.hpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit26]
FileName=canvas_mouse.cpp
CompileCpp=1
Folder=
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

185
assdraw/src/ASSDraw3.layout Normal file
View File

@ -0,0 +1,185 @@
[Editor_10]
CursorCol=32
CursorRow=553
TopLine=535
LeftChar=1
Open=1
Top=0
[Editor_7]
CursorCol=6
CursorRow=227
TopLine=197
LeftChar=1
Open=1
Top=1
[Editor_5]
CursorCol=11
CursorRow=19
TopLine=1
LeftChar=1
Open=1
Top=0
[Editor_18]
CursorCol=11
CursorRow=14
TopLine=1
LeftChar=1
Open=0
Top=0
[Editor_19]
CursorCol=12
CursorRow=3
TopLine=3
LeftChar=1
Open=0
Top=0
[Editor_11]
CursorCol=8
CursorRow=44
TopLine=31
LeftChar=1
Open=0
Top=0
[Editor_3]
CursorCol=1
CursorRow=268
TopLine=243
LeftChar=1
Open=1
Top=0
[Editor_15]
CursorCol=15
CursorRow=7
TopLine=1
LeftChar=1
Open=1
Top=0
[Editor_8]
CursorCol=1
CursorRow=69
TopLine=33
LeftChar=1
Open=0
Top=0
[Editor_16]
CursorCol=2
CursorRow=25
TopLine=1
LeftChar=1
Open=0
Top=0
[Editor_0]
CursorCol=39
CursorRow=212
TopLine=184
LeftChar=1
Open=1
Top=0
[Editors]
Focused=7
Order=5,0,10,17,3,6,7,22,21,20,15
[Editor_1]
Open=0
Top=0
CursorCol=21
CursorRow=63
TopLine=30
LeftChar=1
[Editor_2]
Open=0
Top=0
CursorCol=7
CursorRow=83
TopLine=50
LeftChar=1
[Editor_4]
Open=0
Top=0
CursorCol=19
CursorRow=21
TopLine=21
LeftChar=1
[Editor_6]
Open=1
Top=0
CursorCol=1
CursorRow=577
TopLine=556
LeftChar=1
[Editor_9]
Open=0
Top=0
CursorCol=1
CursorRow=1
TopLine=1
LeftChar=1
[Editor_12]
Open=0
Top=0
CursorCol=6
CursorRow=99
TopLine=91
LeftChar=1
[Editor_13]
Open=0
Top=0
CursorCol=1
CursorRow=204
TopLine=170
LeftChar=1
[Editor_14]
Open=0
Top=0
CursorCol=1
CursorRow=290
TopLine=256
LeftChar=1
[Editor_17]
Open=1
Top=0
CursorCol=68
CursorRow=133
TopLine=112
LeftChar=1
[Editor_20]
Open=1
Top=0
CursorCol=46
CursorRow=195
TopLine=163
LeftChar=1
[Editor_21]
Open=1
Top=0
CursorCol=2
CursorRow=58
TopLine=57
LeftChar=1
[Editor_22]
Open=1
Top=0
CursorCol=32
CursorRow=160
TopLine=129
LeftChar=1
[Editor_23]
Open=0
Top=0
CursorCol=2
CursorRow=6
TopLine=1
LeftChar=1
[Editor_24]
CursorCol=1
CursorRow=56
TopLine=25
LeftChar=1
Open=0
Top=0
[Editor_25]
Open=0
Top=0
CursorCol=18
CursorRow=8
TopLine=1
LeftChar=1

69
assdraw/src/Makefile.win Normal file
View File

@ -0,0 +1,69 @@
# Project: ASSDraw
# Compiler: Default GCC compiler
# Compiler Type: MingW 3
# Makefile created by wxDev-C++ 6.10.2 on 20/01/08 23:46
CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
OBJ = ../Default\ Profile/assdraw.o ../Default\ Profile/cmd.o ../Default\ Profile/engine.o ../Default\ Profile/dlgctrl.o ../Default\ Profile/canvas.o ../Default\ Profile/AGGWindow.o ../Default\ Profile/agg_vcgen_bcspline.o ../Default\ Profile/agg_bcspline.o ../Default\ Profile/library.o ../Default\ Profile/settings.o ../Default\ Profile/assdraw_settings.o ../Default\ Profile/canvas_mouse.o ../Default\ Profile/ASSDraw3_private.res
LINKOBJ = "../Default Profile/assdraw.o" "../Default Profile/cmd.o" "../Default Profile/engine.o" "../Default Profile/dlgctrl.o" "../Default Profile/canvas.o" "../Default Profile/AGGWindow.o" "../Default Profile/agg_vcgen_bcspline.o" "../Default Profile/agg_bcspline.o" "../Default Profile/library.o" "../Default Profile/settings.o" "../Default Profile/assdraw_settings.o" "../Default Profile/canvas_mouse.o" "../Default Profile/ASSDraw3_private.res"
LIBS = -L"D:/Program Files/Dev-Cpp/Lib" -L"E:/DEV/agg-2.5" -L"E:/DEV/wxTreeMultiCtrl" -lwxmsw28_propgrid -mwindows -lwxmsw28 -lwxmsw28_gl -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregex -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32 -lopengl32 -lagg -s
INCS = -I"include" -I"E:/DEV" -I"E:/DEV/agg-2.5/include" -I"E:/DEV/wxTreeMultiCtrl/include"
CXXINCS = -I"D:/Program Files/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"D:/Program Files/Dev-Cpp/include/c++/3.4.2/backward" -I"D:/Program Files/Dev-Cpp/include/c++/3.4.2/mingw32" -I"D:/Program Files/Dev-Cpp/include/c++/3.4.2" -I"D:/Program Files/Dev-Cpp/include" -I"D:/Program Files/Dev-Cpp/" -I"D:/Program Files/Dev-Cpp/include/common/wx/msw" -I"D:/Program Files/Dev-Cpp/include/common/wx/generic" -I"D:/Program Files/Dev-Cpp/include/common/wx/fl" -I"D:/Program Files/Dev-Cpp/include/common/wx/gizmos" -I"D:/Program Files/Dev-Cpp/include/common/wx/html" -I"D:/Program Files/Dev-Cpp/include/common/wx/mmedia" -I"D:/Program Files/Dev-Cpp/include/common/wx/net" -I"D:/Program Files/Dev-Cpp/include/common/wx/ogl" -I"D:/Program Files/Dev-Cpp/include/common/wx/plot" -I"D:/Program Files/Dev-Cpp/include/common/wx/protocol" -I"D:/Program Files/Dev-Cpp/include/common/wx/stc" -I"D:/Program Files/Dev-Cpp/include/common/wx/svg" -I"D:/Program Files/Dev-Cpp/include/common/wx/xml" -I"D:/Program Files/Dev-Cpp/include/common/wx/xrc" -I"D:/Program Files/Dev-Cpp/include/common/wx" -I"D:/Program Files/Dev-Cpp/include/common" -I"E:/dev/ACE-5.5" -I"E:/DEV" -I"E:/DEV/agg-2.5/include" -I"E:/DEV/wxTreeMultiCtrl/include"
RCINCS = --include-dir "D:/PROGRA~1/Dev-Cpp/include/common"
BIN = ../Default\ Profile/ASSDraw3.exe
DEFINES =
CXXFLAGS = $(CXXINCS) $(DEFINES) -D__WXMSW__ -DNO_GCC_PRAGMA -fno-rtti -fno-exceptions -Wno-deprecated -fexpensive-optimizations -O3
CFLAGS = $(INCS) $(DEFINES) -fexpensive-optimizations -O3
GPROF = gprof.exe
RM = rm -f
LINK = g++.exe
.PHONY: all all-before all-after clean clean-custom
all: all-before $(BIN) all-after
clean: clean-custom
$(RM) $(OBJ) $(BIN)
$(BIN): $(OBJ)
$(LINK) $(LINKOBJ) -o "..\Default Profile\ASSDraw3.exe" $(LIBS)
../Default\ Profile/assdraw.o: $(GLOBALDEPS) assdraw.cpp assdraw.hpp _common.hpp enums.hpp include_once.hpp
$(CPP) -c assdraw.cpp -o "../Default Profile/assdraw.o" $(CXXFLAGS)
../Default\ Profile/cmd.o: $(GLOBALDEPS) cmd.cpp
$(CPP) -c cmd.cpp -o "../Default Profile/cmd.o" $(CXXFLAGS)
../Default\ Profile/engine.o: $(GLOBALDEPS) engine.cpp
$(CPP) -c engine.cpp -o "../Default Profile/engine.o" $(CXXFLAGS)
../Default\ Profile/dlgctrl.o: $(GLOBALDEPS) dlgctrl.cpp assdraw.hpp _common.hpp
$(CPP) -c dlgctrl.cpp -o "../Default Profile/dlgctrl.o" $(CXXFLAGS)
../Default\ Profile/canvas.o: $(GLOBALDEPS) canvas.cpp assdraw.hpp _common.hpp cmd.hpp agghelper.hpp
$(CPP) -c canvas.cpp -o "../Default Profile/canvas.o" $(CXXFLAGS)
../Default\ Profile/AGGWindow.o: $(GLOBALDEPS) wxAGG/AGGWindow.cpp wxAGG/AGGWindow.h wxAGG/PixelFormatConvertor.h
$(CPP) -c wxAGG/AGGWindow.cpp -o "../Default Profile/AGGWindow.o" $(CXXFLAGS)
../Default\ Profile/agg_vcgen_bcspline.o: $(GLOBALDEPS) agg_vcgen_bcspline.cpp agg_vcgen_bcspline.h agg_bcspline.h
$(CPP) -c agg_vcgen_bcspline.cpp -o "../Default Profile/agg_vcgen_bcspline.o" $(CXXFLAGS)
../Default\ Profile/agg_bcspline.o: $(GLOBALDEPS) agg_bcspline.cpp agg_bcspline.h
$(CPP) -c agg_bcspline.cpp -o "../Default Profile/agg_bcspline.o" $(CXXFLAGS)
../Default\ Profile/library.o: $(GLOBALDEPS) library.cpp assdraw.hpp _common.hpp library.hpp engine.hpp _common.hpp wxAGG/AGGWindow.h wxAGG/PixelFormatConvertor.h agg_conv_bcspline.h agg_vcgen_bcspline.h agg_bcspline.h
$(CPP) -c library.cpp -o "../Default Profile/library.o" $(CXXFLAGS)
../Default\ Profile/settings.o: $(GLOBALDEPS) settings.cpp assdraw.hpp _common.hpp settings.hpp _common.hpp
$(CPP) -c settings.cpp -o "../Default Profile/settings.o" $(CXXFLAGS)
../Default\ Profile/assdraw_settings.o: $(GLOBALDEPS) assdraw_settings.cpp assdraw.hpp _common.hpp
$(CPP) -c assdraw_settings.cpp -o "../Default Profile/assdraw_settings.o" $(CXXFLAGS)
../Default\ Profile/canvas_mouse.o: $(GLOBALDEPS) canvas_mouse.cpp canvas_mouse.hpp _common.hpp enums.hpp engine.hpp _common.hpp wxAGG/AGGWindow.h wxAGG/PixelFormatConvertor.h agg_conv_bcspline.h agg_vcgen_bcspline.h agg_bcspline.h canvas.hpp engine.hpp enums.hpp
$(CPP) -c canvas_mouse.cpp -o "../Default Profile/canvas_mouse.o" $(CXXFLAGS)
../Default\ Profile/ASSDraw3_private.res: ../Default\ Profile/ASSDraw3_private.rc assdraw.rc
$(WINDRES) --input-format=rc -o "../Default Profile/ASSDraw3_private.res" $(RCINCS) ../DEFAUL~1/ASSDRA~1.RC -O coff

14
assdraw/src/_common.hpp Normal file
View File

@ -0,0 +1,14 @@
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#define TITLE wxT("ASSDraw3")
#define __DPDS__ wxDefaultPosition, wxDefaultSize

View File

@ -0,0 +1,289 @@
//----------------------------------------------------------------------------
// Anti-Grain Geometry (AGG) - Version 2.5
// A high quality rendering engine for C++
// Copyright (C) 2002-2006 Maxim Shemanarev
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://antigrain.com
//
// AGG is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// AGG is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with AGG; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
//----------------------------------------------------------------------------
#include "agg_bcspline.h"
namespace agg
{
//------------------------------------------------------------------------
bcspline::bcspline() :
m_max(0),
m_num(0),
m_x(0),
m_y(0),
m_last_idx(-1)
{
}
//------------------------------------------------------------------------
bcspline::bcspline(int num) :
m_max(0),
m_num(0),
m_x(0),
m_y(0),
m_last_idx(-1)
{
init(num);
}
//------------------------------------------------------------------------
bcspline::bcspline(int num, const double* x, const double* y) :
m_max(0),
m_num(0),
m_x(0),
m_y(0),
m_last_idx(-1)
{
init(num, x, y);
}
//------------------------------------------------------------------------
void bcspline::init(int max)
{
if(max > 2 && max > m_max)
{
m_am.resize(max * 3);
m_max = max;
m_x = &m_am[m_max];
m_y = &m_am[m_max * 2];
}
m_num = 0;
m_last_idx = -1;
}
//------------------------------------------------------------------------
void bcspline::add_point(double x, double y)
{
if(m_num < m_max)
{
m_x[m_num] = x;
m_y[m_num] = y;
++m_num;
}
}
//------------------------------------------------------------------------
void bcspline::prepare()
{
if(m_num > 2)
{
int i, k, n1;
double* temp;
double* r;
double* s;
double h, p, d, f, e;
for(k = 0; k < m_num; k++)
{
m_am[k] = 0.0;
}
n1 = 3 * m_num;
pod_array<double> al(n1);
temp = &al[0];
for(k = 0; k < n1; k++)
{
temp[k] = 0.0;
}
r = temp + m_num;
s = temp + m_num * 2;
n1 = m_num - 1;
d = m_x[1] - m_x[0];
e = (m_y[1] - m_y[0]) / d;
for(k = 1; k < n1; k++)
{
h = d;
d = m_x[k + 1] - m_x[k];
f = e;
e = (m_y[k + 1] - m_y[k]) / d;
al[k] = d / (d + h);
r[k] = 1.0 - al[k];
s[k] = 6.0 * (e - f) / (h + d);
}
for(k = 1; k < n1; k++)
{
p = 1.0 / (r[k] * al[k - 1] + 2.0);
al[k] *= -p;
s[k] = (s[k] - r[k] * s[k - 1]) * p;
}
m_am[n1] = 0.0;
al[n1 - 1] = s[n1 - 1];
m_am[n1 - 1] = al[n1 - 1];
for(k = n1 - 2, i = 0; i < m_num - 2; i++, k--)
{
al[k] = al[k] * al[k + 1] + s[k];
m_am[k] = al[k];
}
}
m_last_idx = -1;
}
//------------------------------------------------------------------------
void bcspline::init(int num, const double* x, const double* y)
{
if(num > 2)
{
init(num);
int i;
for(i = 0; i < num; i++)
{
add_point(*x++, *y++);
}
prepare();
}
m_last_idx = -1;
}
//------------------------------------------------------------------------
void bcspline::bsearch(int n, const double *x, double x0, int *i)
{
int j = n - 1;
int k;
for(*i = 0; (j - *i) > 1; )
{
if(x0 < x[k = (*i + j) >> 1]) j = k;
else *i = k;
}
}
//------------------------------------------------------------------------
double bcspline::interpolation(double x, int i) const
{
int j = i + 1;
double d = m_x[i] - m_x[j];
double h = x - m_x[j];
double r = m_x[i] - x;
double p = d * d / 6.0;
return (m_am[j] * r * r * r + m_am[i] * h * h * h) / 6.0 / d +
((m_y[j] - m_am[j] * p) * r + (m_y[i] - m_am[i] * p) * h) / d;
}
//------------------------------------------------------------------------
double bcspline::extrapolation_left(double x) const
{
double d = m_x[1] - m_x[0];
return (-d * m_am[1] / 6 + (m_y[1] - m_y[0]) / d) *
(x - m_x[0]) +
m_y[0];
}
//------------------------------------------------------------------------
double bcspline::extrapolation_right(double x) const
{
double d = m_x[m_num - 1] - m_x[m_num - 2];
return (d * m_am[m_num - 2] / 6 + (m_y[m_num - 1] - m_y[m_num - 2]) / d) *
(x - m_x[m_num - 1]) +
m_y[m_num - 1];
}
//------------------------------------------------------------------------
double bcspline::get(double x) const
{
if(m_num > 2)
{
int i;
// Extrapolation on the left
if(x < m_x[0]) return extrapolation_left(x);
// Extrapolation on the right
if(x >= m_x[m_num - 1]) return extrapolation_right(x);
// Interpolation
bsearch(m_num, m_x, x, &i);
return interpolation(x, i);
}
return 0.0;
}
//------------------------------------------------------------------------
double bcspline::get_stateful(double x) const
{
if(m_num > 2)
{
// Extrapolation on the left
if(x < m_x[0]) return extrapolation_left(x);
// Extrapolation on the right
if(x >= m_x[m_num - 1]) return extrapolation_right(x);
if(m_last_idx >= 0)
{
// Check if x is not in current range
if(x < m_x[m_last_idx] || x > m_x[m_last_idx + 1])
{
// Check if x between next points (most probably)
if(m_last_idx < m_num - 2 &&
x >= m_x[m_last_idx + 1] &&
x <= m_x[m_last_idx + 2])
{
++m_last_idx;
}
else
if(m_last_idx > 0 &&
x >= m_x[m_last_idx - 1] &&
x <= m_x[m_last_idx])
{
// x is between pevious points
--m_last_idx;
}
else
{
// Else perform full search
bsearch(m_num, m_x, x, &m_last_idx);
}
}
return interpolation(x, m_last_idx);
}
else
{
// Interpolation
bsearch(m_num, m_x, x, &m_last_idx);
return interpolation(x, m_last_idx);
}
}
return 0.0;
}
}

View File

@ -0,0 +1,81 @@
//----------------------------------------------------------------------------
// Anti-Grain Geometry (AGG) - Version 2.5
// A high quality rendering engine for C++
// Copyright (C) 2002-2006 Maxim Shemanarev
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://antigrain.com
//
// AGG is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// AGG is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with AGG; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
//----------------------------------------------------------------------------
#ifndef AGG_bcspline_INCLUDED
#define AGG_bcspline_INCLUDED
#include "agg_array.h"
namespace agg
{
//----------------------------------------------------------------bcspline
// A very simple class of Bi-cubic Spline interpolation.
// First call init(num, x[], y[]) where num - number of source points,
// x, y - arrays of X and Y values respectively. Here Y must be a function
// of X. It means that all the X-coordinates must be arranged in the ascending
// order.
// Then call get(x) that calculates a value Y for the respective X.
// The class supports extrapolation, i.e. you can call get(x) where x is
// outside the given with init() X-range. Extrapolation is a simple linear
// function.
//
// See Implementation agg_bcspline.cpp
//------------------------------------------------------------------------
class bcspline
{
public:
bcspline();
bcspline(int num);
bcspline(int num, const double* x, const double* y);
void init(int num);
void add_point(double x, double y);
void prepare();
void init(int num, const double* x, const double* y);
double get(double x) const;
double get_stateful(double x) const;
private:
bcspline(const bcspline&);
const bcspline& operator = (const bcspline&);
static void bsearch(int n, const double *x, double x0, int *i);
double extrapolation_left(double x) const;
double extrapolation_right(double x) const;
double interpolation(double x, int i) const;
int m_max;
int m_num;
double* m_x;
double* m_y;
pod_array<double> m_am;
mutable int m_last_idx;
};
}
#endif

View File

@ -0,0 +1,58 @@
//----------------------------------------------------------------------------
// Anti-Grain Geometry (AGG) - Version 2.5
// A high quality rendering engine for C++
// Copyright (C) 2002-2006 Maxim Shemanarev
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://antigrain.com
//
// AGG is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// AGG is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with AGG; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
//----------------------------------------------------------------------------
#ifndef AGG_conv_bcspline_INCLUDED
#define AGG_conv_bcspline_INCLUDED
#include "agg_basics.h"
#include "agg_vcgen_bcspline.h"
#include "agg_conv_adaptor_vcgen.h"
namespace agg
{
//---------------------------------------------------------conv_bcspline
template<class VertexSource>
struct conv_bcspline : public conv_adaptor_vcgen<VertexSource, vcgen_bcspline>
{
typedef conv_adaptor_vcgen<VertexSource, vcgen_bcspline> base_type;
conv_bcspline(VertexSource& vs) :
conv_adaptor_vcgen<VertexSource, vcgen_bcspline>(vs) {}
void interpolation_step(double v) { base_type::generator().interpolation_step(v); }
double interpolation_step() const { return base_type::generator().interpolation_step(); }
private:
conv_bcspline(const conv_bcspline<VertexSource>&);
const conv_bcspline<VertexSource>&
operator = (const conv_bcspline<VertexSource>&);
};
}
#endif

View File

@ -0,0 +1,203 @@
//----------------------------------------------------------------------------
// Anti-Grain Geometry (AGG) - Version 2.5
// A high quality rendering engine for C++
// Copyright (C) 2002-2006 Maxim Shemanarev
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://antigrain.com
//
// AGG is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// AGG is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with AGG; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
//----------------------------------------------------------------------------
#include "agg_vcgen_bcspline.h"
namespace agg
{
//------------------------------------------------------------------------
vcgen_bcspline::vcgen_bcspline() :
m_src_vertices(),
m_spline_x(),
m_spline_y(),
m_interpolation_step(1.0/50.0),
m_closed(0),
m_status(initial),
m_src_vertex(0)
{
}
//------------------------------------------------------------------------
void vcgen_bcspline::remove_all()
{
m_src_vertices.remove_all();
m_closed = 0;
m_status = initial;
m_src_vertex = 0;
}
//------------------------------------------------------------------------
void vcgen_bcspline::add_vertex(double x, double y, unsigned cmd)
{
m_status = initial;
if(is_move_to(cmd))
{
m_src_vertices.modify_last(point_d(x, y));
}
else
{
if(is_vertex(cmd))
{
m_src_vertices.add(point_d(x, y));
}
else
{
m_closed = get_close_flag(cmd);
}
}
}
//------------------------------------------------------------------------
void vcgen_bcspline::rewind(unsigned)
{
m_cur_abscissa = 0.0;
m_max_abscissa = 0.0;
m_src_vertex = 0;
if(m_status == initial && m_src_vertices.size() > 2)
{
if(m_closed)
{
m_spline_x.init(m_src_vertices.size() + 8);
m_spline_y.init(m_src_vertices.size() + 8);
m_spline_x.add_point(0.0, m_src_vertices.prev(m_src_vertices.size() - 3).x);
m_spline_y.add_point(0.0, m_src_vertices.prev(m_src_vertices.size() - 3).y);
m_spline_x.add_point(1.0, m_src_vertices[m_src_vertices.size() - 3].x);
m_spline_y.add_point(1.0, m_src_vertices[m_src_vertices.size() - 3].y);
m_spline_x.add_point(2.0, m_src_vertices[m_src_vertices.size() - 2].x);
m_spline_y.add_point(2.0, m_src_vertices[m_src_vertices.size() - 2].y);
m_spline_x.add_point(3.0, m_src_vertices[m_src_vertices.size() - 1].x);
m_spline_y.add_point(3.0, m_src_vertices[m_src_vertices.size() - 1].y);
}
else
{
m_spline_x.init(m_src_vertices.size());
m_spline_y.init(m_src_vertices.size());
}
unsigned i;
for(i = 0; i < m_src_vertices.size(); i++)
{
double x = m_closed ? i + 4 : i;
m_spline_x.add_point(x, m_src_vertices[i].x);
m_spline_y.add_point(x, m_src_vertices[i].y);
}
m_cur_abscissa = 0.0;
m_max_abscissa = m_src_vertices.size() - 1;
if(m_closed)
{
m_cur_abscissa = 4.0;
m_max_abscissa += 5.0;
m_spline_x.add_point(m_src_vertices.size() + 4, m_src_vertices[0].x);
m_spline_y.add_point(m_src_vertices.size() + 4, m_src_vertices[0].y);
m_spline_x.add_point(m_src_vertices.size() + 5, m_src_vertices[1].x);
m_spline_y.add_point(m_src_vertices.size() + 5, m_src_vertices[1].y);
m_spline_x.add_point(m_src_vertices.size() + 6, m_src_vertices[2].x);
m_spline_y.add_point(m_src_vertices.size() + 6, m_src_vertices[2].y);
m_spline_x.add_point(m_src_vertices.size() + 7, m_src_vertices.next(2).x);
m_spline_y.add_point(m_src_vertices.size() + 7, m_src_vertices.next(2).y);
}
m_spline_x.prepare();
m_spline_y.prepare();
}
m_status = ready;
}
//------------------------------------------------------------------------
unsigned vcgen_bcspline::vertex(double* x, double* y)
{
unsigned cmd = path_cmd_line_to;
while(!is_stop(cmd))
{
switch(m_status)
{
case initial:
rewind(0);
case ready:
if(m_src_vertices.size() < 2)
{
cmd = path_cmd_stop;
break;
}
if(m_src_vertices.size() == 2)
{
*x = m_src_vertices[m_src_vertex].x;
*y = m_src_vertices[m_src_vertex].y;
m_src_vertex++;
if(m_src_vertex == 1) return path_cmd_move_to;
if(m_src_vertex == 2) return path_cmd_line_to;
cmd = path_cmd_stop;
break;
}
cmd = path_cmd_move_to;
m_status = polygon;
m_src_vertex = 0;
case polygon:
if(m_cur_abscissa >= m_max_abscissa)
{
if(m_closed)
{
m_status = end_poly;
break;
}
else
{
*x = m_src_vertices[m_src_vertices.size() - 1].x;
*y = m_src_vertices[m_src_vertices.size() - 1].y;
m_status = end_poly;
return path_cmd_line_to;
}
}
*x = m_spline_x.get(m_cur_abscissa);
*y = m_spline_y.get(m_cur_abscissa);
m_src_vertex++;
m_cur_abscissa += m_interpolation_step;
return (m_src_vertex == 1) ? path_cmd_move_to : path_cmd_line_to;
case end_poly:
m_status = stop;
return path_cmd_end_poly | m_closed;
case stop:
return path_cmd_stop;
}
}
return cmd;
}
}

View File

@ -0,0 +1,83 @@
//----------------------------------------------------------------------------
// Anti-Grain Geometry (AGG) - Version 2.5
// A high quality rendering engine for C++
// Copyright (C) 2002-2006 Maxim Shemanarev
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://antigrain.com
//
// AGG is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// AGG is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with AGG; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
//----------------------------------------------------------------------------
#ifndef AGG_vcgen_bcspline_INCLUDED
#define AGG_vcgen_bcspline_INCLUDED
#include "agg_basics.h"
#include "agg_array.h"
#include "agg_bcspline.h"
namespace agg
{
//==========================================================vcgen_bcspline
class vcgen_bcspline
{
enum status_e
{
initial,
ready,
polygon,
end_poly,
stop
};
public:
typedef pod_bvector<point_d, 6> vertex_storage;
vcgen_bcspline();
void interpolation_step(double v) { m_interpolation_step = v; }
double interpolation_step() const { return m_interpolation_step; }
// Vertex Generator Interface
void remove_all();
void add_vertex(double x, double y, unsigned cmd);
// Vertex Source Interface
void rewind(unsigned path_id);
unsigned vertex(double* x, double* y);
private:
vcgen_bcspline(const vcgen_bcspline&);
const vcgen_bcspline& operator = (const vcgen_bcspline&);
vertex_storage m_src_vertices;
bcspline m_spline_x;
bcspline m_spline_y;
double m_interpolation_step;
unsigned m_closed;
status_e m_status;
unsigned m_src_vertex;
double m_cur_abscissa;
double m_max_abscissa;
};
}
#endif

20
assdraw/src/agghelper.hpp Normal file
View File

@ -0,0 +1,20 @@
#pragma once
#include "agg_path_storage.h"
class agghelper
{
public:
static agg::path_storage RectanglePath(double left, double right, double top, double bottom)
{
agg::path_storage path;
path.move_to(left,top);
path.line_to(right,top);
path.line_to(right,bottom);
path.line_to(left,bottom);
path.line_to(left,top);
return path;
}
};

768
assdraw/src/assdraw.cpp Normal file
View File

@ -0,0 +1,768 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////////
// Name: assdraw.cpp
// Purpose: ASSDraw main source file
// Author: ai-chan
// Created: 08/26/06
// Copyright: (c) ai-chan
// Licence: 3-clause BSD
///////////////////////////////////////////////////////////////////////////////
#include "assdraw.hpp"
#include "enums.hpp"
#include "include_once.hpp"
#include <wx/clipbrd.h>
#include <wx/wfstream.h>
#include <wx/filename.h>
#include <wx/dynlib.h>
#include <wx/stdpaths.h>
//DEFINE_EVENT_TYPE(wxEVT_SETTINGS_CHANGED)
// initialize wxWidget to accept our App class
IMPLEMENT_APP(ASSDrawApp)
BEGIN_EVENT_TABLE(ASSDrawFrame, wxFrame)
EVT_TOOL(TB_CLEAR, ASSDrawFrame::OnSelect_Clear)
EVT_TOOL(TB_PREVIEW, ASSDrawFrame::OnSelect_Preview)
//EVT_TOOL(TB_EDITSRC, ASSDrawFrame::OnSelect_EditSrc)
EVT_TOOL(TB_TRANSFORM, ASSDrawFrame::OnSelect_Transform)
EVT_TOOL_RANGE(MODE_ARR, MODE_DEL, ASSDrawFrame::OnChoose_Mode)
EVT_TOOL_RANGE(DRAG_DWG, DRAG_BOTH, ASSDrawFrame::OnChoose_DragMode)
EVT_TOOL_RCLICKED(wxID_ANY, ASSDrawFrame::OnToolRClick)
EVT_COMMAND(wxID_ANY, wxEVT_SETTINGS_CHANGED, ASSDrawFrame::OnSettingsChanged)
EVT_MENU_RANGE(MENU_TB_ALL, MENU_TB_BGIMG, ASSDrawFrame::OnChoose_TBarRClickMenu)
#if wxUSE_MENUS
EVT_MENU(MENU_CLEAR, ASSDrawFrame::OnSelect_Clear)
EVT_MENU(MENU_PREVIEW, ASSDrawFrame::OnSelect_Preview)
EVT_MENU(MENU_TRANSFORM, ASSDrawFrame::OnSelect_Transform)
EVT_MENU(MENU_LIBRARY, ASSDrawFrame::OnSelect_Library)
EVT_MENU(MENU_SETTINGS, ASSDrawFrame::OnSelect_Settings)
EVT_MENU(MENU_RESETPERSPECTIVE, ASSDrawFrame::OnSelect_ResetPerspective)
EVT_MENU(MENU_HELP, ASSDrawFrame::OnSelect_Help)
EVT_MENU(wxID_ABOUT, ASSDrawFrame::OnSelect_About)
EVT_MENU(MENU_UNDO, ASSDrawFrame::OnSelect_Undo)
EVT_MENU(MENU_REDO, ASSDrawFrame::OnSelect_Redo)
EVT_MENU(MENU_PASTE, ASSDrawFrame::OnSelect_Paste)
EVT_MENU(MENU_BGIMG_REMOVE, ASSDrawFrame::OnSelect_RemoveBG)
EVT_MENU(MENU_BGIMG_ALPHA, ASSDrawFrame::OnSelect_AlphaBG)
EVT_MENU_RANGE(MODE_ARR, MODE_NUT_BILINEAR, ASSDrawFrame::OnChoose_Mode)
EVT_MENU_RANGE(DRAG_DWG, DRAG_BOTH, ASSDrawFrame::OnChoose_DragMode)
EVT_MENU_RANGE(MENU_REPOS_TOPLEFT, MENU_REPOS_BOTRIGHT, ASSDrawFrame::OnChoose_Recenter)
EVT_MENU_RANGE(MENU_REPOS_BGTOPLEFT, MENU_REPOS_BGBOTRIGHT, ASSDrawFrame::OnChoose_RecenterToBG)
#endif //wxUSE_MENUS
EVT_CLOSE(ASSDrawFrame::OnClose)
END_EVENT_TABLE()
// ----------------------------------------------------------------------------
// the application class: ASSDrawApp
// ----------------------------------------------------------------------------
// 'Main program' equivalent: the program execution "starts" here
bool ASSDrawApp::OnInit()
{
// create the main application window
ASSDrawFrame * assdrawframe = new ASSDrawFrame( this, TITLE, wxDefaultPosition, wxSize(640, 480) );
SetTopWindow(assdrawframe);
return TRUE;
}
// ----------------------------------------------------------------------------
// main frame: ASSDrawFrame
// ----------------------------------------------------------------------------
// constructor
ASSDrawFrame::ASSDrawFrame( wxApp *app, const wxString& title, const wxPoint& pos, const wxSize& size, long style)
: wxFrame(NULL, wxID_ANY, title, pos, size, style)
{
m_app = app;
m_mgr.SetManagedWindow(this);
m_mgr.SetFlags(m_mgr.GetFlags() | wxAUI_MGR_ALLOW_ACTIVE_PANE);
// set the frame icon
SetIcon(wxICON(appico));
// Create status bar for the frame
#if wxUSE_STATUSBAR
CreateStatusBar(3);
int statwidths[] = { 64, -1, 64 };
GetStatusBar()->SetStatusWidths(3, statwidths);
SetStatusBarPane(1);
#endif // wxUSE_STATUSBAR
InitializeDefaultSettings();
// load config
configfile = wxFileName(::wxGetCwd(), _T("ASSDraw3.cfg")).GetFullPath();
if (!::wxFileExists(configfile))
configfile = wxFileName(wxStandardPaths::Get().GetUserConfigDir(), _T("ASSDraw3.cfg")).GetFullPath();
bool firsttime = !::wxFileExists(configfile);
if (firsttime) wxFileOutputStream(configfile).Close();
wxFileInputStream cfgf(configfile);
config = new wxFileConfig(cfgf);
// nullify transformdlg
transformdlg = NULL;
Maximize(true);
Show(true); // to get the right client size, must call Show() first
// config
LoadSettings();
// THE CANVAS
m_canvas = new ASSDrawCanvas( this , this );
// shapes library
shapelib = new ASSDrawShapeLibrary(this, this);
// source text ctrl
srctxtctrl = new ASSDrawSrcTxtCtrl(this, this);
// settings
/*
settingsdlg = NULL;
wxString settingsdllfile = wxFileName(::wxGetCwd(), "settings.dll").GetFullPath();
if (::wxFileExists(settingsdllfile))
{
wxDynamicLibrary settingsdll(settingsdllfile);
wxString symbol("CreateASSDrawSettingsDialogInstance");
if (settingsdll.IsLoaded() && settingsdll.HasSymbol(symbol))
{
typedef ASSDrawSettingsDialog* (*FuncType)(wxWindow*,ASSDrawFrame*,int);
FuncType func = (FuncType) settingsdll.GetSymbol(symbol);
//wxDYNLIB_FUNCTION(ASSDrawSettingsDialog, CreateASSDrawSettingsDialogInstance, settingsdll)
//ASSDrawSettingsDialog* test = func(NULL,this,971231);
//test->Reparent(this);
//test->Init();
//SetTitle(settingsdllfile);
//settingsdlg = func(NULL,this, 809131);
//settingsdlg->Init();
//m_mgr.AddPane(settingsdlg, wxAuiPaneInfo().Name(wxT("settings")).Caption(wxT("Settings")).Right().Layer(3).Position(0).CloseButton(true).BestSize(wxSize(240, 480)).MinSize(wxSize(200, 200)));
}
}
*/
settingsdlg = new ASSDrawSettingsDialog(this, this);
settingsdlg->Init();
SetMenus();
SetToolBars();
SetPanes();
// config
config->SetPath(_T("info"));
wxString version;
config->Read("version", &version);
config->SetPath("..");
default_perspective = m_mgr.SavePerspective(); // back up default perspective
config->SetPath("perspective");
wxString perspective;
if (config->Read("perspective", &perspective) && version == VERSION) m_mgr.LoadPerspective(perspective, false);
config->SetPath("..");
config->SetPath("library");
int n = 0;
config->Read("n", &n);
for (int i = 0; i < n; i++)
{
wxString libcmds;
config->Read(wxString::Format("%d",i), &libcmds);
shapelib->AddShapePreview(libcmds);
}
config->SetPath("..");
m_mgr.Update();
m_canvas->SetFocus();
m_canvas->Show();
wxSize clientsize = m_canvas->GetClientSize();
m_canvas->ChangeZoomLevelTo(DEFAULT_SCALE, wxPoint(clientsize.x / 2, clientsize.y / 2));
m_canvas->MoveCanvasOriginTo(clientsize.x / 2, clientsize.y / 2);
UpdateASSCommandStringToSrcTxtCtrl(m_canvas->GenerateASS());
UpdateFrameUI();
ApplySettings();
#ifdef BETAVERSION
wxDateTime expire(15, wxDateTime::Dec, 2007, 0, 0, 0);
wxDateTime now = wxDateTime::Now();
if (now.IsLaterThan(expire))
{
wxMessageDialog expired(this, "Thank you for trying ASSDraw3. This beta version has expired. Please visit http://malakith.net/aegisub/index.php?topic=912.0 to get the latest release. Visit now?", wxT("Beta version"), wxYES_NO | wxICON_INFORMATION);
if (expired.ShowModal() == wxID_YES)
::wxLaunchDefaultBrowser(wxString("http://malakith.net/aegisub/index.php?topic=912.0"));
Close();
}
SetTitle(wxString::Format("%s beta %d (expires %s)", TITLE, BETAVERSION, expire.FormatDate().c_str()));
#endif
if (firsttime)
_About();
else if (!behaviors.nosplashscreen)
_About(3);
helpcontroller.SetParentWindow(this);
helpcontroller.Initialize(wxFileName(::wxGetCwd(), "ASSDraw3.chm").GetFullPath());
}
void ASSDrawFrame::SetToolBars()
{
drawtbar = new wxToolBar(this, wxID_ANY, __DPDS__ , wxTB_FLAT | wxTB_TEXT | wxTB_NODIVIDER | wxTB_HORIZONTAL);
drawtbar->AddTool(TB_CLEAR, _T("Clear"), wxBITMAP(new_), wxNullBitmap, wxITEM_NORMAL, "", TIPS_CLEAR);
//tbar->AddTool(TB_EDITSRC, _T("Source"), wxBITMAP(src_), wxNullBitmap, wxITEM_NORMAL, "", TIPS_EDITSRC);
drawtbar->AddCheckTool(TB_PREVIEW, _T("Preview"), wxBITMAP(preview_), wxNullBitmap, "", TIPS_PREVIEW);
//drawtbar->AddTool(TB_TRANSFORM, _T("Transform"), wxBITMAP(rot_), wxNullBitmap, wxITEM_NORMAL, "", TIPS_TRANSFORM);
zoomslider = new wxSlider(drawtbar, TB_ZOOMSLIDER, 1000, 100, 5000, __DPDS__ );
//zoomslider->SetSize(280, zoomslider->GetSize().y);
zoomslider->Connect(wxEVT_SCROLL_LINEUP, wxScrollEventHandler(ASSDrawFrame::OnZoomSliderChanged), NULL, this);
zoomslider->Connect(wxEVT_SCROLL_LINEDOWN, wxScrollEventHandler(ASSDrawFrame::OnZoomSliderChanged), NULL, this);
zoomslider->Connect(wxEVT_SCROLL_PAGEUP, wxScrollEventHandler(ASSDrawFrame::OnZoomSliderChanged), NULL, this);
zoomslider->Connect(wxEVT_SCROLL_PAGEDOWN, wxScrollEventHandler(ASSDrawFrame::OnZoomSliderChanged), NULL, this);
zoomslider->Connect(wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler(ASSDrawFrame::OnZoomSliderChanged), NULL, this);
zoomslider->Connect(wxEVT_SCROLL_CHANGED, wxScrollEventHandler(ASSDrawFrame::OnZoomSliderChanged), NULL, this);
drawtbar->AddControl(zoomslider);
drawtbar->Realize();
m_mgr.AddPane(drawtbar, wxAuiPaneInfo().Name(wxT("drawtbar")).Caption(TBNAME_DRAW).
ToolbarPane().Top().Position(0).Dockable(true).LeftDockable(false).RightDockable(false));
modetbar = new wxToolBar(this, wxID_ANY, __DPDS__ , wxTB_FLAT | wxTB_TEXT | wxTB_NODIVIDER | wxTB_HORIZONTAL);
modetbar->AddRadioTool(MODE_ARR, _T("Drag"), wxBITMAP(arr_), wxNullBitmap, "", TIPS_ARR);
modetbar->AddRadioTool(MODE_M, _T("Move"), wxBITMAP(m_), wxNullBitmap, "", TIPS_M);
//modetbar->AddRadioTool(MODE_N, _T("Move*"), wxBITMAP(n_), wxNullBitmap, "", TIPS_N);
modetbar->AddRadioTool(MODE_L, _T("Line"), wxBITMAP(l_), wxNullBitmap, "", TIPS_L);
modetbar->AddRadioTool(MODE_B, _T("Bezier"), wxBITMAP(b_), wxNullBitmap, "", TIPS_B);
//modetbar->AddRadioTool(MODE_S, _T("Spline"), wxBITMAP(s_), wxNullBitmap, "", TIPS_S);
//modetbar->AddRadioTool(MODE_P, _T("Extend"), wxBITMAP(p_), wxNullBitmap, "", TIPS_P);
//modetbar->AddRadioTool(MODE_C, _T("Close"), wxBITMAP(c_), wxNullBitmap, "", TIPS_C);
modetbar->AddRadioTool(MODE_DEL, _T("Delete"), wxBITMAP(del_), wxNullBitmap, "", TIPS_DEL);
modetbar->AddRadioTool(MODE_SCALEROTATE, _T("Scale/Rotate"), wxBITMAP(sc_rot_), wxNullBitmap, "", TIPS_SCALEROTATE);
modetbar->AddRadioTool(MODE_NUT_BILINEAR, _T("Bilinear"), wxBITMAP(nut_), wxNullBitmap, "", TIPS_NUTB);
//modetbar->AddRadioTool(MODE_NUT_PERSPECTIVE, _T("NUT:P"), wxBITMAP(arr_), wxNullBitmap, "", "");
modetbar->Realize();
m_mgr.AddPane(modetbar, wxAuiPaneInfo().Name(wxT("modetbar")).Caption(TBNAME_MODE).
ToolbarPane().Top().Position(1).Dockable(true).LeftDockable(false).RightDockable(false));
bgimgtbar = new wxToolBar(this, wxID_ANY, __DPDS__ , wxTB_FLAT | wxTB_TEXT | wxTB_NODIVIDER | wxTB_HORIZONTAL);
bgimgtbar->SetToolBitmapSize(wxSize(24,15));
bgimgtbar->AddCheckTool(DRAG_DWG, _T("Pan drawing"), wxBITMAP(pan_shp), wxNullBitmap, "", TIPS_DWG);
bgimgtbar->AddCheckTool(DRAG_BGIMG, _T("Pan background"), wxBITMAP(pan_bg), wxNullBitmap, "", TIPS_BGIMG);
//bgimgtbar->AddRadioTool(DRAG_BOTH, _T("Pan both"), wxBITMAP(pan_both), wxNullBitmap, "", TIPS_BOTH);
bgimgtbar->Realize();
m_mgr.AddPane(bgimgtbar, wxAuiPaneInfo().Name(wxT("bgimgtbar")).Caption(TBNAME_BGIMG).
ToolbarPane().Top().Position(2).Dockable(true).LeftDockable(false).RightDockable(false));
}
void ASSDrawFrame::SetMenus()
{
#if wxUSE_MENUS
drawMenu = new wxMenu;
drawMenu->Append(MENU_CLEAR, _T("&Clear\tCtrl+N"), TIPS_CLEAR);
//drawMenu->Append(MENU_EDITSRC, _T("&Source"), TIPS_EDITSRC);
drawMenu->Append(MENU_PREVIEW, _T("&Preview\tCtrl+P"), TIPS_PREVIEW, wxITEM_CHECK);
drawMenu->Append(MENU_TRANSFORM, _T("&Transform"), TIPS_TRANSFORM);
drawMenu->Append(MENU_PASTE, _T("&Paste\tCtrl+V"), TIPS_PASTE);
drawMenu->AppendSeparator();
drawMenu->Append(MENU_UNDO, _T("&Undo\tCtrl+Z"), TIPS_UNDO);
drawMenu->Append(MENU_REDO, _T("&Redo\tCtrl+Y"), TIPS_REDO);
drawMenu->Enable(MENU_UNDO, false);
drawMenu->Enable(MENU_REDO, false);
modeMenu = new wxMenu;
modeMenu->Append(MODE_ARR, _T("D&rag\tF1"), TIPS_ARR, wxITEM_RADIO);
modeMenu->Append(MODE_M, _T("Draw &M\tF2"), TIPS_M, wxITEM_RADIO);
modeMenu->Append(MODE_L, _T("Draw &L\tF3"), TIPS_L, wxITEM_RADIO);
modeMenu->Append(MODE_B, _T("Draw &B\tF4"), TIPS_B, wxITEM_RADIO);
modeMenu->Append(MODE_DEL, _T("&Delete\tF5"), TIPS_DEL, wxITEM_RADIO);
modeMenu->Append(MODE_SCALEROTATE, _T("&Scale/Rotate\tF6"), TIPS_NUTB, wxITEM_RADIO);
modeMenu->Append(MODE_NUT_BILINEAR, _T("&Bilinear transformation\tF7"), TIPS_SCALEROTATE, wxITEM_RADIO);
bgimgMenu = new wxMenu;
bgimgMenu->Append(DRAG_DWG, _T("Pan/Zoom &Drawing\tShift+F1"), TIPS_DWG, wxITEM_CHECK);
bgimgMenu->Append(DRAG_BGIMG, _T("Pan/Zoom Back&ground\tShift+F2"), TIPS_BGIMG, wxITEM_CHECK);
bgimgMenu->AppendSeparator();
bgimgMenu->Append(MENU_BGIMG_ALPHA, _T("Set background image opacity"), "");
wxMenu* reposbgMenu = new wxMenu;
reposbgMenu->Append( MENU_REPOS_BGTOPLEFT, "Top left\tCtrl+Shift+7" );
reposbgMenu->Append( MENU_REPOS_BGTOPRIGHT, "Top right\tCtrl+Shift+9" );
reposbgMenu->Append( MENU_REPOS_BGCENTER, "&Center\tCtrl+Shift+5" );
reposbgMenu->Append( MENU_REPOS_BGBOTLEFT, "Bottom left\tCtrl+Shift+1" );
reposbgMenu->Append( MENU_REPOS_BGBOTRIGHT, "Bottom right\tCtrl+Shift+3" );
bgimgMenu->Append(MENU_BGIMG_RECENTER, _T("Reposition [&0, 0]"), reposbgMenu);
bgimgMenu->Append(MENU_BGIMG_REMOVE, _T("Remove background\tShift+Del"), "");
wxMenu* reposMenu = new wxMenu;
reposMenu->Append( MENU_REPOS_TOPLEFT, "Top left\tCtrl+7" );
reposMenu->Append( MENU_REPOS_TOPRIGHT, "Top right\tCtrl+9" );
reposMenu->Append( MENU_REPOS_CENTER, "&Center\tCtrl+5" );
reposMenu->Append( MENU_REPOS_BOTLEFT, "Bottom left\tCtrl+1" );
reposMenu->Append( MENU_REPOS_BOTRIGHT, "Bottom right\tCtrl+3" );
tbarMenu = new wxMenu;
tbarMenu->AppendCheckItem(MENU_TB_DRAW, TBNAME_DRAW);
tbarMenu->AppendCheckItem(MENU_TB_MODE, TBNAME_MODE);
tbarMenu->AppendCheckItem(MENU_TB_BGIMG, TBNAME_BGIMG);
tbarMenu->AppendSeparator();
tbarMenu->Append(MENU_TB_ALL, "Show all");
tbarMenu->Append(MENU_TB_NONE, "Hide all");
tbarMenu->Append(MENU_TB_DOCK, "Dock all");
tbarMenu->Append(MENU_TB_UNDOCK, "Undock all");
viewMenu = new wxMenu;
viewMenu->Append(MENU_LIBRARY, _T("&Library"), TIPS_LIBRARY, wxITEM_CHECK);
if (settingsdlg)
viewMenu->Append(MENU_SETTINGS, _T("&Settings"), "", wxITEM_CHECK);
viewMenu->Append(MENU_TBAR, _T("&Toolbars"), tbarMenu);
viewMenu->Append(MENU_RECENTER, _T("Reposition [&0, 0]"), reposMenu);
viewMenu->AppendSeparator();
viewMenu->Append(MENU_RESETPERSPECTIVE, _T("&Reset workspace"));
wxMenu* helpMenu = new wxMenu;
helpMenu->Append(MENU_HELP, _T("&Manual"));
helpMenu->Append(wxID_ABOUT, _T("&About"));
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(drawMenu, _T("&Canvas"));
menuBar->Append(modeMenu, _T("&Mode"));
menuBar->Append(bgimgMenu, _T("&Background"));
menuBar->Append(viewMenu, _T("&Workspace"));
menuBar->Append(helpMenu, _T("&Help"));
SetMenuBar(menuBar);
#endif // wxUSE_MENUS
}
void ASSDrawFrame::SetPanes()
{
m_mgr.AddPane(shapelib, wxAuiPaneInfo().Name(wxT("library")).Caption(wxT("Shapes Library")).
Right().Layer(2).Position(0).CloseButton(true).BestSize(wxSize(120, 480)).MinSize(wxSize(100, 200)));
m_mgr.AddPane(m_canvas, wxAuiPaneInfo().Name(wxT("canvas")).CenterPane());
m_mgr.AddPane(srctxtctrl, wxAuiPaneInfo().Name(wxT("commands")).Caption(wxT("Drawing commands")).
Bottom().Layer(1).CloseButton(false).BestSize(wxSize(320, 48)));
if (settingsdlg)
m_mgr.AddPane(settingsdlg, wxAuiPaneInfo().Name(wxT("settings")).Caption(wxT("Settings")).
Right().Layer(3).Position(0).CloseButton(true).BestSize(wxSize(240, 480)).MinSize(wxSize(200, 200)).Show(false));
}
ASSDrawFrame::~ASSDrawFrame()
{
config->SetPath("info");
config->Write("assdraw3.exe", wxStandardPaths::Get().GetExecutablePath());
config->Write("version", VERSION);
config->SetPath("..");
SaveSettings();
config->SetPath("perspective");
config->Write("perspective", m_mgr.SavePerspective());
config->SetPath("..");
config->DeleteGroup("library");
config->SetPath("library");
typedef std::vector< ASSDrawShapePreview *> PrevVec;
PrevVec shapes = shapelib->GetShapePreviews();
int n = shapes.size();
config->Write("n", n);
for (int i = 0; i < n; i++)
config->Write(wxString::Format("%d",i), shapes[i]->GenerateASS());
config->SetPath("..");
wxFileOutputStream cfgf(configfile);
config->Save(cfgf);
delete config;
if (settingsdlg) settingsdlg->Destroy(); // we need this since wxPropertyGrid must be Clear()ed before deleting
m_mgr.UnInit();
}
void ASSDrawFrame::_Clear()
{
wxMessageDialog msgb(this, _T("Clear the canvas and create a new drawing?"),
_T("Confirmation"), wxOK | wxCANCEL | wxICON_QUESTION );
if (msgb.ShowModal() == wxID_OK)
{
m_canvas->RefreshUndocmds();
m_canvas->AddUndo("Clear canvas");
m_canvas->ResetEngine(true);
wxSize siz = m_canvas->GetClientSize();
m_canvas->ChangeZoomLevelTo(DEFAULT_SCALE, wxPoint(siz.x / 2, siz.y / 2));
m_canvas->MoveCanvasOriginTo(siz.x / 2, siz.y / 2);
UpdateUndoRedoMenu();
m_canvas->RefreshDisplay();
}
}
void ASSDrawFrame::_Preview()
{
m_canvas->SetPreviewMode( !m_canvas->IsPreviewMode() );
UpdateFrameUI();
m_canvas->RefreshDisplay();
}
void ASSDrawFrame::_ToggleLibrary()
{
m_mgr.GetPane(shapelib).Show(!m_mgr.GetPane(shapelib).IsShown());
m_mgr.Update();
UpdateFrameUI();
}
void ASSDrawFrame::_ToggleSettings()
{
if (settingsdlg == NULL) return;
m_mgr.GetPane(settingsdlg).Show(!m_mgr.GetPane(settingsdlg).IsShown());
m_mgr.Update();
UpdateFrameUI();
}
void ASSDrawFrame::_ResetPerspective()
{
m_mgr.LoadPerspective(default_perspective, false);
UpdateFrameUI();
m_mgr.Update();
DRAGMODE bck = m_canvas->GetDragMode();
if (m_canvas->HasBackgroundImage()) m_canvas->SetDragMode(DRAGMODE(true, true));
wxSize clientsize = m_canvas->GetClientSize();
m_canvas->ChangeZoomLevelTo(DEFAULT_SCALE, wxPoint(clientsize.x / 2, clientsize.y / 2));
m_canvas->MoveCanvasOriginTo(clientsize.x / 2, clientsize.y / 2);
m_canvas->SetDragMode(bck);
UpdateFrameUI();
}
void ASSDrawFrame::_Transform()
{
if (transformdlg == NULL)
transformdlg = new ASSDrawTransformDlg( this );
if (transformdlg->ShowModal() == wxID_OK)
{
m_canvas->Transform(
transformdlg->xformvals.f1,
transformdlg->xformvals.f2,
transformdlg->xformvals.f3,
transformdlg->xformvals.f4,
transformdlg->xformvals.f5,
transformdlg->xformvals.f6,
transformdlg->xformvals.f7,
transformdlg->xformvals.f8 );
m_canvas->AddUndo("Transform");
m_canvas->RefreshDisplay();
UpdateUndoRedoMenu();
}
}
void ASSDrawFrame::_Paste()
{
if (wxTheClipboard->Open())
{
if (wxTheClipboard->IsSupported( wxDF_BITMAP ))
{
wxBitmapDataObject data;
wxTheClipboard->GetData( data );
m_canvas->SetBackgroundImage( data.GetBitmap().ConvertToImage() );
//m_canvas->AskUserForBackgroundAlpha();
}
else if (wxTheClipboard->IsSupported( wxDF_TEXT ))
{
wxTextDataObject data;
wxTheClipboard->GetData( data );
UpdateASSCommandStringToSrcTxtCtrl( data.GetText() );
}
wxTheClipboard->Close();
}
}
void ASSDrawFrame::OnChoose_Recenter(wxCommandEvent& event)
{
int x = 0, y = 0;
wxSize f = m_canvas->GetClientSize();
switch (event.GetId())
{
case MENU_REPOS_TOPLEFT: x = 0, y = 0; break;
case MENU_REPOS_TOPRIGHT: x = f.x, y = 0; break;
case MENU_REPOS_CENTER: x = f.x / 2, y = f.y / 2; break;
case MENU_REPOS_BOTLEFT: x = 0, y = f.y; break;
case MENU_REPOS_BOTRIGHT: x = f.x, y = f.y; break;
}
m_canvas->MoveCanvasOriginTo(x, y);
m_canvas->RefreshDisplay();
}
void ASSDrawFrame::OnChoose_RecenterToBG(wxCommandEvent& event)
{
unsigned w, h;
wxRealPoint disp;
double scale;
if (m_canvas->GetBackgroundInfo(w, h, disp, scale))
{
int x = 0, y = 0;
int lx = (int)disp.x, ty = (int)disp.y;
int rx = lx + (int)(w * scale);
int by = ty + (int)(h * scale);
switch (event.GetId())
{
case MENU_REPOS_BGTOPLEFT: x = lx, y = ty; break;
case MENU_REPOS_BGTOPRIGHT: x = rx, y = ty; break;
case MENU_REPOS_BGCENTER: x = (rx + lx) / 2, y = (by + ty) / 2; break;
case MENU_REPOS_BGBOTLEFT: x = lx, y = by; break;
case MENU_REPOS_BGBOTRIGHT: x = rx, y = by; break;
}
m_canvas->MoveCanvasDrawing(x - m_canvas->GetOriginX(), y - m_canvas->GetOriginY());
m_canvas->RefreshDisplay();
}
}
void ASSDrawFrame::_Help()
{
helpcontroller.DisplayContents();
}
void ASSDrawFrame::_About(unsigned timeout)
{
ASSDrawAboutDlg *aboutdlg = new ASSDrawAboutDlg( this, timeout );
aboutdlg->ShowModal();
aboutdlg->Destroy();
}
void ASSDrawFrame::OnChoose_Mode(wxCommandEvent& event)
{
m_canvas->SetDrawMode( (MODE) event.GetId() );
UpdateFrameUI();
}
void ASSDrawFrame::OnChoose_DragMode(wxCommandEvent& event)
{
DRAGMODE dm = m_canvas->GetDragMode();
switch (event.GetId())
{
case DRAG_DWG: dm.drawing = !dm.drawing; break;
case DRAG_BGIMG: dm.bgimg = !dm.bgimg; break;
}
m_canvas->SetDragMode( dm );
UpdateFrameUI();
}
void ASSDrawFrame::OnZoomSliderChanged(wxScrollEvent &event)
{
double zoom = (double) event.GetPosition() / 100.0;
m_canvas->ChangeZoomLevelTo(zoom, wxPoint((int) m_canvas->GetOriginX(), (int) m_canvas->GetOriginY()));
}
void ASSDrawFrame::OnToolRClick(wxCommandEvent& event)
{
int id = event.GetId();
if (drawtbar->FindById(id) != NULL
|| modetbar->FindById(id) != NULL
|| bgimgtbar->FindById(id) != NULL)
{
PopupMenu(tbarMenu);
}
}
void ASSDrawFrame::OnChoose_TBarRClickMenu(wxCommandEvent& event)
{
int id = event.GetId();
wxToolBar* tbar[3] = { drawtbar, modetbar, bgimgtbar };
bool tb[3] = { false, false, false };
bool show[2] = { false, true };
bool dock[2] = { false, true };
switch (id)
{
case MENU_TB_ALL:
tb[0] = true, tb[1] = true, tb[2] = true;
show[0] = true, show[1] = true;
break;
case MENU_TB_NONE:
tb[0] = true, tb[1] = true, tb[2] = true;
show[0] = true, show[1] = false;
break;
case MENU_TB_DOCK:
tb[0] = true, tb[1] = true, tb[2] = true;
dock[0] = true, dock[1] = true;
break;
case MENU_TB_UNDOCK:
tb[0] = true, tb[1] = true, tb[2] = true;
dock[0] = true, dock[1] = false;
break;
case MENU_TB_DRAW:
tb[0] = true;
show[0] = true, show[1] = !m_mgr.GetPane(tbar[0]).IsShown();
break;
case MENU_TB_MODE:
tb[1] = true;
show[0] = true, show[1] = !m_mgr.GetPane(tbar[1]).IsShown();
break;
case MENU_TB_BGIMG:
tb[2] = true;
show[0] = true, show[1] = !m_mgr.GetPane(tbar[2]).IsShown();
break;
}
for (int i = 0; i < 3; i++)
{
if (tb[i])
{
if (show[0])
m_mgr.GetPane(tbar[i]).Show(show[1]);
if (dock[0])
if (dock[1])
m_mgr.GetPane(tbar[i]).Dock();
else
m_mgr.GetPane(tbar[i]).Float();
}
}
m_mgr.Update();
UpdateFrameUI();
}
void ASSDrawFrame::UpdateASSCommandStringFromSrcTxtCtrl(wxString cmds)
{
m_canvas->ParseASS(cmds, true);
m_canvas->RefreshDisplay();
}
void ASSDrawFrame::UpdateASSCommandStringToSrcTxtCtrl(wxString cmd)
{
if (behaviors.capitalizecmds)
cmd.UpperCase();
else
cmd.LowerCase();
srctxtctrl->ChangeValue(cmd);
//srctxtctrl->AppendText(cmd);
}
void ASSDrawFrame::UndoOrRedo(bool isundo)
{
if (isundo)
m_canvas->Undo();
else
m_canvas->Redo();
UpdateUndoRedoMenu();
UpdateFrameUI();
}
void ASSDrawFrame::UpdateUndoRedoMenu()
{
wxString nextUndo = m_canvas->GetTopUndo();
if (nextUndo.IsSameAs(""))
{
drawMenu->SetLabel(MENU_UNDO, "Undo\tCtrl+Z");
drawMenu->Enable(MENU_UNDO, false);
}
else
{
drawMenu->SetLabel(MENU_UNDO, wxString::Format("Undo: %s\tCtrl+Z", nextUndo.c_str()));
drawMenu->Enable(MENU_UNDO, true);
}
wxString nextRedo = m_canvas->GetTopRedo();
if (nextRedo.IsSameAs(""))
{
drawMenu->SetLabel(MENU_REDO, "Redo\tCtrl+Y");
drawMenu->Enable(MENU_REDO, false);
}
else
{
drawMenu->SetLabel(MENU_REDO, wxString::Format("Redo: %s\tCtrl+Y", nextRedo.c_str()));
drawMenu->Enable(MENU_REDO, true);
}
}
void ASSDrawFrame::UpdateFrameUI(unsigned level)
{
bool hasbg = m_canvas->HasBackgroundImage();
int zoom = (int) round(m_canvas->GetScale() * 100.0);
switch (level)
{
case 0: // all
drawtbar->ToggleTool(TB_PREVIEW, m_canvas->IsPreviewMode());
modetbar->ToggleTool(m_canvas->GetDrawMode(), true);
#if wxUSE_MENUS
drawMenu->Check(MENU_PREVIEW, m_canvas->IsPreviewMode());
modeMenu->Check(m_canvas->GetDrawMode(), true);
#endif
case 2: // bgimg & toolbars
//bgimgtbar->ToggleTool(m_canvas->GetDragMode(), true);
bgimgtbar->ToggleTool(DRAG_DWG, m_canvas->GetDragMode().drawing);
bgimgtbar->ToggleTool(DRAG_BGIMG, m_canvas->GetDragMode().bgimg);
bgimgtbar->EnableTool(DRAG_BGIMG, hasbg);
//m_mgr.GetPane(bgimgtbar).Show(hasbg);
m_mgr.Update();
#if wxUSE_MENUS
viewMenu->Check(MENU_LIBRARY, m_mgr.GetPane(shapelib).IsShown());
if (settingsdlg)
viewMenu->Check(MENU_SETTINGS, m_mgr.GetPane(settingsdlg).IsShown());
//bgimgMenu->Check(m_canvas->GetDragMode(), true);
bgimgMenu->Check(DRAG_DWG, m_canvas->GetDragMode().drawing);
bgimgMenu->Check(DRAG_BGIMG, m_canvas->GetDragMode().bgimg);
bgimgMenu->Enable(DRAG_BGIMG, hasbg);
bgimgMenu->Enable(DRAG_BOTH, hasbg);
bgimgMenu->Enable(MENU_BGIMG_ALPHA, hasbg);
bgimgMenu->Enable(MENU_BGIMG_RECENTER, hasbg);
bgimgMenu->Enable(MENU_BGIMG_REMOVE, hasbg);
tbarMenu->Check(MENU_TB_DRAW, m_mgr.GetPane(drawtbar).IsShown());
tbarMenu->Check(MENU_TB_MODE, m_mgr.GetPane(modetbar).IsShown());
tbarMenu->Check(MENU_TB_BGIMG, m_mgr.GetPane(bgimgtbar).IsShown());
#endif
case 3: // zoom slider
zoomslider->SetValue(zoom);
SetStatusText( wxString::Format("%d%%", zoom), 2 );
zoomslider->Enable(m_canvas->GetDragMode().drawing && m_canvas->CanZoom());
}
}
void ASSDrawFrame::OnClose(wxCloseEvent &event)
{
if (event.CanVeto() && behaviors.confirmquit)
{
if (wxMessageDialog(this, wxT("Do you want to close ASSDraw3 now?"), wxT("Confirmation"), wxOK | wxCANCEL).ShowModal() == wxID_OK)
Destroy();
else
event.Veto();
}
else
Destroy();
}

208
assdraw/src/assdraw.hpp Normal file
View File

@ -0,0 +1,208 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////////
// Name: assdraw.hpp
// Purpose: header file for ASSDraw main source file; also includes
// declarations for all GUI elements (except wxRuler, which has
// its own header file)
// Author: ai-chan
// Created: 08/26/06
// Copyright: (c) ai-chan
// Licence: 3-clause BSD
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "_common.hpp"
#include <vector>
#include <wx/aui/aui.h>
#include <wx/fileconf.h>
#include <wx/help.h>
#include "canvas.hpp" // the canvas
#include "dlgctrl.hpp" // custom dialogs & controls
#include "settings.hpp" // settings property grid
#include "library.hpp" // shape library
//#define BETAVERSION 2
#define VERSION "3.0 final"
// this header file declares the following classes
class ASSDrawApp;
class ASSDrawFrame;
class ASSDrawCanvas;
class ASSDrawApp : public wxApp
{
public:
bool OnInit();
};
class ASSDrawFrame : public wxFrame
{
public:
// constructor
ASSDrawFrame(wxApp *app, const wxString& title, const wxPoint& pos, const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_FRAME_STYLE);
virtual ~ASSDrawFrame();
// event handlers (these functions should _not_ be virtual)
// OnSelect_* for single items, OnChoose_* for many-choose-one items
void OnSelect_Clear(wxCommandEvent& WXUNUSED(event)) { _Clear(); }
void OnSelect_Preview(wxCommandEvent& WXUNUSED(event)) { _Preview(); }
void OnSelect_Transform(wxCommandEvent& WXUNUSED(event)) { _Transform(); }
void OnSelect_Library(wxCommandEvent& WXUNUSED(event)) { _ToggleLibrary(); }
void OnSelect_Settings(wxCommandEvent& WXUNUSED(event)) { _ToggleSettings(); }
void OnSelect_ResetPerspective(wxCommandEvent& WXUNUSED(event)) { _ResetPerspective(); }
void OnSelect_Help(wxCommandEvent& WXUNUSED(event)) { _Help(); }
void OnSelect_About(wxCommandEvent& WXUNUSED(event)) { _About(); }
void OnSelect_Undo(wxCommandEvent& WXUNUSED(event)) { UndoOrRedo( true ); }
void OnSelect_Redo(wxCommandEvent& WXUNUSED(event)) { UndoOrRedo( false ); }
void OnSelect_Paste(wxCommandEvent& WXUNUSED(event)) { _Paste(); }
void OnSelect_RemoveBG(wxCommandEvent& WXUNUSED(event)) { m_canvas->RemoveBackgroundImage(); }
void OnSelect_AlphaBG(wxCommandEvent& WXUNUSED(event)) { m_canvas->AskUserForBackgroundAlpha(); }
void OnChoose_Recenter(wxCommandEvent& event);
void OnChoose_RecenterToBG(wxCommandEvent& event);
void OnChoose_Mode(wxCommandEvent& event);
void OnChoose_DragMode(wxCommandEvent& event);
void OnZoomSliderChanged(wxScrollEvent &event);
void OnToolRClick(wxCommandEvent& event);
void OnChoose_TBarRClickMenu(wxCommandEvent& event);
void OnSettingsChanged(wxCommandEvent& event);
void OnClose(wxCloseEvent &event);
void UpdateASSCommandStringToSrcTxtCtrl(wxString cmds);
void UpdateASSCommandStringFromSrcTxtCtrl(wxString cmds);
void UndoOrRedo(bool isundo);
void UpdateUndoRedoMenu();
void _Clear();
void _Preview();
void _Transform();
void _ToggleLibrary();
void _ToggleSettings();
void _Help();
void _About(unsigned timeout = 0);
void _Paste();
void _ResetPerspective();
void UpdateFrameUI(unsigned level = 0);
// the canvas
wxApp *m_app;
ASSDrawCanvas* m_canvas;
wxAuiManager m_mgr;
wxString default_perspective;
ASSDrawSrcTxtCtrl* srctxtctrl;
// config
wxString configfile;
wxFileConfig *config;
// toolbars
wxToolBar *drawtbar, *modetbar, *bgimgtbar;
// zoom slider
wxSlider* zoomslider;
//library
ASSDrawShapeLibrary *shapelib;
typedef std::vector< ASSDrawEngine* > DrawEngineVec;
DrawEngineVec libshapes;
// menus
#if wxUSE_MENUS
wxMenu *drawMenu;
wxMenu *modeMenu;
wxMenu *bgimgMenu;
wxMenu *viewMenu;
wxMenu *tbarMenu;
#endif
// dialogs
ASSDrawTransformDlg* transformdlg;
ASSDrawSettingsDialog* settingsdlg;
// colors
struct
{
wxColour canvas_bg;
wxColour canvas_shape_normal;
wxColour canvas_shape_preview;
wxColour canvas_shape_outline;
wxColour canvas_shape_guideline;
wxColour canvas_shape_mainpoint;
wxColour canvas_shape_controlpoint;
wxColour canvas_shape_selectpoint;
wxColour library_shape;
wxColour library_libarea;
wxColour origin, ruler_h, ruler_v;
} colors;
struct
{
long canvas_shape_normal;
long canvas_shape_preview;
long canvas_shape_outline;
long canvas_shape_guideline;
long canvas_shape_mainpoint;
long canvas_shape_controlpoint;
long canvas_shape_selectpoint;
} alphas;
struct
{
long origincross;
} sizes;
struct
{
bool capitalizecmds;
bool autoaskimgopac;
bool parse_spc;
bool nosplashscreen;
bool confirmquit;
} behaviors;
void LoadSettings();
void SaveSettings();
void InitializeDefaultSettings();
void ApplySettings();
static void wxColourToAggRGBA(wxColour &colour, agg::rgba &rgba);
static void wxColourSetAlpha(wxColour &colour, long alpha);
protected:
virtual void SetToolBars();
virtual void SetMenus();
virtual void SetPanes();
DECLARE_EVENT_TABLE()
wxHelpController helpcontroller;
};

101
assdraw/src/assdraw.rc Normal file
View File

@ -0,0 +1,101 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
APPICO ICON "../tsukasa.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//
ASSDRAW3_ BITMAP "../bitmaps/assdraw3.bmp"
NEW_ BITMAP "../bitmaps/new_.bmp"
SRC_ BITMAP "../bitmaps/src_.bmp"
PREVIEW_ BITMAP "../bitmaps/preview_.bmp"
ARR_ BITMAP "../bitmaps/arr_.bmp"
M_ BITMAP "../bitmaps/m_.bmp"
N_ BITMAP "../bitmaps/n_.bmp"
L_ BITMAP "../bitmaps/l_.bmp"
B_ BITMAP "../bitmaps/b_.bmp"
S_ BITMAP "../bitmaps/s_.bmp"
P_ BITMAP "../bitmaps/p_.bmp"
C_ BITMAP "../bitmaps/c_.bmp"
DEL_ BITMAP "../bitmaps/del_.bmp"
NUT_ BITMAP "../bitmaps/nut_.bmp"
SC_ROT_ BITMAP "../bitmaps/sc_rot_.bmp"
ROT_ BITMAP "../bitmaps/rot_.bmp"
HELP_ BITMAP "../bitmaps/help_.bmp"
TRANSFORM BITMAP "../bitmaps/transform.bmp"
PAN_SHP BITMAP "../bitmaps/pan_shp.bmp"
PAN_BG BITMAP "../bitmaps/pan_bg.bmp"
//PAN_BOTH BITMAP "../bitmaps/pan_both.bmp"
ADD BITMAP "../bitmaps/add_.bmp"
CHECK BITMAP "../bitmaps/check_.bmp"
UNCHECK BITMAP "../bitmaps/uncheck_.bmp"
DELCROSS BITMAP "../bitmaps/del_cross.bmp"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@ -0,0 +1,190 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "assdraw.hpp"
void ASSDrawFrame::InitializeDefaultSettings()
{
colors.canvas_bg = wxColour(0xFF, 0xFF, 0xFF);
colors.canvas_shape_normal = wxColour(0x0, 0x0, 0xFF, 0x99);
colors.canvas_shape_preview = wxColour(0x0, 0x0, 0xFF);
colors.canvas_shape_outline = wxColour(0x0, 0x0, 0x0);
colors.canvas_shape_guideline = wxColour(0x66, 0x66, 0x66);
colors.canvas_shape_mainpoint = wxColour(0xFF, 0x0, 0x0, 0xCC);
colors.canvas_shape_controlpoint = wxColour(0x0, 0xFF, 0x0, 0xCC);
colors.canvas_shape_selectpoint = wxColour(0x0, 0x0, 0xCC);
colors.library_shape = wxColour(0x0, 0x66, 0x99);
colors.library_libarea = wxColour(0xFF, 0xFF, 0x99);
colors.origin = wxColour(0xFF, 0x0, 0x0);
colors.ruler_h = wxColour(0x0, 0x0, 0x66);
colors.ruler_v = wxColour(0x66, 0x0, 0x0);
alphas.canvas_shape_normal = 128;
alphas.canvas_shape_preview = 255;
alphas.canvas_shape_outline = 255;
alphas.canvas_shape_guideline = 255;
alphas.canvas_shape_mainpoint = 128;
alphas.canvas_shape_controlpoint = 128;
alphas.canvas_shape_selectpoint = 255;
sizes.origincross = 2;
behaviors.capitalizecmds = false;
behaviors.autoaskimgopac = true;
behaviors.parse_spc = false;
behaviors.nosplashscreen = false;
behaviors.confirmquit = true;
}
void ASSDrawFrame::ApplySettings()
{
wxColourSetAlpha(colors.canvas_shape_normal, alphas.canvas_shape_normal);
wxColourSetAlpha(colors.canvas_shape_preview, alphas.canvas_shape_preview);
wxColourSetAlpha(colors.canvas_shape_outline, alphas.canvas_shape_outline);
wxColourSetAlpha(colors.canvas_shape_guideline, alphas.canvas_shape_guideline);
wxColourSetAlpha(colors.canvas_shape_mainpoint, alphas.canvas_shape_mainpoint);
wxColourSetAlpha(colors.canvas_shape_controlpoint, alphas.canvas_shape_controlpoint);
wxColourSetAlpha(colors.canvas_shape_selectpoint, alphas.canvas_shape_selectpoint);
wxColourToAggRGBA(colors.canvas_shape_normal, m_canvas->rgba_shape_normal);
wxColourToAggRGBA(colors.canvas_shape_preview, m_canvas->rgba_shape);
wxColourToAggRGBA(colors.canvas_shape_outline, m_canvas->rgba_outline);
wxColourToAggRGBA(colors.canvas_shape_guideline, m_canvas->rgba_guideline);
wxColourToAggRGBA(colors.canvas_shape_mainpoint, m_canvas->rgba_mainpoint);
wxColourToAggRGBA(colors.canvas_shape_controlpoint, m_canvas->rgba_controlpoint);
wxColourToAggRGBA(colors.canvas_shape_selectpoint, m_canvas->rgba_selectpoint);
wxColourToAggRGBA(colors.origin, m_canvas->rgba_origin);
wxColourToAggRGBA(colors.ruler_h, m_canvas->rgba_ruler_h);
wxColourToAggRGBA(colors.ruler_v, m_canvas->rgba_ruler_v);
m_canvas->color_bg.r = colors.canvas_bg.Red();
m_canvas->color_bg.g = colors.canvas_bg.Green();
m_canvas->color_bg.b = colors.canvas_bg.Blue();
m_canvas->color_bg.a = colors.canvas_bg.Alpha();
m_canvas->PrepareBackgroundBitmap(-1.0);
m_canvas->Refresh();
shapelib->libarea->SetBackgroundColour(colors.library_libarea);
typedef std::vector< ASSDrawShapePreview *> PrevVec;
PrevVec shapes = shapelib->GetShapePreviews();
int n = shapes.size();
for (int i = 0; i < n; i++)
wxColourToAggRGBA(colors.library_shape, shapes[i]->rgba_shape);
shapelib->libarea->Refresh();
m_canvas->SetDrawCmdSet(wxT(behaviors.parse_spc? "m n l b s p c _":"m n l b _"));
UpdateASSCommandStringToSrcTxtCtrl(m_canvas->GenerateASS());
}
void ASSDrawFrame::wxColourToAggRGBA(wxColour &colour, agg::rgba &rgba)
{
rgba.r = (double) colour.Red() / 255.0;
rgba.g = (double) colour.Green() / 255.0;
rgba.b = (double) colour.Blue() / 255.0;
rgba.a = (double) colour.Alpha() / 255.0;
}
void ASSDrawFrame::wxColourSetAlpha(wxColour &colour, long alpha)
{
colour.Set(colour.Red(), colour.Green(), colour.Blue(), alpha);
}
void ASSDrawFrame::OnSettingsChanged(wxCommandEvent& event)
{
ApplySettings();
}
void ASSDrawFrame::LoadSettings()
{
#define CFGREADCOLOR(color) if (config->Read(#color, &tmpstr)) color.Set(tmpstr);
#define CFGREAD(var) config->Read(#var, &var);
config->SetPath("settings");
wxString tmpstr;
CFGREADCOLOR(colors.canvas_bg)
CFGREADCOLOR(colors.canvas_shape_normal)
CFGREADCOLOR(colors.canvas_shape_preview)
CFGREADCOLOR(colors.canvas_shape_controlpoint)
CFGREADCOLOR(colors.canvas_shape_guideline)
CFGREADCOLOR(colors.canvas_shape_mainpoint)
CFGREADCOLOR(colors.canvas_shape_outline)
CFGREADCOLOR(colors.canvas_shape_selectpoint)
CFGREADCOLOR(colors.library_libarea)
CFGREADCOLOR(colors.library_shape)
CFGREADCOLOR(colors.origin)
CFGREADCOLOR(colors.ruler_h)
CFGREADCOLOR(colors.ruler_v)
CFGREAD(alphas.canvas_shape_normal)
CFGREAD(alphas.canvas_shape_preview)
CFGREAD(alphas.canvas_shape_controlpoint)
CFGREAD(alphas.canvas_shape_guideline)
CFGREAD(alphas.canvas_shape_mainpoint)
CFGREAD(alphas.canvas_shape_outline)
CFGREAD(alphas.canvas_shape_selectpoint)
CFGREAD(sizes.origincross)
CFGREAD(behaviors.autoaskimgopac)
CFGREAD(behaviors.capitalizecmds)
CFGREAD(behaviors.parse_spc)
CFGREAD(behaviors.nosplashscreen)
CFGREAD(behaviors.confirmquit)
config->SetPath("..");
}
void ASSDrawFrame::SaveSettings()
{
#define CFGWRITE(var) config->Write(#var, var);
#define CFGWRITECOLOR(color) config->Write(#color, color.GetAsString(wxC2S_HTML_SYNTAX));
config->SetPath("settings");
CFGWRITECOLOR(colors.canvas_bg)
CFGWRITECOLOR(colors.canvas_shape_normal)
CFGWRITECOLOR(colors.canvas_shape_preview)
CFGWRITECOLOR(colors.canvas_shape_controlpoint)
CFGWRITECOLOR(colors.canvas_shape_guideline)
CFGWRITECOLOR(colors.canvas_shape_mainpoint)
CFGWRITECOLOR(colors.canvas_shape_outline)
CFGWRITECOLOR(colors.canvas_shape_selectpoint)
CFGWRITECOLOR(colors.library_libarea)
CFGWRITECOLOR(colors.library_shape)
CFGWRITECOLOR(colors.origin)
CFGWRITECOLOR(colors.ruler_h)
CFGWRITECOLOR(colors.ruler_v)
CFGWRITE(alphas.canvas_shape_normal)
CFGWRITE(alphas.canvas_shape_preview)
CFGWRITE(alphas.canvas_shape_controlpoint)
CFGWRITE(alphas.canvas_shape_guideline)
CFGWRITE(alphas.canvas_shape_mainpoint)
CFGWRITE(alphas.canvas_shape_outline)
CFGWRITE(alphas.canvas_shape_selectpoint)
CFGWRITE(sizes.origincross)
CFGWRITE(behaviors.autoaskimgopac)
CFGWRITE(behaviors.capitalizecmds)
CFGWRITE(behaviors.parse_spc)
CFGWRITE(behaviors.nosplashscreen)
CFGWRITE(behaviors.confirmquit)
config->SetPath("..");
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 776 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

BIN
assdraw/src/bitmaps/b_.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 776 B

BIN
assdraw/src/bitmaps/b_.cur Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
assdraw/src/bitmaps/c_.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 776 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 776 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

BIN
assdraw/src/bitmaps/l_.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 776 B

BIN
assdraw/src/bitmaps/m_.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 776 B

BIN
assdraw/src/bitmaps/n_.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 776 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 776 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

BIN
assdraw/src/bitmaps/p_.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 776 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 776 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

BIN
assdraw/src/bitmaps/s_.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 776 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 776 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

2057
assdraw/src/canvas.cpp Normal file

File diff suppressed because it is too large Load Diff

303
assdraw/src/canvas.hpp Normal file
View File

@ -0,0 +1,303 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////////
// Name: canvas.hpp
// Purpose: header file for ASSDraw main canvas class
// Author: ai-chan
// Created: 08/26/06
// Copyright: (c) ai-chan
// Licence: 3-clause BSD
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include <vector>
#include "engine.hpp"
#include "enums.hpp"
#include <wx/dnd.h>
#include <wx/splitter.h>
#include <wx/clntdata.h>
#include "agg_span_allocator.h"
#include "agg_span_interpolator_linear.h"
#include "agg_span_image_filter_rgb.h"
#include "agg_span_image_filter_rgba.h"
#include "agg_image_accessors.h"
#include "agg_conv_clip_polygon.h"
class ASSDrawFrame;
class ASSDrawCanvas;
struct UndoRedo
{
wxString cmds;
wxString desc;
double originx, originy, scale;
std::vector< bool > c1cont;
wxString bgimgfile;
wxRealPoint bgdisp, bgcenter;
double bgscale, bgalpha;
MODE draw_mode;
agg::path_storage backupcmds;
wxRealPoint rectbound[4], rectbound2[4], backup[4];
bool isshapetransformable;
void Import(ASSDrawCanvas *canvas, bool prestage, wxString cmds = _T(""));
void Export(ASSDrawCanvas *canvas);
};
// for multiple point selection
enum SELECTMODE { NEW, ADD, DEL };
class ASSDrawCanvas: public ASSDrawEngine, public wxClientData
{
public:
ASSDrawCanvas( wxWindow *parent, ASSDrawFrame *frame, int extraflags = 0 );
// destructor
~ASSDrawCanvas();
virtual void ResetEngine(bool addM);
virtual void SetPreviewMode( bool mode );
virtual bool IsPreviewMode() { return preview_mode; }
virtual void ParseASS(wxString str, bool addundo = false);
virtual void SetDrawMode( MODE mode );
virtual MODE GetDrawMode() { return draw_mode; }
virtual bool IsTransformMode();
virtual void SetDragMode( DRAGMODE mode );
virtual DRAGMODE GetDragMode() { return drag_mode; }
virtual void RefreshDisplay();
virtual bool CanZoom();
virtual bool CanMove();
virtual void OnMouseMove(wxMouseEvent &event);
virtual void OnMouseLeftUp(wxMouseEvent &event);
virtual void OnMouseLeftDown(wxMouseEvent &event);
virtual void OnMouseRightUp(wxMouseEvent &event);
virtual void OnMouseRightDown(wxMouseEvent &event);
virtual void OnMouseRightDClick(wxMouseEvent &event);
virtual void OnMouseWheel(wxMouseEvent &event);
virtual void CustomOnKeyDown(wxKeyEvent &event);
virtual void CustomOnKeyUp(wxKeyEvent &event);
virtual void ChangeZoomLevel(double zoomamount, wxPoint bgzoomctr);
virtual void ChangeZoomLevelTo(double zoom, wxPoint bgzoomctr);
virtual void ChangeDrawingZoomLevel(double zoom);
virtual void ChangeBackgroundZoomLevel(double zoom, wxRealPoint newcenter);
virtual void MoveCanvas(double xamount, double yamount);
virtual void MoveCanvasOriginTo(double originx, double originy);
virtual void MoveCanvasDrawing(double xamount, double yamount);
virtual void MoveCanvasBackground(double xamount, double yamount);
virtual void OnSelect_ConvertLineToBezier(wxCommandEvent& WXUNUSED(event));
virtual void OnSelect_ConvertBezierToLine(wxCommandEvent& WXUNUSED(event));
virtual void OnSelect_C1ContinuityBezier(wxCommandEvent& WXUNUSED(event));
virtual void OnSelect_Move00Here(wxCommandEvent& WXUNUSED(event));
void OnAlphaSliderChanged(wxScrollEvent &event);
// to replace _PointSystem() that has been made protected
double GetScale() { return pointsys->scale; }
double GetOriginX() { return pointsys->originx; }
double GetOriginY() { return pointsys->originy; }
// undo/redo system
virtual void AddUndo( wxString desc );
virtual bool UndoOrRedo(bool isundo);
virtual bool Undo();
virtual bool Redo();
virtual wxString GetTopUndo();
virtual wxString GetTopRedo();
virtual void RefreshUndocmds();
virtual bool HasBackgroundImage() { return bgimg.bgimg != NULL; }
virtual void RemoveBackgroundImage();
virtual void ReceiveBackgroundImageFileDropEvent(const wxString& filename);
virtual void SetBackgroundImage(const wxImage& img, wxString fname = _T("<clipboard>"), bool ask4alpha = true);
virtual void PrepareBackgroundBitmap(double alpha);
virtual void AskUserForBackgroundAlpha();
virtual bool GetBackgroundInfo(unsigned& w, unsigned& h, wxRealPoint& disp, double& scale);
agg::rgba rgba_shape_normal, rgba_outline, rgba_guideline;
agg::rgba rgba_mainpoint, rgba_controlpoint, rgba_selectpoint;
agg::rgba rgba_origin, rgba_ruler_h, rgba_ruler_v;
protected:
typedef PixelFormat::AGGType::color_type color_type;
typedef agg::span_interpolator_linear<> interpolator_type;
typedef agg::span_image_filter_rgb_bilinear_clip<PixelFormat::AGGType, interpolator_type> span_gen_type;
// The GUI window
ASSDrawFrame* m_frame;
// highlight mechanism
DrawCmd* hilite_cmd;
Point* hilite_point;
// mouse capture
bool capturemouse_left, capturemouse_right;
virtual void CustomOnMouseCaptureLost(wxMouseCaptureLostEvent &event);
virtual void ProcessOnMouseLeftUp();
virtual void ProcessOnMouseRightUp();
// selection mechanism
PointSet selected_points;
// if it has status bar
bool hasStatusBar;
// some mouse readings
Point* mousedownAt_point;
Point* pointedAt_point;
Point* dblclicked_point_right;
wxPoint mouse_point;
// The wxPoint being dragged by left button
wxPoint* dragAnchor_left;
wxPoint* lastDrag_left;
// The wxPoint being dragged by right button
wxPoint* dragAnchor_right;
wxPoint* lastDrag_right;
// true if the drawing origin (0, 0) is being dragged
bool dragOrigin;
// The newest command being initialized thru dragging action
DrawCmd* newcommand;
// the draw mode
MODE draw_mode;
DRAGMODE drag_mode;
// holding shift key temporarily switches to drag mode (MODE_ARR)
// so we want to save the mode before the key-down to restore it on key-up
MODE mode_b4_shift;
// true if preview mode (i.e don't draw anything except the shape itself;
// also draw the shape as closed)
bool preview_mode;
// background image!
struct
{
agg::rendering_buffer ibuf;
wxImage *bgimg;
wxBitmap *bgbmp;
wxString bgimgfile;
agg::path_storage bg_path;
agg::span_allocator<color_type> spanalloc;
//span_gen_type spangen;
agg::trans_affine img_mtx, path_mtx;
wxRealPoint disp, center, new_disp, new_center;
double scale, new_scale, alpha;
wxDialog* alpha_dlg;
wxSlider* alpha_slider;
} bgimg;
// Undo/redo system (simply stores the ASS commands)
std::list<UndoRedo> undos;
std::list<UndoRedo> redos;
UndoRedo _undo;
// last action and commands (for undo/redo system)
wxString undodesc;
wxString oldasscmds;
// was preview_mode
//bool was_preview_mode;
PointSystem* _PointSystem() { return pointsys; }
// for Undo/Redo system
virtual void PrepareUndoRedo(UndoRedo& ur, bool prestage, wxString cmds, wxString desc);
// -------------------- points highlight/selection ---------------------------
// set command and point to highlight
virtual void SetHighlighted ( DrawCmd* cmd, Point* point );
// selects all points within (lx, ty) , (rx, by) returns # of selected points
virtual int SelectPointsWithin( int lx, int rx, int ty, int by, SELECTMODE smode = NEW );
virtual void ClearPointsSelection();
virtual SELECTMODE GetSelectMode(wxMouseEvent &event);
// -------------------- misc ---------------------------
// non-uniform transformation
virtual bool InitiateDraggingIfTransformMode();
virtual void UpdateTranformModeRectCenter();
virtual bool GetThe4thPoint(double ox, double oy, double a1x, double a1y, double a2x, double a2y, double *x, double *y);
enum { NONE, LEFT, RIGHT } backupowner;
agg::path_storage backupcmds;
int rectbound2upd, rectbound2upd2;
wxRealPoint rectbound[4], rectbound2[4], backup[4], rectcenter;
bool isshapetransformable;
// do the real drawing
virtual void DoDraw( RendererBase& rbase, RendererPrimitives& rprim, RendererSolid& rsolid, agg::trans_affine& mtx );
// update background image scale & position
virtual void UpdateBackgroundImgScalePosition(bool firsttime = false);
// perform extra stuff other than calling ASSDrawEngine::ConnectSubsequentCmds
virtual void ConnectSubsequentCmds (DrawCmd* cmd1, DrawCmd* cmd2);
// make sure the c1 continuity is followed after performing a drag-point action
virtual void EnforceC1Continuity (DrawCmd* cmd, Point* pnt);
// after the bounding quadrangle has changed, update the shape to fill up inside it
virtual void UpdateNonUniformTransformation();
friend class UndoRedo;
DECLARE_EVENT_TABLE()
};
class ASSDrawFileDropTarget : public wxFileDropTarget
{
public:
ASSDrawFileDropTarget(ASSDrawCanvas *canvas): wxFileDropTarget()
{
m_canvas = canvas;
}
virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames)
{
m_canvas->ReceiveBackgroundImageFileDropEvent(filenames.Item(0));
}
protected:
ASSDrawCanvas *m_canvas;
};

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "canvas_mouse.hpp"
#include "canvas.hpp"
DEFINE_EVENT_TYPE( wxEVT_MOUSEONCANVAS )
ASSDrawMouseOnCanvasEvent::ASSDrawMouseOnCanvasEvent(const ASSDrawCanvas* canvas)
: wxNotifyEvent(),
_canvas(canvas)
{
_data = NULL;
}
wxEvent* ASSDrawMouseOnCanvasEvent::Clone()
{
ASSDrawMouseOnCanvasEvent *clone = new ASSDrawMouseOnCanvasEvent(_canvas);
clone->SetData(_data);
return clone;
}
void ASSDrawMouseOnCanvasEvent::SetData(MouseOnCanvasData *data)
{
_data = data;
}
MouseOnCanvasData* ASSDrawMouseOnCanvasEvent::GetData()
{
return _data;
}

View File

@ -0,0 +1,85 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "_common.hpp"
#include "enums.hpp"
#include "engine.hpp"
#include <wx/event.h>
struct MouseOnCanvasData
{
MODE mode;
wxMouseEvent event;
enum { NONE, LEFT, RIGHT, BOTH } button;
Point* mousedownAt_point;
Point* pointedAt_point;
Point* dblclicked_point_right;
wxPoint mouse_point;
wxPoint* dragAnchor_left;
wxPoint* lastDrag_left;
wxPoint* dragAnchor_right;
wxPoint* lastDrag_right;
};
class ASSDrawCanvas;
class ASSDrawMouseOnCanvasEvent : public wxNotifyEvent
{
public:
ASSDrawMouseOnCanvasEvent(const ASSDrawCanvas* canvas);
wxEvent* Clone();
void SetData(MouseOnCanvasData *data);
MouseOnCanvasData* GetData();
private:
const ASSDrawCanvas* _canvas;
MouseOnCanvasData* _data;
};
DECLARE_EVENT_TYPE( wxEVT_MOUSEONCANVAS, -1 )
typedef void (wxEvtHandler::*wxMouseOnCanvasEventFunction)(ASSDrawMouseOnCanvasEvent&);
#define EVT_MOUSEONCANVAS(fn) \
DECLARE_EVENT_TABLE_ENTRY( wxEVT_MOUSEONCANVAS, -1, -1, \
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) \
wxStaticCastEvent( wxMouseOnCanvasEventFunction, & fn ), (wxObject *) NULL ),
class ASSDrawMouseOnCanvasHandler
{
};

212
assdraw/src/cmd.cpp Normal file
View File

@ -0,0 +1,212 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////////
// Name: cmd.cpp
// Purpose: ASSDraw drawing command classes
// Author: ai-chan
// Created: 08/26/06
// Copyright: (c) ai-chan
// Licence: 3-clause BSD
///////////////////////////////////////////////////////////////////////////////
#include "cmd.hpp" // the header for this file
#include <wx/log.h>
// ----------------------------------------------------------------------------
// DrawCmd_M
// ----------------------------------------------------------------------------
// constructor
DrawCmd_M::DrawCmd_M ( int x, int y, PointSystem *ps, DrawCmd *prev )
: DrawCmd ( x, y, ps, prev )
{
type = M;
}
// to ASS drawing command
wxString DrawCmd_M::ToString()
{
return wxString::Format(_T("m %d %d"), m_point->x(), m_point->y());
}
// ----------------------------------------------------------------------------
// DrawCmd_L
// ----------------------------------------------------------------------------
// constructor
DrawCmd_L::DrawCmd_L ( int x, int y, PointSystem *ps, DrawCmd *prev )
: DrawCmd ( x, y, ps, prev )
{
type = L;
}
// to ASS drawing command
wxString DrawCmd_L::ToString()
{
return wxString::Format(wxT("l %d %d"), m_point->x(), m_point->y());
}
// ----------------------------------------------------------------------------
// DrawCmd_B
// ----------------------------------------------------------------------------
// constructor
DrawCmd_B::DrawCmd_B
( int x, int y, int x1, int y1, int x2, int y2, PointSystem *ps, DrawCmd *prev )
: DrawCmd ( x, y, ps, prev )
{
type = B;
controlpoints.push_back( new Point(x1, y1, ps, CP, this, 1) );
controlpoints.push_back( new Point(x2, y2, ps, CP, this, 2) );
initialized = true;
C1Cont = false;
}
// constructor
DrawCmd_B::DrawCmd_B ( int x, int y, PointSystem *ps, DrawCmd *prev )
: DrawCmd ( x, y, ps, prev )
{
type = B;
initialized = false;
C1Cont = false;
}
// initialize; generate control points
void DrawCmd_B::Init ( unsigned n )
{
// Ignore if this is already initted
if (initialized) return;
wxPoint wx0 = prev->m_point->ToWxPoint();
wxPoint wx1 = m_point->ToWxPoint();
int xdiff = (wx1.x - wx0.x) / 3;
int ydiff = (wx1.y - wx0.y) / 3;
int xg, yg;
// first control
m_point->pointsys->FromWxPoint( wx0.x + xdiff, wx0.y + ydiff, xg, yg );
controlpoints.push_back( new Point( xg, yg, m_point->pointsys, CP, this, 1 ) );
// second control
m_point->pointsys->FromWxPoint( wx1.x - xdiff, wx1.y - ydiff, xg, yg );
controlpoints.push_back( new Point( xg, yg, m_point->pointsys, CP, this, 2 ) );
initialized = true;
}
// to ASS drawing command
wxString DrawCmd_B::ToString()
{
PointList::iterator iterate = controlpoints.begin();
Point* c1 = (*iterate++);
Point* c2 = (*iterate);
if (initialized)
return wxString::Format(wxT("b %d %d %d %d %d %d"), c1->x(), c1->y(), c2->x(), c2->y(), m_point->x(), m_point->y());
else
return wxString::Format(wxT("b ? ? ? ? %d %d"), m_point->x(), m_point->y());
}
// ----------------------------------------------------------------------------
// DrawCmd_S
// ----------------------------------------------------------------------------
// constructor
DrawCmd_S::DrawCmd_S
( int x, int y, PointSystem *ps, DrawCmd *prev )
: DrawCmd ( x, y, ps, prev )
{
type = S;
initialized = false;
closed = false;
}
// constructor
DrawCmd_S::DrawCmd_S
( int x, int y, std::vector< int > vals, PointSystem *ps, DrawCmd *prev )
: DrawCmd ( x, y, ps, prev )
{
type = S;
std::vector< int >::iterator it = vals.begin();
unsigned n = 0;
while (it != vals.end())
{
int ix = *it; it++;
int iy = *it; it++;
n++;
//::wxLogMessage("%d %d\n", ix, iy);
controlpoints.push_back( new Point( ix, iy, ps, CP, this, n ) );
}
initialized = true;
closed = false;
}
// initialize; generate control points
void DrawCmd_S::Init(unsigned n)
{
// Ignore if this is already initted
if (initialized) return;
wxPoint wx0 = prev->m_point->ToWxPoint();
wxPoint wx1 = m_point->ToWxPoint();
int xdiff = (wx1.x - wx0.x) / 3;
int ydiff = (wx1.y - wx0.y) / 3;
int xg, yg;
// first control
m_point->pointsys->FromWxPoint( wx0.x + xdiff, wx0.y + ydiff, xg, yg );
controlpoints.push_back( new Point( xg, yg, m_point->pointsys, CP, this, 1 ) );
// second control
m_point->pointsys->FromWxPoint( wx1.x - xdiff, wx1.y - ydiff, xg, yg );
controlpoints.push_back( new Point( xg, yg, m_point->pointsys, CP, this, 2 ) );
initialized = true;
}
// to ASS drawing command
wxString DrawCmd_S::ToString()
{
PointList::iterator iterate = controlpoints.begin();
wxString assout = _T("s");
for (; iterate != controlpoints.end(); iterate++)
{
if (initialized)
assout = wxString::Format(wxT("%s %d %d"), assout.c_str(), (*iterate)->x(), (*iterate)->y());
else
assout = wxString::Format(wxT("%s ? ?"), assout.c_str());
}
assout = wxString::Format(wxT("%s %d %d"), assout.c_str(), m_point->x(), m_point->y());
if (closed) assout = wxString::Format(wxT("%s c"), assout.c_str());
return assout;
}

112
assdraw/src/cmd.hpp Normal file
View File

@ -0,0 +1,112 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////////
// Name: cmd.hpp
// Purpose: header file for ASSDraw drawing command classes
// Author: ai-chan
// Created: 08/26/06
// Copyright: (c) ai-chan
// Licence: 3-clause BSD
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "engine.hpp" // include the engine header for DrawCmd
#include <vector> // ok, we use vector too
// this header file declares the following classes
class DrawCmd_M;
class DrawCmd_L;
class DrawCmd_B;
// The M command
class DrawCmd_M: public DrawCmd
{
public:
// Constructor
DrawCmd_M ( int x, int y, PointSystem *ps, DrawCmd *prev );
// to ASS drawing command
wxString ToString();
};
// The L command
class DrawCmd_L: public DrawCmd
{
public:
// Constructor
DrawCmd_L ( int x, int y, PointSystem *ps, DrawCmd *prev );
// to ASS drawing command
wxString ToString();
};
// The B command
class DrawCmd_B: public DrawCmd
{
public:
// Constructor
DrawCmd_B ( int x, int y, int x1, int y1, int x2, int y2, PointSystem *ps, DrawCmd *prev );
// Special constructor where only m_point is defined
// Need to call Init() to generate the controls
DrawCmd_B ( int x, int y, PointSystem *ps, DrawCmd *prev );
// Init this B command; generate controlpoints
void Init ( unsigned n = 0 );
// to ASS drawing command
wxString ToString();
//special
bool C1Cont;
};
// The S command
class DrawCmd_S: public DrawCmd
{
public:
// Constructor
DrawCmd_S ( int x, int y, PointSystem *ps, DrawCmd *prev );
// Constructor (with points info)
DrawCmd_S ( int x, int y, std::vector< int > vals, PointSystem *ps, DrawCmd *prev );
// Init this S command; generate controlpoints
void Init ( unsigned n = 0 );
// to ASS drawing command
wxString ToString();
// special
bool closed;
};

372
assdraw/src/dlgctrl.cpp Normal file
View File

@ -0,0 +1,372 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////////
// Name: dlgctrl.cpp
// Purpose: custom dialogs and controls
// Author: ai-chan
// Created: 08/26/06
// Copyright: (c) ai-chan
// Licence: 3-clause BSD
///////////////////////////////////////////////////////////////////////////////
#include "assdraw.hpp"
BEGIN_EVENT_TABLE(ASSDrawSrcTxtCtrl, wxTextCtrl)
EVT_CHAR(ASSDrawSrcTxtCtrl::CustomOnChar)
EVT_TEXT(wxID_ANY, ASSDrawSrcTxtCtrl::CustomOnText)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(ASSDrawTransformDlg, wxDialog)
EVT_COMBOBOX(-1, ASSDrawTransformDlg::OnTemplatesCombo)
END_EVENT_TABLE()
//BEGIN_EVENT_TABLE(ASSDrawCanvasRecenterButton, wxWindow)
//END_EVENT_TABLE()
// ----------------------------------------------------------------------------
// ASSDrawSrcTxtCtrl
// ----------------------------------------------------------------------------
ASSDrawSrcTxtCtrl::ASSDrawSrcTxtCtrl(wxWindow *parent, ASSDrawFrame *frame)
: wxTextCtrl(parent, wxID_ANY, "", __DPDS__ , wxTE_MULTILINE )
{
m_frame = frame;
}
void ASSDrawSrcTxtCtrl::CustomOnChar(wxKeyEvent &event)
{
switch (event.GetKeyCode())
{
case WXK_RETURN:
m_frame->UpdateASSCommandStringFromSrcTxtCtrl(GetValue());
break;
case WXK_TAB:
break; //do nothing
default:
//m_frame->SetTitle(wxString::Format("Key: %d", event.GetKeyCode()));
event.Skip(true);
}
//SetBackgroundColour(IsModified()? wxColour(0xFF, 0xFF, 0x99):*wxWHITE);
}
void ASSDrawSrcTxtCtrl::CustomOnText(wxCommandEvent &event)
{
//SetBackgroundColour(IsModified()? wxColour(0xFF, 0xFF, 0x99):*wxWHITE);
}
// ----------------------------------------------------------------------------
// ASSDrawTransformDlg
// ----------------------------------------------------------------------------
ASSDrawTransformDlg::ASSDrawTransformDlg(ASSDrawFrame* parent)
: wxDialog(parent, -1, wxString(_T("Transform")))
{
m_frame = parent;
wxBoxSizer* sizer_main = new wxBoxSizer(wxVERTICAL);
this->SetSizer(sizer_main);
wxBoxSizer* sizer_templates = new wxBoxSizer(wxHORIZONTAL);
sizer_main->Add(sizer_templates, 0, wxGROW|wxLEFT, 5);
sizer_templates->Add(new wxStaticText( this, -1, _("Templates"), __DPDS__ , 0 ),
0, wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
combo_templates = new wxComboBox( this, -1, combo_templatesStrings[0], __DPDS__ , 10, combo_templatesStrings, wxCB_READONLY );
sizer_templates->Add(combo_templates, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
wxFlexGridSizer* sizer_fields = new wxFlexGridSizer(3, 4, 0, 0);
sizer_main->Add(sizer_fields, 0, wxALIGN_CENTER_HORIZONTAL|wxLEFT, 5);
int flag_txtctrl = wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL;
int flag_statictxt = wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE;
sizer_fields->Add(new wxStaticText( this, -1, _("m11"), __DPDS__ , 0 ),
0, flag_statictxt, 5);
txtctrl_m11 = new wxTextCtrl( this, -1, _T("1.0"), __DPDS__ , wxTE_RIGHT );
sizer_fields->Add(txtctrl_m11, 0, flag_txtctrl, 5);
sizer_fields->Add(new wxStaticText( this, -1, _("m12"), __DPDS__ , 0 ),
0, flag_statictxt, 5);
txtctrl_m12 = new wxTextCtrl( this, -1, _T("0.0"), __DPDS__ , wxTE_RIGHT );
sizer_fields->Add(txtctrl_m12, 0, flag_txtctrl, 5);
sizer_fields->Add(new wxStaticText( this, -1, _("m21"), __DPDS__ , 0 ),
0, flag_statictxt, 5);
txtctrl_m21 = new wxTextCtrl( this, -1, _T("0.0"), __DPDS__ , wxTE_RIGHT );
sizer_fields->Add(txtctrl_m21, 0, flag_txtctrl, 5);
sizer_fields->Add(new wxStaticText( this, -1, _("m22"), __DPDS__ , 0 ),
0, flag_statictxt, 5);
txtctrl_m22 = new wxTextCtrl( this, -1, _T("1.0"), __DPDS__ , wxTE_RIGHT );
sizer_fields->Add(txtctrl_m22, 0, flag_txtctrl, 5);
sizer_fields->Add(new wxStaticText( this, -1, _("mx"), __DPDS__ , 0 ),
0, flag_statictxt, 5);
txtctrl_mx = new wxTextCtrl( this, -1, _T("0.0"), __DPDS__ , wxTE_RIGHT );
sizer_fields->Add(txtctrl_mx, 0, flag_txtctrl, 5);
sizer_fields->Add(new wxStaticText( this, -1, _("my"), __DPDS__ , 0 ),
0, flag_statictxt, 5);
txtctrl_my = new wxTextCtrl( this, -1, _T("0.0"), __DPDS__ , wxTE_RIGHT );
sizer_fields->Add(txtctrl_my, 0, flag_txtctrl, 5);
sizer_fields->Add(new wxStaticText( this, -1, _("nx"), __DPDS__ , 0 ),
0, flag_statictxt, 5);
txtctrl_nx = new wxTextCtrl( this, -1, _T("0.0"), __DPDS__ , wxTE_RIGHT );
sizer_fields->Add(txtctrl_nx, 0, flag_txtctrl, 5);
sizer_fields->Add(new wxStaticText( this, -1, _("ny"), __DPDS__ , 0 ),
0, flag_statictxt, 5);
txtctrl_ny = new wxTextCtrl( this, -1, _T("0.0"), __DPDS__ , wxTE_RIGHT );
sizer_fields->Add(txtctrl_ny, 0, flag_txtctrl, 5);
wxBitmap staticbmp_bmp(wxBITMAP(transform));
wxStaticBitmap* staticbmp = new wxStaticBitmap( this, -1, staticbmp_bmp, wxDefaultPosition, wxSize(224, 56), 0 );
sizer_main->Add(staticbmp, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
wxStdDialogButtonSizer* sizer_stdbutt = new wxStdDialogButtonSizer;
sizer_main->Add(sizer_stdbutt, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
wxButton* button_ok = new wxButton( this, wxID_OK, _("&OK"), __DPDS__ , 0 );
sizer_stdbutt->AddButton(button_ok);
wxButton* button_cancel = new wxButton( this, wxID_CANCEL, _("&Cancel"), __DPDS__ , 0 );
sizer_stdbutt->AddButton(button_cancel);
sizer_stdbutt->Realize();
sizer_main->Fit(this);
}
void ASSDrawTransformDlg::OnTemplatesCombo(wxCommandEvent &event)
{
int pos = -1;
for (int i = 0; i < combo_templatesCount; i++)
if (combo_templatesStrings[i].IsSameAs(((wxComboBox *) event.GetEventObject())->GetValue()))
{
pos = i;
break;
}
if (pos == -1)
return;
txtctrl_m11->SetValue( wxString::Format("%.1f", combo_templatesValues[pos].f1) );
txtctrl_m12->SetValue( wxString::Format("%.1f", combo_templatesValues[pos].f2) );
txtctrl_m21->SetValue( wxString::Format("%.1f", combo_templatesValues[pos].f3) );
txtctrl_m22->SetValue( wxString::Format("%.1f", combo_templatesValues[pos].f4) );
txtctrl_mx->SetValue( wxString::Format("%.1f", combo_templatesValues[pos].f5) );
txtctrl_my->SetValue( wxString::Format("%.1f", combo_templatesValues[pos].f6) );
txtctrl_nx->SetValue( wxString::Format("%.1f", combo_templatesValues[pos].f7) );
txtctrl_ny->SetValue( wxString::Format("%.1f", combo_templatesValues[pos].f8) );
}
void ASSDrawTransformDlg::EndModal(int retCode)
{
if (retCode != wxID_OK)
{
wxDialog::EndModal(retCode);
return;
}
bool ok = true;
ok = ok && txtctrl_m11->GetValue().ToDouble( &xformvals.f1 );
ok = ok && txtctrl_m12->GetValue().ToDouble( &xformvals.f2 );
ok = ok && txtctrl_m21->GetValue().ToDouble( &xformvals.f3 );
ok = ok && txtctrl_m22->GetValue().ToDouble( &xformvals.f4 );
ok = ok && txtctrl_mx->GetValue().ToDouble( &xformvals.f5 );
ok = ok && txtctrl_my->GetValue().ToDouble( &xformvals.f6 );
ok = ok && txtctrl_nx->GetValue().ToDouble( &xformvals.f7 );
ok = ok && txtctrl_ny->GetValue().ToDouble( &xformvals.f8 );
if (ok)
wxDialog::EndModal(wxID_OK);
else
wxMessageBox("One or more values entered are not real numbers.\nPlease fix.", _T("Value error"), wxOK | wxICON_INFORMATION, m_frame);
}
ASSDrawAboutDlg::ASSDrawAboutDlg(ASSDrawFrame *parent, unsigned timeout)
: wxDialog(parent, wxID_ANY, wxString(TITLE), __DPDS__ , wxSIMPLE_BORDER), time_out(timeout)
{
SetBackgroundColour(*wxWHITE);
htmlwin = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxSize(396, 200), wxHW_DEFAULT_STYLE | wxSIMPLE_BORDER);
htmlwin->SetPage(
"<html><body> \
<p>ASSDraw3 is a tool for designing shapes to be used in ASS subtitle file. \
<p>To add lines or curves, initiate the draw mode by clicking on the drawing tools. \
Then, either click on empty space or drag from an existing point to add the new lines/curves. \
Control points for Bezier curves are generated once you release the mouse button. \
<p>To modify shapes, drag their points (squares) and control points (circles) in the drag mode. \
<p><b>Some tips & tricks:</b> \
<ul> \
<li> Set background image by dragging image file from explorer onto the canvas \
<li> Use the Shapes Library to store your drawings \
<li> Ctrl-Z for undo, Ctrl-Y for redo \
<li> Use your mousewheel to zoom in/out (PageUp/PageDown keys work too) \
<li> Dragging with right mouse button moves the drawing and/or background image around. \
<li> Double clicking with right mouse button for popup menus. \
<li> Holding shift key while in the draw mode temporarily switches to the drag mode \
<li> The shapes origin (coordinate [0, 0] depicted by the small cross) is draggable \
</ul> \
<p><b>Acknowledgements:</b> \
<ul> \
<li> Maxim Shemanarev <a href=\"http://www.antigrain.com\">http://www.antigrain.com</a> for his Anti-Grain Geometry (AGG) graphic toolkit. \
<li> wxWidgets Project <a href=\"http://www.wxwidgets.org\">http://www.wxwidgets.org</a> for the ultracool GUI toolkit. \
<li> Adrian Secord <a href=\"http://mrl.nyu.edu/~ajsecord/index.html\">http://mrl.nyu.edu/~ajsecord/index.html</a> for wxAGG, that combines AGG and wxWidgets\
<li> jfs, ArchMageZeratul, RoRo and everyone at Aegisub's forum <a href=\"http://malakith.net/aegisub\">http://malakith.net/aegisub</a> for all suggestions and supports. \
</ul> \
<p>ai-chan recommends Aegisub for all your subtitle and typesetting needs! \
</body></html>"
);
htmlwin->Connect(wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEventHandler(ASSDrawAboutDlg::OnURL), NULL, this);
wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
sizer->AddGrowableCol(0);
//sizer->AddGrowableRow(1);
sizer->Add(new BigStaticBitmapCtrl(this, wxBITMAP(assdraw3_), *wxWHITE, this), 1, wxEXPAND);
sizer->Add(htmlwin, 1, wxLEFT | wxRIGHT, 2);
sizer->Add(new wxStaticText(this, wxID_ANY, wxString::Format("Version: %s", VERSION)), 1, wxEXPAND | wxALL, 2);
sizer->Add(new wxButton(this, wxID_OK), 0, wxALIGN_CENTER | wxBOTTOM, 10);
SetSizer(sizer);
sizer->Layout();
sizer->Fit(this);
Center();
//if (CanSetTransparent()) SetTransparent(0xCC);
timer.SetOwner(this);
Connect(wxEVT_TIMER, wxTimerEventHandler(ASSDrawAboutDlg::OnTimeout));
Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(ASSDrawAboutDlg::OnMouseEnterWindow));
}
ASSDrawAboutDlg::~ASSDrawAboutDlg()
{
timer.Stop();
}
int ASSDrawAboutDlg::ShowModal()
{
if (time_out > 0)
timer.Start(time_out * 1000, true);
wxDialog::ShowModal();
}
void ASSDrawAboutDlg::OnURL(wxHtmlLinkEvent &event)
{
wxString URL(event.GetLinkInfo().GetHref());
if (URL.StartsWith("http://"))
::wxLaunchDefaultBrowser(URL);
else
event.Skip(true);
}
void ASSDrawAboutDlg::OnTimeout(wxTimerEvent& event)
{
if (IsShown())
EndModal(wxID_OK);
}
void ASSDrawAboutDlg::OnMouseEnterWindow(wxMouseEvent& event)
{
// if mouse enters this dialog, stop the timout timer
// and dialog will only close through user input
timer.Stop();
}
BEGIN_EVENT_TABLE(BigStaticBitmapCtrl, wxPanel)
EVT_PAINT(BigStaticBitmapCtrl::OnPaint)
EVT_MOTION (BigStaticBitmapCtrl::OnMouseMove)
EVT_LEFT_UP(BigStaticBitmapCtrl::OnMouseLeftUp)
EVT_LEFT_DOWN(BigStaticBitmapCtrl::OnMouseLeftDown)
END_EVENT_TABLE()
BigStaticBitmapCtrl::BigStaticBitmapCtrl(wxWindow *parent, wxBitmap bmap, wxColour bgcol, wxWindow *todrag)
: wxPanel(parent, wxID_ANY)
{
bitmap = bmap;
bgbrush = wxBrush(bgcol);
window_to_drag = todrag;
SetSize(bitmap.GetWidth(), bitmap.GetHeight());
Refresh();
}
BigStaticBitmapCtrl::~BigStaticBitmapCtrl()
{
}
void BigStaticBitmapCtrl::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(this);
dc.SetBackground(bgbrush);
dc.Clear();
dc.DrawBitmap(bitmap, wxPoint(0,0));
}
void BigStaticBitmapCtrl::OnMouseLeftDown(wxMouseEvent &event)
{
if (window_to_drag != NULL)
{
dragpoint = event.GetPosition();
}
CaptureMouse();
}
void BigStaticBitmapCtrl::OnMouseLeftUp(wxMouseEvent &event)
{
ReleaseMouse();
}
void BigStaticBitmapCtrl::OnMouseMove(wxMouseEvent &event)
{
if (window_to_drag != NULL && event.Dragging() && HasCapture())
{
wxPoint npoint(event.GetPosition());
wxPoint wndpos = window_to_drag->GetScreenPosition();
wxPoint thispos = this->GetScreenPosition();
//ReleaseMouse();
window_to_drag->Move(wndpos.x + npoint.x - dragpoint.x,
wndpos.y + npoint.y - dragpoint.y);
//CaptureMouse();
if (thispos == this->GetScreenPosition()) // if this ctrl did not move when window_to_drag moved
dragpoint = npoint;
}
event.Skip(true);
}

115
assdraw/src/dlgctrl.hpp Normal file
View File

@ -0,0 +1,115 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "_common.hpp"
#include <wx/html/htmlwin.h>
#include <wx/timer.h>
class ASSDrawFrame;
class ASSDrawSrcTxtCtrl : public wxTextCtrl
{
public:
ASSDrawSrcTxtCtrl(wxWindow *parent, ASSDrawFrame *frame);
virtual void CustomOnChar(wxKeyEvent &event);
virtual void CustomOnText(wxCommandEvent &event);
protected:
ASSDrawFrame *m_frame;
DECLARE_EVENT_TABLE()
};
struct EightDouble
{
double f1, f2, f3, f4, f5, f6, f7, f8;
};
class ASSDrawTransformDlg : public wxDialog
{
public:
ASSDrawTransformDlg(ASSDrawFrame* parent);
void OnTemplatesCombo(wxCommandEvent &event);
void EndModal(int retCode);
ASSDrawFrame* m_frame;
wxComboBox* combo_templates;
wxTextCtrl* txtctrl_m11;
wxTextCtrl* txtctrl_m12;
wxTextCtrl* txtctrl_m21;
wxTextCtrl* txtctrl_m22;
wxTextCtrl* txtctrl_mx;
wxTextCtrl* txtctrl_my;
wxTextCtrl* txtctrl_nx;
wxTextCtrl* txtctrl_ny;
EightDouble xformvals;
static wxString combo_templatesStrings[];
static int combo_templatesCount;
static EightDouble combo_templatesValues[];
DECLARE_EVENT_TABLE()
};
class ASSDrawAboutDlg : public wxDialog
{
public:
ASSDrawAboutDlg(ASSDrawFrame *parent, unsigned timeout = 0);
virtual ~ASSDrawAboutDlg();
virtual void OnURL(wxHtmlLinkEvent &event);
virtual int ShowModal();
virtual void OnTimeout(wxTimerEvent& event);
virtual void OnMouseEnterWindow(wxMouseEvent& event);
protected:
wxTimer timer;
wxHtmlWindow *htmlwin;
const unsigned time_out;
};
class BigStaticBitmapCtrl : public wxPanel
{
public:
BigStaticBitmapCtrl(wxWindow *parent, wxBitmap bmap, wxColour bgcol, wxWindow *todrag = NULL);
virtual ~BigStaticBitmapCtrl();
virtual void OnPaint(wxPaintEvent& event);
virtual void OnMouseLeftDown(wxMouseEvent &event);
virtual void OnMouseLeftUp(wxMouseEvent &event);
virtual void OnMouseMove(wxMouseEvent &event);
protected:
wxBitmap bitmap;
wxBrush bgbrush;
wxWindow *window_to_drag;
wxPoint dragpoint, wndpos;
DECLARE_EVENT_TABLE()
};

749
assdraw/src/engine.cpp Normal file
View File

@ -0,0 +1,749 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////////
// Name: engine.cpp
// Purpose: ASSDraw drawing engine
// Author: ai-chan
// Created: 08/26/06
// Copyright: (c) ai-chan
// Licence: 3-clause BSD
///////////////////////////////////////////////////////////////////////////////
#include "engine.hpp" // the header
#include "cmd.hpp" // we need the drawing command classes declaration
#include <wx/tokenzr.h> // we use string tokenizer
#include <vector> // ok, we use vector too
#include <stdio.h>
#include <algorithm>
// ----------------------------------------------------------------------------
// Point
// ----------------------------------------------------------------------------
// constructor
Point::Point ( int _x, int _y, PointSystem* ps, POINTTYPE t, DrawCmd* cmd, unsigned n )
{
x_ = _x;
y_ = _y;
pointsys = ps;
cmd_main = cmd;
cmd_next = NULL;
type = t;
isselected = false;
num = n;
}
// setters
void Point::setXY( int _x, int _y)
{
x_ = _x;
y_ = _y;
}
// simply returns true if px and py are the coordinate values
bool Point::IsAt( int px, int py )
{
return (x_ == px && y_ == py );
}
// convert this point to wxPoint using scale and originx, originy
wxPoint Point::ToWxPoint ( bool useorigin )
{
if (useorigin)
return pointsys->ToWxPoint( x_, y_ );
else
return *(new wxPoint(x_ * (int) pointsys->scale, y_ * (int) pointsys->scale ));
}
// check if wxpoint is nearby this point
bool Point::CheckWxPoint ( wxPoint wxpoint )
{
wxPoint p = ToWxPoint();
int cx, cy;
pointsys->FromWxPoint( wxpoint, cx, cy );
//delete &p;
return (x_ == cx && y_ == cy );
}
// ----------------------------------------------------------------------------
// DrawCmd
// ----------------------------------------------------------------------------
// constructor
DrawCmd::DrawCmd ( int x, int y, PointSystem *ps, DrawCmd *pv )
{
m_point = new Point ( x, y, ps, MP, this );
m_point->cmd_main = this;
prev = pv;
dobreak = false;
invisible = false;
}
// destructor
DrawCmd::~DrawCmd ( )
{
if (m_point)
delete m_point;
for (PointList::iterator iter_cpoint = controlpoints.begin();
iter_cpoint != controlpoints.end(); iter_cpoint++)
delete (*iter_cpoint);
}
// ----------------------------------------------------------------------------
// ASSDrawEngine
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(ASSDrawEngine, GUI::AGGWindow)
EVT_PAINT (ASSDrawEngine::OnPaint)
END_EVENT_TABLE()
// constructor
ASSDrawEngine::ASSDrawEngine( wxWindow *parent, int extraflags )
: GUI::AGGWindow(parent, -1, wxDefaultPosition, wxDefaultSize,
wxNO_FULL_REPAINT_ON_RESIZE | extraflags )
{
pointsys = new PointSystem(1, 0, 0) ;
refresh_called = false;
fitviewpoint_hmargin = 10;
fitviewpoint_vmargin = 10;
setfitviewpoint = false;
rgba_shape = agg::rgba(0,0,1);
color_bg = PixelFormat::AGGType::color_type(255, 255, 255);
drawcmdset = wxT("m n l b s p c _"); //the spaces and underscore are in there for a reason, guess?
ResetEngine();
}
ASSDrawEngine::~ASSDrawEngine()
{
ResetEngine ( false );
delete pointsys;
}
// parse ASS draw commands; returns the number of parsed commands
int ASSDrawEngine::ParseASS ( wxString str )
{
ResetEngine( false );
str.Replace(_T("\t"), _T(""));
str.Replace(_T("\r"), _T(""));
str.Replace(_T("\n"), _T(""));
str = str.Lower() + wxT(" _ _");
// we don't use regex because the pattern is too simple
wxStringTokenizer tkz( str, wxT(" ") );
wxString currcmd(wxT(""));
std::vector<int> val;
wxString token;
long tmp_int;
bool n_collected = false;
DrawCmd_S *s_command = NULL;
wxPoint tmp_n_pnt;
while ( tkz.HasMoreTokens() )
{
token = tkz.GetNextToken();
if ( drawcmdset.Find(token) > -1 )
{
bool done;
do {
done = true;
// N
if (currcmd.IsSameAs(wxT("n")) && val.size() >= 2)
{
tmp_n_pnt.x = val[0], tmp_n_pnt.y = val[1];
n_collected = true;
}
else if(n_collected)
{
AppendCmd ( L, tmp_n_pnt.x, tmp_n_pnt.y );
n_collected = false;
}
if (s_command != NULL)
{
bool ends = true;
if (currcmd.IsSameAs(wxT("p"))&& val.size() >= 2)
{
s_command->m_point->type = CP;
s_command->m_point->num = s_command->controlpoints.size() + 1;
s_command->controlpoints.push_back(s_command->m_point);
s_command->m_point = new Point(val[0], val[1], pointsys, MP, s_command);
ends = false;
}
else if (currcmd.IsSameAs(wxT("c")))
s_command->closed = true;
if (ends)
{
AppendCmd(s_command);
s_command = NULL;
}
}
// M
if (currcmd.IsSameAs(wxT("m")) && val.size() >= 2)
AppendCmd ( M, val[0], val[1] );
// L
if (currcmd.IsSameAs(wxT("l")) && val.size() >= 2)
{
AppendCmd ( L, val[0], val[1] );
val.erase(val.begin(), val.begin()+2);
// L is greedy
if (val.size() >= 2)
done = false;
}
// B
if (currcmd.IsSameAs(wxT("b")) && val.size() >= 6)
{
AppendCmd ( new DrawCmd_B(val[4], val[5], val[0], val[1],
val[2], val[3], pointsys, LastCmd()) );
val.erase(val.begin(), val.begin()+6);
// so is B
if (val.size() >= 6)
done = false;
}
// S
if (currcmd.IsSameAs(wxT("s")) && val.size() >= 6)
{
int num = (val.size() / 2) * 2;
std::vector<int> val2;
int i = 0;
for (; i < num - 2; i++)
val2.push_back(val[i]);
s_command = new DrawCmd_S(val[num - 2], val[num - 1], val2, pointsys, LastCmd());
}
// more to come later
} while (!done);
val.clear();
currcmd = token;
}
else if (token.ToLong( &tmp_int ))
{
val.push_back( (int) tmp_int );
}
}
return (int) cmds.size();
}
// generate ASS draw commands
wxString ASSDrawEngine::GenerateASS ( )
{
wxString output = _T("");
for (DrawCmdList::iterator iterate = cmds.begin(); iterate != cmds.end(); iterate++)
output = output + (*iterate)->ToString() + _T(" ");
return output;
}
// reset; delete all points and add a new M(0,0)
void ASSDrawEngine::ResetEngine()
{
ResetEngine(true);
}
// reset; delete all points and add a new M(0,0) if addM == true
void ASSDrawEngine::ResetEngine( bool addM )
{
for (DrawCmdList::iterator iterate = cmds.begin(); iterate != cmds.end(); iterate++)
delete (*iterate);
cmds.clear();
if (addM) AppendCmd( M, 0, 0 );
}
// Create draw command of type 'type' and m_point (x, y), append to the
// list and return it
DrawCmd* ASSDrawEngine::AppendCmd ( CMDTYPE type, int x, int y )
{
// use a variation of this method
return AppendCmd( NewCmd( type, x, y ) );
}
// Append draw command
DrawCmd* ASSDrawEngine::AppendCmd ( DrawCmd* cmd )
{
// no NULL command!
if (cmd == NULL) return NULL;
// set dependency of this command on the m_point of the last command
if (!cmds.empty())
ConnectSubsequentCmds( cmds.back(), cmd );
else
{
// since this is the first command, if it's not an M make it into one
if (cmd->type != M)
cmd = NewCmd( M, cmd->m_point->x(), cmd->m_point->y() );
ConnectSubsequentCmds( NULL, cmd );
}
// put it in the list
cmds.push_back( cmd );
return cmd;
}
// create draw command of type 'type' and m_point (x, y), insert to the
// list after the _cmd and return it
DrawCmd* ASSDrawEngine::InsertCmd ( CMDTYPE type, int x, int y, DrawCmd* _cmd )
{
// prepare the new DrawCmd
DrawCmd* c = NewCmd( type, x, y );
// use a variation of this method
InsertCmd( c, _cmd );
return NULL;
}
// insert draw command cmd after _cmd
void ASSDrawEngine::InsertCmd ( DrawCmd* cmd, DrawCmd* _cmd )
{
DrawCmdList::iterator iterate = cmds.begin();
for (; iterate != cmds.end() && *iterate != _cmd; iterate++)
{
// do nothing
}
if (iterate == cmds.end())
{
AppendCmd( cmd );
}
else
{
iterate++;
if (iterate != cmds.end())
{
ConnectSubsequentCmds( cmd, (*iterate) );
}
cmds.insert( iterate, cmd );
ConnectSubsequentCmds( _cmd, cmd );
}
}
DrawCmd* ASSDrawEngine::NewCmd ( CMDTYPE type, int x, int y )
{
DrawCmd* c = NULL;
switch (type)
{
case M:
c = new DrawCmd_M(x, y, pointsys, LastCmd());
break;
case L:
c = new DrawCmd_L(x, y, pointsys, LastCmd());
break;
case B:
c = new DrawCmd_B(x, y, pointsys, LastCmd());
break;
case S:
c = new DrawCmd_S(x, y, pointsys, LastCmd());
break;
}
return c;
}
// returns the iterator for the list
DrawCmdList::iterator ASSDrawEngine::Iterator ( )
{
return cmds.begin();
}
// returns the 'end' iterator for the list
DrawCmdList::iterator ASSDrawEngine::IteratorEnd ( )
{
return cmds.end();
}
// returns the last command in the list
DrawCmd* ASSDrawEngine::LastCmd ()
{
if (cmds.size() == 0)
return NULL;
else
return cmds.back();
}
// move all points by relative amount of x, y coordinates
void ASSDrawEngine::MovePoints ( int x, int y )
{
DrawCmdList::iterator iterate = cmds.begin();
PointList::iterator iterate2;
for (; iterate != cmds.end(); iterate++)
{
(*iterate)->m_point->setXY( (*iterate)->m_point->x() + x, (*iterate)->m_point->y() + y );
for (iterate2 = (*iterate)->controlpoints.begin();
iterate2 != (*iterate)->controlpoints.end(); iterate2++)
{
(*iterate2)->setXY( (*iterate2)->x() + x, (*iterate2)->y() + y );
}
}
}
// transform all points using the calculation:
// | (m11) (m12) | x | (x - mx) | + | nx |
// | (m21) (m22) | | (y - my) | | ny |
void ASSDrawEngine::Transform( float m11, float m12, float m21, float m22,
float mx, float my, float nx, float ny )
{
DrawCmdList::iterator iterate = cmds.begin();
PointList::iterator iterate2;
float x, y;
for (; iterate != cmds.end(); iterate++)
{
x = ((float) (*iterate)->m_point->x()) - mx;
y = ((float) (*iterate)->m_point->y()) - my;
(*iterate)->m_point->setXY((int) (x * m11 + y * m12 + nx), (int) (x * m21 + y * m22 + ny) );
for (iterate2 = (*iterate)->controlpoints.begin();
iterate2 != (*iterate)->controlpoints.end(); iterate2++)
{
x = ((float) (*iterate2)->x()) - mx;
y = ((float) (*iterate2)->y()) - my;
(*iterate2)->setXY((int) (x * m11 + y * m12 + nx), (int) (x * m21 + y * m22 + ny) );
}
}
}
// returns some DrawCmd if its m_point = (x, y)
DrawCmd* ASSDrawEngine::PointAt ( int x, int y )
{
DrawCmd* c = NULL;
DrawCmdList::iterator iterate = cmds.begin();
for (; iterate != cmds.end(); iterate++)
{
if ( (*iterate)->m_point->IsAt( x, y ) )
c = (*iterate);
}
//delete &iterate;
return c;
}
// returns some DrawCmd if one of its control point = (x, y)
// also set &point to refer to that control point
DrawCmd* ASSDrawEngine::ControlAt ( int x, int y, Point* &point )
{
DrawCmd* c = NULL;
point = NULL;
DrawCmdList::iterator cmd_iterator = cmds.begin();
PointList::iterator pnt_iterator;
PointList::iterator end;
for (; cmd_iterator != cmds.end(); cmd_iterator++)
{
pnt_iterator = (*cmd_iterator)->controlpoints.begin();
end = (*cmd_iterator)->controlpoints.end();
for (; pnt_iterator != end; pnt_iterator++)
{
if ( (*pnt_iterator)->IsAt( x, y ) )
{
c = (*cmd_iterator);
point = (*pnt_iterator);
}
}
}
return c;
}
// attempts to delete a commmand, returns true|false if successful|fail
bool ASSDrawEngine::DeleteCommand ( DrawCmd* cmd )
{
DrawCmdList::iterator iterate = cmds.begin();
// can't delete the first command without deleting other commands first
if ( cmd == (*iterate) && cmds.size() > 1) return false;
DrawCmd* lastiter = NULL;
for (; iterate != cmds.end(); iterate++)
{
if ( cmd == (*iterate) )
{
iterate++;
DrawCmd* nxt = (iterate != cmds.end()? (*iterate):NULL);
ConnectSubsequentCmds( lastiter, nxt );
iterate--;
cmds.erase( iterate );
delete cmd;
break;
}
else
lastiter = (*iterate);
}
return true;
}
// set stuff to connect two drawing commands cmd1 and cmd2 such that
// cmd1 comes right before cmd2
void ASSDrawEngine::ConnectSubsequentCmds (DrawCmd* cmd1, DrawCmd* cmd2)
{
if (cmd1 != NULL)
{
cmd1->m_point->cmd_next = cmd2;
}
if (cmd2 != NULL)
{
cmd2->prev = cmd1;
}
}
void ASSDrawEngine::RefreshDisplay()
{
if (!refresh_called)
{
Refresh();
refresh_called = true;
}
}
void ASSDrawEngine::OnPaint(wxPaintEvent& event)
{
draw();
onPaint(event);
if (setfitviewpoint)
{
FitToViewPoint( fitviewpoint_hmargin, fitviewpoint_vmargin );
setfitviewpoint = false;
RefreshDisplay();
}
}
void ASSDrawEngine::draw()
{
refresh_called = false;
PixelFormat::AGGType pixf(rBuf);
RendererBase rbase(pixf);
RendererPrimitives rprim(rbase);
RendererSolid rsolid(rbase);
agg::trans_affine mtx;
ConstructPathsAndCurves(mtx, rm_path, rb_path, rm_curve);
rasterizer.reset();
update_rendered_bound_coords(true);
DoDraw(rbase, rprim, rsolid, mtx);
delete rm_path, rb_path, rm_curve;
}
void ASSDrawEngine::ConstructPathsAndCurves(agg::trans_affine& mtx,
trans_path*& _rm_path, trans_path*& _rb_path, agg::conv_curve<trans_path>*& _rm_curve)
{
mtx *= agg::trans_affine_scaling(pointsys->scale);
mtx *= agg::trans_affine_translation(pointsys->originx, pointsys->originy);
m_path.remove_all();
b_path.remove_all();
DrawCmdList::iterator ci = cmds.begin();
while (ci != cmds.end())
{
AddDrawCmdToAGGPathStorage(*ci, m_path);
AddDrawCmdToAGGPathStorage(*ci, b_path, CTRL_LN);
ci++;
}
_rm_path = new trans_path(m_path, mtx);
_rb_path = new trans_path(b_path, mtx);
_rm_curve = new agg::conv_curve<trans_path>(*rm_path);
}
void ASSDrawEngine::DoDraw( RendererBase& rbase, RendererPrimitives& rprim, RendererSolid& rsolid, agg::trans_affine& mtx )
{
Draw_Clear( rbase );
Draw_Draw( rbase, rprim, rsolid, mtx, rgba_shape );
}
void ASSDrawEngine::Draw_Clear( RendererBase& rbase )
{
rbase.clear(color_bg);
}
void ASSDrawEngine::Draw_Draw( RendererBase& rbase, RendererPrimitives& rprim, RendererSolid& rsolid, agg::trans_affine& mtx, agg::rgba color )
{
agg::conv_contour< agg::conv_curve< agg::conv_transform< agg::path_storage > > > contour(*rm_curve);
rasterizer.add_path(contour);
render_scanlines_aa_solid(rbase, color);
}
void ASSDrawEngine::AddDrawCmdToAGGPathStorage(DrawCmd* cmd, agg::path_storage& path, DRAWCMDMODE mode)
{
if (mode == HILITE && cmd->prev)
path.move_to(cmd->prev->m_point->x(), cmd->prev->m_point->y());
switch(cmd->type)
{
case M:
path.move_to(cmd->m_point->x(),cmd->m_point->y());
break;
case B:
if (cmd->initialized)
{
//path.move_to(cmd->prev->m_point->x(),cmd->prev->m_point->y());
PointList::iterator iterate = cmd->controlpoints.begin();
int x[2], y[2];
x[0] = (*iterate)->x();
y[0] = (*iterate)->y();
iterate++;
x[1] = (*iterate)->x();
y[1] = (*iterate)->y();
path.curve4(x[0], y[0], x[1], y[1], cmd->m_point->x(),cmd->m_point->y());
break;
}
case L:
if (mode == CTRL_LN)
path.move_to(cmd->m_point->x(),cmd->m_point->y());
else
path.line_to(cmd->m_point->x(),cmd->m_point->y());
break;
case S:
unsigned np = cmd->controlpoints.size();
agg::pod_array<double> m_polygon(np * 2);
unsigned _pn = 0;
PointList::iterator iterate = cmd->controlpoints.begin();
while (iterate != cmd->controlpoints.end())
{
m_polygon[_pn] = (*iterate)->x(); _pn++;
m_polygon[_pn] = (*iterate)->y(); _pn++;
iterate++;
}
//m_polygon[_pn++] = cmd->m_point->x();
//m_polygon[_pn++] = cmd->m_point->y();
//path.move_to(cmd->prev->m_point->x(),cmd->prev->m_point->y());
if (mode == CTRL_LN)
{
_pn = 0;
while (_pn < np * 2)
{
path.line_to((int) m_polygon[_pn],(int) m_polygon[_pn + 1]);
_pn += 2;
}
path.line_to(cmd->m_point->x(), cmd->m_point->y());
}
else
{
//path.line_to((int) m_polygon[0],(int) m_polygon[1]);
aggpolygon poly(&m_polygon[0], np, false, false);
agg::conv_bcspline<agg::simple_polygon_vertex_source> bspline(poly);
bspline.interpolation_step(0.01);
agg::path_storage npath;
npath.join_path(bspline);
path.join_path(npath);
if (mode == HILITE)
path.move_to((int) m_polygon[np * 2 - 2], (int) m_polygon[np * 2 - 1] );
path.line_to(cmd->m_point->x(), cmd->m_point->y());
}
break;
}
}
void ASSDrawEngine::render_scanlines_aa_solid(RendererBase& rbase, agg::rgba rgba, bool affectboundaries)
{
agg::render_scanlines_aa_solid(rasterizer, scanline, rbase, rgba);
if (affectboundaries) update_rendered_bound_coords();
}
void ASSDrawEngine::render_scanlines(RendererSolid& rsolid, bool affectboundaries)
{
agg::render_scanlines(rasterizer, scanline, rsolid);
if (affectboundaries) update_rendered_bound_coords();
}
void ASSDrawEngine::update_rendered_bound_coords(bool rendered_fresh)
{
int min_x = rasterizer.min_x();
int min_y = rasterizer.min_y();
int max_x = rasterizer.max_x();
int max_y = rasterizer.max_y();
if (min_x < rendered_min_x || rendered_fresh) rendered_min_x = min_x;
if (min_y < rendered_min_y || rendered_fresh) rendered_min_y = min_y;
if (max_x > rendered_max_x || rendered_fresh) rendered_max_x = max_x;
if (max_y > rendered_max_y || rendered_fresh) rendered_max_y = max_y;
}
void ASSDrawEngine::FitToViewPoint(int hmargin, int vmargin)
{
wxSize v = GetClientSize();
double wide = rendered_max_x - rendered_min_x;
double high = rendered_max_y - rendered_min_y;
double widthratio = (double) (v.x - hmargin * 2) / wide;
double heightratio = (double) (v.y - vmargin * 2) / high;
double ratio = (widthratio < heightratio? widthratio:heightratio);
pointsys->scale = pointsys->scale * ratio;
if (pointsys->scale < 0.01) pointsys->scale = 0.01;
double new_min_x = pointsys->originx + (rendered_min_x - pointsys->originx) * ratio;
double new_max_x = pointsys->originx + (rendered_max_x - pointsys->originx) * ratio;
pointsys->originx += (v.x - new_max_x + new_min_x) / 2 - new_min_x;
double new_min_y = pointsys->originy + (rendered_min_y - pointsys->originy) * ratio;
double new_max_y = pointsys->originy + (rendered_max_y - pointsys->originy) * ratio;
pointsys->originy += (v.y - new_max_y + new_min_y) / 2 - new_min_y;
RefreshDisplay();
}
void ASSDrawEngine::SetFitToViewPointOnNextPaint(int hmargin, int vmargin)
{
if (vmargin >= 0) fitviewpoint_vmargin = vmargin;
if (hmargin >= 0) fitviewpoint_hmargin = hmargin;
setfitviewpoint = true;
}
std::vector< bool > ASSDrawEngine::PrepareC1ContData()
{
std::vector< bool > out;
for (DrawCmdList::iterator it = cmds.begin(); it != cmds.end(); it++)
{
bool c1 = false;
if ((*it)->type == B)
{
DrawCmd_B *cmdb = static_cast<DrawCmd_B *>(*it);
c1 = cmdb->C1Cont;
}
out.push_back(c1);
}
return out;
}

406
assdraw/src/engine.hpp Normal file
View File

@ -0,0 +1,406 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////////
// Name: engine.hpp
// Purpose: header file for ASSDraw drawing engine
// Author: ai-chan
// Created: 08/26/06
// Copyright: (c) ai-chan
// Licence: 3-clause BSD
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "_common.hpp"
// we use these 2 standard libraries
#include <math.h>
#include <list>
#include <set>
#include <vector>
// agg support
#include "wxAGG/AGGWindow.h"
#include "agg_color_rgba.h"
#include "agg_rasterizer_scanline_aa.h"
#include "agg_scanline_p.h"
#include "agg_renderer_base.h"
#include "agg_renderer_primitives.h"
#include "agg_renderer_scanline.h"
#include "agg_path_storage.h"
#include "agg_curves.h"
#include "agg_conv_curve.h"
#include "agg_conv_contour.h"
#include "agg_conv_stroke.h"
#include "agg_conv_bcspline.h"
#include "agg_math.h"
#define DEFAULT_SCALE 10
// this header file declare the following classes
class DrawEngine;
class Point;
class PointSystem;
class DrawCmd;
typedef std::list<DrawCmd*> DrawCmdList;
typedef std::list<Point*> PointList;
typedef std::set<Point*> PointSet;
// Command type
enum CMDTYPE
{
M = 0,
N = 1,
L = 2,
B = 3,
S = 4,
P = 5,
C = 6
};
// Point type
enum POINTTYPE
{
MP, // main point
CP // control point
};
// A PointSystem is a centralized entity holding the parameters:
// scale, originx and originy, all of which are needed by Point
class PointSystem
{
public:
double scale, originx, originy;
PointSystem ( double sc = 1.0, double origx = 0.0, double origy = 0.0 )
{ Set( sc, origx, origy ); }
// set scale, originx and originy;
void Set( double sc, double origx, double origy )
{ scale = sc, originx = origx, originy = origy; }
wxRealPoint ToWxRealPoint ( double x, double y )
{ return wxRealPoint( originx + x * scale, originy + y * scale ); }
// given drawing command coordinates returns the wxPoint on the GUI
wxPoint ToWxPoint ( double x, double y )
{ return wxPoint( (int) (originx + x * scale), (int) (originy + y * scale) ); }
// given wxPoint on the GUI returns the nearest drawing command coords
void FromWxPoint ( int wxpx, int wxpy, int &x, int &y )
{
x = int( floor( ((double) wxpx - originx) / scale + 0.5 ) );
y = int( floor( ((double) wxpy - originy) / scale + 0.5 ) );
}
// given wxPoint on the GUI returns the nearest drawing command coords
void FromWxPoint ( wxPoint wxp, int &x, int &y )
{
FromWxPoint( wxp.x, wxp.y, x, y );
}
};
// The point class
// note: this actually refers to the x,y-coordinate in drawing commands,
// not the coordinate in the GUI
class Point
{
public:
POINTTYPE type;
PointSystem *pointsys;
// drawing commands that depend on this point
DrawCmd* cmd_main;
DrawCmd* cmd_next;
bool isselected;
unsigned num;
// constructor
//Point ( ) { cmd_main = NULL; cmd_next = NULL; }
// constructor
Point ( int _x, int _y, PointSystem* ps, POINTTYPE t, DrawCmd* cmd, unsigned n = 0 );
// getters
int x() { return x_; }
int y() { return y_; }
//set x and y
void setXY( int _x, int _y);
// simply returns true if px and py are the coordinate values
bool IsAt( int px, int py );
// convert this point to wxPoint using scale and originx, originy
wxPoint ToWxPoint () { return ToWxPoint(true); }
// convert this point to wxPoint using scale;
// also use originx and originy if useorigin = true
wxPoint ToWxPoint (bool useorigin);
// check if wxpoint is nearby this point
bool CheckWxPoint ( wxPoint wxpoint );
private:
int x_, y_;
};
// The base class for all draw commands
class DrawCmd
{
public:
CMDTYPE type;
// main point (almost every command has one)
// for B and S it's the last (destination) point
Point* m_point;
// other points than the main point
// subclasses must populate this list even if they define
// new variables for other points
PointList controlpoints;
// Linked list feature
DrawCmd *prev;
// Must set to true if the next command should NOT utilize this command
// for the drawing
bool dobreak;
// Set to true if invisible m_point (not drawn)
bool invisible;
// true if this DrawCmd has been initialized with Init(), false otherwise
// (initialized means that the control points have been generated)
bool initialized;
// -----------------------------------------------------------
// Constructor(s)
DrawCmd ( int x, int y, PointSystem *ps, DrawCmd *pv );
// Destructor
virtual ~DrawCmd ();
// Init the draw command (for example to generate the control points)
virtual void Init(unsigned n = 0) { initialized = true; }
virtual wxString ToString() { return wxT(""); }
};
class ASSDrawEngine: public GUI::AGGWindow
{
public:
ASSDrawEngine( wxWindow *parent, int extraflags = 0 );
// destructor
~ASSDrawEngine();
virtual void SetDrawCmdSet(wxString set) { drawcmdset = set; }
virtual void ResetEngine();
virtual void ResetEngine(bool addM);
virtual void RefreshDisplay();
void FitToViewPoint(int hmargin, int vmargin);
void SetFitToViewPointOnNextPaint(int hmargin = -1, int vmargin = -1);
PointSystem* _PointSystem() { return pointsys; }
// ASS draw commands; returns the number of parsed commands
virtual int ParseASS ( wxString str );
// generate ASS draw commands
virtual wxString GenerateASS ( );
// drawing
virtual void OnPaint(wxPaintEvent &event);
// -------------------- adding new commands ----------------------------
// create draw command of type 'type' and m_point (x, y), append to the
// list and return it
virtual DrawCmd* AppendCmd ( CMDTYPE type, int x, int y );
// append draw command
virtual DrawCmd* AppendCmd ( DrawCmd* cmd );
// create draw command of type 'type' and m_point (x, y), insert to the
// list after the _cmd and return it
virtual DrawCmd* InsertCmd ( CMDTYPE type, int x, int y, DrawCmd* _cmd );
// insert draw command cmd after _cmd
virtual void InsertCmd ( DrawCmd* cmd, DrawCmd* _cmd );
// Create new DrawCmd
DrawCmd* NewCmd ( CMDTYPE type, int x, int y );
// -------------------- read/modify commands ---------------------------
// returns the iterator for the list
virtual DrawCmdList::iterator Iterator ( );
// returns the 'end' iterator for the list
virtual DrawCmdList::iterator IteratorEnd ( );
// returns the last command in the list
virtual DrawCmd* LastCmd ();
// returns the total number of commands in the list
//virtual int CmdCount () { return cmds.size(); }
// move all points by relative amount of x, y coordinates
virtual void MovePoints ( int x, int y );
// transform all points using the calculation:
// | (m11) (m12) | x | (x - mx) | + | nx |
// | (m21) (m22) | | (y - my) | | ny |
virtual void Transform( float m11, float m12, float m21, float m22,
float mx, float my, float nx, float ny );
// returns some DrawCmd if its m_point = (x, y)
virtual DrawCmd* PointAt ( int x, int y );
// returns some DrawCmd if one of its control point = (x, y)
// also set &point to refer to that control point
virtual DrawCmd* ControlAt ( int x, int y, Point* &point );
// attempts to delete a commmand, returns true|false if successful|fail
virtual bool DeleteCommand ( DrawCmd* cmd );
agg::rgba rgba_shape;
PixelFormat::AGGType::color_type color_bg;
protected:
/// The AGG base renderer
typedef agg::renderer_base<PixelFormat::AGGType> RendererBase;
/// The AGG primitives renderer
typedef agg::renderer_primitives<RendererBase> RendererPrimitives;
/// The AGG solid renderer
typedef agg::renderer_scanline_aa_solid<RendererBase> RendererSolid;
enum DRAWCMDMODE {
NORMAL,
CTRL_LN,
HILITE
};
DrawCmdList cmds;
wxString drawcmdset;
PointSystem* pointsys;
// for FitToViewPoint feature
bool setfitviewpoint;
int fitviewpoint_vmargin, fitviewpoint_hmargin;
// AGG
agg::rasterizer_scanline_aa<> rasterizer; ///< Scanline rasterizer
agg::scanline_p8 scanline; ///< Scanline container
void render_scanlines_aa_solid(RendererBase& rbase, agg::rgba rbga, bool affectboundaries = true);
void render_scanlines(RendererSolid& rsolid, bool affectboundaries = true);
int rendered_min_x, rendered_min_y, rendered_max_x, rendered_max_y; //bounding coord of rendered shapes
void update_rendered_bound_coords(bool rendered_fresh = false);
typedef agg::conv_transform<agg::path_storage> trans_path;
agg::path_storage m_path, b_path;
trans_path *rm_path, *rb_path;
agg::conv_curve<trans_path> *rm_curve;
void draw();
virtual void ConstructPathsAndCurves(agg::trans_affine& mtx, trans_path*& _rm_path, trans_path*& _rb_path, agg::conv_curve<trans_path>*& _rm_curve);
virtual void DoDraw( RendererBase& rbase, RendererPrimitives& rprim, RendererSolid& rsolid, agg::trans_affine& mtx );
virtual void Draw_Clear( RendererBase& rbase );
virtual void Draw_Draw( RendererBase& rbase, RendererPrimitives& rprim, RendererSolid& rsolid, agg::trans_affine& mtx, agg::rgba color );
bool refresh_called;
// set stuff to connect two drawing commands cmd1 and cmd2 such that
// cmd1 comes right before cmd2
virtual void ConnectSubsequentCmds (DrawCmd* cmd1, DrawCmd* cmd2);
virtual void AddDrawCmdToAGGPathStorage(DrawCmd* cmd, agg::path_storage& path, DRAWCMDMODE mode = NORMAL);
virtual std::vector< bool > PrepareC1ContData();
DECLARE_EVENT_TABLE()
};
namespace agg
{
class simple_polygon_vertex_source
{
public:
simple_polygon_vertex_source(const double* polygon, unsigned np,
bool roundoff = false,
bool close = true) :
m_polygon(polygon),
m_num_points(np),
m_vertex(0),
m_roundoff(roundoff),
m_close(close)
{
}
void close(bool f) { m_close = f; }
bool close() const { return m_close; }
void rewind(unsigned)
{
m_vertex = 0;
}
unsigned vertex(double* x, double* y)
{
if(m_vertex > m_num_points) return path_cmd_stop;
if(m_vertex == m_num_points)
{
++m_vertex;
return path_cmd_end_poly | (m_close ? path_flags_close : 0);
}
*x = m_polygon[m_vertex * 2];
*y = m_polygon[m_vertex * 2 + 1];
if(m_roundoff)
{
*x = floor(*x) + 0.5;
*y = floor(*y) + 0.5;
}
++m_vertex;
return (m_vertex == 1) ? path_cmd_move_to : path_cmd_line_to;
}
private:
const double* m_polygon;
unsigned m_num_points;
unsigned m_vertex;
bool m_roundoff;
bool m_close;
};
};
typedef agg::simple_polygon_vertex_source aggpolygon;

113
assdraw/src/enums.hpp Normal file
View File

@ -0,0 +1,113 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
// enum for IDs of menus
enum {
MENU_DUMMY = 200,
MENU_CLEAR,
MENU_PREVIEW,
MENU_TRANSFORM,
MENU_LIBRARY,
MENU_HELP,
MENU_RESETPERSPECTIVE,
MENU_SETTINGS,
MENU_UNDO,
MENU_REDO,
MENU_PASTE,
MENU_BGIMG_LOAD,
MENU_BGIMG_ALPHA,
MENU_BGIMG_REMOVE,
MENU_RECENTER,
MENU_TBAR,
MENU_REPOS_TOPLEFT,
MENU_REPOS_TOPRIGHT,
MENU_REPOS_CENTER,
MENU_REPOS_BOTLEFT,
MENU_REPOS_BOTRIGHT,
MENU_BGIMG_RECENTER,
MENU_REPOS_BGTOPLEFT,
MENU_REPOS_BGTOPRIGHT,
MENU_REPOS_BGCENTER,
MENU_REPOS_BGBOTLEFT,
MENU_REPOS_BGBOTRIGHT,
MENU_DRC_LNTOBEZ,
MENU_DRC_C1CONTBEZ,
MENU_DRC_BEZTOLN,
MENU_DRC_MOVE00,
MENU_TB_ALL,
MENU_TB_NONE,
MENU_TB_DOCK,
MENU_TB_UNDOCK,
MENU_TB_DRAW,
MENU_TB_MODE,
MENU_TB_BGIMG
};
// enum for modes (i.e. create m, b, l etc or normal mode)
// also use as tools IDs
enum MODE
{
MODE_ARR = 100,
MODE_M = 101,
MODE_N = 102,
MODE_L = 103,
MODE_B = 104,
MODE_S = 105,
MODE_P = 106,
MODE_C = 107,
MODE_DEL = 108,
MODE_SCALEROTATE = 109,
MODE_NUT_BILINEAR = 110
};
// enum for IDs of other tools on the toolbar
enum {
TB_CLEAR = 111,
TB_EDITSRC = 112,
TB_PREVIEW = 113,
TB_TRANSFORM = 114,
TB_HELP = 115,
TB_ZOOMSLIDER = 116,
TB_BGALPHA_SLIDER = 117
};
enum DRAGMODETOOL
{
DRAG_DWG = 120,
DRAG_BGIMG = 121,
DRAG_BOTH = 122
};
struct DRAGMODE
{
bool drawing;
bool bgimg;
DRAGMODE() { drawing = true, bgimg = false; }
DRAGMODE(bool d, bool b) { drawing = d, bgimg = b; }
};

View File

@ -0,0 +1,94 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////////
// Name: include_once.hpp
// Purpose: A header file that is included exactly once for the whole code
// (supposed to be included by assdraw.cpp only)
// Put must-define-exactly-once codes here
// Author: ai-chan
// Created: 08/26/06
// Copyright: (c) ai-chan
// Licence: 3-clause BSD
///////////////////////////////////////////////////////////////////////////////
// tooltips
const wxString TIPS_CLEAR = wxT("Clear the canvas and create a new drawing");
const wxString TIPS_EDITSRC = wxT("Edit the source");
const wxString TIPS_PREVIEW = wxT("Draw the shapes without enlarged points and control points");
const wxString TIPS_TRANSFORM = wxT("Transform the drawing using matrix transformation");
const wxString TIPS_LIBRARY = wxT("Shapes library");
const wxString TIPS_HELP = wxT("Help! Help!");
const wxString TIPS_PASTE = wxT("Depending on what's in the clipboard, import as drawing commands or background");
const wxString TIPS_UNDO = wxT("Undo last action");
const wxString TIPS_REDO = wxT("Redo last undo");
const wxString TIPS_ARR = wxT("Drag mode");
const wxString TIPS_M = wxT("Draw M mode (Close current shape and move the virtual pen to a new point)");
const wxString TIPS_N = wxT("Draw N mode (Same as M but doesn't close the shape)");
const wxString TIPS_L = wxT("Draw L mode (Straight line)");
const wxString TIPS_B = wxT("Draw B mode (Cubic Bezier curve)");
const wxString TIPS_S = wxT("Draw S mode (Spline)");
const wxString TIPS_P = wxT("Draw P mode (Extends a spline with another point)");
const wxString TIPS_C = wxT("Draw C mode (Close the last spline)");
const wxString TIPS_DEL = wxT("Delete mode");
const wxString TIPS_NUTB = wxT("Bilinear transformation mode: Drag the vertices to distort the shape; Dragging an edge moves two adjacent vertices together");
const wxString TIPS_SCALEROTATE = wxT("Scale/Rotate mode: Drag a vertex or an edge to rescale the shape; Right-drag to rotate");
const wxString TIPS_DWG = wxT("Right-dragging pans drawing, mousewheel zooms in/out drawing");
const wxString TIPS_BGIMG = wxT("Right-dragging pans background, mousewheel zooms in/out background");
const wxString TIPS_BOTH = wxT("Right-dragging pans drawing & background, mousewheel zooms in/out drawing & background");
const wxString TBNAME_DRAW = wxT("Canvas");
const wxString TBNAME_MODE = wxT("Drawing mode");
const wxString TBNAME_BGIMG = wxT("Background");
const wxString TBNAME_ZOOM = wxT("Zoom");
wxString ASSDrawTransformDlg::combo_templatesStrings[] = {
_("<Select>"),
_("Move 5 units down"),
_("Move 5 units right"),
_("Rotate 90° clockwise at (1, 2)"),
_("Rotate 90° counterclockwise at (-1, 2)"),
_("Rotate 180° at (0, 0)"),
_("Flip horizontally at X = 4"),
_("Flip vertically at Y = 3"),
_("Scale up horizontally by a factor of 2"),
_("Scale up vertically by a factor of 3")
};
int ASSDrawTransformDlg::combo_templatesCount = 10;
EightDouble ASSDrawTransformDlg::combo_templatesValues[] = {
{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f }, //<Select>
{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 5.0f }, //5 units down
{ 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 5.0f, 0.0f }, //5 units left
{ 0.0f, -1.0f, 1.0f, 0.0f, 1.0f, 2.0f, 1.0f, 2.0f }, //90 CW (1,2)
{ 0.0f, 1.0f, -1.0f, 0.0f, -1.0f, 2.0f, -1.0f, 2.0f }, //90 CCW, (-1,2)
{ -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f }, //180 (0,0)
{ -1.0f, 0.0f, 0.0f, 1.0f, 4.0f, 0.0f, 4.0f, 0.0f }, //Flip X = 4
{ 1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 3.0f, 0.0f, 3.0f }, //Flip Y = 3
{ 2.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f }, //Scale X * 2
{ 1.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f } //Scale Y * 3
};

259
assdraw/src/library.cpp Normal file
View File

@ -0,0 +1,259 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "assdraw.hpp"
#include "library.hpp"
#include <wx/clipbrd.h>
BEGIN_EVENT_TABLE(ASSDrawShapePreview, ASSDrawEngine)
EVT_SIZE(ASSDrawShapePreview::OnSize)
END_EVENT_TABLE()
ASSDrawShapePreview::ASSDrawShapePreview( wxWindow *parent, ASSDrawShapeLibrary *_shapelib, wxString initialcmds )
: ASSDrawEngine(parent, wxSIMPLE_BORDER)
{
shapelib = _shapelib;
if (ParseASS(initialcmds) > 0)
SetFitToViewPointOnNextPaint(5, 5);
cb = new wxCheckBox(this, wxID_ANY, "");
}
void ASSDrawShapePreview::OnSize(wxSizeEvent& event)
{
return;
wxSize siz = event.GetSize();
if (shapelib->layout == HORIZONTAL)
SetSize(siz.x, siz.x);
else
SetSize(siz.y, siz.y);
SetFitToViewPointOnNextPaint(10, 10);
}
BEGIN_EVENT_TABLE(ASSDrawShapeLibrary, wxScrolledWindow)
EVT_SIZE(ASSDrawShapeLibrary::OnSize)
EVT_MENU_RANGE(MENU_RANGE_START, MENU_RANGE_END, ASSDrawShapeLibrary::OnPopupMenuClicked)
EVT_TOOL(TOOL_SAVE, ASSDrawShapeLibrary::SaveShapeFromCanvas)
EVT_TOOL_RANGE(TOOL_CHECK, TOOL_UNCHECK, ASSDrawShapeLibrary::CheckUncheckAllPreviews)
EVT_TOOL(TOOL_DELETE, ASSDrawShapeLibrary::DeleteChecked)
END_EVENT_TABLE()
ASSDrawShapeLibrary::ASSDrawShapeLibrary( wxWindow *parent, ASSDrawFrame *frame )
: wxScrolledWindow(parent, wxID_ANY)
{
m_frame = frame;
//sizer = NULL;
layout = VERTICAL;
wxToolBar *tbar = new wxToolBar(this, wxID_ANY, __DPDS__ , wxTB_HORIZONTAL | wxNO_BORDER | wxTB_FLAT | wxTB_NODIVIDER);
tbar->SetMargins(0, 3);
tbar->AddTool(TOOL_SAVE, wxBITMAP(add), "Save canvas");
tbar->AddSeparator();
tbar->AddTool(TOOL_CHECK, wxBITMAP(check), "Select all");
tbar->AddTool(TOOL_UNCHECK, wxBITMAP(uncheck), "Select none");
tbar->AddTool(TOOL_DELETE, wxBITMAP(delcross), "Delete selected");
libarea = new wxScrolledWindow(this, wxID_ANY, __DPDS__ , wxScrolledWindowStyle | wxSIMPLE_BORDER);
libarea->SetBackgroundColour(wxColour(0xFF, 0xFF, 0x99));
sizer = new wxFlexGridSizer(0, 1, 0, 0);
((wxFlexGridSizer*) sizer)->AddGrowableCol(0);
libarea->SetSizer(sizer);
libarea->SetScrollbars(20, 20, 50, 50);
libsizer = new wxFlexGridSizer(2, 1, 0, 0);
libsizer->AddGrowableCol(0);
libsizer->AddGrowableRow(1);
libsizer->Add(tbar, 0, wxBOTTOM, 2);
libsizer->Add(libarea,1,wxEXPAND);
tbar->Realize();
libsizer->Layout();
SetSizer(libsizer);
}
void ASSDrawShapeLibrary::OnSize(wxSizeEvent& event)
{
if (sizer == NULL || sizer->GetChildren().size() == 0) return;
wxSize siz = GetClientSize();
libsizer->SetDimension(0, 0, siz.x, siz.y);
UpdatePreviewDisplays();
}
ASSDrawShapePreview* ASSDrawShapeLibrary::AddShapePreview(wxString cmds, bool addtotop)
{
ASSDrawShapePreview *prev = new ASSDrawShapePreview(libarea, this, cmds);
prev->Connect(wxEVT_LEFT_DCLICK, wxMouseEventHandler(ASSDrawShapeLibrary::OnMouseLeftDClick), NULL, this);
prev->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(ASSDrawShapeLibrary::OnMouseRightClick), NULL, this);
ASSDrawFrame::wxColourToAggRGBA(m_frame->colors.library_shape, prev->rgba_shape);
if (addtotop)
sizer->Insert(0, prev, 1, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 5);
else
sizer->Add(prev, 1, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 5);
UpdatePreviewDisplays();
return prev;
}
void ASSDrawShapeLibrary::UpdatePreviewDisplays()
{
wxSize siz = GetClientSize();
int dim = siz.x - 15;
libarea->Show(false);
wxwxSizerItemListNode *node = sizer->GetChildren().GetFirst();
while (node != NULL)
{
ASSDrawShapePreview *shprvw = (ASSDrawShapePreview *) node->GetData()->GetWindow();
shprvw->SetSize(dim, dim);
sizer->SetItemMinSize(shprvw, dim - 20, dim - 20);
shprvw->SetFitToViewPointOnNextPaint(10, 10);
shprvw->Refresh();
node = node->GetNext();
}
sizer->Layout();
sizer->FitInside(libarea);
libarea->Show(true);
}
void ASSDrawShapeLibrary::OnMouseLeftDClick(wxMouseEvent &event)
{
ASSDrawShapePreview *preview = (ASSDrawShapePreview *) event.GetEventObject();
LoadToCanvas(preview);
}
void ASSDrawShapeLibrary::OnMouseRightClick(wxMouseEvent &event)
{
ASSDrawShapePreview *prev = (ASSDrawShapePreview *) event.GetEventObject();
if (prev && prev->shapelib == this)
{
activepreview = prev;
wxMenu *menu = new wxMenu;
wxMenuItem *menuload = new wxMenuItem(menu, MENU_LOAD, wxT("Load to canvas"));
wxFont f = menuload->GetFont();
f.SetWeight(wxFONTWEIGHT_BOLD);
menuload->SetFont(f);
menu->Append(menuload);
//menu->Append(MENU_LOAD, wxT("Load to canvas"))->GetFont().SetWeight(wxFONTWEIGHT_BOLD);
menu->Append(MENU_COPYCLIPBOARD, wxT("Copy commands to clipboard"));
menu->Append(MENU_SAVECANVAS, wxT("Save canvas here"));
wxMenu *submenu = new wxMenu;
submenu->Append(MENU_DELETE, wxT("Confirm delete?"));
menu->Append(MENU_DUMMY, wxT("Delete from library"), submenu);
PopupMenu(menu);
delete menu;
}
}
void ASSDrawShapeLibrary::OnPopupMenuClicked(wxCommandEvent &event)
{
int id = event.GetId();
switch(id)
{
case MENU_LOAD:
LoadToCanvas(activepreview);
break;
case MENU_COPYCLIPBOARD:
if (wxTheClipboard->Open())
{
if (wxTheClipboard->IsSupported( wxDF_TEXT ))
{
wxTheClipboard->SetData( new wxTextDataObject( activepreview->GenerateASS() ) );
}
wxTheClipboard->Close();
}
break;
case MENU_SAVECANVAS:
activepreview->ParseASS(m_frame->m_canvas->GenerateASS());
activepreview->SetFitToViewPointOnNextPaint();
activepreview->RefreshDisplay();
break;
case MENU_DELETE:
sizer->Detach(activepreview);
activepreview->Show(false);
activepreview->Destroy();
UpdatePreviewDisplays();
Refresh();
break;
}
}
void ASSDrawShapeLibrary::SaveShapeFromCanvas(wxCommandEvent& WXUNUSED(event))
{
AddShapePreview(m_frame->m_canvas->GenerateASS(), true);
}
void ASSDrawShapeLibrary::CheckUncheckAllPreviews(wxCommandEvent &event)
{
bool checked = event.GetId() == TOOL_CHECK;
wxwxSizerItemListNode *node = sizer->GetChildren().GetFirst();
while (node != NULL)
{
ASSDrawShapePreview *shprvw = (ASSDrawShapePreview *) node->GetData()->GetWindow();
shprvw->cb->SetValue(checked);
node = node->GetNext();
}
}
void ASSDrawShapeLibrary::DeleteChecked(wxCommandEvent& WXUNUSED(event))
{
wxwxSizerItemListNode *node = sizer->GetChildren().GetFirst();
while (node != NULL)
{
ASSDrawShapePreview *shprvw = (ASSDrawShapePreview *) node->GetData()->GetWindow();
if (shprvw->cb->GetValue())
{
sizer->Detach(shprvw);
shprvw->Show(false);
shprvw->Destroy();
}
node = node->GetNext();
}
UpdatePreviewDisplays();
Refresh();
}
std::vector< ASSDrawShapePreview *> ASSDrawShapeLibrary::GetShapePreviews()
{
std::vector< ASSDrawShapePreview *> out;
wxwxSizerItemListNode *node = sizer->GetChildren().GetFirst();
while (node != NULL)
{
ASSDrawShapePreview *shprvw = (ASSDrawShapePreview *) node->GetData()->GetWindow();
out.push_back(shprvw);
node = node->GetNext();
}
return out;
}
void ASSDrawShapeLibrary::LoadToCanvas(ASSDrawShapePreview *preview)
{
m_frame->m_canvas->AddUndo("Load shape from library");
m_frame->m_canvas->ParseASS(preview->GenerateASS());
m_frame->m_canvas->RefreshDisplay();
m_frame->m_canvas->RefreshUndocmds();
m_frame->UpdateFrameUI();
}

88
assdraw/src/library.hpp Normal file
View File

@ -0,0 +1,88 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "engine.hpp"
#include <wx/scrolwin.h>
class ASSDrawFrame;
class ASSDrawShapeLibrary;
enum LIBLAYOUT { VERTICAL, HORIZONTAL };
enum {
MENU_RANGE_START = 450,
MENU_LOAD,
MENU_COPYCLIPBOARD,
MENU_SAVECANVAS,
MENU_DELETE,
MENU_RANGE_END,
TOOL_SAVE,
TOOL_CHECK,
TOOL_UNCHECK,
TOOL_DELETE
};
class ASSDrawShapePreview : public ASSDrawEngine
{
protected:
ASSDrawShapePreview( wxWindow *parent, ASSDrawShapeLibrary *shapelib, wxString initialcmds = _T(""));
virtual void OnSize(wxSizeEvent& event);
ASSDrawShapeLibrary *shapelib;
wxCheckBox *cb;
DECLARE_EVENT_TABLE()
friend class ASSDrawShapeLibrary;
};
class ASSDrawShapeLibrary : public wxScrolledWindow
{
public:
ASSDrawShapeLibrary( wxWindow *parent, ASSDrawFrame *frame );
virtual ASSDrawShapePreview* AddShapePreview(wxString cmds, bool addtotop = false);
virtual void OnSize(wxSizeEvent& event);
virtual void OnMouseLeftDClick(wxMouseEvent &event);
virtual void OnMouseRightClick(wxMouseEvent &event);
virtual void OnPopupMenuClicked(wxCommandEvent &event);
virtual void SaveShapeFromCanvas(wxCommandEvent& WXUNUSED(event));
virtual void CheckUncheckAllPreviews(wxCommandEvent &event);
virtual void DeleteChecked(wxCommandEvent& WXUNUSED(event));
virtual void UpdatePreviewDisplays();
virtual std::vector< ASSDrawShapePreview *> GetShapePreviews();
virtual void LoadToCanvas(ASSDrawShapePreview *preview);
wxScrolledWindow* libarea;
wxFlexGridSizer *libsizer;
wxSizer* sizer;
LIBLAYOUT layout;
protected:
ASSDrawFrame *m_frame;
ASSDrawShapePreview *activepreview;
DECLARE_EVENT_TABLE()
};

15
assdraw/src/resource.h Normal file
View File

@ -0,0 +1,15 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by assdraw.rc
//
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

223
assdraw/src/settings.cpp Normal file
View File

@ -0,0 +1,223 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
///////////////////////////////////////////////////////////////////////////////
// Name: settings.cpp
// Purpose: settings property grid
// Author: ai-chan
// Created: 08/26/06
// Copyright: (c) ai-chan
// Licence: 3-clause BSD
///////////////////////////////////////////////////////////////////////////////
#include "assdraw.hpp"
#include "settings.hpp"
DEFINE_EVENT_TYPE(wxEVT_SETTINGS_CHANGED)
// ----------------------------------------------------------------------------
// ASSDrawSettingsDialog
// ----------------------------------------------------------------------------
ASSDrawSettingsDialog::ASSDrawSettingsDialog(wxWindow *parent, ASSDrawFrame *frame, int id)
: wxPanel(parent, id)
{
m_frame = frame;
propgrid = NULL;
}
void ASSDrawSettingsDialog::Init()
{
propgrid = new wxPropertyGrid(this,
wxID_ANY,
wxDefaultPosition,
wxDefaultSize,
//wxPG_BOLD_MODIFIED |
//wxPG_SPLITTER_AUTO_CENTER |
//wxPG_AUTO_SORT |
//wxPG_HIDE_MARGIN | wxPG_STATIC_SPLITTER |
wxPG_TOOLTIPS |
//wxPG_NOCATEGORIES |
wxTAB_TRAVERSAL //|
//wxSUNKEN_BORDER
);
#define APPENDCOLOURPROP(pgid, label, color) pgid = propgrid->Append( wxColourProperty(wxT(label), wxPG_LABEL, color) );
#define APPENDUINTPROP(pgid, label, uint) \
pgid = propgrid->Append( wxUIntProperty(wxT(label), wxPG_LABEL, uint) ); \
propgrid->SetPropertyValidator( pgid, validator );
#define APPENDBOOLPROP(pgid, label, boolvar) \
pgid = propgrid->Append( wxBoolProperty ( wxT(label), wxPG_LABEL, boolvar ) ); \
propgrid->SetPropertyAttribute( pgid, wxPG_BOOL_USE_CHECKBOX, (long)1 );
wxLongPropertyValidator validator(0x0,0xFF);
propgrid->Append( wxPropertyCategory(wxT("Appearance"),wxPG_LABEL) );
APPENDCOLOURPROP(colors_canvas_bg_pgid, "Canvas", m_frame->colors.canvas_bg)
APPENDCOLOURPROP(colors_canvas_shape_normal_pgid, "Drawing", m_frame->colors.canvas_shape_normal)
APPENDUINTPROP(alphas_canvas_shape_normal_pgid, "Drawing @", m_frame->alphas.canvas_shape_normal)
APPENDCOLOURPROP(colors_canvas_shape_preview_pgid, "Preview", m_frame->colors.canvas_shape_preview)
APPENDUINTPROP(alphas_canvas_shape_preview_pgid, "Preview @", m_frame->alphas.canvas_shape_preview)
APPENDCOLOURPROP(colors_canvas_shape_outline_pgid, "Outline", m_frame->colors.canvas_shape_outline)
APPENDUINTPROP(alphas_canvas_shape_outline_pgid, "Outline @", m_frame->alphas.canvas_shape_outline)
APPENDCOLOURPROP(colors_canvas_shape_guideline_pgid, "Control lines", m_frame->colors.canvas_shape_guideline)
APPENDUINTPROP(alphas_canvas_shape_guideline_pgid, "Control lines @", m_frame->alphas.canvas_shape_guideline)
APPENDCOLOURPROP(colors_canvas_shape_mainpoint_pgid, "Points", m_frame->colors.canvas_shape_mainpoint)
APPENDUINTPROP(alphas_canvas_shape_mainpoint_pgid, "Points @", m_frame->alphas.canvas_shape_mainpoint)
APPENDCOLOURPROP(colors_canvas_shape_controlpoint_pgid, "Control points", m_frame->colors.canvas_shape_controlpoint)
APPENDUINTPROP(alphas_canvas_shape_controlpoint_pgid, "Control points @", m_frame->alphas.canvas_shape_controlpoint)
APPENDCOLOURPROP(colors_canvas_shape_selectpoint_pgid, "Selected points", m_frame->colors.canvas_shape_selectpoint)
APPENDUINTPROP(alphas_canvas_shape_selectpoint_pgid, "Selected points @", m_frame->alphas.canvas_shape_selectpoint)
APPENDCOLOURPROP(colors_library_libarea_pgid, "Library", m_frame->colors.library_libarea)
APPENDCOLOURPROP(colors_library_shape_pgid, "Library shapes", m_frame->colors.library_shape)
APPENDCOLOURPROP(colors_origin_pgid, "Origin", m_frame->colors.origin)
APPENDUINTPROP(sizes_origincross_pgid, "Origin cross size", m_frame->sizes.origincross)
APPENDCOLOURPROP(colors_ruler_h_pgid, "H ruler", m_frame->colors.ruler_h)
APPENDCOLOURPROP(colors_ruler_v_pgid, "V ruler", m_frame->colors.ruler_v)
propgrid->Append( wxPropertyCategory(wxT("Behaviors"),wxPG_LABEL) );
APPENDBOOLPROP(behaviors_capitalizecmds_pgid, "Capitalize commands", m_frame->behaviors.capitalizecmds);
APPENDBOOLPROP(behaviors_autoaskimgopac_pgid, "Ask for image opacity", m_frame->behaviors.autoaskimgopac);
APPENDBOOLPROP(behaviors_parse_spc_pgid, "Parse S/P/C", m_frame->behaviors.parse_spc);
APPENDBOOLPROP(behaviors_nosplashscreen_pgid, "No splash screen", m_frame->behaviors.nosplashscreen);
APPENDBOOLPROP(behaviors_confirmquit_pgid, "Confirm quit", m_frame->behaviors.confirmquit);
wxFlexGridSizer *sizer = new wxFlexGridSizer(2, 1, 0, 0);
sizer->AddGrowableCol(0);
sizer->AddGrowableRow(0);
sizer->Add(propgrid, 1, wxEXPAND);
wxBoxSizer *bsizer = new wxBoxSizer(wxHORIZONTAL);
wxButton *abutton = new wxButton(this, wxID_ANY, "Apply");
abutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ASSDrawSettingsDialog::OnSettingsApplyButtonClicked), NULL, this);
bsizer->Add(abutton, 2, wxEXPAND);
wxButton *rbutton = new wxButton(this, wxID_ANY, "Revert");
rbutton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(ASSDrawSettingsDialog::OnSettingsRevertButtonClicked), NULL, this);
bsizer->Add(rbutton, 1, wxEXPAND);
bsizer->Layout();
sizer->Add(bsizer, 1, wxEXPAND);
sizer->Layout();
SetSizer(sizer);
}
ASSDrawSettingsDialog::~ASSDrawSettingsDialog()
{
if (propgrid) propgrid->Clear();
}
void ASSDrawSettingsDialog::OnSettingsApplyButtonClicked(wxCommandEvent &event)
{
wxButton *button = (wxButton *) event.GetEventObject();
//wxPropertyGrid *propgrid = (wxPropertyGrid *) button->GetClientData();
if (propgrid == NULL) return;
#define PARSECOLOR(color, pgid) \
{ \
wxVariant variant = propgrid->GetPropertyValue(pgid); \
color = *wxGetVariantCast(variant,wxColour); \
}
#define PARSE(ptr, pgid) propgrid->GetPropertyValue(pgid).Convert(ptr);
PARSECOLOR(m_frame->colors.canvas_bg, colors_canvas_bg_pgid)
PARSECOLOR(m_frame->colors.canvas_shape_controlpoint, colors_canvas_shape_controlpoint_pgid)
PARSECOLOR(m_frame->colors.canvas_shape_guideline, colors_canvas_shape_guideline_pgid)
PARSECOLOR(m_frame->colors.canvas_shape_mainpoint, colors_canvas_shape_mainpoint_pgid)
PARSECOLOR(m_frame->colors.canvas_shape_normal, colors_canvas_shape_normal_pgid)
PARSECOLOR(m_frame->colors.canvas_shape_outline, colors_canvas_shape_outline_pgid)
PARSECOLOR(m_frame->colors.canvas_shape_preview, colors_canvas_shape_preview_pgid)
PARSECOLOR(m_frame->colors.canvas_shape_selectpoint, colors_canvas_shape_selectpoint_pgid)
PARSECOLOR(m_frame->colors.library_libarea, colors_library_libarea_pgid)
PARSECOLOR(m_frame->colors.library_shape, colors_library_shape_pgid)
PARSECOLOR(m_frame->colors.origin, colors_origin_pgid)
PARSECOLOR(m_frame->colors.ruler_h, colors_ruler_h_pgid)
PARSECOLOR(m_frame->colors.ruler_v, colors_ruler_v_pgid)
PARSE(&m_frame->alphas.canvas_shape_controlpoint, alphas_canvas_shape_controlpoint_pgid)
PARSE(&m_frame->alphas.canvas_shape_guideline, alphas_canvas_shape_guideline_pgid)
PARSE(&m_frame->alphas.canvas_shape_mainpoint, alphas_canvas_shape_mainpoint_pgid)
PARSE(&m_frame->alphas.canvas_shape_normal, alphas_canvas_shape_normal_pgid)
PARSE(&m_frame->alphas.canvas_shape_outline, alphas_canvas_shape_outline_pgid)
PARSE(&m_frame->alphas.canvas_shape_preview, alphas_canvas_shape_preview_pgid)
PARSE(&m_frame->alphas.canvas_shape_selectpoint, alphas_canvas_shape_selectpoint_pgid)
PARSE(&m_frame->sizes.origincross, sizes_origincross_pgid)
PARSE(&m_frame->behaviors.autoaskimgopac, behaviors_autoaskimgopac_pgid)
PARSE(&m_frame->behaviors.capitalizecmds, behaviors_capitalizecmds_pgid)
PARSE(&m_frame->behaviors.parse_spc, behaviors_parse_spc_pgid)
PARSE(&m_frame->behaviors.nosplashscreen, behaviors_nosplashscreen_pgid)
PARSE(&m_frame->behaviors.confirmquit, behaviors_confirmquit_pgid)
wxCommandEvent evento( wxEVT_SETTINGS_CHANGED, event.GetId() );
evento.SetEventObject( button );
m_frame->GetEventHandler()->ProcessEvent( evento );
}
void ASSDrawSettingsDialog::OnSettingsRevertButtonClicked(wxCommandEvent &event)
{
RefreshSettingsDisplay();
}
void ASSDrawSettingsDialog::RefreshSettingsDisplay()
{
if (propgrid == NULL) return;
#define UPDATESETTING(value, pgid) propgrid->SetPropertyValue(pgid, value);
UPDATESETTING(m_frame->colors.canvas_bg, colors_canvas_bg_pgid)
UPDATESETTING(m_frame->colors.canvas_shape_controlpoint, colors_canvas_shape_controlpoint_pgid)
UPDATESETTING(m_frame->colors.canvas_shape_guideline, colors_canvas_shape_guideline_pgid)
UPDATESETTING(m_frame->colors.canvas_shape_mainpoint, colors_canvas_shape_mainpoint_pgid)
UPDATESETTING(m_frame->colors.canvas_shape_normal, colors_canvas_shape_normal_pgid)
UPDATESETTING(m_frame->colors.canvas_shape_outline, colors_canvas_shape_outline_pgid)
UPDATESETTING(m_frame->colors.canvas_shape_preview, colors_canvas_shape_preview_pgid)
UPDATESETTING(m_frame->colors.canvas_shape_selectpoint, colors_canvas_shape_selectpoint_pgid)
UPDATESETTING(m_frame->colors.library_libarea, colors_library_libarea_pgid)
UPDATESETTING(m_frame->colors.library_shape, colors_library_shape_pgid)
UPDATESETTING(m_frame->colors.origin, colors_origin_pgid)
UPDATESETTING(m_frame->colors.ruler_h, colors_ruler_h_pgid)
UPDATESETTING(m_frame->colors.ruler_v, colors_ruler_v_pgid)
UPDATESETTING(m_frame->alphas.canvas_shape_controlpoint, alphas_canvas_shape_controlpoint_pgid)
UPDATESETTING(m_frame->alphas.canvas_shape_guideline, alphas_canvas_shape_guideline_pgid)
UPDATESETTING(m_frame->alphas.canvas_shape_mainpoint, alphas_canvas_shape_mainpoint_pgid)
UPDATESETTING(m_frame->alphas.canvas_shape_normal, alphas_canvas_shape_normal_pgid)
UPDATESETTING(m_frame->alphas.canvas_shape_outline, alphas_canvas_shape_outline_pgid)
UPDATESETTING(m_frame->alphas.canvas_shape_preview, alphas_canvas_shape_preview_pgid)
UPDATESETTING(m_frame->alphas.canvas_shape_selectpoint, alphas_canvas_shape_selectpoint_pgid)
UPDATESETTING(m_frame->sizes.origincross, sizes_origincross_pgid)
UPDATESETTING(m_frame->behaviors.capitalizecmds, behaviors_capitalizecmds_pgid)
UPDATESETTING(m_frame->behaviors.autoaskimgopac, behaviors_autoaskimgopac_pgid)
UPDATESETTING(m_frame->behaviors.parse_spc, behaviors_parse_spc_pgid)
UPDATESETTING(m_frame->behaviors.nosplashscreen, behaviors_nosplashscreen_pgid)
UPDATESETTING(m_frame->behaviors.confirmquit, behaviors_confirmquit_pgid)
}

119
assdraw/src/settings.hpp Normal file
View File

@ -0,0 +1,119 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "_common.hpp"
#include <wx/propgrid/propgrid.h>
#include <wx/propgrid/advprops.h>
class ASSDrawFrame;
DECLARE_EVENT_TYPE(wxEVT_SETTINGS_CHANGED, -1)
class ASSDrawSettingsDialog : public wxPanel
{
public:
ASSDrawFrame* m_frame;
ASSDrawSettingsDialog( wxWindow *parent, ASSDrawFrame *frame, int id = wxID_ANY );
virtual ~ASSDrawSettingsDialog();
virtual void Init();
virtual void OnSettingsApplyButtonClicked(wxCommandEvent &event);
virtual void OnSettingsRevertButtonClicked(wxCommandEvent &event);
virtual void RefreshSettingsDisplay();
wxPGId colors_canvas_bg_pgid;
wxPGId colors_canvas_shape_normal_pgid;
wxPGId colors_canvas_shape_preview_pgid;
wxPGId colors_canvas_shape_outline_pgid;
wxPGId colors_canvas_shape_guideline_pgid;
wxPGId colors_canvas_shape_mainpoint_pgid;
wxPGId colors_canvas_shape_controlpoint_pgid;
wxPGId colors_canvas_shape_selectpoint_pgid;
wxPGId colors_library_shape_pgid;
wxPGId colors_library_libarea_pgid;
wxPGId colors_origin_pgid;
wxPGId colors_ruler_h_pgid;
wxPGId colors_ruler_v_pgid;
wxPGId alphas_canvas_shape_normal_pgid;
wxPGId alphas_canvas_shape_preview_pgid;
wxPGId alphas_canvas_shape_outline_pgid;
wxPGId alphas_canvas_shape_guideline_pgid;
wxPGId alphas_canvas_shape_mainpoint_pgid;
wxPGId alphas_canvas_shape_controlpoint_pgid;
wxPGId alphas_canvas_shape_selectpoint_pgid;
wxPGId sizes_origincross_pgid;
wxPGId behaviors_capitalizecmds_pgid;
wxPGId behaviors_autoaskimgopac_pgid;
wxPGId behaviors_parse_spc_pgid;
wxPGId behaviors_nosplashscreen_pgid;
wxPGId behaviors_confirmquit_pgid;
wxPropertyGrid *propgrid;
//DECLARE_EVENT_TABLE()
};
class wxLongPropertyValidator : public wxValidator
{
public:
wxLongPropertyValidator( const int min, const int max )
: wxValidator()
{
m_min = min, m_max = max;
}
virtual wxObject* Clone() const
{
return new wxLongPropertyValidator( m_min, m_max );
}
virtual bool Validate(wxWindow* WXUNUSED(parent))
{
wxTextCtrl* tc = wxDynamicCast(GetWindow(), wxTextCtrl);
wxCHECK_MSG(tc, true, wxT("validator window must be wxTextCtrl"));
wxString val = tc->GetValue();
long valint = 0;
val.ToLong(&valint);
if (valint < m_min) valint = m_min;
if (valint > m_max) valint = m_max;
tc->SetValue(wxString::Format(_T("%d"), valint));
return true;
}
private:
int m_min, m_max;
};

BIN
assdraw/src/tsukasa.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -0,0 +1,124 @@
#include "AGGWindow.h"
#include "agg_rendering_buffer.h"
#include "agg_pixfmt_rgb.h"
namespace GUI {
BEGIN_EVENT_TABLE(AGGWindow, wxWindow)
EVT_PAINT(AGGWindow::onPaint)
EVT_SIZE(AGGWindow::onSize)
EVT_ERASE_BACKGROUND(AGGWindow::onEraseBackground)
END_EVENT_TABLE()
AGGWindow::AGGWindow(wxWindow* parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, long style):
wxWindow(parent, id, pos, size, style, wxT("AGGWindow")),
bitmap(NULL) {
}
void AGGWindow::init(const int width, const int height) {
memDC.SelectObject(wxNullBitmap);
delete bitmap;
int ncheight = height, ncwidth = width;
if (ncwidth < 1) ncwidth = 1;
if (ncheight < 1) ncheight = 1;
bitmap = new wxBitmap(ncwidth, ncheight, PixelFormat::wxWidgetsType::BitsPerPixel);
memDC.SelectObject(*bitmap);
// Draw the bitmap
attachAndDraw();
// Request a full redraw of the window
Refresh(false);
}
AGGWindow::~AGGWindow() {
memDC.SelectObject(wxNullBitmap);
delete bitmap;
}
void AGGWindow::attachAndDraw() {
// Get raw access to the wxWidgets bitmap -- this locks the pixels and
// unlocks on destruction.
PixelData data(*bitmap);
assert(data);
#if 1
// This cast looks like it is ignoring byte-ordering, but the
// pixel format already explicitly handles that.
assert(data.GetPixels().IsOk());
wxAlphaPixelFormat::ChannelType* pd = (wxAlphaPixelFormat::ChannelType*) &data.GetPixels().Data();
// wxWidgets always returns a pointer to the first row of pixels, whether
// that is stored at the beginning of the buffer (stride > 0) or at the
// end of the buffer (stride < 0). AGG always wants a pointer to the
// beginning of the buffer, no matter what the stride. (AGG does handle
// negative strides correctly.)
// Upshot: if the stride is negative, rewind the pointer from the end of
// the buffer to the beginning.
const int stride = data.GetRowStride();
if (stride < 0)
pd += (data.GetHeight() - 1) * stride;
rBuf.attach(pd, data.GetWidth(), data.GetHeight(), stride);
// Call the user code to actually draw.
draw();
#else
PixelData::Iterator p(data);
// we draw a (10, 10)-(20, 20) rect manually using the given r, g, b
p.Offset(data, 10, 10);
for ( int y = 0; y < 10; ++y )
{
PixelData::Iterator rowStart = p;
for ( int x = 0; x < 10; ++x, ++p )
{
p.Red() = 255;
p.Green() = 0;
p.Blue() = 255;
}
p = rowStart;
p.OffsetY(data, 1);
}
#endif
}
void AGGWindow::onSize(wxSizeEvent& event) {
const wxSize size = GetClientSize();
if (bitmap && size.GetWidth() == bitmap->GetWidth() && size.GetHeight() == bitmap->GetHeight())
return;
init(size.GetWidth(), size.GetHeight());
}
void AGGWindow::onPaint(wxPaintEvent& event) {
wxPaintDC dc(this);
wxCoord width, height;
dc.GetSize(&width, &height);
if (!bitmap || bitmap->GetWidth() != width || bitmap->GetHeight() != height)
init(width, height);
// Iterate over regions needing repainting
wxRegionIterator regions(GetUpdateRegion());
wxRect rect;
while (regions) {
rect = regions.GetRect();
dc.Blit(rect.x, rect.y, rect.width, rect.height, &memDC, rect.x, rect.y);
++regions;
}
}
void AGGWindow::onEraseBackground(wxEraseEvent& WXUNUSED(event)) {
// Do nothing to "avoid flashing in MSW" Grr.
}
}

View File

@ -0,0 +1,68 @@
#ifndef WX_AGG_WINDOW_H
#define WX_AGG_WINDOW_H
#include "PixelFormatConvertor.h"
#include <wx/bitmap.h>
#include <wx/rawbmp.h>
#include <wx/window.h>
#include <wx/dcmemory.h>
#include "agg_rendering_buffer.h"
namespace GUI {
/// A simple widget that displays a bitmap that AGG can draw on.
/// It reallocates the bitmap so that it always is the current size of the
/// entire panel and calls the virtual method draw() to draw to the bitmap.
/// This should be useable anywhere a wxWindow can be, e.g. in actual windows,
/// buttons, etc.
class AGGWindow: public wxWindow {
public:
/// Create an AGGWindow. Defaults are taken from wxWindow::wxWindow(), see
/// that documentation for more information.
AGGWindow(wxWindow* parent, wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxTAB_TRAVERSAL);
/// Clean up resources held
virtual ~AGGWindow();
protected:
/// The conversion between wxWidgets' pixel format and AGG's pixel format
typedef PixelFormatConvertor<wxNativePixelFormat> PixelFormat;
/// The wxWidgets "pixel data" type, an accessor to the raw pixels
typedef wxPixelData<wxBitmap, PixelFormat::wxWidgetsType> PixelData;
/// Create the bitmap given the current size.
void init(const int width, const int height);
/// Attach the AGG rendering buffer to the bitmap and call the user draw() code.
void attachAndDraw();
/// Paint the bitmap onto the panel.
void onPaint(wxPaintEvent& event);
/// Resize the bitmap to match the window.
void onSize(wxSizeEvent& event);
/// Handle the erase-background event.
void onEraseBackground(wxEraseEvent& event);
/// Draw into the bitmap using AGG.
virtual void draw() = 0;
wxBitmap* bitmap; ///< wxWidgets bitmap for AGG to draw into
wxMemoryDC memDC; ///< Memory "device context" for drawing the bitmap
agg::rendering_buffer rBuf; ///< AGG's rendering buffer, pointing into the bitmap
DECLARE_EVENT_TABLE() /// Allocate wxWidgets storage for event handlers
};
}
#endif

View File

@ -0,0 +1,117 @@
/*
* Copyright (c) 2007, ai-chan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the ASSDraw3 Team nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY AI-CHAN ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AI-CHAN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef WX_AGG_PIXEL_FORMAT_CONVERTOR_H
#define WX_AGG_PIXEL_FORMAT_CONVERTOR_H
#include "agg_pixfmt_rgb.h"
#include "agg_pixfmt_rgba.h"
namespace {
/// Given a particular combination of channel type, bits per pixel and
/// channel indices, return the AGG format that matches.
/// The actual template specializations that follow give the actual types,
/// and using a combination of parameters that are not listed will give
/// a compile-time error.
template <typename Channel, int bitsPerPixel, int r, int g, int b, int a>
struct wxWidgetsToAGGHelper {
//empty
};
/// 24-bit RGB
template <> struct wxWidgetsToAGGHelper<unsigned char, 24, 0, 1, 2, -1> {
typedef agg::pixfmt_rgb24 format;
};
/// 24-bit BGR
template <> struct wxWidgetsToAGGHelper<unsigned char, 24, 2, 1, 0, -1> {
typedef agg::pixfmt_bgr24 format;
};
/// 32-bit RGB, alpha unused but stored as ARGB.
template <> struct wxWidgetsToAGGHelper<unsigned char, 32, 1, 2, 3, -1> {
typedef agg::pixfmt_argb32 format;
};
/// 32-bit RGB, alpha unused but stored as RGBA.
template <> struct wxWidgetsToAGGHelper<unsigned char, 32, 0, 1, 2, -1> {
typedef agg::pixfmt_rgba32 format;
};
/// 32-bit BGR, alpha unused but stored as ABGR.
template <> struct wxWidgetsToAGGHelper<unsigned char, 32, 3, 2, 1, -1> {
typedef agg::pixfmt_abgr32 format;
};
/// 32-bit BGR, alpha unused but stored as BGRA.
template <> struct wxWidgetsToAGGHelper<unsigned char, 32, 2, 1, 0, -1> {
typedef agg::pixfmt_bgra32 format;
};
/// 32-bit RGBA
template <> struct wxWidgetsToAGGHelper<unsigned char, 32, 0, 1, 2, 3> {
typedef agg::pixfmt_rgba32 format;
};
/// 32-bit BGRA
template <> struct wxWidgetsToAGGHelper<unsigned char, 32, 2, 1, 0, 3> {
typedef agg::pixfmt_bgra32 format;
};
/// 32-bit ARGB
template <> struct wxWidgetsToAGGHelper<unsigned char, 32, 1, 2, 3, 0> {
typedef agg::pixfmt_argb32 format;
};
/// 32-bit ABGR
template <> struct wxWidgetsToAGGHelper<unsigned char, 32, 3, 2, 1, 0> {
typedef agg::pixfmt_abgr32 format;
};
}
namespace GUI {
/// Convert between a wxWidgets pixel format class and an AGG pixel format class.
/// Usage examples:
/// PixelFormatConvertor<wxNativePixelFormat>::AGGType or
/// PixelFormatConvertor<wxAlphaPixelFormat>::AGGType.
template <typename wxWidgetsPixelFormat>
class PixelFormatConvertor {
public:
typedef wxWidgetsPixelFormat wxWidgetsType;
// Break out the wxWidgets parameters and feed to the helper class.
typedef typename wxWidgetsToAGGHelper<typename wxWidgetsPixelFormat::ChannelType,
wxWidgetsPixelFormat::BitsPerPixel,
wxWidgetsPixelFormat::RED,
wxWidgetsPixelFormat::GREEN,
wxWidgetsPixelFormat::BLUE,
wxWidgetsPixelFormat::ALPHA>::format AGGType;
};
}
#endif