Compare commits
146 Commits
Author | SHA1 | Date | |
---|---|---|---|
0d81865f3b | |||
12cfe16cb4 | |||
e773f9ae6d | |||
5c46cfe20a | |||
2d9001db6e | |||
8ff15fd0e1 | |||
8e4ea8437f | |||
48f24c0cf3 | |||
8d85093874 | |||
1beeb8d6e4 | |||
f9b07b29a9 | |||
9bc330e5e8 | |||
a51e20b370 | |||
ef6ef6256e | |||
4edbc29e72 | |||
b72c775a04 | |||
0c9f04bc71 | |||
034057dcd2 | |||
016316518d | |||
ac9ccd04e2 | |||
ce8d71f47e | |||
29cd0d80f3 | |||
d3f5a41c0d | |||
3f181c6248 | |||
8ae14281cc | |||
9de77c9f21 | |||
d31865a9ef | |||
cf62f2ac0b | |||
16362e1b13 | |||
aa79919496 | |||
6df145455e | |||
daceb326c5 | |||
5fbadc0d80 | |||
473bd4705c | |||
c570d8fd75 | |||
7909d4d94b | |||
138d5d02d2 | |||
0683583da1 | |||
1decd64a30 | |||
9e1cfef924 | |||
e384f7d2e2 | |||
be3d2cf20d | |||
54ae52e117 | |||
b480acc6a0 | |||
007e4d4e11 | |||
6070ebead5 | |||
5b081c8859 | |||
29e205d441 | |||
1f5272415c | |||
d1b12a07ac | |||
f2f8158efb | |||
77877c118f | |||
e0c16486d3 | |||
ba491736c1 | |||
0e817a88a7 | |||
5d4b8b87a3 | |||
94c29c2ff5 | |||
e260b36585 | |||
3d42ab25b2 | |||
0a6250141a | |||
3d58bcae6c | |||
281103c46e | |||
e6ed0c28a3 | |||
522006f67a | |||
e11355193b | |||
30cdb6d335 | |||
c40e27bc17 | |||
3d6cd3e576 | |||
4b7b18ca6f | |||
9e6e39e3d8 | |||
c600d62bd2 | |||
f114676db7 | |||
0ec3787fc4 | |||
40cced7be0 | |||
81a9e7a678 | |||
6328fe760f | |||
932974d744 | |||
eb4941417c | |||
93deb1c2c5 | |||
c9b581f6db | |||
6a6f75b3ce | |||
04a1633a90 | |||
b168e8ca76 | |||
fa6f2e5db6 | |||
1c66282b01 | |||
5cbb9b8664 | |||
6254490a23 | |||
43e60e300c | |||
fe95abca0f | |||
bcecd3058b | |||
68a807ccb5 | |||
7a355b39a0 | |||
0f1489727c | |||
bab3d6677e | |||
bcb709300c | |||
4f2f01ea36 | |||
8592cd2e53 | |||
b4c1a4c714 | |||
294af67099 | |||
3585a6f96e | |||
0914e2816e | |||
0b41c0f648 | |||
beb2fa6ba9 | |||
61fb6c5e6f | |||
d310a77893 | |||
84f366e7e4 | |||
561d016a45 | |||
334d6ad21f | |||
0382b3858b | |||
2aa87b5fac | |||
d7fef0f88b | |||
c7131678f8 | |||
5224c9ddd8 | |||
3265a96fe6 | |||
5831447f75 | |||
043f077408 | |||
25bb46d097 | |||
5cb1d0cd03 | |||
123ea31191 | |||
1df5d0da38 | |||
50f159c982 | |||
df5aef363b | |||
0642e17aa8 | |||
1402394d07 | |||
e1ba57c92f | |||
2db04fe7d6 | |||
dc61be27f0 | |||
7fd49aaccb | |||
cffaec09b2 | |||
62a7755407 | |||
2ab1e29365 | |||
fe110a3d8e | |||
5afec16258 | |||
fad483ce7a | |||
b10e87d2b7 | |||
61ee1d9b32 | |||
ce1a5c4918 | |||
796cd4466e | |||
0f49c884f2 | |||
c8dae1cb79 | |||
54837d0e21 | |||
001e35cf7b | |||
ac5083633b | |||
c32af500dc | |||
dc4de32162 | |||
243990a90f |
6
.gitignore
vendored
@ -5,6 +5,9 @@
|
||||
node_modules
|
||||
npm-debug.log
|
||||
|
||||
# node webkit cache
|
||||
cache
|
||||
|
||||
# sublime text stuff (the -project should actually be shared, but then we'd have to share the same disk location)
|
||||
*.sublime-project
|
||||
*.sublime-workspace
|
||||
@ -20,5 +23,8 @@ diff.txt
|
||||
dest
|
||||
build/closure/closure_compiled_binary.js
|
||||
|
||||
# plato report directory
|
||||
report
|
||||
|
||||
# marked as private
|
||||
*.private.*
|
154
Gruntfile.js
@ -1,16 +1,3 @@
|
||||
/**
|
||||
* How to run grunt tasks:
|
||||
* - At project root, run 'npm install' - It will install nodedependencies declared in package,json in <root>/.node_modules
|
||||
* - install grunt CLI tools globally, run 'npm install -g grunt-cli'
|
||||
* - run a grunt target defined in Gruntfiles.js, ex: 'grunt lint'
|
||||
*
|
||||
* Note: The 'ghost' grunt task have special deps on CasperJS and phantomjs.
|
||||
* For now, It's configured to run only on TravisCI where these deps are
|
||||
* correctly defined.
|
||||
* If you run this task locally, it may require some env set up first.
|
||||
*/
|
||||
|
||||
|
||||
module.exports = function(grunt) {
|
||||
var dateFormat = require('dateformat');
|
||||
var now = new Date();
|
||||
@ -77,27 +64,44 @@ module.exports = function(grunt) {
|
||||
};
|
||||
};
|
||||
|
||||
// load all grunt tasks
|
||||
require('load-grunt-tasks')(grunt);
|
||||
|
||||
grunt.initConfig({
|
||||
clean: {
|
||||
before: ['dest'],
|
||||
after: ['build/closure/closure_compiled_binary.js']
|
||||
before: ['dest']
|
||||
},
|
||||
leadingIndent : {
|
||||
options: {
|
||||
indentation : "spaces"
|
||||
},
|
||||
css : ['src/css/**/*.css']
|
||||
},
|
||||
jscs : {
|
||||
options : {
|
||||
"preset": "google",
|
||||
"maximumLineLength": 120,
|
||||
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
|
||||
"validateQuoteMarks": { "mark": "'", "escape": true },
|
||||
"disallowMultipleVarDecl": "exceptUndefined",
|
||||
"disallowSpacesInAnonymousFunctionExpression": null
|
||||
},
|
||||
js : [ 'src/js/**/*.js' , '!src/js/**/lib/**/*.js' ]
|
||||
},
|
||||
jshint: {
|
||||
options: {
|
||||
indent:2,
|
||||
undef : true,
|
||||
latedef : true,
|
||||
browser : true,
|
||||
trailing : true,
|
||||
curly : true,
|
||||
es3 : true,
|
||||
globals : {'$':true, 'jQuery' : true, 'pskl':true, 'Events':true, 'Constants':true, 'console' : true, 'module':true, 'require':true}
|
||||
globals : {'$':true, 'jQuery' : true, 'pskl':true, 'Events':true, 'Constants':true, 'console' : true, 'module':true, 'require':true, 'Q':true}
|
||||
},
|
||||
files: [
|
||||
'Gruntfile.js',
|
||||
'package.json',
|
||||
'src/js/**/*.js',
|
||||
'!src/js/lib/**/*.js' // Exclude lib folder (note the leading !)
|
||||
'!src/js/**/lib/**/*.js' // Exclude lib folder (note the leading !)
|
||||
]
|
||||
},
|
||||
express: {
|
||||
@ -144,7 +148,7 @@ module.exports = function(grunt) {
|
||||
options : {
|
||||
mangle : true
|
||||
},
|
||||
my_target : {
|
||||
js : {
|
||||
files : {
|
||||
'dest/js/piskel-packaged-min.js' : ['dest/js/piskel-packaged' + version + '.js']
|
||||
}
|
||||
@ -161,7 +165,7 @@ module.exports = function(grunt) {
|
||||
]
|
||||
},
|
||||
files: [
|
||||
{expand: true, flatten: true, src: ['src/piskel-boot-0.1.0.js'], dest: 'dest/'}
|
||||
{src: ['src/piskel-boot.js'], dest: 'dest/piskel-boot.js'}
|
||||
]
|
||||
},
|
||||
editor: {
|
||||
@ -170,6 +174,9 @@ module.exports = function(grunt) {
|
||||
{
|
||||
match: /templates\//g,
|
||||
replacement: "../templates"+version+"/"
|
||||
},{
|
||||
match: /piskel-boot.js/g,
|
||||
replacement: "../piskel-boot"+version+".js"
|
||||
},{
|
||||
match: /^(.|[\r\n])*<!--body-main-start-->/,
|
||||
replacement: "",
|
||||
@ -194,6 +201,7 @@ module.exports = function(grunt) {
|
||||
main: {
|
||||
files: [
|
||||
{src: ['dest/js/piskel-packaged-min.js'], dest: 'dest/js/piskel-packaged-min' + version + '.js'},
|
||||
{src: ['dest/piskel-boot.js'], dest: 'dest/piskel-boot' + version + '.js'},
|
||||
{src: ['src/logo.png'], dest: 'dest/logo.png'},
|
||||
{src: ['src/js/lib/iframeLoader-0.1.0.js'], dest: 'dest/js/lib/iframeLoader-0.1.0.js'},
|
||||
{src: ['src/js/lib/gif/gif.ie.worker.js'], dest: 'dest/js/lib/gif/gif.ie.worker.js'},
|
||||
@ -203,58 +211,6 @@ module.exports = function(grunt) {
|
||||
]
|
||||
}
|
||||
},
|
||||
closureCompiler: {
|
||||
options: {
|
||||
// [REQUIRED] Path to closure compiler
|
||||
compilerFile: 'build/closure/closure_compiler_20130823.jar',
|
||||
|
||||
// [OPTIONAL] set to true if you want to check if files were modified
|
||||
// before starting compilation (can save some time in large sourcebases)
|
||||
//checkModified: true,
|
||||
|
||||
// [OPTIONAL] Set Closure Compiler Directives here
|
||||
compilerOpts: {
|
||||
/**
|
||||
* Keys will be used as directives for the compiler
|
||||
* values can be strings or arrays.
|
||||
* If no value is required use null
|
||||
*/
|
||||
//compilation_level: 'ADVANCED_OPTIMIZATIONS',
|
||||
compilation_level: 'SIMPLE_OPTIMIZATIONS',
|
||||
externs: ['build/closure/piskel-closure-externs.js'],
|
||||
// Inject some constants in JS code, could we use that for appengine wiring ?
|
||||
//define: ["'goog.DEBUG=false'"],
|
||||
warning_level: 'verbose',
|
||||
jscomp_off: ['checkTypes', 'fileoverviewTags'],
|
||||
summary_detail_level: 1,
|
||||
language_in: 'ECMASCRIPT3'
|
||||
//output_wrapper: '"(function(){%output%}).call(this);"'
|
||||
},
|
||||
execOpts: { // [OPTIONAL] Set exec method options
|
||||
maxBuffer: 999999 * 1024
|
||||
}
|
||||
|
||||
},
|
||||
compile: {
|
||||
|
||||
/**
|
||||
*[OPTIONAL] Here you can add new or override previous option of the Closure Compiler Directives.
|
||||
* IMPORTANT! The feature is enabled as a temporary solution to [#738](https://github.com/gruntjs/grunt/issues/738).
|
||||
* As soon as issue will be fixed this feature will be removed.
|
||||
*/
|
||||
TEMPcompilerOpts: {
|
||||
},
|
||||
src: [
|
||||
'src/js/**/*.js',
|
||||
'src/piskel-boot-0.1.0.js',
|
||||
'src/piskel-script-list.js',
|
||||
'!src/js/lib/**/*.js'
|
||||
],
|
||||
|
||||
// This generated JS binary is currently not used and even excluded from source control using .gitignore.
|
||||
dest: 'build/closure/closure_compiled_binary.js'
|
||||
}
|
||||
},
|
||||
karma: {
|
||||
unit: {
|
||||
configFile: 'karma.conf.js'
|
||||
@ -262,6 +218,7 @@ module.exports = function(grunt) {
|
||||
},
|
||||
nodewebkit: {
|
||||
options: {
|
||||
version : "0.11.5",
|
||||
build_dir: './dest/desktop/', // destination folder of releases.
|
||||
mac: true,
|
||||
win: true,
|
||||
@ -272,66 +229,33 @@ module.exports = function(grunt) {
|
||||
}
|
||||
});
|
||||
|
||||
grunt.config.set('leadingIndent.indentation', 'spaces');
|
||||
grunt.config.set('leadingIndent.jsFiles', {
|
||||
src: [
|
||||
'src/js/**/*.js',
|
||||
'!src/js/lib/**/*.js'
|
||||
]
|
||||
});
|
||||
grunt.config.set('leadingIndent.cssFiles', {
|
||||
src: ['src/css/**/*.css']
|
||||
});
|
||||
|
||||
grunt.loadNpmTasks('grunt-closure-tools');
|
||||
grunt.loadNpmTasks('grunt-contrib-clean');
|
||||
grunt.loadNpmTasks('grunt-contrib-concat');
|
||||
grunt.loadNpmTasks('grunt-contrib-copy');
|
||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||
grunt.loadNpmTasks('grunt-contrib-uglify');
|
||||
grunt.loadNpmTasks('grunt-contrib-watch');
|
||||
grunt.loadNpmTasks('grunt-express');
|
||||
grunt.loadNpmTasks('grunt-replace');
|
||||
grunt.loadNpmTasks('grunt-ghost');
|
||||
grunt.loadNpmTasks('grunt-open');
|
||||
grunt.loadNpmTasks('grunt-karma');
|
||||
grunt.loadNpmTasks('grunt-leading-indent');
|
||||
grunt.loadNpmTasks('grunt-node-webkit-builder');
|
||||
grunt.loadNpmTasks('grunt-contrib-copy');
|
||||
|
||||
// Validate
|
||||
grunt.registerTask('lint', ['leadingIndent:jsFiles', 'leadingIndent:cssFiles', 'jshint']);
|
||||
grunt.registerTask('lint', ['jscs:js', 'leadingIndent:css', 'jshint']);
|
||||
|
||||
// karma/unit-tests task
|
||||
grunt.registerTask('unit-test', ['karma']);
|
||||
|
||||
// Validate & Test
|
||||
grunt.registerTask('test-travis', ['lint', 'compile', 'unit-test', 'express:test', 'ghost:travis']);
|
||||
grunt.registerTask('test-travis', ['lint', 'unit-test', 'express:test', 'ghost:travis']);
|
||||
// Validate & Test (faster version) will NOT work on travis !!
|
||||
grunt.registerTask('test-local', ['lint', 'compile', 'unit-test', 'express:test', 'ghost:local']);
|
||||
grunt.registerTask('test-local', ['lint', 'unit-test', 'express:test', 'ghost:local']);
|
||||
grunt.registerTask('test-local-nolint', ['unit-test', 'express:test', 'ghost:local']);
|
||||
|
||||
grunt.registerTask('test', ['test-travis']);
|
||||
grunt.registerTask('precommit', ['test-local']);
|
||||
|
||||
|
||||
// Compile JS code (eg verify JSDoc annotation and types, no actual minified code generated).
|
||||
grunt.registerTask('compile', ['closureCompiler:compile', 'clean:after']);
|
||||
|
||||
grunt.registerTask('rep', ['replace:main', 'replace:editor']);
|
||||
|
||||
grunt.registerTask('merge', ['concat:js', 'concat:css', 'uglify', 'rep', 'copy']);
|
||||
grunt.registerTask('build', ['concat:js', 'concat:css', 'uglify', 'replace:main', 'replace:editor', 'copy']);
|
||||
|
||||
// Validate & Build
|
||||
grunt.registerTask('default', ['clean:before', 'lint', 'compile', 'merge']);
|
||||
grunt.registerTask('default', ['clean:before', 'lint', 'build']);
|
||||
|
||||
// Build stand alone app with nodewebkit
|
||||
grunt.registerTask('desktop', ['default', 'nodewebkit']);
|
||||
|
||||
grunt.registerTask('server', ['merge', 'express:regular', 'open:regular', 'express-keepalive']);
|
||||
|
||||
// Start webserver and watch for changes
|
||||
grunt.registerTask('server:watch', ['server', 'watch']);
|
||||
grunt.registerTask('serve', ['build', 'express:regular', 'open:regular', 'express-keepalive', 'watch']);
|
||||
|
||||
// Start webserver on src folder, in debug mode
|
||||
grunt.registerTask('server:debug', ['express:debug', 'open:debug', 'express-keepalive']);
|
||||
grunt.registerTask('serve-debug', ['express:debug', 'open:debug', 'express-keepalive']);
|
||||
grunt.registerTask('play', ['serve-debug']);
|
||||
};
|
||||
|
661
LICENSE
Normal file
@ -0,0 +1,661 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
20
README.md
@ -32,13 +32,13 @@ Integrated in **[piskelapp.com](http://piskelapp.com)**, you can share everythin
|
||||
Piskel supports the following browsers :
|
||||
* **Chrome** (latest)
|
||||
* **Firefox** (latest)
|
||||
* **Internet Explorer** 10+
|
||||
* **Internet Explorer** 11+
|
||||
|
||||
... and a fairly recent computer.
|
||||
|
||||
We don't plan/want/could be forced into supporting older IEs. For Opera and Safari, we've never tested them but the gap shouldn't be huge.
|
||||
|
||||
## Offline version (Windows and MacOS)
|
||||
## Offline version
|
||||
|
||||
Offline builds are available. More details in the [dedicated wiki page](https://github.com/juliandescottes/piskel/wiki/Desktop-applications).
|
||||
|
||||
@ -49,6 +49,7 @@ The Piskel editor is purely built in **JavaScript, HTML and CSS**. It uses Canva
|
||||
We also use the following **libraries** :
|
||||
* [spectrum](https://github.com/bgrins/spectrum) : awesome standalone colorpicker
|
||||
* [gifjs](http://jnordberg.github.io/gif.js/) : generate animated GIFs in javascript, using webworkers
|
||||
* [supergif](https://github.com/buzzfeed/libgif-js) : modified version of SuperGif to parse and import GIFs
|
||||
* [jszip](https://github.com/Stuk/jszip) : create, read and edit .zip files with Javascript
|
||||
* [canvas-toBlob](https://github.com/eligrey/canvas-toBlob.js/) : shim for canvas toBlob
|
||||
* [jquery](http://jquery.com/) : used sporadically in the application
|
||||
@ -66,9 +67,20 @@ Help is always welcome !
|
||||
* **Issues** : Found a problem when using the application, want to request a feature, [open an issue](https://github.com/juliandescottes/piskel/issues).
|
||||
* **Participate** : Have a look at the [wiki](https://github.com/juliandescottes/piskel/wiki) to set up the development environment
|
||||
|
||||
## Licensing
|
||||
## License
|
||||
|
||||
Probably need to pick one at some point ... Until then it's a "do whatever you want with it" license.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
## Mobile/Tablets
|
||||
|
||||
|
@ -1,18 +0,0 @@
|
||||
/**
|
||||
* @fileoverview Externs for Piskel
|
||||
*
|
||||
* @externs
|
||||
*/
|
||||
|
||||
// Piskel externs.
|
||||
var exports;
|
||||
var pskl_exports;
|
||||
var $;
|
||||
var console;
|
||||
var pskl;
|
||||
|
||||
// Piskel libs externs.
|
||||
var define;
|
||||
var jQuery;
|
||||
var getComputedStyle;
|
||||
var URL;
|
88
misc/icons/SVG/flip.svg
Normal file
@ -0,0 +1,88 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="770.71875"
|
||||
height="581.4375"
|
||||
id="svg2"
|
||||
version="1.1"
|
||||
inkscape:version="0.48.4 r9939"
|
||||
sodipodi:docname="mirror.svg"
|
||||
inkscape:export-filename="C:\Development\git\piskel\src\img\tools\flip.png"
|
||||
inkscape:export-xdpi="35.446629"
|
||||
inkscape:export-ydpi="35.446629">
|
||||
<defs
|
||||
id="defs4" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="0.7"
|
||||
inkscape:cx="612.40785"
|
||||
inkscape:cy="222.08964"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
fit-margin-top="0"
|
||||
fit-margin-left="0"
|
||||
fit-margin-right="0"
|
||||
fit-margin-bottom="0"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1148"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1" />
|
||||
<metadata
|
||||
id="metadata7">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(-63.5625,-233.7818)">
|
||||
<path
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:none"
|
||||
d="m 359.2768,233.7907 -295.7143,581.4286 295.7143,0 z"
|
||||
id="rect2987"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cccc"
|
||||
inkscape:export-filename="C:\Development\git\piskel\src\img\tools\flip.png"
|
||||
inkscape:export-xdpi="35.446629"
|
||||
inkscape:export-ydpi="35.446629" />
|
||||
<path
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:none"
|
||||
d="m 538.5625,233.7818 295.71875,581.4375 -295.71875,0 0,-581.4375 z m 29.125,117.4375 0,434.28125 218.59375,0 L 567.6875,351.2193 z"
|
||||
id="rect2987-1"
|
||||
inkscape:connector-curvature="0"
|
||||
inkscape:export-filename="C:\Development\git\piskel\src\img\tools\flip.png"
|
||||
inkscape:export-xdpi="35.446629"
|
||||
inkscape:export-ydpi="35.446629" />
|
||||
<path
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:none"
|
||||
d="m 435.5625,233.93805 0,41.28125 25.71875,0 0,-41.28125 -25.71875,0 z m 0,91.28125 0,40 25.71875,0 0,-40 -25.71875,0 z m 0,90 0,40 25.71875,0 0,-40 -25.71875,0 z m 0,90 0,40 25.71875,0 0,-40 -25.71875,0 z m 0,90 0,40 25.71875,0 0,-40 -25.71875,0 z m 0,90 0,40 25.71875,0 0,-40 -25.71875,0 z m 0,90 0,40 25.71875,0 0,-40 -25.71875,0 z"
|
||||
id="rect3796"
|
||||
inkscape:export-filename="C:\Development\git\piskel\src\img\tools\flip.png"
|
||||
inkscape:export-xdpi="35.446629"
|
||||
inkscape:export-ydpi="35.446629"
|
||||
inkscape:connector-curvature="0" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 3.2 KiB |
BIN
misc/icons/noun-project/sheep/icon_8389.png
Normal file
After Width: | Height: | Size: 52 KiB |
41
misc/icons/noun-project/sheep/icon_8389.svg
Normal file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
width="99.997px" height="69.373px" viewBox="0 0 99.997 69.373" enable-background="new 0 0 99.997 69.373" xml:space="preserve">
|
||||
<path fill="#010101" d="M81.635,0.222c0.553-0.327,1.242-0.219,1.85-0.133c1.502,0.296,2.658,1.426,3.533,2.62
|
||||
c0.608-0.379,1.252-0.777,1.983-0.842c0.595-0.015,1.09,0.416,1.394,0.889c0.568,0.909,0.76,2.02,1.442,2.864
|
||||
C92,5.829,92.246,5.941,92.482,6.044c0.968,0.409,1.846,0.996,2.688,1.615c0.361,0.223,0.396,0.691,0.529,1.056
|
||||
c0.478,1.579,0.306,3.241,0.149,4.853c-0.035,0.812-0.104,1.659,0.172,2.438c0.42,0.954,1.229,1.655,1.746,2.547
|
||||
c1.191,2.13,2.146,4.467,2.229,6.937v0.088c-0.071,1.268-0.203,2.647-1.062,3.653c-0.707,0.846-1.85,1.101-2.896,1.223
|
||||
c-0.747,0.104-1.508,0.127-2.258,0.077c-1.912-0.275-3.812-0.628-5.724-0.911c-0.34-0.052-0.719-0.055-1,0.167
|
||||
c-0.391,0.281-0.494,0.786-0.537,1.235c-0.068,1.177,0.133,2.405-0.312,3.532c-0.227,0.604-0.768,0.999-1.266,1.371
|
||||
c-1.092,0.753-2.313,1.291-3.441,1.981c-0.164,0.115-0.125,0.348-0.125,0.521c0.075,0.916,0.332,1.821,0.253,2.747
|
||||
c-0.021,0.597-0.271,1.188-0.72,1.587c-0.768,0.709-1.434,1.519-2.068,2.346c-0.104,0.142-0.222,0.283-0.256,0.461
|
||||
c-0.264,1.272-0.385,2.576-0.74,3.83c-0.201,0.641-0.416,1.34-0.943,1.793c-0.633,0.492-1.456-0.342-2.098,0.164
|
||||
c-1.191,0.882-1.558,2.412-2.379,3.582c-0.469,0.595-1.104,1.039-1.805,1.319c-0.331,4.37-0.625,8.741-0.896,13.115h-5.166
|
||||
c0.16-2.783,0.32-5.567,0.486-8.351c0.203-1.728-0.097-3.444-0.312-5.152c-0.017-0.364-0.43-0.709-0.785-0.543
|
||||
c-1.037,0.3-2.131,0.459-3.204,0.289c-0.87-0.227-1.536-0.877-2.11-1.533c-1.765,1.695-4.326,2.275-6.712,2.025
|
||||
c-0.471-0.726-0.792-1.629-1.603-2.049c-0.539-0.324-1.198-0.155-1.729,0.098c-1.214,0.558-1.945,1.805-3.197,2.305
|
||||
c-1.1,0.51-2.359,0.188-3.41-0.291c-1.127-0.54-2.176-1.242-3.186-1.975c-0.52,0.236-0.837,0.728-1.123,1.195
|
||||
c-0.968,0.117-1.964,0.449-2.923,0.103c-1.548-0.399-2.625-1.652-3.94-2.472c-0.886,0.66-1.608,1.58-2.68,1.957
|
||||
c-0.698,0.24-1.468,0.399-2.196,0.207c-0.825-0.181-1.609-0.5-2.425-0.705c-0.27-0.078-0.558-0.037-0.807,0.082
|
||||
c-1.433,0.646-2.197,2.23-3.688,2.779c-0.307,0.148-0.632,0.043-0.936-0.047c-0.346,3.812-0.79,7.618-1.159,11.43
|
||||
c-1.811,0.006-3.623-0.002-5.434,0.004c-0.078-0.656-0.297-1.312-0.188-1.978c0.27-2.282,0.637-4.551,0.9-6.833
|
||||
c0.181-1.895-0.835-3.648-2.096-4.977c0.154-0.737-0.056-1.502-0.528-2.078c-1.24-1.65-3.362-2.342-4.546-4.043
|
||||
c-0.357-0.53-0.698-1.256-0.328-1.864c0.285-0.724,0.94-1.381,0.769-2.21c-0.04-0.262-0.165-0.502-0.347-0.691
|
||||
c-1.07-1.188-1.971-2.514-2.849-3.844c-0.403-0.59-0.372-1.338-0.438-2.02c-0.141-1.194,0.732-2.201,0.798-3.364
|
||||
c-0.196-0.665-0.84-1.073-1.192-1.654C0.638,31.785,0.077,30.231,0,28.62v-0.446c0.086-0.751,0.078-1.537,0.396-2.239
|
||||
c0.522-1.006,1.566-1.623,2.075-2.636c-0.222-0.968-0.747-1.833-0.966-2.799c-0.097-1.466,0.425-2.955,1.404-4.049
|
||||
c0.664-0.035,1.319-0.157,1.968-0.296c0.633-0.125,1.1-0.631,1.448-1.145c0.703-1.045,0.832-2.351,1.479-3.422
|
||||
c0.255-0.444,0.607-0.855,1.08-1.074c0.692-0.327,1.395-0.631,2.119-0.88c0.38-0.117,0.779-0.237,1.18-0.167
|
||||
c0.894,0.134,1.771,0.361,2.665,0.5c0.624,0.088,1.321-0.085,1.74-0.58c0.379-0.424,0.483-1.003,0.574-1.544
|
||||
c0.926-0.306,1.929-0.646,2.907-0.389c1.367,0.311,2.72,0.672,4.091,0.96c0.748-0.367,1.104-1.208,1.849-1.582
|
||||
c0.884-0.481,1.947-0.333,2.873-0.064c1.13,0.322,1.991,1.168,3.041,1.655c0.735-0.438,1.304-1.316,2.246-1.275
|
||||
c1.698,0.444,3.091,1.803,4.899,1.868c1.229,0.001,1.779-1.354,2.912-1.594c0.744-0.228,1.496,0.125,2.104,0.54
|
||||
c0.745,0.517,1.432,1.11,2.132,1.684c1.052-0.622,2.251-1.085,3.492-1.026c1.448,0.261,2.847,0.754,4.294,1.011
|
||||
c0.615-0.026,0.967-0.649,1.489-0.902c1.062-0.497,2.237-0.755,3.409-0.756c1.316,0.169,2.543,0.712,3.82,1.042
|
||||
c0.623-0.171,1.135-0.659,1.803-0.686c1.026-0.025,2.055-0.006,3.08-0.008c0.401-0.321,0.769-0.709,1.26-0.9
|
||||
c0.869-0.37,1.744-0.836,2.703-0.898c0.994,0.08,1.975,0.287,2.964,0.402c0.235-1.401,0.842-2.703,1.481-3.958
|
||||
c1.241-0.227,2.463-0.58,3.66-0.973C80.409,1.51,80.956,0.784,81.635,0.222z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 4.2 KiB |
8
misc/icons/noun-project/sheep/license.txt
Normal file
@ -0,0 +1,8 @@
|
||||
Thank you for using The Noun Project. This icon is licensed under Creative
|
||||
Commons Attribution and must be attributed as:
|
||||
|
||||
Sheep by Unrecognized MJ from The Noun Project
|
||||
|
||||
If you have a Premium Account or have purchased a license for this icon, you
|
||||
don't need to worry about attribution! We will share the profits from your
|
||||
purchase with this icon's designer.
|
@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" width="89.231px" height="100px" viewBox="0 0 89.231 100" enable-background="new 0 0 89.231 100" xml:space="preserve">
|
||||
<path d="M14.652,64.026c-0.603-2.09-1-4.267-1.15-6.511H0c0.18,3.858,0.86,7.586,1.962,11.13L14.652,64.026z"/>
|
||||
<path d="M14.332,88.192l8.684-10.35c-2.899-2.792-5.273-6.127-6.926-9.857L3.402,72.604C5.9,78.563,9.655,83.87,14.332,88.192z"/>
|
||||
<path d="M42.483,86.499c-6.051-0.409-11.626-2.559-16.245-5.943l-8.681,10.346c6.985,5.336,15.582,8.661,24.926,9.099V86.499z"/>
|
||||
<path d="M44.589,10.768V0L14.266,17.506l30.323,17.506V24.245c17.186,0,31.166,13.98,31.166,31.165 c0,16.477-12.854,29.999-29.061,31.087v13.502C70.337,98.896,89.231,79.32,89.231,55.41C89.231,30.794,69.205,10.768,44.589,10.768z "/>
|
||||
</svg>
|
After Width: | Height: | Size: 843 B |
8
misc/icons/noun-project/undo-kyle_levi_fox/license.txt
Normal file
@ -0,0 +1,8 @@
|
||||
Thank you for using The Noun Project. This icon is licensed under Creative
|
||||
Commons Attribution and must be attributed as:
|
||||
|
||||
Undo by Kyle Levi Fox from The Noun Project
|
||||
|
||||
If you have a Premium Account or have purchased a license for this icon, you
|
||||
don't need to worry about attribution! We will share the profits from your
|
||||
purchase with this icon's designer.
|
@ -1,16 +0,0 @@
|
||||
setlocal
|
||||
@echo off
|
||||
|
||||
pushd ..\..
|
||||
set PISKEL_HOME=%cd%
|
||||
popd
|
||||
|
||||
echo "Updating Piskel icon"
|
||||
|
||||
ResHacker -addoverwrite "%PISKEL_HOME%\dest\desktop\releases\windows\piskel.exe", "%PISKEL_HOME%\dest\desktop\releases\windows\piskel-release.exe", "%PISKEL_HOME%\src\logo.ico", ICONGROUP, IDR_MAINFRAME, 1033
|
||||
|
||||
pause
|
||||
|
||||
explorer "%PISKEL_HOME%\dest\desktop\releases\windows"
|
||||
|
||||
endlocal
|
@ -6,14 +6,11 @@ SETLOCAL
|
||||
set PISKEL_HOME=%cd%
|
||||
POPD
|
||||
|
||||
set VBOX_PATH="C:\Program Files (x86)\Enigma Virtual Box"
|
||||
set RESOURCE_HACKER_PATH="C:\Program Files (x86)\Resource Hacker"
|
||||
|
||||
set APP_BIN="%PISKEL_HOME%\dest\desktop\cache\win\0.9.2"
|
||||
set MISC_FOLDER=%PISKEL_HOME%\misc
|
||||
set RELEASES_FOLDER=%PISKEL_HOME%\dest\desktop\releases
|
||||
set DEST_FOLDER=%RELEASES_FOLDER%\piskel\win\piskel
|
||||
|
||||
set RELEASES_FOLDER=%PISKEL_HOME%\dest\desktop
|
||||
set DEST_FOLDER=%RELEASES_FOLDER%\piskel\win32
|
||||
|
||||
ECHO "Updating Piskel icon -- Using Resource Hacker"
|
||||
%RESOURCE_HACKER_PATH%\ResHacker -addoverwrite "%DEST_FOLDER%\piskel.exe", "%DEST_FOLDER%\piskel-logo.exe", "%MISC_FOLDER%\desktop\logo.ico", ICONGROUP, IDR_MAINFRAME, 1033
|
||||
|
30
package.json
@ -3,7 +3,7 @@
|
||||
"name": "piskel",
|
||||
"main": "./dest/index.html",
|
||||
"description": "Web based 2d animations editor",
|
||||
"version": "0.3.0",
|
||||
"version": "0.5.2",
|
||||
"homepage": "http://github.com/juliandescottes/piskel",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -14,27 +14,27 @@
|
||||
"start": "nodewebkit"
|
||||
},
|
||||
"devDependencies": {
|
||||
"dateformat": "1.0.8-1.2.3",
|
||||
"dateformat": "^1.0.11",
|
||||
"grunt": "~0.4.5",
|
||||
"grunt-closure-tools": "~0.9.7",
|
||||
"grunt-contrib-clean": "0.5.0",
|
||||
"grunt-contrib-concat": "0.5.0",
|
||||
"grunt-contrib-copy": "0.5.0",
|
||||
"grunt-contrib-jshint": "0.10.0",
|
||||
"grunt-contrib-uglify": "0.5.0",
|
||||
"grunt-contrib-clean": "^0.6.0",
|
||||
"grunt-contrib-concat": "^0.5.1",
|
||||
"grunt-contrib-copy": "^0.8.0",
|
||||
"grunt-contrib-jshint": "^0.11.1",
|
||||
"grunt-contrib-uglify": "^0.9.1",
|
||||
"grunt-contrib-watch": "0.6.1",
|
||||
"grunt-express": "1.4.1",
|
||||
"grunt-ghost": "1.1.0",
|
||||
"grunt-leading-indent": "0.1.0",
|
||||
"grunt-node-webkit-builder": "0.1.21",
|
||||
"grunt-jscs": "^1.6.0",
|
||||
"grunt-karma": "^0.10.1",
|
||||
"grunt-leading-indent": "^0.2.0",
|
||||
"grunt-node-webkit-builder": "^1.0.2",
|
||||
"grunt-open": "0.2.3",
|
||||
"grunt-replace": "0.7.8",
|
||||
"grunt-karma": "~0.8.2",
|
||||
"karma": "0.12.17",
|
||||
"grunt-replace": "^0.8.0",
|
||||
"karma": "0.12.31",
|
||||
"karma-chrome-launcher": "^0.1.4",
|
||||
"karma-jasmine": "^0.3.5",
|
||||
"karma-phantomjs-launcher": "^0.1.4",
|
||||
"karma-jasmine": "^0.2.0",
|
||||
"nodewebkit": "~0.10.1"
|
||||
"load-grunt-tasks": "^3.1.0"
|
||||
},
|
||||
"window": {
|
||||
"title": "Piskel",
|
||||
|
@ -27,12 +27,10 @@
|
||||
position: absolute;
|
||||
z-index: 10000;
|
||||
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
|
||||
padding: 50px;
|
||||
top: 50px;
|
||||
right: 50px;
|
||||
bottom: 50px;
|
||||
left: 50px;
|
||||
|
||||
box-sizing: border-box;
|
||||
-moz-box-sizing : border-box;
|
||||
|
@ -66,7 +66,8 @@
|
||||
display: none;
|
||||
}
|
||||
|
||||
.color-picker-slider {
|
||||
.color-picker-slider,
|
||||
.color-picker-input {
|
||||
padding: 0 10px;
|
||||
height : 25px;
|
||||
overflow: hidden;
|
||||
@ -91,6 +92,14 @@
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.color-picker-input {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.color-picker-input .textfield{
|
||||
width:100%;
|
||||
}
|
||||
|
||||
.color-picker-slider input[type="range"][data-dimension="h"] {
|
||||
background-image:linear-gradient(to right, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
|
||||
}
|
@ -60,7 +60,7 @@
|
||||
|
||||
.color-preview {
|
||||
width: 170px;
|
||||
height: 76px;
|
||||
height: 70px;
|
||||
margin: 11px;
|
||||
}
|
||||
|
||||
|
@ -2,28 +2,67 @@
|
||||
/* Import dialog */
|
||||
/************************************************************************************************/
|
||||
|
||||
#dialog-container.import-image {
|
||||
width: 550px;
|
||||
height: 360px;
|
||||
top : 50%;
|
||||
left : 50%;
|
||||
position : absolute;
|
||||
margin-left: -250px;
|
||||
}
|
||||
|
||||
.show #dialog-container.import-image {
|
||||
margin-top: -150px;
|
||||
}
|
||||
|
||||
.import-subsection {
|
||||
margin-left: 25px;
|
||||
}
|
||||
|
||||
.import-section:not(.import-subsection) > .dialog-section-title {
|
||||
width: 50px;
|
||||
}
|
||||
|
||||
.import-section-preview-title {
|
||||
position: absolute;
|
||||
margin-left: 50%;
|
||||
margin-top: -28px;
|
||||
}
|
||||
|
||||
.import-section-preview {
|
||||
display : inline-block;
|
||||
height : 60px;
|
||||
width: 60px;
|
||||
border : 1px dashed #999;
|
||||
position: absolute;
|
||||
display: inline-block;
|
||||
border: 1px dashed #999;
|
||||
border-radius: 3px;
|
||||
margin-left: 50%;
|
||||
}
|
||||
|
||||
.import-section-preview img {
|
||||
max-width: 220px;
|
||||
max-height: 220px;
|
||||
}
|
||||
|
||||
.import-section-preview.no-border {
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
.import-section-preview canvas {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.dialog-section-title {
|
||||
display : inline-block;
|
||||
width: 55px;
|
||||
width: 80px;
|
||||
}
|
||||
|
||||
.import-size-field,
|
||||
.resize-size-field {
|
||||
width: 50px;
|
||||
margin-right: 8px;
|
||||
text-align: right;
|
||||
.dialog-section-radio {
|
||||
margin-top: 15px;
|
||||
vertical-align: sub;
|
||||
}
|
||||
|
||||
.import-size-field:nth-of-type(2),
|
||||
.resize-size-field:nth-of-type(2) {
|
||||
.import-size-field:nth-of-type(2) {
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
@ -31,12 +70,17 @@
|
||||
display: inline-block;
|
||||
overflow: hidden;
|
||||
|
||||
height: 2rem;
|
||||
word-break : break-all;
|
||||
width: 200px;
|
||||
vertical-align: middle;
|
||||
|
||||
word-break : break-all;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
font-style: italic;
|
||||
font-weight: normal;
|
||||
text-shadow: none;
|
||||
color: gold;
|
||||
}
|
||||
|
||||
[name=smooth-resize-checkbox] {
|
||||
@ -44,12 +88,13 @@
|
||||
}
|
||||
|
||||
.dialog-import-body {
|
||||
padding:10px 20px;
|
||||
font-size:1.5em
|
||||
padding: 10px 20px;
|
||||
font-size:1.3em
|
||||
}
|
||||
|
||||
.import-button {
|
||||
font-size: 1em;
|
||||
height: auto;
|
||||
padding: 5px 10px;
|
||||
height: 28px;
|
||||
padding: 0px 10px;
|
||||
margin-top: 15px;
|
||||
}
|
@ -65,19 +65,6 @@
|
||||
margin-top: -250px;
|
||||
}
|
||||
|
||||
#dialog-container.import-image {
|
||||
width: 500px;
|
||||
height: 300px;
|
||||
top : 50%;
|
||||
left : 50%;
|
||||
position : absolute;
|
||||
margin-left: -250px;
|
||||
}
|
||||
|
||||
.show #dialog-container.import-image {
|
||||
margin-top: -150px;
|
||||
}
|
||||
|
||||
.dialog-wrapper {
|
||||
height: 100%;
|
||||
position : relative;
|
||||
|
@ -3,14 +3,15 @@
|
||||
}
|
||||
|
||||
.textfield {
|
||||
box-sizing:border-box;
|
||||
|
||||
background : black;
|
||||
border : 1px solid #888;
|
||||
border-radius : 2px;
|
||||
padding : 3px 10px;
|
||||
color : white;
|
||||
|
||||
box-sizing:border-box;
|
||||
-moz-box-sizing:border-box;
|
||||
height: 23px;
|
||||
}
|
||||
|
||||
.textfield[disabled=disabled] {
|
||||
@ -22,8 +23,8 @@
|
||||
}
|
||||
|
||||
.button {
|
||||
height: 24px;
|
||||
box-sizing: border-box;
|
||||
height: 24px;
|
||||
|
||||
background-color: #3f3f3f;
|
||||
border: 1px solid #333;
|
||||
@ -34,7 +35,7 @@
|
||||
text-decoration: none;
|
||||
|
||||
color: white;
|
||||
text-shadow: 0px -1px 0 black;
|
||||
text-shadow: 0 -1px 0 black;
|
||||
font-weight: bold;
|
||||
font-size: 1rem;
|
||||
text-align: center;
|
||||
@ -56,7 +57,7 @@
|
||||
border-bottom-color: rgb(151, 133, 0);
|
||||
|
||||
color: black;
|
||||
text-shadow: 0px 1px 0 #fff;
|
||||
text-shadow: 0 1px 0 #fff;
|
||||
}
|
||||
|
||||
.button-primary:hover {
|
||||
@ -69,8 +70,16 @@
|
||||
cursor:default;
|
||||
background-color: #aaa;
|
||||
color: #777;
|
||||
text-shadow: 0px 1px 0 #bbb;
|
||||
text-shadow: 0 1px 0 #bbb;
|
||||
border-color: #666;
|
||||
border-top-color: #999;
|
||||
border-bottom-color: #555;
|
||||
}
|
||||
|
||||
.import-size-field,
|
||||
.resize-size-field,
|
||||
.export-size-field {
|
||||
width: 50px;
|
||||
margin-right: 8px;
|
||||
text-align: right;
|
||||
}
|
@ -23,8 +23,8 @@
|
||||
-o-transition: all 500ms ease-out;
|
||||
transition: all 500ms ease-out;
|
||||
|
||||
background-image: linear-gradient(45deg, rgba(0,0,0, 0.8) 25%, transparent 25%, transparent 75%, rgba(0,0,0, 0.8) 75%, rgba(0,0,0, 0.8)),
|
||||
linear-gradient(-45deg, rgba(0,0,0, 0.8) 25%, transparent 25%, transparent 75%, rgba(0,0,0, 0.8) 75%, rgba(0,0,0, 0.8));
|
||||
background-image: linear-gradient(45deg, #1D1D1D 20%, transparent 25%, transparent 75%, #1D1D1D 80%, #1D1D1D),
|
||||
linear-gradient(-45deg, #1D1D1D 20%, transparent 25%, transparent 75%, #1D1D1D 80%, #1D1D1D);
|
||||
background-size: 29px 45px;
|
||||
background-repeat: repeat-x;
|
||||
background-position-x: 3px;
|
154
src/css/layout.css
Normal file
@ -0,0 +1,154 @@
|
||||
/**
|
||||
* Application layout
|
||||
*/
|
||||
|
||||
.main-wrapper {
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
right: 0;
|
||||
bottom: 5px;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.column-wrapper {
|
||||
text-align: center;
|
||||
font-size: 0;
|
||||
position: absolute;
|
||||
left: 100px; /* Reserve room for tools on the left edge of the screen. */
|
||||
top: 0;
|
||||
right: 50px; /* Reserve room for actions on the right edge of the screen. */
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.column {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.left-column {
|
||||
vertical-align: top;
|
||||
height: 100%;
|
||||
margin-right: 7px;
|
||||
}
|
||||
|
||||
.main-column {
|
||||
height: 100%;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.right-column {
|
||||
vertical-align: top;
|
||||
margin-left: 10px;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.drawing-canvas-container {
|
||||
font-size: 0;
|
||||
}
|
||||
|
||||
.sticky-section {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.sticky-section .sticky-section-wrap {
|
||||
display: table;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.sticky-section .vertical-centerer {
|
||||
display: table-cell;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.left-sticky-section.sticky-section {
|
||||
left: 0;
|
||||
max-width: 100px;
|
||||
}
|
||||
|
||||
.left-sticky-section .tool-icon {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.cursor-coordinates {
|
||||
color:#888;
|
||||
font-size:12px;
|
||||
font-weight:bold;
|
||||
font-family:Courier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Canvases layout
|
||||
*/
|
||||
|
||||
.canvas {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.canvas-container {
|
||||
position: relative;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.canvas-container .canvas-background {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.light-picker-background,
|
||||
.light-canvas-background .canvas-background {
|
||||
background: url(../img/canvas_background/light_canvas_background.png) repeat;
|
||||
}
|
||||
|
||||
.medium-picker-background,
|
||||
.medium-canvas-background .canvas-background {
|
||||
background: url(../img/canvas_background/medium_canvas_background.png) repeat;
|
||||
}
|
||||
|
||||
.lowcont-medium-picker-background,
|
||||
.lowcont-medium-canvas-background .canvas-background {
|
||||
background: url(../img/canvas_background/lowcont_medium_canvas_background.png) repeat;
|
||||
}
|
||||
|
||||
.lowcont-dark-picker-background,
|
||||
.lowcont-dark-canvas-background .canvas-background {
|
||||
background: url(../img/canvas_background/lowcont_dark_canvas_background.png) repeat;
|
||||
}
|
||||
|
||||
.layers-canvas,
|
||||
.canvas.onion-skin-canvas {
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
||||
.canvas.canvas-overlay,
|
||||
.canvas.layers-canvas,
|
||||
.canvas.onion-skin-canvas {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.tools-wrapper,
|
||||
.options-wrapper,
|
||||
.palette-wrapper {
|
||||
float : left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Z-indexes should match the drawing area canvas superposition order :
|
||||
* - 1 : draw layers below current layer
|
||||
* - 2 : draw current layer
|
||||
* - 3 : draw layers above current layer
|
||||
* - 4 : draw the tools overlay
|
||||
*/
|
||||
.canvas.layers-below-canvas {z-index: 7;}
|
||||
.canvas.drawing-canvas {z-index: 8;}
|
||||
.canvas.canvas-overlay {z-index: 9;}
|
||||
.canvas.onion-skin-canvas {z-index: 10;}
|
||||
.canvas.layers-above-canvas {z-index: 11;}
|
@ -3,7 +3,7 @@ html, body {
|
||||
margin : 0;
|
||||
overflow: hidden;
|
||||
cursor : default;
|
||||
font-family: arial;
|
||||
font-family: Arial;
|
||||
font-size: 11px;
|
||||
-webkit-touch-callout: none;
|
||||
-webkit-user-select: none;
|
||||
@ -19,6 +19,12 @@ ul, li {
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
/** Firefox overrides this with -moz-use-system-font */
|
||||
button,
|
||||
input,
|
||||
input[type="submit"] {
|
||||
font-family: Arial;
|
||||
}
|
||||
|
||||
/* Force apparition of scrollbars on leopard */
|
||||
::-webkit-scrollbar {
|
||||
|
3
src/css/settings-application.css
Normal file
@ -0,0 +1,3 @@
|
||||
/*******************************/
|
||||
/* Application Setting panel */
|
||||
/*******************************/
|
@ -23,6 +23,10 @@
|
||||
float: left;
|
||||
}
|
||||
|
||||
.png-export-preview .light-picker-background {
|
||||
max-width:240px;
|
||||
}
|
||||
|
||||
.gif-upload-status {
|
||||
width: 180px;
|
||||
margin-left: 5px;
|
||||
|
103
src/css/settings-resize.css
Normal file
@ -0,0 +1,103 @@
|
||||
.resize-section-title {
|
||||
vertical-align: top;
|
||||
display: inline-block;
|
||||
padding-top: 5px;
|
||||
width: 25%;
|
||||
}
|
||||
|
||||
/*****************/
|
||||
/* ANCHOR WIDGET */
|
||||
/*****************/
|
||||
|
||||
.resize-origin-container {
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
width: 70px;
|
||||
margin-top: 5px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.transition .resize-origin-option,
|
||||
.transition .resize-origin-option:before {
|
||||
transition: background-color 0.2s, border-color 0.2s;
|
||||
}
|
||||
|
||||
.resize-origin-option {
|
||||
float: left;
|
||||
position: relative;
|
||||
|
||||
box-sizing: border-box;
|
||||
margin: 0 1px 1px 0;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
|
||||
background : #888;
|
||||
|
||||
font-size: 8px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.disabled .resize-origin-option {
|
||||
cursor: default;
|
||||
background : #555;
|
||||
border-color: #555 !important;
|
||||
}
|
||||
|
||||
.resize-origin-option.selected {
|
||||
border : 3px solid gold;
|
||||
}
|
||||
|
||||
.resize-origin-option:before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
display: block;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
margin: -2px;
|
||||
}
|
||||
|
||||
.resize-origin-option.selected:before {
|
||||
content: '';
|
||||
width: 4px;
|
||||
height: 4px;
|
||||
background: gold;
|
||||
}
|
||||
|
||||
.disabled .resize-origin-option.selected:before {
|
||||
background: #555;
|
||||
}
|
||||
|
||||
.disabled .resize-origin-option[data-neighbor]:before {
|
||||
border-color: #555 !important;
|
||||
}
|
||||
|
||||
.resize-origin-option[data-neighbor]:before {
|
||||
width: 0;
|
||||
height: 0;
|
||||
border-width: 4px;
|
||||
border-style: solid;
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
.resize-origin-option[data-neighbor="bottom"]:before {
|
||||
border-top-color: gold;
|
||||
margin-left: -4px;
|
||||
}
|
||||
|
||||
.resize-origin-option[data-neighbor="left"]:before {
|
||||
border-right-color: gold;
|
||||
margin-top: -4px;
|
||||
margin-left: -6px;
|
||||
}
|
||||
|
||||
.resize-origin-option[data-neighbor="top"]:before {
|
||||
border-bottom-color: gold;
|
||||
margin-top: -6px;
|
||||
margin-left: -4px;
|
||||
}
|
||||
|
||||
.resize-origin-option[data-neighbor="right"]:before {
|
||||
border-left-color: gold;
|
||||
margin-top: -4px;
|
||||
}
|
@ -184,12 +184,15 @@
|
||||
border: gold 1px solid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/************************************************************************************************/
|
||||
/* Save panel */
|
||||
/************************************************************************************************/
|
||||
|
||||
.anonymous .save-public-section,
|
||||
.anonymous #save-online-button {
|
||||
display : none;
|
||||
}
|
||||
|
||||
.save-field {
|
||||
width: 100%;
|
||||
}
|
||||
@ -208,4 +211,11 @@
|
||||
font-weight: bold;
|
||||
color: white;
|
||||
font-style: normal;
|
||||
}
|
||||
}
|
||||
|
||||
.save-desktop-file-name {
|
||||
word-wrap: break-word;
|
||||
font-weight: bold;
|
||||
color: white;
|
||||
font-style: normal;
|
||||
}
|
||||
|
@ -1,9 +1,5 @@
|
||||
body {
|
||||
background: radial-gradient(circle, #000, #373737);
|
||||
/* 16/06/2013 : -webkit still needed for
|
||||
safari, safari mobile and android browser and chrome for android
|
||||
cf http://caniuse.com/css-gradients */
|
||||
background: -webkit-radial-gradient(circle, #000, #373737);
|
||||
background: #1D1D1D;
|
||||
}
|
||||
|
||||
/* Browser fixes */
|
||||
@ -20,148 +16,10 @@ body {
|
||||
user-select: initial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Application layout
|
||||
*/
|
||||
|
||||
.main-wrapper {
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
right: 0;
|
||||
bottom: 5px;
|
||||
left: 0;
|
||||
.no-overflow {
|
||||
overflow : hidden;
|
||||
}
|
||||
|
||||
.column-wrapper {
|
||||
text-align: center;
|
||||
font-size: 0;
|
||||
position: absolute;
|
||||
left: 100px; /* Reserve room for tools on the left edge of the screen. */
|
||||
top: 0;
|
||||
right: 50px; /* Reserve room for actions on the right edge of the screen. */
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.column {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.left-column {
|
||||
vertical-align: top;
|
||||
height: 100%;
|
||||
margin-right: 7px;
|
||||
}
|
||||
|
||||
.main-column {
|
||||
height: 100%;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.right-column {
|
||||
vertical-align: top;
|
||||
margin-left: 10px;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.drawing-canvas-container {
|
||||
font-size: 0;
|
||||
}
|
||||
|
||||
.sticky-section {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.sticky-section .sticky-section-wrap {
|
||||
display: table;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.sticky-section .vertical-centerer {
|
||||
display: table-cell;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.left-sticky-section.sticky-section {
|
||||
left: 0;
|
||||
max-width: 100px;
|
||||
}
|
||||
|
||||
.left-sticky-section .tool-icon {
|
||||
float: left;
|
||||
}
|
||||
|
||||
/**
|
||||
* Canvases layout
|
||||
*/
|
||||
|
||||
.canvas {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.canvas-container {
|
||||
position: relative;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.canvas-container .canvas-background {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.light-picker-background,
|
||||
.light-canvas-background .canvas-background {
|
||||
background: url(../img/canvas_background/light_canvas_background.png) repeat;
|
||||
}
|
||||
|
||||
.medium-picker-background,
|
||||
.medium-canvas-background .canvas-background {
|
||||
background: url(../img/canvas_background/medium_canvas_background.png) repeat;
|
||||
}
|
||||
|
||||
.lowcont-medium-picker-background,
|
||||
.lowcont-medium-canvas-background .canvas-background {
|
||||
background: url(../img/canvas_background/lowcont_medium_canvas_background.png) repeat;
|
||||
}
|
||||
|
||||
.lowcont-dark-picker-background,
|
||||
.lowcont-dark-canvas-background .canvas-background {
|
||||
background: url(../img/canvas_background/lowcont_dark_canvas_background.png) repeat;
|
||||
}
|
||||
|
||||
.layers-canvas,
|
||||
.canvas.onion-skin-canvas {
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
||||
.canvas.canvas-overlay,
|
||||
.canvas.layers-canvas,
|
||||
.canvas.onion-skin-canvas {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Z-indexes should match the drawing area canvas superposition order :
|
||||
* - 1 : draw layers below current layer
|
||||
* - 2 : draw current layer
|
||||
* - 3 : draw layers above current layer
|
||||
* - 4 : draw the tools overlay
|
||||
*/
|
||||
.canvas.layers-below-canvas {z-index: 7;}
|
||||
.canvas.drawing-canvas {z-index: 8;}
|
||||
.canvas.canvas-overlay {z-index: 9;}
|
||||
.canvas.onion-skin-canvas {z-index: 10;}
|
||||
.canvas.layers-above-canvas {z-index: 11;}
|
||||
|
||||
.image-link {
|
||||
color : gold;
|
||||
}
|
||||
@ -189,9 +47,11 @@ body {
|
||||
left:0;
|
||||
}
|
||||
|
||||
.cursor-coordinates {
|
||||
color:#888;
|
||||
font-size:12px;
|
||||
font-weight:bold;
|
||||
font-family:Courier;
|
||||
}
|
||||
.uppercase {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.checkbox-fix {
|
||||
vertical-align: -2px;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
@ -3,9 +3,9 @@
|
||||
*/
|
||||
|
||||
.preview-container {
|
||||
border : 0px Solid black;
|
||||
border-radius:5px 0px 0px 5px;
|
||||
box-shadow : 0px 0px 2px rgba(0,0,0,0.2);
|
||||
border : 0 Solid black;
|
||||
border-radius:5px 0 0 5px;
|
||||
box-shadow : 0 0 2px rgba(0,0,0,0.2);
|
||||
font-size: 0;
|
||||
}
|
||||
|
||||
@ -14,7 +14,12 @@
|
||||
}
|
||||
|
||||
.preview-container canvas {
|
||||
border : 0px Solid transparent;
|
||||
border : 0 Solid transparent;
|
||||
}
|
||||
|
||||
.canvas-container .animated-preview-canvas-background {
|
||||
position : relative;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#animated-preview-container {
|
||||
@ -23,9 +28,10 @@
|
||||
overflow : hidden;
|
||||
}
|
||||
|
||||
#animated-preview-canvas-container {
|
||||
.canvas-container-wrapper {
|
||||
height :200px;
|
||||
width : 200px;
|
||||
overflow:hidden;
|
||||
}
|
||||
|
||||
.tiled-frame-container {
|
||||
@ -73,4 +79,28 @@
|
||||
.preview-toggle-onion-skin-enabled,
|
||||
.preview-toggle-onion-skin-enabled:hover {
|
||||
color : gold;
|
||||
}
|
||||
}
|
||||
|
||||
.open-popup-preview-button {
|
||||
position : absolute;
|
||||
z-index: 500;
|
||||
right : 10px;
|
||||
top : 10px;
|
||||
width : 24px;
|
||||
height: 18px;
|
||||
|
||||
border : 2px solid white;
|
||||
background : rgba(0,0,0,0.3);
|
||||
cursor : pointer;
|
||||
|
||||
opacity: 0;
|
||||
transition: 0.3s opacity, 0.3s border-color;
|
||||
}
|
||||
|
||||
.minimap-container:hover .open-popup-preview-button {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.open-popup-preview-button:hover {
|
||||
border-color: gold;
|
||||
}
|
||||
|
@ -1,10 +1,3 @@
|
||||
|
||||
.tools-wrapper,
|
||||
.options-wrapper,
|
||||
.palette-wrapper {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.tool-icon {
|
||||
position : relative;
|
||||
cursor : pointer;
|
||||
@ -88,8 +81,8 @@
|
||||
|
||||
.tool-icon.tool-lighten {
|
||||
background-image: url(../img/tools/lighten.png);
|
||||
background-size: 30px 30px;
|
||||
background-position: 8px 8px;
|
||||
background-size: 30px 30px;
|
||||
}
|
||||
|
||||
.tool-icon.tool-colorpicker {
|
||||
@ -103,6 +96,24 @@
|
||||
background-size: 36px 36px;
|
||||
}
|
||||
|
||||
.tool-icon.tool-flip {
|
||||
background-image: url(../img/tools/flip.png);
|
||||
background-position: 7px 11px;
|
||||
background-size: 32px;
|
||||
}
|
||||
|
||||
.tool-icon.tool-rotate {
|
||||
background-image: url(../img/tools/rotate.png);
|
||||
background-position: 10px 9px;
|
||||
background-size: 26px;
|
||||
}
|
||||
|
||||
.tool-icon.tool-clone {
|
||||
background-image: url(../img/tools/clone.png);
|
||||
background-position: 9px 15px;
|
||||
background-size: 30px;
|
||||
}
|
||||
|
||||
/*
|
||||
* Tool cursors:
|
||||
*/
|
||||
|
4
src/css/transformations.css
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
.transformations-container .tool-icon {
|
||||
float:left;
|
||||
}
|
BIN
src/img/tools/clone.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
src/img/tools/flip.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
src/img/tools/rotate.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
@ -44,6 +44,7 @@
|
||||
<div class="column right-column">
|
||||
<iframe src="templates/preview.html" onload="iframeloader.onLoad(event)" data-iframe-loader="display"></iframe>
|
||||
<iframe src="templates/layers-list.html" onload="iframeloader.onLoad(event)" data-iframe-loader="display"></iframe>
|
||||
<iframe src="templates/transformations.html" onload="iframeloader.onLoad(event)" data-iframe-loader="display"></iframe>
|
||||
<iframe src="templates/palettes-list.html" onload="iframeloader.onLoad(event)" data-iframe-loader="display"></iframe>
|
||||
<div class="pull-bottom cursor-coordinates"></div>
|
||||
</div>
|
||||
@ -75,10 +76,12 @@
|
||||
|
||||
<iframe src="templates/cheatsheet.html" onload="iframeloader.onLoad(event)" data-iframe-loader="display"></iframe>
|
||||
<iframe src="templates/misc-templates.html" onload="iframeloader.onLoad(event)" data-iframe-loader="display"></iframe>
|
||||
<iframe src="templates/popup-preview.html" onload="iframeloader.onLoad(event)" data-iframe-loader="display"></iframe>
|
||||
|
||||
<script type="text/javascript" src="piskel-boot.js"></script>
|
||||
<!--body-main-end-->
|
||||
<!-- the comment above indicates the end of the markup reused by the editor integrated in piskelapp.com -->
|
||||
<!-- do not delete, do not move :) -->
|
||||
|
||||
<script type="text/javascript" src="piskel-boot-0.1.0.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -11,7 +11,7 @@ var Constants = {
|
||||
MAX_HEIGHT : 1024,
|
||||
MAX_WIDTH : 1024,
|
||||
|
||||
MAX_CURRENT_COLORS_DISPLAYED : 100,
|
||||
MAX_PALETTE_COLORS : 100,
|
||||
|
||||
MINIMUM_ZOOM : 1,
|
||||
|
||||
@ -21,16 +21,8 @@ var Constants = {
|
||||
DEFAULT_PEN_COLOR : '#000000',
|
||||
TRANSPARENT_COLOR : 'rgba(0, 0, 0, 0)',
|
||||
|
||||
OVERLAY_ONION_SKIN : 'onion-skin',
|
||||
OVERLAY_LAYER_PREVIEW : 'layer-preview',
|
||||
OVERLAY_DISABLED : 'no-overlay',
|
||||
|
||||
NO_PALETTE_ID : '__no-palette',
|
||||
CURRENT_COLORS_PALETTE_ID : '__current-colors',
|
||||
|
||||
// Used for Spectrum input
|
||||
PREFERRED_COLOR_FORMAT : 'rgb',
|
||||
|
||||
/*
|
||||
* Fake semi-transparent color used to highlight transparent
|
||||
* strokes and rectangles:
|
||||
@ -43,23 +35,6 @@ var Constants = {
|
||||
*/
|
||||
TOOL_TARGET_HIGHLIGHT_COLOR: 'rgba(255, 255, 255, 0.2)',
|
||||
|
||||
/*
|
||||
* Default entry point for piskel web service:
|
||||
*/
|
||||
STATIC : {
|
||||
URL : {
|
||||
SAVE : 'http://3.piskel-app.appspot.com/store',
|
||||
GET : 'http://3.piskel-app.appspot.com/get'
|
||||
}
|
||||
},
|
||||
APPENGINE : {
|
||||
URL : {
|
||||
SAVE : 'save'
|
||||
}
|
||||
},
|
||||
IMAGE_SERVICE_UPLOAD_URL : 'http://piskel-imgstore-a.appspot.com/__/upload',
|
||||
IMAGE_SERVICE_GET_URL : 'http://piskel-imgstore-a.appspot.com/img/',
|
||||
|
||||
ZOOMED_OUT_BACKGROUND_COLOR : '#A0A0A0',
|
||||
|
||||
LEFT_BUTTON : 0,
|
||||
@ -71,5 +46,10 @@ var Constants = {
|
||||
EMPTY_FUNCTION : function () {},
|
||||
|
||||
// TESTS
|
||||
DRAWING_TEST_FOLDER : 'drawing'
|
||||
};
|
||||
DRAWING_TEST_FOLDER : 'drawing',
|
||||
|
||||
// SERVICE URLS
|
||||
APPENGINE_SAVE_URL : 'save',
|
||||
IMAGE_SERVICE_UPLOAD_URL : 'http://piskel-imgstore-b.appspot.com/__/upload',
|
||||
IMAGE_SERVICE_GET_URL : 'http://piskel-imgstore-b.appspot.com/img/'
|
||||
};
|
||||
|
@ -1,12 +1,13 @@
|
||||
// TODO(grosbouddha): put under pskl namespace.
|
||||
var Events = {
|
||||
|
||||
TOOL_SELECTED : "TOOL_SELECTED",
|
||||
SELECT_TOOL : "SELECT_TOOL",
|
||||
TOOL_SELECTED : 'TOOL_SELECTED',
|
||||
SELECT_TOOL : 'SELECT_TOOL',
|
||||
|
||||
TOOL_RELEASED : "TOOL_RELEASED",
|
||||
SELECT_PRIMARY_COLOR: "SELECT_PRIMARY_COLOR",
|
||||
SELECT_SECONDARY_COLOR: "SELECT_SECONDARY_COLOR",
|
||||
TOOL_RELEASED : 'TOOL_RELEASED',
|
||||
TOOL_PRESSED : 'TOOL_PRESSED',
|
||||
SELECT_PRIMARY_COLOR: 'SELECT_PRIMARY_COLOR',
|
||||
SELECT_SECONDARY_COLOR: 'SELECT_SECONDARY_COLOR',
|
||||
PRIMARY_COLOR_SELECTED : 'PRIMARY_COLOR_SELECTED',
|
||||
SECONDARY_COLOR_SELECTED : 'SECONDARY_COLOR_SELECTED',
|
||||
|
||||
@ -25,40 +26,43 @@ var Events = {
|
||||
* 1st argument: Name of the settings
|
||||
* 2nd argument: New value
|
||||
*/
|
||||
USER_SETTINGS_CHANGED: "USER_SETTINGS_CHANGED",
|
||||
USER_SETTINGS_CHANGED: 'USER_SETTINGS_CHANGED',
|
||||
|
||||
CLOSE_SETTINGS_DRAWER : "CLOSE_SETTINGS_DRAWER",
|
||||
CLOSE_SETTINGS_DRAWER : 'CLOSE_SETTINGS_DRAWER',
|
||||
|
||||
/**
|
||||
* The framesheet was reseted and is now probably drastically different.
|
||||
* Number of frames, content of frames, color used for the palette may have changed.
|
||||
*/
|
||||
PISKEL_RESET: "PISKEL_RESET",
|
||||
PISKEL_SAVE_STATE: "PISKEL_SAVE_STATE",
|
||||
PISKEL_RESET: 'PISKEL_RESET',
|
||||
PISKEL_SAVE_STATE: 'PISKEL_SAVE_STATE',
|
||||
|
||||
PISKEL_SAVED: "PISKEL_SAVED",
|
||||
HISTORY_STATE_SAVED: 'HISTORY_STATE_SAVED',
|
||||
HISTORY_STATE_LOADED: 'HISTORY_STATE_LOADED',
|
||||
|
||||
FRAME_SIZE_CHANGED : "FRAME_SIZE_CHANGED",
|
||||
PISKEL_SAVED: 'PISKEL_SAVED',
|
||||
|
||||
SELECTION_CREATED: "SELECTION_CREATED",
|
||||
SELECTION_MOVE_REQUEST: "SELECTION_MOVE_REQUEST",
|
||||
SELECTION_DISMISSED: "SELECTION_DISMISSED",
|
||||
FRAME_SIZE_CHANGED : 'FRAME_SIZE_CHANGED',
|
||||
|
||||
SHOW_NOTIFICATION: "SHOW_NOTIFICATION",
|
||||
HIDE_NOTIFICATION: "HIDE_NOTIFICATION",
|
||||
SELECTION_CREATED: 'SELECTION_CREATED',
|
||||
SELECTION_MOVE_REQUEST: 'SELECTION_MOVE_REQUEST',
|
||||
SELECTION_DISMISSED: 'SELECTION_DISMISSED',
|
||||
|
||||
SHOW_PROGRESS: "SHOW_PROGRESS",
|
||||
UPDATE_PROGRESS: "UPDATE_PROGRESS",
|
||||
HIDE_PROGRESS: "HIDE_PROGRESS",
|
||||
SHOW_NOTIFICATION: 'SHOW_NOTIFICATION',
|
||||
HIDE_NOTIFICATION: 'HIDE_NOTIFICATION',
|
||||
|
||||
ZOOM_CHANGED : "ZOOM_CHANGED",
|
||||
SHOW_PROGRESS: 'SHOW_PROGRESS',
|
||||
UPDATE_PROGRESS: 'UPDATE_PROGRESS',
|
||||
HIDE_PROGRESS: 'HIDE_PROGRESS',
|
||||
|
||||
CURRENT_COLORS_UPDATED : "CURRENT_COLORS_UPDATED",
|
||||
ZOOM_CHANGED : 'ZOOM_CHANGED',
|
||||
|
||||
MOUSE_EVENT : "MOUSE_EVENT",
|
||||
CURRENT_COLORS_UPDATED : 'CURRENT_COLORS_UPDATED',
|
||||
|
||||
MOUSE_EVENT : 'MOUSE_EVENT',
|
||||
|
||||
// Tests
|
||||
TEST_RECORD_END : "TEST_RECORD_END",
|
||||
TEST_CASE_END : "TEST_CASE_END",
|
||||
TEST_SUITE_END : "TEST_SUITE_END"
|
||||
};
|
||||
TEST_RECORD_END : 'TEST_RECORD_END',
|
||||
TEST_CASE_END : 'TEST_CASE_END',
|
||||
TEST_SUITE_END : 'TEST_SUITE_END'
|
||||
};
|
||||
|
@ -3,7 +3,7 @@
|
||||
* @require Events
|
||||
*/
|
||||
(function () {
|
||||
var ns = $.namespace("pskl");
|
||||
var ns = $.namespace('pskl');
|
||||
/**
|
||||
* Main application controller
|
||||
*/
|
||||
@ -18,15 +18,11 @@
|
||||
this.shortcutService = new pskl.service.keyboard.ShortcutService();
|
||||
this.shortcutService.init();
|
||||
|
||||
var size = {
|
||||
height : Constants.DEFAULT.HEIGHT,
|
||||
width : Constants.DEFAULT.WIDTH
|
||||
};
|
||||
|
||||
var size = pskl.UserSettings.get(pskl.UserSettings.DEFAULT_SIZE);
|
||||
var descriptor = new pskl.model.piskel.Descriptor('New Piskel', '');
|
||||
var piskel = new pskl.model.Piskel(size.width, size.height, descriptor);
|
||||
|
||||
var layer = new pskl.model.Layer("Layer 1");
|
||||
var layer = new pskl.model.Layer('Layer 1');
|
||||
var frame = new pskl.model.Frame(size.width, size.height);
|
||||
|
||||
layer.addFrame(frame);
|
||||
@ -48,23 +44,36 @@
|
||||
this.currentColorsService = new pskl.service.CurrentColorsService(this.piskelController);
|
||||
this.currentColorsService.init();
|
||||
|
||||
this.palettesListController = new pskl.controller.PalettesListController(this.paletteController, this.currentColorsService);
|
||||
this.palettesListController = new pskl.controller.PalettesListController(
|
||||
this.paletteController,
|
||||
this.currentColorsService);
|
||||
this.palettesListController.init();
|
||||
|
||||
this.cursorCoordinatesController = new pskl.controller.CursorCoordinatesController(this.piskelController);
|
||||
this.cursorCoordinatesController.init();
|
||||
|
||||
this.drawingController = new pskl.controller.DrawingController(this.piskelController, this.paletteController, $('#drawing-canvas-container'));
|
||||
this.drawingController = new pskl.controller.DrawingController(
|
||||
this.piskelController,
|
||||
this.paletteController,
|
||||
$('#drawing-canvas-container'));
|
||||
this.drawingController.init();
|
||||
|
||||
this.animationController = new pskl.controller.AnimatedPreviewController(this.piskelController, $('#animated-preview-canvas-container'));
|
||||
this.animationController.init();
|
||||
this.previewController = new pskl.controller.preview.PreviewController(
|
||||
this.piskelController,
|
||||
$('#animated-preview-canvas-container'));
|
||||
this.previewController.init();
|
||||
|
||||
this.minimapController = new pskl.controller.MinimapController(this.piskelController, this.animationController, this.drawingController, $('#animated-preview-canvas-container'));
|
||||
this.minimapController = new pskl.controller.MinimapController(
|
||||
this.piskelController,
|
||||
this.previewController,
|
||||
this.drawingController,
|
||||
$('.minimap-container'));
|
||||
this.minimapController.init();
|
||||
|
||||
this.previewFilmController = new pskl.controller.PreviewFilmController(this.piskelController, $('#preview-list'));
|
||||
this.previewFilmController.init();
|
||||
this.framesListController = new pskl.controller.FramesListController(
|
||||
this.piskelController,
|
||||
$('#preview-list'));
|
||||
this.framesListController.init();
|
||||
|
||||
this.layersListController = new pskl.controller.LayersListController(this.piskelController);
|
||||
this.layersListController.init();
|
||||
@ -87,6 +96,9 @@
|
||||
this.notificationController = new pskl.controller.NotificationController();
|
||||
this.notificationController.init();
|
||||
|
||||
this.transformationsController = new pskl.controller.TransformationsController();
|
||||
this.transformationsController.init();
|
||||
|
||||
this.progressBarController = new pskl.controller.ProgressBarController();
|
||||
this.progressBarController.init();
|
||||
|
||||
@ -96,6 +108,9 @@
|
||||
this.localStorageService = new pskl.service.LocalStorageService(this.piskelController);
|
||||
this.localStorageService.init();
|
||||
|
||||
this.desktopStorageService = new pskl.service.DesktopStorageService(this.piskelController);
|
||||
this.desktopStorageService.init();
|
||||
|
||||
this.imageUploadService = new pskl.service.ImageUploadService();
|
||||
this.imageUploadService.init();
|
||||
|
||||
@ -111,7 +126,9 @@
|
||||
this.beforeUnloadService = new pskl.service.BeforeUnloadService(this.piskelController);
|
||||
this.beforeUnloadService.init();
|
||||
|
||||
this.fileDropperService = new pskl.service.FileDropperService(this.piskelController, $('#drawing-canvas-container').get(0));
|
||||
this.fileDropperService = new pskl.service.FileDropperService(
|
||||
this.piskelController,
|
||||
document.querySelector('#drawing-canvas-container'));
|
||||
this.fileDropperService.init();
|
||||
|
||||
if (this.isAppEngineVersion) {
|
||||
@ -135,13 +152,20 @@
|
||||
if (pskl.devtools) {
|
||||
pskl.devtools.init();
|
||||
}
|
||||
|
||||
if (pskl.utils.Environment.detectNodeWebkit() && pskl.utils.UserAgent.isMac) {
|
||||
var gui = require('nw.gui');
|
||||
var mb = new gui.Menu({type:'menubar'});
|
||||
mb.createMacBuiltin('Piskel');
|
||||
gui.Window.get().menu = mb;
|
||||
}
|
||||
},
|
||||
|
||||
loadPiskel_ : function (serializedPiskel, descriptor, fps) {
|
||||
pskl.utils.serialization.Deserializer.deserialize(serializedPiskel, function (piskel) {
|
||||
piskel.setDescriptor(descriptor);
|
||||
pskl.app.piskelController.setPiskel(piskel);
|
||||
pskl.app.animationController.setFPS(fps);
|
||||
pskl.app.previewController.setFPS(fps);
|
||||
});
|
||||
},
|
||||
|
||||
@ -162,8 +186,8 @@
|
||||
|
||||
render : function (delta) {
|
||||
this.drawingController.render(delta);
|
||||
this.animationController.render(delta);
|
||||
this.previewFilmController.render(delta);
|
||||
this.previewController.render(delta);
|
||||
this.framesListController.render(delta);
|
||||
},
|
||||
|
||||
getFirstFrameAsPng : function () {
|
||||
@ -171,13 +195,13 @@
|
||||
var canvasRenderer = new pskl.rendering.CanvasRenderer(firstFrame, 1);
|
||||
canvasRenderer.drawTransparentAs('rgba(0,0,0,0)');
|
||||
var firstFrameCanvas = canvasRenderer.render();
|
||||
return firstFrameCanvas.toDataURL("image/png");
|
||||
return firstFrameCanvas.toDataURL('image/png');
|
||||
},
|
||||
|
||||
getFramesheetAsPng : function () {
|
||||
var renderer = new pskl.rendering.PiskelRenderer(this.piskelController);
|
||||
var framesheetCanvas = renderer.renderAsCanvas();
|
||||
return framesheetCanvas.toDataURL("image/png");
|
||||
return framesheetCanvas.toDataURL('image/png');
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
@ -1,153 +0,0 @@
|
||||
(function () {
|
||||
var ns = $.namespace("pskl.controller");
|
||||
|
||||
// Preview is a square of PREVIEW_SIZE x PREVIEW_SIZE
|
||||
var PREVIEW_SIZE = 200;
|
||||
|
||||
ns.AnimatedPreviewController = function (piskelController, container) {
|
||||
this.piskelController = piskelController;
|
||||
this.container = container;
|
||||
|
||||
this.elapsedTime = 0;
|
||||
this.currentIndex = 0;
|
||||
|
||||
this.setFPS(Constants.DEFAULT.FPS);
|
||||
|
||||
var frame = this.piskelController.getCurrentFrame();
|
||||
|
||||
this.renderer = new pskl.rendering.frame.TiledFrameRenderer(this.container);
|
||||
};
|
||||
|
||||
ns.AnimatedPreviewController.prototype.init = function () {
|
||||
// the oninput event won't work on IE10 unfortunately, but at least will provide a
|
||||
// consistent behavior across all other browsers that support the input type range
|
||||
// see https://bugzilla.mozilla.org/show_bug.cgi?id=853670
|
||||
$("#preview-fps")[0].addEventListener('change', this.onFPSSliderChange.bind(this));
|
||||
document.querySelector(".right-column").style.width = Constants.ANIMATED_PREVIEW_WIDTH + 'px';
|
||||
|
||||
this.toggleOnionSkinEl = document.querySelector(".preview-toggle-onion-skin");
|
||||
this.toggleOnionSkinEl.addEventListener('click', this.toggleOnionSkin_.bind(this));
|
||||
|
||||
pskl.app.shortcutService.addShortcut('alt+O', this.toggleOnionSkin_.bind(this));
|
||||
|
||||
$.subscribe(Events.FRAME_SIZE_CHANGED, this.onFrameSizeChange_.bind(this));
|
||||
$.subscribe(Events.USER_SETTINGS_CHANGED, $.proxy(this.onUserSettingsChange_, this));
|
||||
|
||||
this.updateZoom_();
|
||||
this.updateOnionSkinPreview_();
|
||||
};
|
||||
|
||||
ns.AnimatedPreviewController.prototype.onUserSettingsChange_ = function (evt, name, value) {
|
||||
if (name == pskl.UserSettings.ONION_SKIN) {
|
||||
this.updateOnionSkinPreview_();
|
||||
} else {
|
||||
this.updateZoom_();
|
||||
this.updateContainerDimensions_();
|
||||
}
|
||||
};
|
||||
|
||||
ns.AnimatedPreviewController.prototype.updateOnionSkinPreview_ = function () {
|
||||
var enabledClassname = 'preview-toggle-onion-skin-enabled';
|
||||
if (pskl.UserSettings.get(pskl.UserSettings.ONION_SKIN)) {
|
||||
this.toggleOnionSkinEl.classList.add(enabledClassname);
|
||||
} else {
|
||||
this.toggleOnionSkinEl.classList.remove(enabledClassname);
|
||||
}
|
||||
};
|
||||
|
||||
ns.AnimatedPreviewController.prototype.updateZoom_ = function () {
|
||||
var isTiled = pskl.UserSettings.get(pskl.UserSettings.TILED_PREVIEW);
|
||||
var zoom = isTiled ? 1 : this.calculateZoom_();
|
||||
this.renderer.setZoom(zoom);
|
||||
};
|
||||
|
||||
ns.AnimatedPreviewController.prototype.getZoom = function () {
|
||||
return this.calculateZoom_();
|
||||
};
|
||||
|
||||
ns.AnimatedPreviewController.prototype.getCoordinates = function(x, y) {
|
||||
var containerOffset = this.container.offset();
|
||||
x = x - containerOffset.left;
|
||||
y = y - containerOffset.top;
|
||||
var zoom = this.getZoom();
|
||||
return {
|
||||
x : Math.floor(x / zoom),
|
||||
y : Math.floor(y / zoom)
|
||||
};
|
||||
};
|
||||
|
||||
ns.AnimatedPreviewController.prototype.onFPSSliderChange = function (evt) {
|
||||
this.setFPS(parseInt($("#preview-fps")[0].value, 10));
|
||||
};
|
||||
|
||||
ns.AnimatedPreviewController.prototype.setFPS = function (fps) {
|
||||
if (fps) {
|
||||
this.fps = fps;
|
||||
$("#preview-fps").val(this.fps);
|
||||
$("#display-fps").html(this.fps + " FPS");
|
||||
}
|
||||
};
|
||||
|
||||
ns.AnimatedPreviewController.prototype.getFPS = function () {
|
||||
return this.fps;
|
||||
};
|
||||
|
||||
ns.AnimatedPreviewController.prototype.render = function (delta) {
|
||||
this.elapsedTime += delta;
|
||||
var index = Math.floor(this.elapsedTime / (1000/this.fps));
|
||||
if (index != this.currentIndex) {
|
||||
this.currentIndex = index;
|
||||
if (!this.piskelController.hasFrameAt(this.currentIndex)) {
|
||||
this.currentIndex = 0;
|
||||
this.elapsedTime = 0;
|
||||
}
|
||||
var frame = this.piskelController.getFrameAt(this.currentIndex);
|
||||
this.renderer.render(frame);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculate the preview zoom depending on the framesheet size
|
||||
*/
|
||||
ns.AnimatedPreviewController.prototype.calculateZoom_ = function () {
|
||||
var frame = this.piskelController.getCurrentFrame();
|
||||
var previewSize = 200,
|
||||
hZoom = previewSize / frame.getHeight(),
|
||||
wZoom = previewSize / frame.getWidth();
|
||||
|
||||
return Math.min(hZoom, wZoom);
|
||||
};
|
||||
|
||||
ns.AnimatedPreviewController.prototype.onFrameSizeChange_ = function () {
|
||||
this.updateZoom_();
|
||||
this.updateContainerDimensions_();
|
||||
};
|
||||
|
||||
ns.AnimatedPreviewController.prototype.updateContainerDimensions_ = function () {
|
||||
var containerEl = this.container.get(0);
|
||||
var isTiled = pskl.UserSettings.get(pskl.UserSettings.TILED_PREVIEW);
|
||||
var height, width;
|
||||
|
||||
if (isTiled) {
|
||||
height = PREVIEW_SIZE;
|
||||
width = PREVIEW_SIZE;
|
||||
} else {
|
||||
var zoom = this.getZoom();
|
||||
var frame = this.piskelController.getCurrentFrame();
|
||||
height = frame.getHeight() * zoom;
|
||||
width = frame.getWidth() * zoom;
|
||||
}
|
||||
|
||||
containerEl.style.height = height + "px";
|
||||
containerEl.style.width = width + "px";
|
||||
containerEl.style.marginTop = ((PREVIEW_SIZE - height) / 2) + "px";
|
||||
containerEl.style.marginBottom = ((PREVIEW_SIZE - height) / 2) + "px";
|
||||
containerEl.style.marginLeft = ((PREVIEW_SIZE - width) / 2) + "px";
|
||||
containerEl.style.marginRight = ((PREVIEW_SIZE - width) / 2) + "px";
|
||||
};
|
||||
|
||||
ns.AnimatedPreviewController.prototype.toggleOnionSkin_ = function () {
|
||||
var currentValue = pskl.UserSettings.get(pskl.UserSettings.ONION_SKIN);
|
||||
pskl.UserSettings.set(pskl.UserSettings.ONION_SKIN, !currentValue);
|
||||
};
|
||||
})();
|
@ -10,7 +10,6 @@
|
||||
this.updateBackgroundClass_(pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND));
|
||||
};
|
||||
|
||||
|
||||
ns.CanvasBackgroundController.prototype.onUserSettingsChange_ = function (evt, settingName, settingValue) {
|
||||
if (settingName == pskl.UserSettings.CANVAS_BACKGROUND) {
|
||||
this.updateBackgroundClass_(settingValue);
|
||||
@ -25,4 +24,4 @@
|
||||
this.body.classList.add(newClass);
|
||||
this.body.dataset.currentBackgroundClass = newClass;
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -4,8 +4,10 @@
|
||||
ns.CursorCoordinatesController = function (piskelController) {
|
||||
this.piskelController = piskelController;
|
||||
this.origin = null;
|
||||
this.coordinates = {x:-1,y:-1};
|
||||
|
||||
this.coordinates = {
|
||||
x : -1,
|
||||
y : -1
|
||||
};
|
||||
};
|
||||
|
||||
ns.CursorCoordinatesController.prototype.init = function () {
|
||||
@ -31,9 +33,9 @@
|
||||
if (currentFrame.containsPixel(x, y)) {
|
||||
html += x + ':' + y;
|
||||
if (this.origin) {
|
||||
var dX = Math.abs(x-this.origin.x) + 1;
|
||||
var dY = Math.abs(y-this.origin.y) + 1;
|
||||
html += ' (' + dX + 'x' + dY +')';
|
||||
var dX = Math.abs(x - this.origin.x) + 1;
|
||||
var dY = Math.abs(y - this.origin.y) + 1;
|
||||
html += ' (' + dX + 'x' + dY + ')';
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +45,7 @@
|
||||
ns.CursorCoordinatesController.prototype.getFrameSizeHTML_ = function () {
|
||||
var w = this.piskelController.getWidth();
|
||||
var h = this.piskelController.getHeight();
|
||||
return '['+w+'x'+h+'] ';
|
||||
return '[' + w + 'x' + h + '] ';
|
||||
};
|
||||
|
||||
ns.CursorCoordinatesController.prototype.onCursorMoved_ = function (event, x, y) {
|
||||
@ -60,5 +62,4 @@
|
||||
this.origin = null;
|
||||
this.redraw();
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
@ -1,6 +1,6 @@
|
||||
(function () {
|
||||
|
||||
var ns = $.namespace("pskl.controller");
|
||||
var ns = $.namespace('pskl.controller');
|
||||
|
||||
ns.DrawingController = function (piskelController, paletteController, container) {
|
||||
/**
|
||||
@ -10,6 +10,8 @@
|
||||
|
||||
this.paletteController = paletteController;
|
||||
|
||||
this.dragHandler = new ns.drawing.DragHandler(this);
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
@ -20,20 +22,19 @@
|
||||
*/
|
||||
this.container = container;
|
||||
|
||||
// TODO(vincz): Store user prefs in a localstorage string ?
|
||||
var renderingOptions = {
|
||||
"zoom": this.calculateZoom_(),
|
||||
"supportGridRendering" : true,
|
||||
"height" : this.getContainerHeight_(),
|
||||
"width" : this.getContainerWidth_(),
|
||||
"xOffset" : 0,
|
||||
"yOffset" : 0
|
||||
var cfg = {
|
||||
'zoom': this.calculateZoom_(),
|
||||
'supportGridRendering' : true,
|
||||
'height' : this.getContainerHeight_(),
|
||||
'width' : this.getContainerWidth_(),
|
||||
'xOffset' : 0,
|
||||
'yOffset' : 0
|
||||
};
|
||||
|
||||
this.overlayRenderer = new pskl.rendering.frame.CachedFrameRenderer(this.container, renderingOptions, ["canvas-overlay"]);
|
||||
this.renderer = new pskl.rendering.frame.CachedFrameRenderer(this.container, renderingOptions, ["drawing-canvas"]);
|
||||
this.onionSkinRenderer = new pskl.rendering.OnionSkinRenderer(this.container, renderingOptions, piskelController);
|
||||
this.layersRenderer = new pskl.rendering.layer.LayersRenderer(this.container, renderingOptions, piskelController);
|
||||
this.overlayRenderer = new pskl.rendering.frame.CachedFrameRenderer(this.container, cfg, ['canvas-overlay']);
|
||||
this.renderer = new pskl.rendering.frame.CachedFrameRenderer(this.container, cfg, ['drawing-canvas']);
|
||||
this.onionSkinRenderer = pskl.rendering.OnionSkinRenderer.createInContainer(this.container, cfg, piskelController);
|
||||
this.layersRenderer = new pskl.rendering.layer.LayersRenderer(this.container, cfg, piskelController);
|
||||
|
||||
this.compositeRenderer = new pskl.rendering.CompositeRenderer();
|
||||
this.compositeRenderer
|
||||
@ -62,20 +63,23 @@
|
||||
$(window).resize($.proxy(this.startResizeTimer_, this));
|
||||
|
||||
$.subscribe(Events.USER_SETTINGS_CHANGED, $.proxy(this.onUserSettingsChange_, this));
|
||||
$.subscribe(Events.FRAME_SIZE_CHANGED, $.proxy(this.onFrameSizeChanged_, this));
|
||||
$.subscribe(Events.FRAME_SIZE_CHANGED, $.proxy(this.onFrameSizeChange_, this));
|
||||
|
||||
pskl.app.shortcutService.addShortcut('0', this.resetZoom_.bind(this));
|
||||
pskl.app.shortcutService.addShortcut('+', this.increaseZoom_.bind(this, 1));
|
||||
pskl.app.shortcutService.addShortcut('-', this.decreaseZoom_.bind(this, 1));
|
||||
|
||||
window.setTimeout(this.afterWindowResize_.bind(this), 100);
|
||||
window.setTimeout(function () {
|
||||
this.afterWindowResize_();
|
||||
this.resetZoom_();
|
||||
}.bind(this), 100);
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.initMouseBehavior = function() {
|
||||
var body = $('body');
|
||||
this.container.mousedown($.proxy(this.onMousedown_, this));
|
||||
|
||||
if (pskl.utils.UserAgent.isChrome) {
|
||||
if (pskl.utils.UserAgent.isChrome || pskl.utils.UserAgent.isIE11) {
|
||||
this.container.on('mousewheel', $.proxy(this.onMousewheel_, this));
|
||||
} else {
|
||||
this.container.on('wheel', $.proxy(this.onMousewheel_, this));
|
||||
@ -87,6 +91,7 @@
|
||||
|
||||
// Deactivate right click:
|
||||
body.contextmenu(this.onCanvasContextMenu_);
|
||||
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.startResizeTimer_ = function () {
|
||||
@ -98,6 +103,7 @@
|
||||
|
||||
ns.DrawingController.prototype.afterWindowResize_ = function () {
|
||||
var initialWidth = this.compositeRenderer.getDisplaySize().width;
|
||||
|
||||
this.compositeRenderer.setDisplaySize(this.getContainerWidth_(), this.getContainerHeight_());
|
||||
this.centerColumnWrapperHorizontally_();
|
||||
var ratio = this.compositeRenderer.getDisplaySize().width / initialWidth;
|
||||
@ -111,7 +117,7 @@
|
||||
* @private
|
||||
*/
|
||||
ns.DrawingController.prototype.onUserSettingsChange_ = function (evt, settingsName, settingsValue) {
|
||||
if(settingsName == pskl.UserSettings.SHOW_GRID) {
|
||||
if (settingsName == pskl.UserSettings.SHOW_GRID) {
|
||||
console.warn('DrawingController:onUserSettingsChange_ not implemented !');
|
||||
} else if (settingsName == pskl.UserSettings.ONION_SKIN || settingsName == pskl.UserSettings.LAYER_PREVIEW) {
|
||||
this.onionSkinRenderer.clear();
|
||||
@ -122,7 +128,7 @@
|
||||
}
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.onFrameSizeChanged_ = function () {
|
||||
ns.DrawingController.prototype.onFrameSizeChange_ = function () {
|
||||
this.compositeRenderer.setDisplaySize(this.getContainerWidth_(), this.getContainerHeight_());
|
||||
this.centerColumnWrapperHorizontally_();
|
||||
this.compositeRenderer.setZoom(this.calculateZoom_());
|
||||
@ -138,15 +144,14 @@
|
||||
var frame = this.piskelController.getCurrentFrame();
|
||||
var coords = this.getSpriteCoordinates(event.clientX, event.clientY);
|
||||
|
||||
if (event.button === Constants.MIDDLE_BUTTON) {
|
||||
if (frame.containsPixel(coords.x, coords.y)) {
|
||||
$.publish(Events.SELECT_PRIMARY_COLOR, [frame.getPixel(coords.x, coords.y)]);
|
||||
}
|
||||
} else {
|
||||
this.isClicked = true;
|
||||
this.setCurrentButton(event);
|
||||
this.currentToolBehavior.hideHighlightedPixel(this.overlayFrame);
|
||||
this.isClicked = true;
|
||||
this.setCurrentButton(event);
|
||||
|
||||
if (event.button === Constants.MIDDLE_BUTTON) {
|
||||
this.dragHandler.startDrag(event.clientX, event.clientY);
|
||||
} else {
|
||||
this.currentToolBehavior.hideHighlightedPixel(this.overlayFrame);
|
||||
$.publish(Events.TOOL_PRESSED);
|
||||
this.currentToolBehavior.applyToolAt(
|
||||
coords.x,
|
||||
coords.y,
|
||||
@ -168,35 +173,12 @@
|
||||
var currentTime = new Date().getTime();
|
||||
// Throttling of the mousemove event:
|
||||
|
||||
if ((currentTime - this.previousMousemoveTime) > Constants.MOUSEMOVE_THROTTLING ) {
|
||||
if ((currentTime - this.previousMousemoveTime) > Constants.MOUSEMOVE_THROTTLING) {
|
||||
this.moveTool_(this._clientX, this._clientY, event);
|
||||
this.previousMousemoveTime = currentTime;
|
||||
}
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.resetZoom_ = function () {
|
||||
this.setZoom_(this.calculateZoom_());
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.increaseZoom_ = function (zoomMultiplier) {
|
||||
var step = (zoomMultiplier || 1) * this.getZoomStep_();
|
||||
this.setZoom_(this.renderer.getZoom() + step);
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.decreaseZoom_ = function (zoomMultiplier) {
|
||||
var step = (zoomMultiplier || 1) * this.getZoomStep_();
|
||||
this.setZoom_(this.renderer.getZoom() - step);
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.getZoomStep_ = function () {
|
||||
return this.calculateZoom_() / 10;
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.setZoom_ = function (zoom) {
|
||||
this.compositeRenderer.setZoom(zoom);
|
||||
$.publish(Events.ZOOM_CHANGED);
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@ -209,19 +191,22 @@
|
||||
var currentFrame = this.piskelController.getCurrentFrame();
|
||||
|
||||
if (this.isClicked) {
|
||||
$.publish(Events.MOUSE_EVENT, [event, this]);
|
||||
// Warning : do not call setCurrentButton here
|
||||
// mousemove do not have the correct mouse button information on all browsers
|
||||
this.currentToolBehavior.moveToolAt(
|
||||
coords.x | 0,
|
||||
coords.y | 0,
|
||||
this.getCurrentColor_(),
|
||||
currentFrame,
|
||||
this.overlayFrame,
|
||||
event
|
||||
);
|
||||
if (this.currentMouseButton_ == Constants.MIDDLE_BUTTON) {
|
||||
this.dragHandler.updateDrag(x, y);
|
||||
} else {
|
||||
$.publish(Events.MOUSE_EVENT, [event, this]);
|
||||
// Warning : do not call setCurrentButton here
|
||||
// mousemove do not have the correct mouse button information on all browsers
|
||||
this.currentToolBehavior.moveToolAt(
|
||||
coords.x | 0,
|
||||
coords.y | 0,
|
||||
this.getCurrentColor_(),
|
||||
currentFrame,
|
||||
this.overlayFrame,
|
||||
event
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
||||
this.currentToolBehavior.moveUnactiveToolAt(
|
||||
coords.x,
|
||||
coords.y,
|
||||
@ -236,8 +221,16 @@
|
||||
|
||||
ns.DrawingController.prototype.onMousewheel_ = function (jQueryEvent) {
|
||||
var event = jQueryEvent.originalEvent;
|
||||
var delta = event.wheelDeltaY || (-2 * event.deltaY);
|
||||
var modifier = Math.abs(delta/120);
|
||||
// Ratio between wheelDeltaY (mousewheel event) and deltaY (wheel event) is -40
|
||||
var delta;
|
||||
if (pskl.utils.UserAgent.isChrome) {
|
||||
delta = event.wheelDeltaY;
|
||||
} else if (pskl.utils.UserAgent.isIE11) {
|
||||
delta = event.wheelDelta;
|
||||
} else if (pskl.utils.UserAgent.isFirefox) {
|
||||
delta = -40 * event.deltaY;
|
||||
}
|
||||
var modifier = Math.abs(delta / 120);
|
||||
if (delta > 0) {
|
||||
this.increaseZoom_(modifier);
|
||||
} else if (delta < 0) {
|
||||
@ -245,11 +238,23 @@
|
||||
}
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.increaseZoom_ = function (zoomMultiplier) {
|
||||
var step = (zoomMultiplier || 1) * this.getZoomStep_();
|
||||
this.setZoom_(this.renderer.getZoom() + step);
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.decreaseZoom_ = function (zoomMultiplier) {
|
||||
var step = (zoomMultiplier || 1) * this.getZoomStep_();
|
||||
this.setZoom_(this.renderer.getZoom() - step);
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ns.DrawingController.prototype.onMouseup_ = function (event) {
|
||||
if(this.isClicked) {
|
||||
var frame = this.piskelController.getCurrentFrame();
|
||||
var coords = this.getSpriteCoordinates(event.clientX, event.clientY);
|
||||
if (this.isClicked) {
|
||||
$.publish(Events.MOUSE_EVENT, [event, this]);
|
||||
// A mouse button was clicked on the drawing canvas before this mouseup event,
|
||||
// the user was probably drawing on the canvas.
|
||||
@ -259,17 +264,24 @@
|
||||
this.isClicked = false;
|
||||
this.setCurrentButton(event);
|
||||
|
||||
var coords = this.getSpriteCoordinates(event.clientX, event.clientY);
|
||||
this.currentToolBehavior.releaseToolAt(
|
||||
coords.x,
|
||||
coords.y,
|
||||
this.getCurrentColor_(),
|
||||
this.piskelController.getCurrentFrame(),
|
||||
this.overlayFrame,
|
||||
event
|
||||
);
|
||||
if (event.button === Constants.MIDDLE_BUTTON) {
|
||||
if (this.dragHandler.isDragging()) {
|
||||
this.dragHandler.stopDrag();
|
||||
} else if (frame.containsPixel(coords.x, coords.y)) {
|
||||
$.publish(Events.SELECT_PRIMARY_COLOR, [frame.getPixel(coords.x, coords.y)]);
|
||||
}
|
||||
} else {
|
||||
this.currentToolBehavior.releaseToolAt(
|
||||
coords.x,
|
||||
coords.y,
|
||||
this.getCurrentColor_(),
|
||||
this.piskelController.getCurrentFrame(),
|
||||
this.overlayFrame,
|
||||
event
|
||||
);
|
||||
|
||||
$.publish(Events.TOOL_RELEASED);
|
||||
$.publish(Events.TOOL_RELEASED);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -301,9 +313,9 @@
|
||||
// on a mouse move event
|
||||
// This always matches a LEFT mouse button which is __really__ not helpful
|
||||
|
||||
if(this.currentMouseButton_ == Constants.RIGHT_BUTTON) {
|
||||
if (this.currentMouseButton_ == Constants.RIGHT_BUTTON) {
|
||||
return this.paletteController.getSecondaryColor();
|
||||
} else if(this.currentMouseButton_ == Constants.LEFT_BUTTON) {
|
||||
} else if (this.currentMouseButton_ == Constants.LEFT_BUTTON) {
|
||||
return this.paletteController.getPrimaryColor();
|
||||
} else {
|
||||
return Constants.DEFAULT_PEN_COLOR;
|
||||
@ -345,10 +357,10 @@
|
||||
* @private
|
||||
*/
|
||||
ns.DrawingController.prototype.calculateZoom_ = function() {
|
||||
var frameHeight = this.piskelController.getCurrentFrame().getHeight(),
|
||||
frameWidth = this.piskelController.getCurrentFrame().getWidth();
|
||||
var frameHeight = this.piskelController.getCurrentFrame().getHeight();
|
||||
var frameWidth = this.piskelController.getCurrentFrame().getWidth();
|
||||
|
||||
return Math.min(this.getAvailableWidth_()/frameWidth, this.getAvailableHeight_()/frameHeight);
|
||||
return Math.min(this.getAvailableWidth_() / frameWidth, this.getAvailableHeight_() / frameHeight);
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.getAvailableHeight_ = function () {
|
||||
@ -356,22 +368,24 @@
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.getAvailableWidth_ = function () {
|
||||
var leftSectionWidth = $('.left-column').outerWidth(true),
|
||||
rightSectionWidth = $('.right-column').outerWidth(true),
|
||||
toolsContainerWidth = $('#tool-section').outerWidth(true),
|
||||
settingsContainerWidth = $('#application-action-section').outerWidth(true),
|
||||
availableWidth = $('#main-wrapper').width() - leftSectionWidth - rightSectionWidth - toolsContainerWidth - settingsContainerWidth;
|
||||
var leftSectionWidth = $('.left-column').outerWidth(true);
|
||||
var rightSectionWidth = $('.right-column').outerWidth(true);
|
||||
var toolsContainerWidth = $('#tool-section').outerWidth(true);
|
||||
var settingsContainerWidth = $('#application-action-section').outerWidth(true);
|
||||
|
||||
var usedWidth = leftSectionWidth + rightSectionWidth + toolsContainerWidth + settingsContainerWidth;
|
||||
var availableWidth = $('#main-wrapper').width() - usedWidth;
|
||||
|
||||
var comfortMargin = 10;
|
||||
return availableWidth - comfortMargin;
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.getContainerHeight_ = function () {
|
||||
return this.calculateZoom_() * this.piskelController.getCurrentFrame().getHeight();
|
||||
return this.getAvailableHeight_();
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.getContainerWidth_ = function () {
|
||||
return this.calculateZoom_() * this.piskelController.getCurrentFrame().getWidth();
|
||||
return this.getAvailableWidth_();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -389,8 +403,26 @@
|
||||
return this.compositeRenderer;
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.getOffset = function () {
|
||||
return this.compositeRenderer.getOffset();
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.setOffset = function (x, y) {
|
||||
this.compositeRenderer.setOffset(x, y);
|
||||
$.publish(Events.ZOOM_CHANGED);
|
||||
};
|
||||
})();
|
||||
|
||||
ns.DrawingController.prototype.resetZoom_ = function () {
|
||||
this.setZoom_(this.calculateZoom_());
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.getZoomStep_ = function () {
|
||||
return this.calculateZoom_() / 10;
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.setZoom_ = function (zoom) {
|
||||
this.compositeRenderer.setZoom(zoom);
|
||||
$.publish(Events.ZOOM_CHANGED);
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -1,5 +1,5 @@
|
||||
(function () {
|
||||
var ns = $.namespace("pskl.controller");
|
||||
var ns = $.namespace('pskl.controller');
|
||||
|
||||
var ACTION = {
|
||||
SELECT : 'select',
|
||||
@ -8,8 +8,7 @@
|
||||
NEW_FRAME : 'newframe'
|
||||
};
|
||||
|
||||
ns.PreviewFilmController = function (piskelController, container) {
|
||||
|
||||
ns.FramesListController = function (piskelController, container) {
|
||||
this.piskelController = piskelController;
|
||||
this.container = container;
|
||||
this.refreshZoom_();
|
||||
@ -21,7 +20,7 @@
|
||||
this.cachedFrameProcessor.setOutputCloner(this.clonePreviewCanvas_.bind(this));
|
||||
};
|
||||
|
||||
ns.PreviewFilmController.prototype.init = function() {
|
||||
ns.FramesListController.prototype.init = function() {
|
||||
$.subscribe(Events.TOOL_RELEASED, this.flagForRedraw_.bind(this));
|
||||
$.subscribe(Events.PISKEL_RESET, this.flagForRedraw_.bind(this));
|
||||
$.subscribe(Events.USER_SETTINGS_CHANGED, this.flagForRedraw_.bind(this));
|
||||
@ -33,29 +32,30 @@
|
||||
this.updateScrollerOverflows();
|
||||
};
|
||||
|
||||
ns.PreviewFilmController.prototype.flagForRedraw_ = function () {
|
||||
ns.FramesListController.prototype.flagForRedraw_ = function () {
|
||||
this.redrawFlag = true;
|
||||
};
|
||||
|
||||
ns.PreviewFilmController.prototype.refreshZoom_ = function () {
|
||||
ns.FramesListController.prototype.refreshZoom_ = function () {
|
||||
this.zoom = this.calculateZoom_();
|
||||
};
|
||||
|
||||
ns.PreviewFilmController.prototype.render = function () {
|
||||
ns.FramesListController.prototype.render = function () {
|
||||
if (this.redrawFlag) {
|
||||
this.createPreviews_();
|
||||
this.redrawFlag = false;
|
||||
}
|
||||
};
|
||||
|
||||
ns.PreviewFilmController.prototype.updateScrollerOverflows = function () {
|
||||
ns.FramesListController.prototype.updateScrollerOverflows = function () {
|
||||
var scroller = $('#preview-list-scroller');
|
||||
var scrollerHeight = scroller.height();
|
||||
var scrollTop = scroller.scrollTop();
|
||||
var scrollerContentHeight = $('#preview-list').height();
|
||||
var treshold = $('.top-overflow').height();
|
||||
var overflowTop = false,
|
||||
overflowBottom = false;
|
||||
var overflowTop = false;
|
||||
var overflowBottom = false;
|
||||
|
||||
if (scrollerHeight < scrollerContentHeight) {
|
||||
if (scrollTop > treshold) {
|
||||
overflowTop = true;
|
||||
@ -70,7 +70,7 @@
|
||||
wrapper.toggleClass('bottom-overflow-visible', overflowBottom);
|
||||
};
|
||||
|
||||
ns.PreviewFilmController.prototype.onContainerClick_ = function (event) {
|
||||
ns.FramesListController.prototype.onContainerClick_ = function (event) {
|
||||
var target = pskl.utils.Dom.getParentWithData(event.target, 'tileAction');
|
||||
if (!target) {
|
||||
return;
|
||||
@ -92,124 +92,128 @@
|
||||
}
|
||||
};
|
||||
|
||||
ns.PreviewFilmController.prototype.createPreviews_ = function () {
|
||||
|
||||
this.container.html("");
|
||||
ns.FramesListController.prototype.createPreviews_ = function () {
|
||||
this.container.html('');
|
||||
// Manually remove tooltips since mouseout events were shortcut by the DOM refresh:
|
||||
$(".tooltip").remove();
|
||||
$('.tooltip').remove();
|
||||
|
||||
var frameCount = this.piskelController.getFrameCount();
|
||||
|
||||
for (var i = 0, l = frameCount; i < l ; i++) {
|
||||
for (var i = 0 ; i < frameCount ; i++) {
|
||||
this.container.append(this.createPreviewTile_(i));
|
||||
}
|
||||
// Append 'new empty frame' button
|
||||
var newFrameButton = document.createElement("div");
|
||||
newFrameButton.id = "add-frame-action";
|
||||
newFrameButton.className = "add-frame-action";
|
||||
var newFrameButton = document.createElement('div');
|
||||
newFrameButton.id = 'add-frame-action';
|
||||
newFrameButton.className = 'add-frame-action';
|
||||
newFrameButton.setAttribute('data-tile-action', ACTION.NEW_FRAME);
|
||||
newFrameButton.innerHTML = "<p class='label'>Add new frame</p>";
|
||||
newFrameButton.innerHTML = '<p class="label">Add new frame</p>';
|
||||
this.container.append(newFrameButton);
|
||||
|
||||
var needDragndropBehavior = (frameCount > 1);
|
||||
if(needDragndropBehavior) {
|
||||
if (needDragndropBehavior) {
|
||||
this.initDragndropBehavior_();
|
||||
}
|
||||
this.updateScrollerOverflows();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ns.PreviewFilmController.prototype.initDragndropBehavior_ = function () {
|
||||
ns.FramesListController.prototype.initDragndropBehavior_ = function () {
|
||||
|
||||
$("#preview-list").sortable({
|
||||
placeholder: "preview-tile-drop-proxy",
|
||||
$('#preview-list').sortable({
|
||||
placeholder: 'preview-tile-drop-proxy',
|
||||
update: $.proxy(this.onUpdate_, this),
|
||||
items: ".preview-tile"
|
||||
items: '.preview-tile'
|
||||
});
|
||||
$("#preview-list").disableSelection();
|
||||
$('#preview-list').disableSelection();
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ns.PreviewFilmController.prototype.onUpdate_ = function( event, ui ) {
|
||||
var originFrameId = parseInt(ui.item.data("tile-number"), 10);
|
||||
ns.FramesListController.prototype.onUpdate_ = function (event, ui) {
|
||||
var originFrameId = parseInt(ui.item.data('tile-number'), 10);
|
||||
var targetInsertionId = $('.preview-tile').index(ui.item);
|
||||
|
||||
this.piskelController.moveFrame(originFrameId, targetInsertionId);
|
||||
this.piskelController.setCurrentFrameIndex(targetInsertionId);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* TODO(vincz): clean this giant rendering function & remove listeners.
|
||||
*/
|
||||
ns.PreviewFilmController.prototype.createPreviewTile_ = function(tileNumber) {
|
||||
ns.FramesListController.prototype.createPreviewTile_ = function(tileNumber) {
|
||||
var currentFrame = this.piskelController.getCurrentLayer().getFrameAt(tileNumber);
|
||||
|
||||
var previewTileRoot = document.createElement("li");
|
||||
previewTileRoot.setAttribute("data-tile-number", tileNumber);
|
||||
var previewTileRoot = document.createElement('li');
|
||||
previewTileRoot.setAttribute('data-tile-number', tileNumber);
|
||||
previewTileRoot.setAttribute('data-tile-action', ACTION.SELECT);
|
||||
previewTileRoot.classList.add("preview-tile");
|
||||
previewTileRoot.classList.add('preview-tile');
|
||||
if (this.piskelController.getCurrentFrame() == currentFrame) {
|
||||
previewTileRoot.classList.add("selected");
|
||||
previewTileRoot.classList.add('selected');
|
||||
}
|
||||
|
||||
var canvasContainer = document.createElement("div");
|
||||
canvasContainer.classList.add("canvas-container", pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND));
|
||||
var canvasContainer = document.createElement('div');
|
||||
canvasContainer.classList.add('canvas-container', pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND));
|
||||
|
||||
var height = this.zoom * this.piskelController.getCurrentFrame().getHeight();
|
||||
var horizontalMargin = (Constants.PREVIEW_FILM_SIZE - height) / 2;
|
||||
canvasContainer.style.marginTop = horizontalMargin + 'px';
|
||||
|
||||
var canvasBackground = document.createElement("div");
|
||||
canvasBackground.className = "canvas-background";
|
||||
var width = this.zoom * this.piskelController.getCurrentFrame().getWidth();
|
||||
var verticalMargin = (Constants.PREVIEW_FILM_SIZE - width) / 2;
|
||||
canvasContainer.style.marginLeft = verticalMargin + 'px';
|
||||
canvasContainer.style.marginRight = verticalMargin + 'px';
|
||||
|
||||
var canvasBackground = document.createElement('div');
|
||||
canvasBackground.className = 'canvas-background';
|
||||
canvasContainer.appendChild(canvasBackground);
|
||||
|
||||
var cloneFrameButton = document.createElement("button");
|
||||
var cloneFrameButton = document.createElement('button');
|
||||
cloneFrameButton.setAttribute('rel', 'tooltip');
|
||||
cloneFrameButton.setAttribute('data-placement', 'right');
|
||||
cloneFrameButton.setAttribute('data-tile-number', tileNumber);
|
||||
cloneFrameButton.setAttribute('data-tile-action', ACTION.CLONE);
|
||||
cloneFrameButton.setAttribute('title', 'Duplicate this frame');
|
||||
cloneFrameButton.className = "tile-overlay duplicate-frame-action";
|
||||
cloneFrameButton.className = 'tile-overlay duplicate-frame-action';
|
||||
previewTileRoot.appendChild(cloneFrameButton);
|
||||
|
||||
|
||||
canvasContainer.appendChild(this.getCanvasForFrame(currentFrame));
|
||||
previewTileRoot.appendChild(canvasContainer);
|
||||
|
||||
if(tileNumber > 0 || this.piskelController.getFrameCount() > 1) {
|
||||
if (tileNumber > 0 || this.piskelController.getFrameCount() > 1) {
|
||||
// Add 'remove frame' button.
|
||||
var deleteButton = document.createElement("button");
|
||||
var deleteButton = document.createElement('button');
|
||||
deleteButton.setAttribute('rel', 'tooltip');
|
||||
deleteButton.setAttribute('data-placement', 'right');
|
||||
deleteButton.setAttribute('title', 'Delete this frame');
|
||||
deleteButton.setAttribute('data-tile-number', tileNumber);
|
||||
deleteButton.setAttribute('data-tile-action', ACTION.DELETE);
|
||||
deleteButton.className = "tile-overlay delete-frame-action";
|
||||
deleteButton.className = 'tile-overlay delete-frame-action';
|
||||
previewTileRoot.appendChild(deleteButton);
|
||||
|
||||
// Add 'dragndrop handle'.
|
||||
var dndHandle = document.createElement("div");
|
||||
dndHandle.className = "tile-overlay dnd-action";
|
||||
var dndHandle = document.createElement('div');
|
||||
dndHandle.className = 'tile-overlay dnd-action';
|
||||
previewTileRoot.appendChild(dndHandle);
|
||||
}
|
||||
var tileCount = document.createElement("div");
|
||||
tileCount.className = "tile-overlay tile-count";
|
||||
var tileCount = document.createElement('div');
|
||||
tileCount.className = 'tile-overlay tile-count';
|
||||
tileCount.innerHTML = tileNumber + 1;
|
||||
previewTileRoot.appendChild(tileCount);
|
||||
|
||||
return previewTileRoot;
|
||||
};
|
||||
|
||||
ns.PreviewFilmController.prototype.getCanvasForFrame = function (frame) {
|
||||
ns.FramesListController.prototype.getCanvasForFrame = function (frame) {
|
||||
var canvas = this.cachedFrameProcessor.get(frame, this.zoom);
|
||||
return canvas;
|
||||
};
|
||||
|
||||
ns.PreviewFilmController.prototype.frameToPreviewCanvas_ = function (frame) {
|
||||
ns.FramesListController.prototype.frameToPreviewCanvas_ = function (frame) {
|
||||
var canvasRenderer = new pskl.rendering.CanvasRenderer(frame, this.zoom);
|
||||
canvasRenderer.drawTransparentAs(Constants.TRANSPARENT_COLOR);
|
||||
var canvas = canvasRenderer.render();
|
||||
@ -217,7 +221,7 @@
|
||||
return canvas;
|
||||
};
|
||||
|
||||
ns.PreviewFilmController.prototype.clonePreviewCanvas_ = function (canvas) {
|
||||
ns.FramesListController.prototype.clonePreviewCanvas_ = function (canvas) {
|
||||
var clone = pskl.utils.CanvasUtils.clone(canvas);
|
||||
clone.classList.add('tile-view', 'canvas');
|
||||
return clone;
|
||||
@ -226,11 +230,10 @@
|
||||
/**
|
||||
* Calculate the preview zoom depending on the piskel size
|
||||
*/
|
||||
ns.PreviewFilmController.prototype.calculateZoom_ = function () {
|
||||
var curFrame = this.piskelController.getCurrentFrame(),
|
||||
frameHeight = curFrame.getHeight(),
|
||||
frameWidth = curFrame.getWidth();
|
||||
ns.FramesListController.prototype.calculateZoom_ = function () {
|
||||
var frame = this.piskelController.getCurrentFrame();
|
||||
var frameSize = Math.max(frame.getHeight(), frame.getWidth());
|
||||
|
||||
return Math.min(Constants.PREVIEW_FILM_SIZE/frameHeight, Constants.PREVIEW_FILM_SIZE/frameWidth);
|
||||
return Constants.PREVIEW_FILM_SIZE / frameSize;
|
||||
};
|
||||
})();
|
||||
})();
|
@ -47,7 +47,7 @@
|
||||
};
|
||||
|
||||
ns.LayersListController.prototype.toggleButtonDisabledState_ = function (buttonAction, isDisabled) {
|
||||
var button = document.querySelector('.layers-button[data-action="'+buttonAction+'"]');
|
||||
var button = document.querySelector('.layers-button[data-action="' + buttonAction + '"]');
|
||||
if (isDisabled) {
|
||||
button.setAttribute('disabled', 'disabled');
|
||||
} else {
|
||||
@ -94,7 +94,7 @@
|
||||
|
||||
ns.LayersListController.prototype.renameCurrentLayer_ = function () {
|
||||
var layer = this.piskelController.getCurrentLayer();
|
||||
var name = window.prompt("Please enter the layer name", layer.getName());
|
||||
var name = window.prompt('Please enter the layer name', layer.getName());
|
||||
if (name) {
|
||||
var index = this.piskelController.getCurrentLayerIndex();
|
||||
this.piskelController.renameLayerAt(index, name);
|
||||
@ -129,4 +129,4 @@
|
||||
var currentValue = pskl.UserSettings.get(pskl.UserSettings.LAYER_PREVIEW);
|
||||
pskl.UserSettings.set(pskl.UserSettings.LAYER_PREVIEW, !currentValue);
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -1,21 +1,22 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.controller');
|
||||
|
||||
ns.MinimapController = function (piskelController, animationController, drawingController, container) {
|
||||
ns.MinimapController = function (piskelController, previewController, drawingController, container) {
|
||||
this.piskelController = piskelController;
|
||||
this.animationController = animationController;
|
||||
this.previewController = previewController;
|
||||
this.drawingController = drawingController;
|
||||
this.container = container;
|
||||
|
||||
this.isClicked = false;
|
||||
this.isVisible = false;
|
||||
};
|
||||
|
||||
ns.MinimapController.prototype.init = function () {
|
||||
// Create minimap DOM elements
|
||||
this.cropFrame = document.createElement('DIV');
|
||||
this.cropFrame.className = 'minimap-crop-frame';
|
||||
this.cropFrame.style.display = 'none';
|
||||
$(this.container).append(this.cropFrame);
|
||||
this.minimapEl = document.createElement('DIV');
|
||||
this.minimapEl.className = 'minimap-crop-frame';
|
||||
this.minimapEl.style.display = 'none';
|
||||
$(this.container).append(this.minimapEl);
|
||||
|
||||
// Init mouse events
|
||||
$(this.container).mousedown(this.onMinimapMousedown_.bind(this));
|
||||
@ -26,34 +27,81 @@
|
||||
};
|
||||
|
||||
ns.MinimapController.prototype.renderMinimap_ = function () {
|
||||
var zoomRatio = this.getDrawingAreaZoomRatio_();
|
||||
if (zoomRatio > 1) {
|
||||
this.displayCropFrame_(zoomRatio, this.drawingController.getRenderer().getOffset());
|
||||
var verticalRatio = this.getVerticalRatio_();
|
||||
var horizontalRatio = this.getHorizontalRatio_();
|
||||
if (verticalRatio > 1 || horizontalRatio > 1) {
|
||||
this.displayMinimap_();
|
||||
} else {
|
||||
this.hideCropFrame_();
|
||||
this.hideMinimap_();
|
||||
}
|
||||
};
|
||||
|
||||
ns.MinimapController.prototype.displayCropFrame_ = function (ratio, offset) {
|
||||
this.cropFrame.style.display = 'block';
|
||||
this.cropFrame.style.top = (offset.y * this.animationController.getZoom()) + 'px';
|
||||
this.cropFrame.style.left = (offset.x * this.animationController.getZoom()) + 'px';
|
||||
var zoomRatio = this.getDrawingAreaZoomRatio_();
|
||||
this.cropFrame.style.width = (this.container.width() / zoomRatio) + 'px';
|
||||
this.cropFrame.style.height = (this.container.height() / zoomRatio) + 'px';
|
||||
ns.MinimapController.prototype.displayMinimap_ = function () {
|
||||
var minimapSize = this.getMinimapSize_();
|
||||
var previewSize = this.getPreviewSize_();
|
||||
|
||||
var containerHeight = this.container.height();
|
||||
var containerWidth = this.container.width();
|
||||
|
||||
// offset(x, y) in frame pixels
|
||||
var offset = this.drawingController.getRenderer().getOffset();
|
||||
|
||||
// the preview is centered in a square container
|
||||
// if the sprite is not a square, a margin is needed on the appropriate coordinate
|
||||
// before adding the offset coming from the drawing area
|
||||
var leftMargin = (containerWidth - Math.max(minimapSize.width, previewSize.width)) / 2;
|
||||
var leftOffset = offset.x * this.previewController.getZoom();
|
||||
var left = leftMargin + leftOffset;
|
||||
|
||||
var topMargin = (containerHeight - Math.max(minimapSize.height, previewSize.height)) / 2;
|
||||
var topOffset = offset.y * this.previewController.getZoom();
|
||||
var top = topMargin + topOffset;
|
||||
|
||||
this.minimapEl.style.display = 'block';
|
||||
this.minimapEl.style.width = Math.min(minimapSize.width, containerWidth) + 'px';
|
||||
this.minimapEl.style.height = Math.min(minimapSize.height, containerHeight) + 'px';
|
||||
this.minimapEl.style.left = Math.max(0, left) + 'px';
|
||||
this.minimapEl.style.top = Math.max(0, top) + 'px';
|
||||
|
||||
this.isVisible = true;
|
||||
};
|
||||
|
||||
ns.MinimapController.prototype.hideCropFrame_ = function () {
|
||||
this.cropFrame.style.display = 'none';
|
||||
ns.MinimapController.prototype.getMinimapSize_ = function () {
|
||||
// Calculate the ratio to translate drawing area sizes to animated preview sizes
|
||||
var drawingAreaZoom = this.drawingController.getRenderer().getZoom();
|
||||
var animatedPreviewZoom = this.previewController.getZoom();
|
||||
var ratio = drawingAreaZoom / animatedPreviewZoom;
|
||||
|
||||
var displaySize = this.drawingController.getRenderer().getDisplaySize();
|
||||
var minimapWidth = displaySize.width / ratio;
|
||||
var minimapHeight = displaySize.height / ratio;
|
||||
|
||||
return {
|
||||
width : minimapWidth,
|
||||
height: minimapHeight
|
||||
};
|
||||
};
|
||||
|
||||
ns.MinimapController.prototype.getPreviewSize_ = function () {
|
||||
var frame = this.piskelController.getCurrentFrame();
|
||||
var previewWidth = frame.getWidth() * this.previewController.getZoom();
|
||||
var previewHeight = frame.getHeight() * this.previewController.getZoom();
|
||||
|
||||
return {
|
||||
width : previewWidth,
|
||||
height: previewHeight
|
||||
};
|
||||
};
|
||||
|
||||
ns.MinimapController.prototype.hideMinimap_ = function () {
|
||||
this.minimapEl.style.display = 'none';
|
||||
this.isVisible = false;
|
||||
};
|
||||
|
||||
ns.MinimapController.prototype.onMinimapMousemove_ = function (evt) {
|
||||
if (this.isClicked) {
|
||||
if (this.getDrawingAreaZoomRatio_() > 1) {
|
||||
var coords = this.getCoordinatesCenteredAround_(evt.clientX, evt.clientY);
|
||||
this.drawingController.setOffset(coords.x, coords.y);
|
||||
}
|
||||
if (this.isVisible && this.isClicked) {
|
||||
var coords = this.getCoordinatesCenteredAround_(evt.clientX, evt.clientY);
|
||||
this.drawingController.setOffset(coords.x, coords.y);
|
||||
}
|
||||
};
|
||||
|
||||
@ -66,25 +114,35 @@
|
||||
};
|
||||
|
||||
ns.MinimapController.prototype.getCoordinatesCenteredAround_ = function (x, y) {
|
||||
var frameCoords = this.animationController.getCoordinates(x, y);
|
||||
var zoomRatio = this.getDrawingAreaZoomRatio_();
|
||||
var frameCoords = this.previewController.getCoordinates(x, y);
|
||||
|
||||
var frameWidth = this.piskelController.getCurrentFrame().getWidth();
|
||||
var frameHeight = this.piskelController.getCurrentFrame().getHeight();
|
||||
|
||||
var width = frameWidth / zoomRatio;
|
||||
var height = frameHeight / zoomRatio;
|
||||
var width = frameWidth / this.getHorizontalRatio_();
|
||||
var height = frameHeight / this.getVerticalRatio_();
|
||||
|
||||
return {
|
||||
x : frameCoords.x - (width/2),
|
||||
y : frameCoords.y - (height/2)
|
||||
x : frameCoords.x - (width / 2),
|
||||
y : frameCoords.y - (height / 2)
|
||||
};
|
||||
};
|
||||
|
||||
ns.MinimapController.prototype.getDrawingAreaZoomRatio_ = function () {
|
||||
ns.MinimapController.prototype.getVerticalRatio_ = function () {
|
||||
var drawingAreaZoom = this.drawingController.getRenderer().getZoom();
|
||||
var drawingAreaFullHeight = this.piskelController.getCurrentFrame().getHeight() * drawingAreaZoom;
|
||||
var zoomRatio = drawingAreaFullHeight / this.drawingController.getRenderer().getDisplaySize().height;
|
||||
var frame = this.piskelController.getCurrentFrame();
|
||||
var frameTotalHeight = frame.getHeight() * drawingAreaZoom;
|
||||
var frameDisplayHeight = this.drawingController.getRenderer().getDisplaySize().height;
|
||||
|
||||
return zoomRatio;
|
||||
return frameTotalHeight / frameDisplayHeight;
|
||||
};
|
||||
})();
|
||||
|
||||
ns.MinimapController.prototype.getHorizontalRatio_ = function () {
|
||||
var drawingAreaZoom = this.drawingController.getRenderer().getZoom();
|
||||
var frame = this.piskelController.getCurrentFrame();
|
||||
var frameTotalWidth = frame.getWidth() * drawingAreaZoom;
|
||||
var frameDisplayWidth = this.drawingController.getRenderer().getDisplaySize().width;
|
||||
|
||||
return frameTotalWidth / frameDisplayWidth;
|
||||
};
|
||||
})();
|
||||
|
@ -1,5 +1,5 @@
|
||||
(function () {
|
||||
var ns = $.namespace("pskl.controller");
|
||||
var ns = $.namespace('pskl.controller');
|
||||
|
||||
ns.NotificationController = function () {};
|
||||
|
||||
@ -18,22 +18,27 @@
|
||||
this.removeMessage_();
|
||||
|
||||
var message = document.createElement('div');
|
||||
message.id = "user-message";
|
||||
message.className = "user-message";
|
||||
message.id = 'user-message';
|
||||
message.className = 'user-message';
|
||||
message.innerHTML = messageInfo.content;
|
||||
message.innerHTML = message.innerHTML + "<div title='Close message' class='close'>x</div>";
|
||||
message.innerHTML = message.innerHTML + '<div title="Close message" class="close">x</div>';
|
||||
document.body.appendChild(message);
|
||||
$(message).find(".close").click($.proxy(this.removeMessage_, this));
|
||||
if(messageInfo.behavior) {
|
||||
|
||||
message.querySelector('.close').addEventListener('click', this.removeMessage_.bind(this));
|
||||
if (messageInfo.behavior) {
|
||||
messageInfo.behavior(message);
|
||||
}
|
||||
|
||||
if (messageInfo.hideDelay) {
|
||||
window.setTimeout(this.removeMessage_.bind(this), messageInfo.hideDelay);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ns.NotificationController.prototype.removeMessage_ = function (evt) {
|
||||
var message = $("#user-message");
|
||||
var message = $('#user-message');
|
||||
if (message.length) {
|
||||
message.remove();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
(function () {
|
||||
var ns = $.namespace("pskl.controller");
|
||||
var ns = $.namespace('pskl.controller');
|
||||
|
||||
ns.PaletteController = function () {
|
||||
this.primaryColor = Constants.DEFAULT_PEN_COLOR;
|
||||
@ -50,7 +50,7 @@
|
||||
*/
|
||||
ns.PaletteController.prototype.onPickerChange_ = function(evt, isPrimary) {
|
||||
var inputPicker = $(evt.target);
|
||||
if(evt.data.isPrimary) {
|
||||
if (evt.data.isPrimary) {
|
||||
this.setPrimaryColor(inputPicker.val());
|
||||
} else {
|
||||
this.setSecondaryColor(inputPicker.val());
|
||||
@ -62,7 +62,7 @@
|
||||
*/
|
||||
ns.PaletteController.prototype.onColorSelected_ = function(args, evt, color) {
|
||||
var inputPicker = $(evt.target);
|
||||
if(args.isPrimary) {
|
||||
if (args.isPrimary) {
|
||||
this.setPrimaryColor(color);
|
||||
} else {
|
||||
this.setSecondaryColor(color);
|
||||
@ -114,10 +114,10 @@
|
||||
// The colorpicker can't be set to a transparent state.
|
||||
// We set its background to white and insert the
|
||||
// string "TRANSPARENT" to mimic this state:
|
||||
colorPicker.spectrum("set", Constants.TRANSPARENT_COLOR);
|
||||
colorPicker.spectrum('set', Constants.TRANSPARENT_COLOR);
|
||||
colorPicker.val(Constants.TRANSPARENT_COLOR);
|
||||
} else {
|
||||
colorPicker.spectrum("set", color);
|
||||
colorPicker.spectrum('set', color);
|
||||
}
|
||||
this.setTitleOnPicker_(color, colorPicker);
|
||||
};
|
||||
@ -127,6 +127,3 @@
|
||||
colorPicker.next(spectrumInputSelector).attr('title', title);
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
|
||||
|
@ -10,7 +10,6 @@
|
||||
// I apologize to my future self for this one.
|
||||
var NO_SCROLL_MAX_COLORS = 20;
|
||||
|
||||
|
||||
ns.PalettesListController = function (paletteController, usedColorService) {
|
||||
this.usedColorService = usedColorService;
|
||||
this.paletteService = pskl.app.paletteService;
|
||||
@ -39,7 +38,6 @@
|
||||
$.subscribe(Events.SECONDARY_COLOR_SELECTED, this.highlightSelectedColors.bind(this));
|
||||
$.subscribe(Events.USER_SETTINGS_CHANGED, $.proxy(this.onUserSettingsChange_, this));
|
||||
|
||||
|
||||
pskl.app.shortcutService.addShortcuts(['>', 'shift+>'], this.selectNextColor_.bind(this));
|
||||
pskl.app.shortcutService.addShortcut('<', this.selectPreviousColor_.bind(this));
|
||||
|
||||
@ -91,8 +89,8 @@
|
||||
colors = palette.getColors();
|
||||
}
|
||||
|
||||
if (colors.length > Constants.MAX_CURRENT_COLORS_DISPLAYED) {
|
||||
colors = colors.slice(0, Constants.MAX_CURRENT_COLORS_DISPLAYED);
|
||||
if (colors.length > Constants.MAX_PALETTE_COLORS) {
|
||||
colors = colors.slice(0, Constants.MAX_PALETTE_COLORS);
|
||||
}
|
||||
|
||||
return colors;
|
||||
@ -193,7 +191,7 @@
|
||||
};
|
||||
|
||||
ns.PalettesListController.prototype.getColorContainer_ = function (color) {
|
||||
return this.colorListContainer_.querySelector('.palettes-list-color[data-color="'+color+'"]');
|
||||
return this.colorListContainer_.querySelector('.palettes-list-color[data-color="' + color + '"]');
|
||||
};
|
||||
|
||||
ns.PalettesListController.prototype.removeClass_ = function (cssClass) {
|
||||
@ -207,4 +205,4 @@
|
||||
this.fillPaletteList();
|
||||
this.updateFromUserSettings();
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -58,4 +58,4 @@
|
||||
this.progressBarStatus = null;
|
||||
}
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -1,5 +1,5 @@
|
||||
(function () {
|
||||
var ns = $.namespace("pskl.controller");
|
||||
var ns = $.namespace('pskl.controller');
|
||||
|
||||
ns.ToolController = function () {
|
||||
var toDescriptor = function (id, shortcut, instance) {
|
||||
@ -7,23 +7,22 @@
|
||||
};
|
||||
|
||||
this.tools = [
|
||||
toDescriptor('simplePen', 'P', new pskl.drawingtools.SimplePen()),
|
||||
toDescriptor('verticalMirrorPen', 'V', new pskl.drawingtools.VerticalMirrorPen()),
|
||||
toDescriptor('paintBucket', 'B', new pskl.drawingtools.PaintBucket()),
|
||||
toDescriptor('colorSwap', 'A', new pskl.drawingtools.ColorSwap()),
|
||||
toDescriptor('eraser', 'E', new pskl.drawingtools.Eraser()),
|
||||
toDescriptor('stroke', 'L', new pskl.drawingtools.Stroke()),
|
||||
toDescriptor('rectangle', 'R', new pskl.drawingtools.Rectangle()),
|
||||
toDescriptor('circle', 'C', new pskl.drawingtools.Circle()),
|
||||
toDescriptor('move', 'M', new pskl.drawingtools.Move()),
|
||||
toDescriptor('rectangleSelect', 'S', new pskl.drawingtools.RectangleSelect()),
|
||||
toDescriptor('shapeSelect', 'Z', new pskl.drawingtools.ShapeSelect()),
|
||||
toDescriptor('lighten', 'U', new pskl.drawingtools.Lighten()),
|
||||
toDescriptor('colorPicker', 'O', new pskl.drawingtools.ColorPicker())
|
||||
toDescriptor('simplePen', 'P', new pskl.tools.drawing.SimplePen()),
|
||||
toDescriptor('verticalMirrorPen', 'V', new pskl.tools.drawing.VerticalMirrorPen()),
|
||||
toDescriptor('paintBucket', 'B', new pskl.tools.drawing.PaintBucket()),
|
||||
toDescriptor('colorSwap', 'A', new pskl.tools.drawing.ColorSwap()),
|
||||
toDescriptor('eraser', 'E', new pskl.tools.drawing.Eraser()),
|
||||
toDescriptor('stroke', 'L', new pskl.tools.drawing.Stroke()),
|
||||
toDescriptor('rectangle', 'R', new pskl.tools.drawing.Rectangle()),
|
||||
toDescriptor('circle', 'C', new pskl.tools.drawing.Circle()),
|
||||
toDescriptor('move', 'M', new pskl.tools.drawing.Move()),
|
||||
toDescriptor('rectangleSelect', 'S', new pskl.tools.drawing.RectangleSelect()),
|
||||
toDescriptor('shapeSelect', 'Z', new pskl.tools.drawing.ShapeSelect()),
|
||||
toDescriptor('lighten', 'U', new pskl.tools.drawing.Lighten()),
|
||||
toDescriptor('colorPicker', 'O', new pskl.tools.drawing.ColorPicker())
|
||||
];
|
||||
|
||||
this.currentSelectedTool = this.tools[0];
|
||||
this.previousSelectedTool = this.tools[0];
|
||||
this.toolIconRenderer = new pskl.tools.IconMarkupRenderer();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -37,7 +36,7 @@
|
||||
// Set SimplePen as default selected tool:
|
||||
this.selectTool_(this.tools[0]);
|
||||
// Activate listener on tool panel:
|
||||
$("#tool-section").mousedown($.proxy(this.onToolIconClicked_, this));
|
||||
$('#tool-section').mousedown($.proxy(this.onToolIconClicked_, this));
|
||||
|
||||
$.subscribe(Events.SELECT_TOOL, this.onSelectToolEvent_.bind(this));
|
||||
};
|
||||
@ -46,14 +45,14 @@
|
||||
* @private
|
||||
*/
|
||||
ns.ToolController.prototype.activateToolOnStage_ = function(tool) {
|
||||
var stage = $("body");
|
||||
var previousSelectedToolClass = stage.data("selected-tool-class");
|
||||
if(previousSelectedToolClass) {
|
||||
var stage = $('body');
|
||||
var previousSelectedToolClass = stage.data('selected-tool-class');
|
||||
if (previousSelectedToolClass) {
|
||||
stage.removeClass(previousSelectedToolClass);
|
||||
stage.removeClass(pskl.drawingtools.Move.TOOL_ID);
|
||||
stage.removeClass(pskl.tools.drawing.Move.TOOL_ID);
|
||||
}
|
||||
stage.addClass(tool.instance.toolId);
|
||||
stage.data("selected-tool-class", tool.instance.toolId);
|
||||
stage.data('selected-tool-class', tool.instance.toolId);
|
||||
};
|
||||
|
||||
ns.ToolController.prototype.onSelectToolEvent_ = function(event, toolId) {
|
||||
@ -84,9 +83,9 @@
|
||||
*/
|
||||
ns.ToolController.prototype.onToolIconClicked_ = function(evt) {
|
||||
var target = $(evt.target);
|
||||
var clickedTool = target.closest(".tool-icon");
|
||||
var clickedTool = target.closest('.tool-icon');
|
||||
|
||||
if(clickedTool.length) {
|
||||
if (clickedTool.length) {
|
||||
var toolId = clickedTool.data().toolId;
|
||||
var tool = this.getToolById_(toolId);
|
||||
if (tool) {
|
||||
@ -105,48 +104,26 @@
|
||||
};
|
||||
|
||||
ns.ToolController.prototype.getToolById_ = function (toolId) {
|
||||
for(var i = 0 ; i < this.tools.length ; i++) {
|
||||
var tool = this.tools[i];
|
||||
if (tool.instance.toolId == toolId) {
|
||||
return tool;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return pskl.utils.Array.find(this.tools, function (tool) {
|
||||
return tool.instance.toolId == toolId;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ns.ToolController.prototype.createToolsDom_ = function() {
|
||||
var toolMarkup = '';
|
||||
for(var i = 0 ; i < this.tools.length ; i++) {
|
||||
toolMarkup += this.getToolMarkup_(this.tools[i]);
|
||||
var html = '';
|
||||
for (var i = 0 ; i < this.tools.length ; i++) {
|
||||
var tool = this.tools[i];
|
||||
html += this.toolIconRenderer.render(tool.instance, tool.shortcut);
|
||||
}
|
||||
$('#tools-container').html(toolMarkup);
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ns.ToolController.prototype.getToolMarkup_ = function(tool) {
|
||||
var toolId = tool.instance.toolId;
|
||||
|
||||
var classList = ['tool-icon', toolId];
|
||||
if (this.currentSelectedTool == tool) {
|
||||
classList.push('selected');
|
||||
}
|
||||
|
||||
var tpl = pskl.utils.Template.get('drawing-tool-item-template');
|
||||
return pskl.utils.Template.replace(tpl, {
|
||||
cssclass : classList.join(' '),
|
||||
toolid : toolId,
|
||||
title : tool.instance.getTooltipText(tool.shortcut)
|
||||
});
|
||||
$('#tools-container').html(html);
|
||||
};
|
||||
|
||||
ns.ToolController.prototype.addKeyboardShortcuts_ = function () {
|
||||
for(var i = 0 ; i < this.tools.length ; i++) {
|
||||
for (var i = 0 ; i < this.tools.length ; i++) {
|
||||
pskl.app.shortcutService.addShortcut(this.tools[i].shortcut, this.onKeyboardShortcut_.bind(this));
|
||||
}
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
41
src/js/controller/TransformationsController.js
Normal file
@ -0,0 +1,41 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.controller');
|
||||
|
||||
ns.TransformationsController = function () {
|
||||
|
||||
var toDescriptor = function (id, shortcut, instance) {
|
||||
return {id:id, shortcut:shortcut, instance:instance};
|
||||
};
|
||||
|
||||
this.tools = [
|
||||
toDescriptor('flip', '', new pskl.tools.transform.Flip()),
|
||||
toDescriptor('rotate', '', new pskl.tools.transform.Rotate()),
|
||||
toDescriptor('clone', '', new pskl.tools.transform.Clone())
|
||||
];
|
||||
|
||||
this.toolIconRenderer = new pskl.tools.IconMarkupRenderer();
|
||||
};
|
||||
|
||||
ns.TransformationsController.prototype.init = function () {
|
||||
var container = document.querySelector('.transformations-container');
|
||||
this.toolsContainer = container.querySelector('.tools-wrapper');
|
||||
container.addEventListener('click', this.onTransformationClick.bind(this));
|
||||
this.createToolsDom_();
|
||||
};
|
||||
|
||||
ns.TransformationsController.prototype.onTransformationClick = function (evt) {
|
||||
var toolId = evt.target.dataset.toolId;
|
||||
this.tools.forEach(function (tool) {
|
||||
if (tool.instance.toolId === toolId) {
|
||||
tool.instance.apply(evt);
|
||||
}
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
ns.TransformationsController.prototype.createToolsDom_ = function() {
|
||||
var html = this.tools.reduce(function (p, tool) {
|
||||
return p + this.toolIconRenderer.render(tool.instance, tool.shortcut, 'left');
|
||||
}.bind(this), '');
|
||||
this.toolsContainer.innerHTML = html;
|
||||
};
|
||||
})();
|
@ -3,7 +3,6 @@
|
||||
|
||||
ns.AbstractDialogController = function () {};
|
||||
|
||||
|
||||
ns.AbstractDialogController.prototype.init = function () {
|
||||
this.closeButton = document.querySelector('.dialog-close');
|
||||
this.closeButton.addEventListener('click', this.closeDialog.bind(this));
|
||||
@ -22,5 +21,4 @@
|
||||
dialogTitle.innerText = title;
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
@ -9,7 +9,7 @@
|
||||
ns.BrowseLocalController.prototype.init = function () {
|
||||
this.superclass.init.call(this);
|
||||
|
||||
this.localStorageItemTemplate_ = pskl.utils.Template.get("local-storage-item-template");
|
||||
this.localStorageItemTemplate_ = pskl.utils.Template.get('local-storage-item-template');
|
||||
|
||||
this.service_ = pskl.app.localStorageService;
|
||||
this.piskelList = $('.local-piskel-list');
|
||||
@ -37,7 +37,7 @@
|
||||
};
|
||||
|
||||
ns.BrowseLocalController.prototype.fillLocalPiskelsList_ = function () {
|
||||
var html = "";
|
||||
var html = '';
|
||||
var keys = this.service_.getKeys();
|
||||
|
||||
keys.sort(function (k1, k2) {
|
||||
@ -47,11 +47,11 @@
|
||||
});
|
||||
|
||||
keys.forEach((function (key) {
|
||||
var date = pskl.utils.DateUtils.format(key.date, "{{Y}}/{{M}}/{{D}} {{H}}:{{m}}");
|
||||
var date = pskl.utils.DateUtils.format(key.date, '{{Y}}/{{M}}/{{D}} {{H}}:{{m}}');
|
||||
html += pskl.utils.Template.replace(this.localStorageItemTemplate_, {name : key.name, date : date});
|
||||
}).bind(this));
|
||||
|
||||
var tableBody_ = this.piskelList.get(0).tBodies[0];
|
||||
tableBody_.innerHTML = html;
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -27,7 +27,7 @@
|
||||
importFileButton.addEventListener('click', this.onImportFileButtonClick_.bind(this));
|
||||
|
||||
var colorsListContainer = document.querySelector('.colors-container');
|
||||
this.colorsListWidget = new pskl.controller.widgets.ColorsList(colorsListContainer);
|
||||
this.colorsListWidget = new pskl.widgets.ColorsList(colorsListContainer);
|
||||
|
||||
var palette;
|
||||
var isCurrentColorsPalette = paletteId == Constants.CURRENT_COLORS_PALETTE_ID;
|
||||
@ -101,7 +101,7 @@
|
||||
|
||||
pskl.utils.BlobUtils.stringToBlob(paletteAsString, function(blob) {
|
||||
pskl.utils.FileUtils.downloadAsFile(blob, this.palette.name + '.gpl');
|
||||
}.bind(this), "application/json");
|
||||
}.bind(this), 'application/json');
|
||||
};
|
||||
|
||||
ns.CreatePaletteController.prototype.onImportFileButtonClick_ = function () {
|
||||
@ -116,12 +116,14 @@
|
||||
};
|
||||
|
||||
ns.CreatePaletteController.prototype.displayErrorMessage_ = function (message) {
|
||||
message = "Could not import palette : " + message;
|
||||
$.publish(Events.SHOW_NOTIFICATION, [{"content": message}]);
|
||||
message = 'Could not import palette : ' + message;
|
||||
$.publish(Events.SHOW_NOTIFICATION, [{
|
||||
'content' : message
|
||||
}]);
|
||||
window.setTimeout($.publish.bind($, Events.HIDE_NOTIFICATION), 2000);
|
||||
};
|
||||
|
||||
ns.CreatePaletteController.prototype.onNameInputChange_ = function (evt) {
|
||||
this.palette.name = pskl.utils.escapeHtml(this.nameInput.value);
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -92,4 +92,4 @@
|
||||
return this.currentDialog_ !== null;
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
@ -1,6 +1,5 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.controller.dialogs');
|
||||
var PREVIEW_HEIGHT = 60;
|
||||
|
||||
ns.ImportImageController = function (piskelController) {
|
||||
this.importedImage_ = null;
|
||||
@ -18,12 +17,25 @@
|
||||
|
||||
this.fileNameContainer = $('.import-image-file-name');
|
||||
|
||||
this.importType = $('[name=import-type]');
|
||||
|
||||
this.resizeWidth = $('[name=resize-width]');
|
||||
this.resizeHeight = $('[name=resize-height]');
|
||||
this.smoothResize = $('[name=smooth-resize-checkbox]');
|
||||
|
||||
this.frameSizeX = $('[name=frame-size-x]');
|
||||
this.frameSizeY = $('[name=frame-size-y]');
|
||||
this.frameOffsetX = $('[name=frame-offset-x]');
|
||||
this.frameOffsetY = $('[name=frame-offset-y]');
|
||||
|
||||
this.importType.change(this.onImportTypeChange_.bind(this));
|
||||
|
||||
this.resizeWidth.keyup(this.onResizeInputKeyUp_.bind(this, 'width'));
|
||||
this.resizeHeight.keyup(this.onResizeInputKeyUp_.bind(this, 'height'));
|
||||
this.frameSizeX.keyup(this.onFrameInputKeyUp_.bind(this, 'frameSizeX'));
|
||||
this.frameSizeY.keyup(this.onFrameInputKeyUp_.bind(this, 'frameSizeY'));
|
||||
this.frameOffsetX.keyup(this.onFrameInputKeyUp_.bind(this, 'frameOffsetX'));
|
||||
this.frameOffsetY.keyup(this.onFrameInputKeyUp_.bind(this, 'frameOffsetY'));
|
||||
|
||||
this.importImageForm = $('[name=import-image-form]');
|
||||
this.importImageForm.submit(this.onImportFormSubmit_.bind(this));
|
||||
@ -31,6 +43,20 @@
|
||||
pskl.utils.FileUtils.readImageFile(this.file_, this.onImageLoaded_.bind(this));
|
||||
};
|
||||
|
||||
ns.ImportImageController.prototype.onImportTypeChange_ = function (evt) {
|
||||
if (this.getImportType_() === 'single') {
|
||||
// Using single image, so remove the frame grid
|
||||
this.hideFrameGrid_();
|
||||
} else {
|
||||
// Using spritesheet import, so draw the frame grid in the preview
|
||||
var x = this.sanitizeInputValue_(this.frameOffsetX, 0);
|
||||
var y = this.sanitizeInputValue_(this.frameOffsetY, 0);
|
||||
var w = this.sanitizeInputValue_(this.frameSizeX, 1);
|
||||
var h = this.sanitizeInputValue_(this.frameSizeY, 1);
|
||||
this.drawFrameGrid_(x, y, w, h);
|
||||
}
|
||||
};
|
||||
|
||||
ns.ImportImageController.prototype.onImportFormSubmit_ = function (evt) {
|
||||
evt.originalEvent.preventDefault();
|
||||
this.importImageToPiskel_();
|
||||
@ -42,12 +68,23 @@
|
||||
}
|
||||
};
|
||||
|
||||
ns.ImportImageController.prototype.onFrameInputKeyUp_ = function (from, evt) {
|
||||
if (this.importedImage_) {
|
||||
this.synchronizeFrameFields_(evt.target.value, from);
|
||||
}
|
||||
};
|
||||
|
||||
ns.ImportImageController.prototype.synchronizeResizeFields_ = function (value, from) {
|
||||
value = parseInt(value, 10);
|
||||
if (isNaN(value)) {
|
||||
value = 0;
|
||||
}
|
||||
var height = this.importedImage_.height, width = this.importedImage_.width;
|
||||
var height = this.importedImage_.height;
|
||||
var width = this.importedImage_.width;
|
||||
|
||||
// Select single image import type since the user changed a value here
|
||||
this.importType.filter('[value="single"]').attr('checked', 'checked');
|
||||
|
||||
if (from === 'width') {
|
||||
this.resizeHeight.val(Math.round(value * height / width));
|
||||
} else {
|
||||
@ -55,11 +92,43 @@
|
||||
}
|
||||
};
|
||||
|
||||
ns.ImportImageController.prototype.synchronizeFrameFields_ = function (value, from) {
|
||||
value = parseInt(value, 10);
|
||||
if (isNaN(value)) {
|
||||
value = 0;
|
||||
}
|
||||
|
||||
// Parse the frame input values
|
||||
var frameSizeX = this.sanitizeInputValue_(this.frameSizeX, 1);
|
||||
var frameSizeY = this.sanitizeInputValue_(this.frameSizeY, 1);
|
||||
var frameOffsetX = this.sanitizeInputValue_(this.frameOffsetX, 0);
|
||||
var frameOffsetY = this.sanitizeInputValue_(this.frameOffsetY, 0);
|
||||
|
||||
// Select spritesheet import type since the user changed a value here
|
||||
this.importType.filter('[value="sheet"]').attr('checked', 'checked');
|
||||
|
||||
// Draw the grid
|
||||
this.drawFrameGrid_(frameOffsetX, frameOffsetY, frameSizeX, frameSizeY);
|
||||
};
|
||||
|
||||
ns.ImportImageController.prototype.sanitizeInputValue_ = function(input, minValue) {
|
||||
var value = parseInt(input.val(), 10);
|
||||
if (value <= minValue || isNaN(value)) {
|
||||
input.val(minValue);
|
||||
value = minValue;
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
ns.ImportImageController.prototype.getImportType_ = function () {
|
||||
return this.importType.filter(':checked').val();
|
||||
};
|
||||
|
||||
ns.ImportImageController.prototype.onImageLoaded_ = function (image) {
|
||||
this.importedImage_ = image;
|
||||
|
||||
var w = this.importedImage_.width,
|
||||
h = this.importedImage_.height;
|
||||
var w = this.importedImage_.width;
|
||||
var h = this.importedImage_.height;
|
||||
|
||||
// FIXME : We remove the onload callback here because JsGif will insert
|
||||
// the image again and we want to avoid retriggering the image onload
|
||||
@ -67,11 +136,18 @@
|
||||
|
||||
var fileName = this.extractFileNameFromPath_(this.file_.name);
|
||||
this.fileNameContainer.html(fileName);
|
||||
this.fileNameContainer.attr('title', fileName);
|
||||
|
||||
this.resizeWidth.val(w);
|
||||
this.resizeHeight.val(h);
|
||||
|
||||
this.frameSizeX.val(w);
|
||||
this.frameSizeY.val(h);
|
||||
this.frameOffsetX.val(0);
|
||||
this.frameOffsetY.val(0);
|
||||
|
||||
this.importPreview.width('auto');
|
||||
this.importPreview.height('auto');
|
||||
this.importPreview.html('');
|
||||
this.importPreview.append(this.createImagePreview_());
|
||||
};
|
||||
@ -79,7 +155,6 @@
|
||||
ns.ImportImageController.prototype.createImagePreview_ = function () {
|
||||
var image = document.createElement('IMG');
|
||||
image.src = this.importedImage_.src;
|
||||
image.setAttribute('height', PREVIEW_HEIGHT);
|
||||
return image;
|
||||
};
|
||||
|
||||
@ -92,7 +167,7 @@
|
||||
} else {
|
||||
parts = [path];
|
||||
}
|
||||
return parts[parts.length-1];
|
||||
return parts[parts.length - 1];
|
||||
};
|
||||
|
||||
ns.ImportImageController.prototype.importImageToPiskel_ = function () {
|
||||
@ -103,16 +178,32 @@
|
||||
gif : image
|
||||
});
|
||||
|
||||
var resizeW = this.resizeWidth.val();
|
||||
var resizeH = this.resizeHeight.val();
|
||||
|
||||
gifLoader.load({
|
||||
success : function(){
|
||||
success : function () {
|
||||
var images = gifLoader.getFrames().map(function (frame) {
|
||||
return pskl.utils.CanvasUtils.createFromImageData(frame.data);
|
||||
});
|
||||
this.createPiskelFromImages_(images);
|
||||
|
||||
if (this.getImportType_() === 'single' || images.length > 1) {
|
||||
// Single image import or animated gif
|
||||
this.createPiskelFromImages_(images, resizeW, resizeH);
|
||||
} else {
|
||||
// Spritesheet
|
||||
this.createImagesFromSheet_(images[0]);
|
||||
}
|
||||
this.closeDialog();
|
||||
}.bind(this),
|
||||
error : function () {
|
||||
this.createPiskelFromImages_([image]);
|
||||
error: function () {
|
||||
if (this.getImportType_() === 'single') {
|
||||
// Single image
|
||||
this.createPiskelFromImages_([image], resizeW, resizeH);
|
||||
} else {
|
||||
// Spritesheet
|
||||
this.createImagesFromSheet_(image);
|
||||
}
|
||||
this.closeDialog();
|
||||
}.bind(this)
|
||||
});
|
||||
@ -121,9 +212,24 @@
|
||||
}
|
||||
};
|
||||
|
||||
ns.ImportImageController.prototype.createFramesFromImages_ = function (images) {
|
||||
var w = this.resizeWidth.val();
|
||||
var h = this.resizeHeight.val();
|
||||
ns.ImportImageController.prototype.createImagesFromSheet_ = function (image) {
|
||||
var x = this.sanitizeInputValue_(this.frameOffsetX, 0);
|
||||
var y = this.sanitizeInputValue_(this.frameOffsetY, 0);
|
||||
var w = this.sanitizeInputValue_(this.frameSizeX, 1);
|
||||
var h = this.sanitizeInputValue_(this.frameSizeY, 1);
|
||||
|
||||
var images = pskl.utils.CanvasUtils.createFramesFromImage(
|
||||
image,
|
||||
x,
|
||||
y,
|
||||
w,
|
||||
h,
|
||||
/*useHorizonalStrips=*/ true,
|
||||
/*ignoreEmptyFrames=*/ true);
|
||||
this.createPiskelFromImages_(images, w, h);
|
||||
};
|
||||
|
||||
ns.ImportImageController.prototype.createFramesFromImages_ = function (images, w, h) {
|
||||
var smoothing = !!this.smoothResize.prop('checked');
|
||||
|
||||
var frames = images.map(function (image) {
|
||||
@ -133,13 +239,81 @@
|
||||
return frames;
|
||||
};
|
||||
|
||||
ns.ImportImageController.prototype.createPiskelFromImages_ = function (images) {
|
||||
var frames = this.createFramesFromImages_(images);
|
||||
ns.ImportImageController.prototype.createPiskelFromImages_ = function (images, w, h) {
|
||||
var frames = this.createFramesFromImages_(images, w, h);
|
||||
var layer = pskl.model.Layer.fromFrames('Layer 1', frames);
|
||||
var descriptor = new pskl.model.piskel.Descriptor('Imported piskel', '');
|
||||
var piskel = pskl.model.Piskel.fromLayers([layer], descriptor);
|
||||
|
||||
pskl.app.piskelController.setPiskel(piskel);
|
||||
pskl.app.animationController.setFPS(Constants.DEFAULT.FPS);
|
||||
pskl.app.previewController.setFPS(Constants.DEFAULT.FPS);
|
||||
};
|
||||
})();
|
||||
|
||||
ns.ImportImageController.prototype.drawFrameGrid_ = function (frameX, frameY, frameW, frameH) {
|
||||
if (!this.importedImage_) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Grab the sizes of the source and preview images
|
||||
var width = this.importedImage_.width;
|
||||
var height = this.importedImage_.height;
|
||||
var previewWidth = this.importPreview.width();
|
||||
var previewHeight = this.importPreview.height();
|
||||
|
||||
var canvasWrapper = this.importPreview.children('canvas');
|
||||
var canvas = canvasWrapper.get(0);
|
||||
if (!canvasWrapper.length) {
|
||||
// Create a new canvas for the grid
|
||||
canvas = pskl.utils.CanvasUtils.createCanvas(
|
||||
previewWidth + 1,
|
||||
previewHeight + 1);
|
||||
this.importPreview.append(canvas);
|
||||
canvasWrapper = $(canvas);
|
||||
}
|
||||
|
||||
var context = canvas.getContext('2d');
|
||||
context.clearRect(0, 0, canvas.width, canvas.height);
|
||||
context.beginPath();
|
||||
|
||||
// Calculate the number of whole frames
|
||||
var countX = Math.floor((width - frameX) / frameW);
|
||||
var countY = Math.floor((height - frameY) / frameH);
|
||||
|
||||
if (countX > 0 && countY > 0) {
|
||||
var scaleX = previewWidth / width;
|
||||
var scaleY = previewHeight / height;
|
||||
var maxWidth = countX * frameW + frameX;
|
||||
var maxHeight = countY * frameH + frameY;
|
||||
|
||||
// Draw the vertical lines
|
||||
for (var x = frameX + 0.5; x < maxWidth + 1 && x < width + 1; x += frameW) {
|
||||
context.moveTo(x * scaleX, frameY * scaleY);
|
||||
context.lineTo(x * scaleX, maxHeight * scaleY);
|
||||
}
|
||||
|
||||
// Draw the horizontal lines
|
||||
for (var y = frameY + 0.5; y < maxHeight + 1 && y < height + 1; y += frameH) {
|
||||
context.moveTo(frameX * scaleX, y * scaleY);
|
||||
context.lineTo(maxWidth * scaleX, y * scaleY);
|
||||
}
|
||||
|
||||
// Set the line style to dashed
|
||||
context.lineWidth = 1;
|
||||
context.setLineDash([2, 1]);
|
||||
context.strokeStyle = '#000000';
|
||||
context.stroke();
|
||||
|
||||
// Show the canvas
|
||||
canvasWrapper.show();
|
||||
this.importPreview.addClass('no-border');
|
||||
} else {
|
||||
this.hideFrameGrid_();
|
||||
}
|
||||
};
|
||||
|
||||
ns.ImportImageController.prototype.hideFrameGrid_ = function() {
|
||||
this.importPreview.children('canvas').hide();
|
||||
this.importPreview.removeClass('no-border');
|
||||
};
|
||||
|
||||
})();
|
||||
|
84
src/js/controller/drawing/DragHandler.js
Normal file
@ -0,0 +1,84 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.controller.drawing');
|
||||
|
||||
/**
|
||||
* Multiplier applied between the mouse movement and viewport movement
|
||||
* @type {Number}
|
||||
*/
|
||||
var MULTIPLIER = 2;
|
||||
|
||||
/**
|
||||
* Dedicated handler to drag the drawing canvas using the mouse
|
||||
* Will store the initial coordinates as well as the status of the drag
|
||||
* @param {DrawingController} drawingController
|
||||
*/
|
||||
ns.DragHandler = function (drawingController) {
|
||||
this.drawingController = drawingController;
|
||||
|
||||
this.isDragging_ = false;
|
||||
this.updateOrigin_(-1, -1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize a drag session.
|
||||
* @param {Number} x : x coordinate of the mouse event that initiated the drag
|
||||
* @param {Number} y : y coordinate of the mouse event that initiated the drag
|
||||
*/
|
||||
ns.DragHandler.prototype.startDrag = function (x, y) {
|
||||
var coords = this.drawingController.getSpriteCoordinates(x, y);
|
||||
this.updateOrigin_(coords.x, coords.y);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the drag status
|
||||
* @param {Number} x : x coordinate of the mouse event that triggered the update
|
||||
* @param {Number} y : y coordinate of the mouse event that triggered the update
|
||||
*/
|
||||
ns.DragHandler.prototype.updateDrag = function (x, y) {
|
||||
var currentOffset = this.drawingController.getOffset();
|
||||
var offset = this.calculateOffset_(x, y);
|
||||
if (currentOffset.y !== offset.y || currentOffset.x !== offset.x) {
|
||||
this.isDragging_ = true;
|
||||
this.drawingController.setOffset(offset.x, offset.y);
|
||||
|
||||
// retrieve the updated coordinates after moving the sprite
|
||||
// and store them as the new drag origin
|
||||
var coords = this.drawingController.getSpriteCoordinates(x, y);
|
||||
this.updateOrigin_(coords.x, coords.y);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop the drag session
|
||||
*/
|
||||
ns.DragHandler.prototype.stopDrag = function () {
|
||||
this.isDragging_ = false;
|
||||
this.origin = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Will return true if the drag handler effectively MOVED the offset
|
||||
* during the current drag session
|
||||
*/
|
||||
ns.DragHandler.prototype.isDragging = function () {
|
||||
return this.isDragging_;
|
||||
};
|
||||
|
||||
ns.DragHandler.prototype.calculateOffset_ = function (x, y) {
|
||||
var coords = this.drawingController.getSpriteCoordinates(x, y);
|
||||
var currentOffset = this.drawingController.getOffset();
|
||||
|
||||
var offset = {
|
||||
x : currentOffset.x - MULTIPLIER * (coords.x - this.origin.x),
|
||||
y : currentOffset.y - MULTIPLIER * (coords.y - this.origin.y)
|
||||
};
|
||||
|
||||
return offset;
|
||||
};
|
||||
|
||||
ns.DragHandler.prototype.updateOrigin_ = function (x, y) {
|
||||
this.origin = this.origin || {};
|
||||
this.origin.x = x;
|
||||
this.origin.y = y;
|
||||
};
|
||||
})();
|
@ -38,12 +38,12 @@
|
||||
/**
|
||||
* TODO : this should be removed
|
||||
* FPS should be stored in the Piskel model and not in the
|
||||
* animationController
|
||||
* previewController
|
||||
* Then piskelController should be able to return this information
|
||||
* @return {Number} Frames per second for the current animation
|
||||
*/
|
||||
ns.PiskelController.prototype.getFPS = function () {
|
||||
return pskl.app.animationController.getFPS();
|
||||
return pskl.app.previewController.getFPS();
|
||||
};
|
||||
|
||||
ns.PiskelController.prototype.getLayers = function () {
|
||||
@ -78,7 +78,6 @@
|
||||
return layer.getFrameAt(this.currentFrameIndex);
|
||||
};
|
||||
|
||||
|
||||
ns.PiskelController.prototype.getCurrentLayerIndex = function () {
|
||||
return this.currentLayerIndex;
|
||||
};
|
||||
@ -125,7 +124,8 @@
|
||||
};
|
||||
|
||||
ns.PiskelController.prototype.createEmptyFrame_ = function () {
|
||||
var w = this.piskel.getWidth(), h = this.piskel.getHeight();
|
||||
var w = this.piskel.getWidth();
|
||||
var h = this.piskel.getHeight();
|
||||
return new pskl.model.Frame(w, h);
|
||||
};
|
||||
|
||||
@ -147,7 +147,7 @@
|
||||
this.getLayers().forEach(function (l) {
|
||||
l.duplicateFrameAt(index);
|
||||
});
|
||||
this.setCurrentFrameIndex(index+1);
|
||||
this.setCurrentFrameIndex(index + 1);
|
||||
};
|
||||
|
||||
ns.PiskelController.prototype.moveFrame = function (fromIndex, toIndex) {
|
||||
@ -207,21 +207,21 @@
|
||||
|
||||
ns.PiskelController.prototype.mergeDownLayerAt = function (index) {
|
||||
var layer = this.getLayerByIndex(index);
|
||||
var downLayer = this.getLayerByIndex(index-1);
|
||||
var downLayer = this.getLayerByIndex(index - 1);
|
||||
if (layer && downLayer) {
|
||||
var mergedLayer = pskl.utils.LayerUtils.mergeLayers(layer, downLayer);
|
||||
this.removeLayerAt(index);
|
||||
this.piskel.addLayerAt(mergedLayer, index);
|
||||
this.removeLayerAt(index-1);
|
||||
this.removeLayerAt(index - 1);
|
||||
this.selectLayer(mergedLayer);
|
||||
}
|
||||
};
|
||||
|
||||
ns.PiskelController.prototype.generateLayerName_ = function () {
|
||||
var name = "Layer " + this.layerIdCounter;
|
||||
var name = 'Layer ' + this.layerIdCounter;
|
||||
while (this.hasLayerForName_(name)) {
|
||||
this.layerIdCounter++;
|
||||
name = "Layer " + this.layerIdCounter;
|
||||
name = 'Layer ' + this.layerIdCounter;
|
||||
}
|
||||
return name;
|
||||
};
|
||||
@ -259,6 +259,11 @@
|
||||
this.selectLayer(layer);
|
||||
};
|
||||
|
||||
ns.PiskelController.prototype.removeCurrentLayer = function () {
|
||||
var currentLayerIndex = this.getCurrentLayerIndex();
|
||||
this.removeLayerAt(currentLayerIndex);
|
||||
};
|
||||
|
||||
ns.PiskelController.prototype.removeLayerAt = function (index) {
|
||||
if (this.getLayers().length > 1) {
|
||||
var layer = this.getLayerAt(index);
|
||||
@ -272,4 +277,4 @@
|
||||
ns.PiskelController.prototype.serialize = function (expanded) {
|
||||
return pskl.utils.Serializer.serializePiskel(this.piskel, expanded);
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -7,6 +7,29 @@
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.init = function () {
|
||||
// DECORATED WITH RESET
|
||||
this.resetWrap_('setCurrentFrameIndex');
|
||||
this.resetWrap_('selectNextFrame');
|
||||
this.resetWrap_('selectPreviousFrame');
|
||||
this.resetWrap_('setCurrentLayerIndex');
|
||||
this.resetWrap_('selectLayer');
|
||||
// DECORATED WITH SAVE, NO RESET
|
||||
this.saveWrap_('renameLayerAt', false);
|
||||
// DECORATED WITH SAVE, WITH RESET
|
||||
this.saveWrap_('removeCurrentLayer', true);
|
||||
this.saveWrap_('addFrame', true);
|
||||
this.saveWrap_('addFrameAtCurrentIndex', true);
|
||||
this.saveWrap_('addFrameAt', true);
|
||||
this.saveWrap_('removeFrameAt', true);
|
||||
this.saveWrap_('duplicateCurrentFrame', true);
|
||||
this.saveWrap_('duplicateFrameAt', true);
|
||||
this.saveWrap_('moveFrame', true);
|
||||
this.saveWrap_('createLayer', true);
|
||||
this.saveWrap_('mergeDownLayerAt', true);
|
||||
this.saveWrap_('moveLayerUp', true);
|
||||
this.saveWrap_('moveLayerDown', true);
|
||||
this.saveWrap_('removeCurrentLayer', true);
|
||||
|
||||
pskl.app.shortcutService.addShortcut('up', this.selectPreviousFrame.bind(this));
|
||||
pskl.app.shortcutService.addShortcut('down', this.selectNextFrame.bind(this));
|
||||
pskl.app.shortcutService.addShortcut('n', this.addFrameAtCurrentIndex.bind(this));
|
||||
@ -23,128 +46,55 @@
|
||||
});
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.addFrame = function () {
|
||||
this.addFrameAt(this.getFrameCount());
|
||||
ns.PublicPiskelController.prototype.resetWrap_ = function (methodName) {
|
||||
this[methodName] = function () {
|
||||
this.piskelController[methodName].apply(this.piskelController, arguments);
|
||||
$.publish(Events.PISKEL_RESET);
|
||||
};
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.addFrameAtCurrentIndex = function () {
|
||||
this.addFrameAt(this.getCurrentFrameIndex());
|
||||
ns.PublicPiskelController.prototype.saveWrap_ = function (methodName, reset) {
|
||||
this[methodName] = reset ? function () {
|
||||
var stateInfo = this.getStateInfo_();
|
||||
this.piskelController[methodName].apply(this.piskelController, arguments);
|
||||
this.raiseSaveStateEvent_(this.piskelController[methodName], arguments, stateInfo);
|
||||
$.publish(Events.PISKEL_RESET);
|
||||
} : function () {
|
||||
var stateInfo = this.getStateInfo_();
|
||||
this.piskelController[methodName].apply(this.piskelController, arguments);
|
||||
this.raiseSaveStateEvent_(this.piskelController[methodName], arguments, stateInfo);
|
||||
};
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.addFrameAt = function (index) {
|
||||
this.raiseSaveStateEvent_(this.piskelController.addFrameAt, [index]);
|
||||
this.piskelController.addFrameAt(index);
|
||||
$.publish(Events.PISKEL_RESET);
|
||||
ns.PublicPiskelController.prototype.getStateInfo_ = function () {
|
||||
var stateInfo = {
|
||||
frameIndex : this.piskelController.currentFrameIndex,
|
||||
layerIndex : this.piskelController.currentLayerIndex
|
||||
};
|
||||
return stateInfo;
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.removeFrameAt = function (index) {
|
||||
this.raiseSaveStateEvent_(this.piskelController.removeFrameAt, [index]);
|
||||
this.piskelController.removeFrameAt(index);
|
||||
$.publish(Events.PISKEL_RESET);
|
||||
ns.PublicPiskelController.prototype.raiseSaveStateEvent_ = function (fn, args, stateInfo) {
|
||||
$.publish(Events.PISKEL_SAVE_STATE, {
|
||||
type : pskl.service.HistoryService.REPLAY,
|
||||
scope : this,
|
||||
replay : {
|
||||
fn : fn,
|
||||
args : args
|
||||
},
|
||||
state : stateInfo
|
||||
});
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.duplicateCurrentFrame = function () {
|
||||
this.duplicateFrameAt(this.getCurrentFrameIndex());
|
||||
ns.PublicPiskelController.prototype.setSavePath = function (savePath) {
|
||||
this.piskelController.piskel.savePath = savePath;
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.getSavePath = function () {
|
||||
return this.piskelController.piskel.savePath;
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.replay = function (frame, replayData) {
|
||||
replayData.fn.apply(this.piskelController, replayData.args);
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.duplicateFrameAt = function (index) {
|
||||
this.raiseSaveStateEvent_(this.piskelController.duplicateFrameAt, [index]);
|
||||
this.piskelController.duplicateFrameAt(index);
|
||||
$.publish(Events.PISKEL_RESET);
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.moveFrame = function (fromIndex, toIndex) {
|
||||
this.raiseSaveStateEvent_(this.piskelController.moveFrame, [fromIndex, toIndex]);
|
||||
this.piskelController.moveFrame(fromIndex, toIndex);
|
||||
$.publish(Events.PISKEL_RESET);
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.setCurrentFrameIndex = function (index) {
|
||||
this.piskelController.setCurrentFrameIndex(index);
|
||||
$.publish(Events.PISKEL_RESET);
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.selectNextFrame = function () {
|
||||
this.piskelController.selectNextFrame();
|
||||
$.publish(Events.PISKEL_RESET);
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.selectPreviousFrame = function () {
|
||||
this.piskelController.selectPreviousFrame();
|
||||
$.publish(Events.PISKEL_RESET);
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.setCurrentLayerIndex = function (index) {
|
||||
this.piskelController.setCurrentLayerIndex(index);
|
||||
$.publish(Events.PISKEL_RESET);
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.selectLayer = function (layer) {
|
||||
this.piskelController.selectLayer(layer);
|
||||
$.publish(Events.PISKEL_RESET);
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.renameLayerAt = function (index, name) {
|
||||
this.raiseSaveStateEvent_(this.piskelController.renameLayerAt, [index, name]);
|
||||
this.piskelController.renameLayerAt(index, name);
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.createLayer = function (name) {
|
||||
this.raiseSaveStateEvent_(this.piskelController.createLayer, [name]);
|
||||
this.piskelController.createLayer(name);
|
||||
$.publish(Events.PISKEL_RESET);
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.mergeDownLayerAt = function (index) {
|
||||
this.raiseSaveStateEvent_(this.piskelController.mergeDownLayerAt, [index]);
|
||||
this.piskelController.mergeDownLayerAt(index);
|
||||
$.publish(Events.PISKEL_RESET);
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.moveLayerUp = function () {
|
||||
this.raiseSaveStateEvent_(this.piskelController.moveLayerUp, []);
|
||||
this.piskelController.moveLayerUp();
|
||||
$.publish(Events.PISKEL_RESET);
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.moveLayerDown = function () {
|
||||
this.raiseSaveStateEvent_(this.piskelController.moveLayerDown, []);
|
||||
this.piskelController.moveLayerDown();
|
||||
$.publish(Events.PISKEL_RESET);
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.removeCurrentLayer = function () {
|
||||
var currentLayerIndex = this.getCurrentLayerIndex();
|
||||
this.raiseSaveStateEvent_(this.piskelController.removeLayerAt, [currentLayerIndex]);
|
||||
this.piskelController.removeLayerAt(currentLayerIndex);
|
||||
$.publish(Events.PISKEL_RESET);
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.getCurrentLayerIndex = function () {
|
||||
return this.piskelController.getCurrentLayerIndex();
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.getCurrentFrameIndex = function () {
|
||||
return this.piskelController.currentFrameIndex;
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.getPiskel = function () {
|
||||
return this.piskelController.piskel;
|
||||
};
|
||||
|
||||
ns.PublicPiskelController.prototype.raiseSaveStateEvent_ = function (fn, args) {
|
||||
$.publish(Events.PISKEL_SAVE_STATE, {
|
||||
type : pskl.service.HistoryService.REPLAY_NO_SNAPSHOT,
|
||||
scope : this,
|
||||
replay : {
|
||||
fn : fn,
|
||||
args : args
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
87
src/js/controller/preview/PopupPreviewController.js
Normal file
@ -0,0 +1,87 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.controller.preview');
|
||||
|
||||
var POPUP_TITLE = 'Piskel - preview';
|
||||
|
||||
ns.PopupPreviewController = function (piskelController) {
|
||||
this.piskelController = piskelController;
|
||||
this.popup = null;
|
||||
this.renderer = null;
|
||||
this.renderFlag = false;
|
||||
};
|
||||
|
||||
ns.PopupPreviewController.prototype.init = function () {
|
||||
pskl.utils.Event.addEventListener(window, 'unload', this.onMainWindowUnload_, this);
|
||||
};
|
||||
|
||||
ns.PopupPreviewController.prototype.isOpen = function () {
|
||||
return !!this.popup;
|
||||
};
|
||||
|
||||
ns.PopupPreviewController.prototype.open = function () {
|
||||
if (!this.isOpen()) {
|
||||
this.popup = window.open('about:blank', '', 'width=320,height=320');
|
||||
window.setTimeout(this.onPopupLoaded.bind(this), 500);
|
||||
} else {
|
||||
this.popup.focus();
|
||||
}
|
||||
};
|
||||
|
||||
ns.PopupPreviewController.prototype.onPopupLoaded = function () {
|
||||
this.popup.document.title = POPUP_TITLE;
|
||||
this.popup.document.body.innerHTML = pskl.utils.Template.get('popup-preview-partial');
|
||||
pskl.utils.Event.addEventListener(this.popup, 'resize', this.onWindowResize_, this);
|
||||
pskl.utils.Event.addEventListener(this.popup, 'unload', this.onPopupClosed_, this);
|
||||
var container = this.popup.document.querySelector('.preview-container');
|
||||
this.renderer = new pskl.rendering.frame.TiledFrameRenderer($(container));
|
||||
this.updateZoom_();
|
||||
this.renderFlag = true;
|
||||
};
|
||||
|
||||
ns.PopupPreviewController.prototype.render = function (frame) {
|
||||
if (this.isOpen() && this.renderer) {
|
||||
this.renderer.render(frame);
|
||||
this.renderFlag = false;
|
||||
}
|
||||
};
|
||||
|
||||
ns.PopupPreviewController.prototype.onWindowResize_ = function (frame) {
|
||||
this.updateZoom_();
|
||||
this.renderFlag = true;
|
||||
};
|
||||
|
||||
ns.PopupPreviewController.prototype.updateZoom_ = function () {
|
||||
var documentElement = this.popup.document.documentElement;
|
||||
var wZoom = documentElement.clientWidth / this.piskelController.getWidth();
|
||||
var hZoom = documentElement.clientHeight / this.piskelController.getHeight();
|
||||
var zoom = Math.min(wZoom, hZoom);
|
||||
|
||||
this.renderer.setZoom(zoom);
|
||||
|
||||
var height = this.piskelController.getHeight() * zoom;
|
||||
var width = this.piskelController.getWidth() * zoom;
|
||||
|
||||
var container = this.popup.document.querySelector('.preview-container');
|
||||
container.style.height = height + 'px';
|
||||
container.style.width = width + 'px';
|
||||
|
||||
var horizontalMargin = (documentElement.clientHeight - height) / 2;
|
||||
container.style.marginTop = horizontalMargin + 'px';
|
||||
container.style.marginBottom = horizontalMargin + 'px';
|
||||
|
||||
var verticalMargin = (documentElement.clientWidth - width) / 2;
|
||||
container.style.marginLeft = verticalMargin + 'px';
|
||||
container.style.marginRight = verticalMargin + 'px';
|
||||
};
|
||||
|
||||
ns.PopupPreviewController.prototype.onPopupClosed_ = function () {
|
||||
var popup = this.popup;
|
||||
this.popup = null;
|
||||
};
|
||||
|
||||
ns.PopupPreviewController.prototype.onMainWindowUnload_ = function () {
|
||||
if (this.isOpen()) {
|
||||
this.popup.close();
|
||||
}
|
||||
};
|
||||
})();
|
209
src/js/controller/preview/PreviewController.js
Normal file
@ -0,0 +1,209 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.controller.preview');
|
||||
|
||||
// Preview is a square of PREVIEW_SIZE x PREVIEW_SIZE
|
||||
var PREVIEW_SIZE = 200;
|
||||
|
||||
ns.PreviewController = function (piskelController, container) {
|
||||
this.piskelController = piskelController;
|
||||
this.container = container;
|
||||
|
||||
this.elapsedTime = 0;
|
||||
this.currentIndex = 0;
|
||||
|
||||
this.renderFlag = true;
|
||||
|
||||
this.fpsRangeInput = $('#preview-fps');
|
||||
this.fpsCounterDisplay = $('#display-fps');
|
||||
|
||||
this.setFPS(Constants.DEFAULT.FPS);
|
||||
|
||||
var frame = this.piskelController.getCurrentFrame();
|
||||
|
||||
this.renderer = new pskl.rendering.frame.TiledFrameRenderer(this.container);
|
||||
this.popupPreviewController = new ns.PopupPreviewController(piskelController);
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.init = function () {
|
||||
// the oninput event won't work on IE10 unfortunately, but at least will provide a
|
||||
// consistent behavior across all other browsers that support the input type range
|
||||
// see https://bugzilla.mozilla.org/show_bug.cgi?id=853670
|
||||
this.fpsRangeInput.on('input change', this.onFPSSliderChange.bind(this));
|
||||
document.querySelector('.right-column').style.width = Constants.ANIMATED_PREVIEW_WIDTH + 'px';
|
||||
|
||||
this.toggleOnionSkinEl = document.querySelector('.preview-toggle-onion-skin');
|
||||
this.toggleOnionSkinEl.addEventListener('click', this.toggleOnionSkin_.bind(this));
|
||||
|
||||
pskl.utils.Event.addEventListener('.open-popup-preview-button', 'click', this.onOpenPopupPreviewClick_, this);
|
||||
|
||||
pskl.app.shortcutService.addShortcut('alt+O', this.toggleOnionSkin_.bind(this));
|
||||
|
||||
$.subscribe(Events.FRAME_SIZE_CHANGED, this.onFrameSizeChange_.bind(this));
|
||||
$.subscribe(Events.USER_SETTINGS_CHANGED, $.proxy(this.onUserSettingsChange_, this));
|
||||
|
||||
$.subscribe(Events.PISKEL_SAVE_STATE, this.setRenderFlag_.bind(this, true));
|
||||
$.subscribe(Events.PISKEL_RESET, this.setRenderFlag_.bind(this, true));
|
||||
|
||||
this.popupPreviewController.init();
|
||||
|
||||
this.updateZoom_();
|
||||
this.updateOnionSkinPreview_();
|
||||
this.updateMaxFPS_();
|
||||
this.updateContainerDimensions_();
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.onOpenPopupPreviewClick_ = function () {
|
||||
this.popupPreviewController.open();
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.onUserSettingsChange_ = function (evt, name, value) {
|
||||
if (name == pskl.UserSettings.ONION_SKIN) {
|
||||
this.updateOnionSkinPreview_();
|
||||
} else if (name == pskl.UserSettings.MAX_FPS) {
|
||||
this.updateMaxFPS_();
|
||||
} else {
|
||||
this.updateZoom_();
|
||||
this.updateContainerDimensions_();
|
||||
}
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.updateOnionSkinPreview_ = function () {
|
||||
var enabledClassname = 'preview-toggle-onion-skin-enabled';
|
||||
if (pskl.UserSettings.get(pskl.UserSettings.ONION_SKIN)) {
|
||||
this.toggleOnionSkinEl.classList.add(enabledClassname);
|
||||
} else {
|
||||
this.toggleOnionSkinEl.classList.remove(enabledClassname);
|
||||
}
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.updateMaxFPS_ = function () {
|
||||
var maxFps = pskl.UserSettings.get(pskl.UserSettings.MAX_FPS);
|
||||
this.fpsRangeInput.get(0).setAttribute('max', maxFps);
|
||||
this.setFPS(Math.min(this.fps, maxFps));
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.updateZoom_ = function () {
|
||||
var isTiled = pskl.UserSettings.get(pskl.UserSettings.TILED_PREVIEW);
|
||||
var zoom = isTiled ? 1 : this.calculateZoom_();
|
||||
this.renderer.setZoom(zoom);
|
||||
this.setRenderFlag_(true);
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.getZoom = function () {
|
||||
return this.calculateZoom_();
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.getCoordinates = function(x, y) {
|
||||
var containerOffset = this.container.offset();
|
||||
x = x - containerOffset.left;
|
||||
y = y - containerOffset.top;
|
||||
var zoom = this.getZoom();
|
||||
return {
|
||||
x : Math.floor(x / zoom),
|
||||
y : Math.floor(y / zoom)
|
||||
};
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.onFPSSliderChange = function (evt) {
|
||||
this.setFPS(parseInt(this.fpsRangeInput[0].value, 10));
|
||||
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.setFPS = function (fps) {
|
||||
if (typeof fps === 'number') {
|
||||
this.fps = fps;
|
||||
// reset
|
||||
this.fpsRangeInput.get(0).value = 0;
|
||||
// set proper value
|
||||
this.fpsRangeInput.get(0).value = this.fps;
|
||||
this.fpsRangeInput.blur();
|
||||
this.fpsCounterDisplay.html(this.fps + ' FPS');
|
||||
}
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.getFPS = function () {
|
||||
return this.fps;
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.render = function (delta) {
|
||||
this.elapsedTime += delta;
|
||||
var index = this.getNextIndex_(delta);
|
||||
if (this.shoudlRender_() || this.currentIndex != index) {
|
||||
this.currentIndex = index;
|
||||
var frame = this.piskelController.getFrameAt(this.currentIndex);
|
||||
this.renderer.render(frame);
|
||||
this.renderFlag = false;
|
||||
|
||||
this.popupPreviewController.render(frame);
|
||||
}
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.getNextIndex_ = function (delta) {
|
||||
if (this.fps === 0) {
|
||||
return this.piskelController.getCurrentFrameIndex();
|
||||
} else {
|
||||
var index = Math.floor(this.elapsedTime / (1000 / this.fps));
|
||||
if (!this.piskelController.hasFrameAt(index)) {
|
||||
this.elapsedTime = 0;
|
||||
index = 0;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculate the preview zoom depending on the framesheet size
|
||||
*/
|
||||
ns.PreviewController.prototype.calculateZoom_ = function () {
|
||||
var frame = this.piskelController.getCurrentFrame();
|
||||
var hZoom = PREVIEW_SIZE / frame.getHeight();
|
||||
var wZoom = PREVIEW_SIZE / frame.getWidth();
|
||||
|
||||
return Math.min(hZoom, wZoom);
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.onFrameSizeChange_ = function () {
|
||||
this.updateZoom_();
|
||||
this.updateContainerDimensions_();
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.updateContainerDimensions_ = function () {
|
||||
var containerEl = this.container.get(0);
|
||||
var isTiled = pskl.UserSettings.get(pskl.UserSettings.TILED_PREVIEW);
|
||||
var height, width;
|
||||
|
||||
if (isTiled) {
|
||||
height = PREVIEW_SIZE;
|
||||
width = PREVIEW_SIZE;
|
||||
} else {
|
||||
var zoom = this.getZoom();
|
||||
var frame = this.piskelController.getCurrentFrame();
|
||||
height = frame.getHeight() * zoom;
|
||||
width = frame.getWidth() * zoom;
|
||||
}
|
||||
|
||||
containerEl.style.height = height + 'px';
|
||||
containerEl.style.width = width + 'px';
|
||||
|
||||
var horizontalMargin = (PREVIEW_SIZE - height) / 2;
|
||||
containerEl.style.marginTop = horizontalMargin + 'px';
|
||||
containerEl.style.marginBottom = horizontalMargin + 'px';
|
||||
|
||||
var verticalMargin = (PREVIEW_SIZE - width) / 2;
|
||||
containerEl.style.marginLeft = verticalMargin + 'px';
|
||||
containerEl.style.marginRight = verticalMargin + 'px';
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.setRenderFlag_ = function (bool) {
|
||||
this.renderFlag = bool;
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.shoudlRender_ = function () {
|
||||
return this.renderFlag || this.popupPreviewController.renderFlag;
|
||||
};
|
||||
|
||||
ns.PreviewController.prototype.toggleOnionSkin_ = function () {
|
||||
var currentValue = pskl.UserSettings.get(pskl.UserSettings.ONION_SKIN);
|
||||
pskl.UserSettings.set(pskl.UserSettings.ONION_SKIN, !currentValue);
|
||||
};
|
||||
})();
|
24
src/js/controller/settings/AbstractSettingController.js
Normal file
@ -0,0 +1,24 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.controller.settings');
|
||||
ns.AbstractSettingController = function () {};
|
||||
|
||||
ns.AbstractSettingController.prototype.addEventListener = function (el, type, callback) {
|
||||
pskl.utils.Event.addEventListener(el, type, callback, this);
|
||||
};
|
||||
|
||||
ns.AbstractSettingController.prototype.destroy = function () {
|
||||
pskl.utils.Event.removeAllEventListeners(this);
|
||||
this.nullifyDomReferences_();
|
||||
};
|
||||
|
||||
ns.AbstractSettingController.prototype.nullifyDomReferences_ = function () {
|
||||
for (var key in this) {
|
||||
if (this.hasOwnProperty(key)) {
|
||||
var isHTMLElement = this[key] && this[key].nodeName;
|
||||
if (isHTMLElement) {
|
||||
this[key] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
@ -1,41 +1,83 @@
|
||||
(function () {
|
||||
var ns = $.namespace("pskl.controller.settings");
|
||||
var ns = $.namespace('pskl.controller.settings');
|
||||
|
||||
ns.ApplicationSettingsController = function () {};
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
pskl.utils.inherit(ns.ApplicationSettingsController, pskl.controller.settings.AbstractSettingController);
|
||||
|
||||
ns.ApplicationSettingsController.prototype.init = function() {
|
||||
// Highlight selected background picker:
|
||||
var backgroundClass = pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND);
|
||||
$('#background-picker-wrapper')
|
||||
.find('.background-picker[data-background-class=' + backgroundClass + ']')
|
||||
.addClass('selected');
|
||||
this.backgroundContainer = document.querySelector('.background-picker-wrapper');
|
||||
this.addEventListener(this.backgroundContainer, 'click', this.onBackgroundClick_);
|
||||
|
||||
// Highlight selected background :
|
||||
var background = pskl.UserSettings.get(pskl.UserSettings.CANVAS_BACKGROUND);
|
||||
var selectedBackground = this.backgroundContainer.querySelector('[data-background=' + background + ']');
|
||||
if (selectedBackground) {
|
||||
selectedBackground.classList.add('selected');
|
||||
}
|
||||
|
||||
// Grid display and size
|
||||
var gridWidth = pskl.UserSettings.get(pskl.UserSettings.GRID_WIDTH);
|
||||
$('#grid-width').val(gridWidth);
|
||||
$('#grid-width').change(this.onGridWidthChange.bind(this));
|
||||
var gridSelect = document.querySelector('.grid-width-select');
|
||||
var selectedOption = gridSelect.querySelector('option[value="' + gridWidth + '"]');
|
||||
if (selectedOption) {
|
||||
selectedOption.setAttribute('selected', 'selected');
|
||||
}
|
||||
|
||||
// Handle canvas background changes:
|
||||
$('#background-picker-wrapper').click(this.onBackgroundClick.bind(this));
|
||||
this.addEventListener(gridSelect, 'change', this.onGridWidthChange_);
|
||||
|
||||
// Tiled preview
|
||||
var tiledPreview = pskl.UserSettings.get(pskl.UserSettings.TILED_PREVIEW);
|
||||
var tiledPreviewCheckbox = document.querySelector('.tiled-preview-checkbox');
|
||||
if (tiledPreview) {
|
||||
tiledPreviewCheckbox.setAttribute('checked', tiledPreview);
|
||||
}
|
||||
this.addEventListener(tiledPreviewCheckbox, 'change', this.onTiledPreviewChange_);
|
||||
|
||||
// Max FPS
|
||||
var maxFpsInput = document.querySelector('.max-fps-input');
|
||||
maxFpsInput.value = pskl.UserSettings.get(pskl.UserSettings.MAX_FPS);
|
||||
this.addEventListener(maxFpsInput, 'change', this.onMaxFpsChange_);
|
||||
|
||||
// Form
|
||||
this.applicationSettingsForm = document.querySelector('[name="application-settings-form"]');
|
||||
this.addEventListener(this.applicationSettingsForm, 'submit', this.onFormSubmit_);
|
||||
};
|
||||
|
||||
ns.ApplicationSettingsController.prototype.onGridWidthChange = function (evt) {
|
||||
var width = $('#grid-width').val();
|
||||
pskl.UserSettings.set(pskl.UserSettings.GRID_WIDTH, parseInt(width, 10));
|
||||
ns.ApplicationSettingsController.prototype.onGridWidthChange_ = function (evt) {
|
||||
var width = parseInt(evt.target.value, 10);
|
||||
pskl.UserSettings.set(pskl.UserSettings.GRID_WIDTH, width);
|
||||
};
|
||||
|
||||
ns.ApplicationSettingsController.prototype.onBackgroundClick = function (evt) {
|
||||
var target = $(evt.target).closest('.background-picker');
|
||||
if (target.length) {
|
||||
var backgroundClass = target.data('background-class');
|
||||
pskl.UserSettings.set(pskl.UserSettings.CANVAS_BACKGROUND, backgroundClass);
|
||||
ns.ApplicationSettingsController.prototype.onTiledPreviewChange_ = function (evt) {
|
||||
pskl.UserSettings.set(pskl.UserSettings.TILED_PREVIEW, evt.currentTarget.checked);
|
||||
};
|
||||
|
||||
$('.background-picker').removeClass('selected');
|
||||
target.addClass('selected');
|
||||
ns.ApplicationSettingsController.prototype.onBackgroundClick_ = function (evt) {
|
||||
var target = evt.target;
|
||||
var background = target.dataset.background;
|
||||
if (background) {
|
||||
pskl.UserSettings.set(pskl.UserSettings.CANVAS_BACKGROUND, background);
|
||||
var selected = this.backgroundContainer.querySelector('.selected');
|
||||
if (selected) {
|
||||
selected.classList.remove('selected');
|
||||
}
|
||||
target.classList.add('selected');
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
ns.ApplicationSettingsController.prototype.onMaxFpsChange_ = function (evt) {
|
||||
var target = evt.target;
|
||||
var fps = parseInt(target.value, 10);
|
||||
if (fps && !isNaN(fps)) {
|
||||
pskl.UserSettings.set(pskl.UserSettings.MAX_FPS, fps);
|
||||
} else {
|
||||
target.value = pskl.UserSettings.get(pskl.UserSettings.MAX_FPS);
|
||||
}
|
||||
};
|
||||
|
||||
ns.ApplicationSettingsController.prototype.onFormSubmit_ = function (evt) {
|
||||
evt.preventDefault();
|
||||
$.publish(Events.CLOSE_SETTINGS_DRAWER);
|
||||
};
|
||||
})();
|
||||
|
@ -1,160 +0,0 @@
|
||||
(function () {
|
||||
var ns = $.namespace("pskl.controller.settings");
|
||||
|
||||
var URL_MAX_LENGTH = 30;
|
||||
var MAX_GIF_COLORS = 256;
|
||||
var MAX_EXPORT_ZOOM = 20;
|
||||
var DEFAULT_EXPORT_ZOOM = 10;
|
||||
|
||||
ns.GifExportController = function (piskelController) {
|
||||
this.piskelController = piskelController;
|
||||
};
|
||||
|
||||
/**
|
||||
* List of Resolutions applicable for Gif export
|
||||
* @static
|
||||
* @type {Array} array of Objects {zoom:{Number}, default:{Boolean}}
|
||||
*/
|
||||
ns.GifExportController.RESOLUTIONS = [];
|
||||
for (var i = 1 ; i <= MAX_EXPORT_ZOOM ; i++) {
|
||||
ns.GifExportController.RESOLUTIONS.push({
|
||||
zoom : i
|
||||
});
|
||||
}
|
||||
|
||||
ns.GifExportController.prototype.init = function () {
|
||||
this.optionTemplate_ = pskl.utils.Template.get("gif-export-option-template");
|
||||
|
||||
this.uploadStatusContainerEl = document.querySelector(".gif-upload-status");
|
||||
|
||||
this.previewContainerEl = document.querySelector(".gif-export-preview");
|
||||
this.selectResolutionEl = document.querySelector(".gif-export-select-resolution");
|
||||
|
||||
this.uploadButton = $(".gif-upload-button");
|
||||
this.uploadButton.click(this.onUploadButtonClick_.bind(this));
|
||||
|
||||
this.downloadButton = $(".gif-download-button");
|
||||
this.downloadButton.click(this.onDownloadButtonClick_.bind(this));
|
||||
|
||||
this.createOptionElements_();
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.onUploadButtonClick_ = function (evt) {
|
||||
evt.originalEvent.preventDefault();
|
||||
var zoom = this.getSelectedZoom_(),
|
||||
fps = this.piskelController.getFPS();
|
||||
|
||||
this.renderAsImageDataAnimatedGIF(zoom, fps, this.onGifRenderingCompleted_.bind(this));
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.onDownloadButtonClick_ = function (evt) {
|
||||
var fileName = this.piskelController.getPiskel().getDescriptor().name + '.gif';
|
||||
var zoom = this.getSelectedZoom_(),
|
||||
fps = this.piskelController.getFPS();
|
||||
|
||||
this.renderAsImageDataAnimatedGIF(zoom, fps, function (imageData) {
|
||||
pskl.utils.BlobUtils.dataToBlob(imageData, "image/gif", function(blob) {
|
||||
pskl.utils.FileUtils.downloadAsFile(blob, fileName);
|
||||
});
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.onGifRenderingCompleted_ = function (imageData) {
|
||||
this.updatePreview_(imageData);
|
||||
this.previewContainerEl.classList.add("preview-upload-ongoing");
|
||||
pskl.app.imageUploadService.upload(imageData, this.onImageUploadCompleted_.bind(this));
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.onImageUploadCompleted_ = function (imageUrl) {
|
||||
this.updatePreview_(imageUrl);
|
||||
this.updateStatus_(imageUrl);
|
||||
this.previewContainerEl.classList.remove("preview-upload-ongoing");
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.updatePreview_ = function (src) {
|
||||
this.previewContainerEl.innerHTML = "<div><img style='max-width:32px;' src='"+src+"'/></div>";
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.getSelectedZoom_ = function () {
|
||||
return this.selectResolutionEl.value;
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.createOptionElements_ = function () {
|
||||
var resolutions = ns.GifExportController.RESOLUTIONS;
|
||||
for (var i = 0 ; i < resolutions.length ; i++) {
|
||||
var option = this.createOptionForResolution_(resolutions[i]);
|
||||
this.selectResolutionEl.appendChild(option);
|
||||
}
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.createOptionForResolution_ = function (resolution) {
|
||||
var zoom = resolution.zoom;
|
||||
var label = zoom*this.piskelController.getWidth() + "x" + zoom*this.piskelController.getHeight();
|
||||
var value = zoom;
|
||||
|
||||
var isSelected = zoom === DEFAULT_EXPORT_ZOOM;
|
||||
var selected = isSelected ? 'selected' : '';
|
||||
var optionHTML = pskl.utils.Template.replace(this.optionTemplate_, {value : value, label : label, selected : selected});
|
||||
var optionEl = pskl.utils.Template.createFromHTML(optionHTML);
|
||||
|
||||
return optionEl;
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.renderAsImageDataAnimatedGIF = function(zoom, fps, cb) {
|
||||
var colorCount = pskl.app.currentColorsService.getCurrentColors().length;
|
||||
var preserveColors = colorCount < MAX_GIF_COLORS;
|
||||
var gif = new window.GIF({
|
||||
workers: 2,
|
||||
quality: 1,
|
||||
width: this.piskelController.getWidth()*zoom,
|
||||
height: this.piskelController.getHeight()*zoom,
|
||||
preserveColors : preserveColors
|
||||
});
|
||||
|
||||
for (var i = 0; i < this.piskelController.getFrameCount(); i++) {
|
||||
var frame = this.piskelController.getFrameAt(i);
|
||||
var canvasRenderer = new pskl.rendering.CanvasRenderer(frame, zoom);
|
||||
var canvas = canvasRenderer.render();
|
||||
gif.addFrame(canvas.getContext('2d'), {
|
||||
delay: 1000 / fps
|
||||
});
|
||||
}
|
||||
|
||||
$.publish(Events.SHOW_PROGRESS, [{"name": 'Building animated GIF ...'}]);
|
||||
gif.on('progress', function(percentage) {
|
||||
$.publish(Events.UPDATE_PROGRESS, [{"progress": (percentage*100).toFixed(1)}]);
|
||||
}.bind(this));
|
||||
|
||||
gif.on('finished', function(blob) {
|
||||
$.publish(Events.HIDE_PROGRESS);
|
||||
pskl.utils.FileUtils.readFile(blob, cb);
|
||||
}.bind(this));
|
||||
|
||||
gif.render();
|
||||
};
|
||||
|
||||
// FIXME : HORRIBLE COPY/PASTA
|
||||
|
||||
ns.GifExportController.prototype.updateStatus_ = function (imageUrl, error) {
|
||||
if (imageUrl) {
|
||||
var linkTpl = "<a class='image-link' href='{{link}}' target='_blank'>{{shortLink}}</a>";
|
||||
var linkHtml = pskl.utils.Template.replace(linkTpl, {
|
||||
link : imageUrl,
|
||||
shortLink : this.shorten_(imageUrl, URL_MAX_LENGTH, '...')
|
||||
});
|
||||
this.uploadStatusContainerEl.innerHTML = 'Your image is now available at : ' + linkHtml;
|
||||
} else {
|
||||
// FIXME : Should display error message instead
|
||||
}
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.shorten_ = function (url, maxLength, suffix) {
|
||||
if (url.length > maxLength) {
|
||||
var index = Math.round((maxLength-suffix.length) / 2);
|
||||
var part1 = url.substring(0, index);
|
||||
var part2 = url.substring(url.length - index, url.length);
|
||||
url = part1 + suffix + part2;
|
||||
}
|
||||
return url;
|
||||
};
|
||||
})();
|
@ -3,28 +3,44 @@
|
||||
|
||||
ns.ImportController = function (piskelController) {
|
||||
this.piskelController = piskelController;
|
||||
this.importedImage_ = null;
|
||||
};
|
||||
|
||||
pskl.utils.inherit(ns.ImportController, pskl.controller.settings.AbstractSettingController);
|
||||
|
||||
ns.ImportController.prototype.init = function () {
|
||||
this.browseLocalButton = document.querySelector('.browse-local-button');
|
||||
this.browseLocalButton.addEventListener('click', this.onBrowseLocalClick_.bind(this));
|
||||
this.hiddenFileInput = document.querySelector('[name="file-upload-input"]');
|
||||
this.addEventListener(this.hiddenFileInput, 'change', this.onFileUploadChange_);
|
||||
|
||||
this.hiddenFileInput = $('[name=file-upload-input]');
|
||||
this.hiddenFileInput.change(this.onFileUploadChange_.bind(this));
|
||||
this.hiddenOpenPiskelInput = document.querySelector('[name="open-piskel-input"]');
|
||||
|
||||
this.fileInputButton = $('.file-input-button');
|
||||
this.fileInputButton.click(this.onFileInputClick_.bind(this));
|
||||
this.addEventListener('.browse-local-button', 'click', this.onBrowseLocalClick_);
|
||||
this.addEventListener('.file-input-button', 'click', this.onFileInputClick_);
|
||||
|
||||
this.hiddenOpenPiskelInput = $('[name=open-piskel-input]');
|
||||
this.hiddenOpenPiskelInput.change(this.onOpenPiskelChange_.bind(this));
|
||||
// different handlers, depending on the Environment
|
||||
if (pskl.utils.Environment.detectNodeWebkit()) {
|
||||
this.addEventListener('.open-piskel-button', 'click', this.openPiskelDesktop_);
|
||||
} else {
|
||||
this.addEventListener(this.hiddenOpenPiskelInput, 'change', this.onOpenPiskelChange_);
|
||||
this.addEventListener('.open-piskel-button', 'click', this.onOpenPiskelClick_);
|
||||
}
|
||||
|
||||
this.openPiskelInputButton = $('.open-piskel-button');
|
||||
this.openPiskelInputButton.click(this.onOpenPiskelClick_.bind(this));
|
||||
this.initRestoreSession_();
|
||||
};
|
||||
|
||||
this.prevSessionContainer = $('.previous-session');
|
||||
this.previousSessionTemplate_ = pskl.utils.Template.get("previous-session-info-template");
|
||||
this.fillRestoreSession_();
|
||||
ns.ImportController.prototype.initRestoreSession_ = function () {
|
||||
var previousSessionContainer = document.querySelector('.previous-session');
|
||||
var previousInfo = pskl.app.backupService.getPreviousPiskelInfo();
|
||||
if (previousInfo) {
|
||||
var previousSessionTemplate_ = pskl.utils.Template.get('previous-session-info-template');
|
||||
var date = pskl.utils.DateUtils.format(previousInfo.date, '{{H}}:{{m}} - {{Y}}/{{M}}/{{D}}');
|
||||
previousSessionContainer.innerHTML = pskl.utils.Template.replace(previousSessionTemplate_, {
|
||||
name : previousInfo.name,
|
||||
date : date
|
||||
});
|
||||
this.addEventListener('.restore-session-button', 'click', this.onRestorePreviousSessionClick_);
|
||||
} else {
|
||||
previousSessionContainer.innerHTML = 'No piskel backup was found on this browser.';
|
||||
}
|
||||
};
|
||||
|
||||
ns.ImportController.prototype.closeDrawer_ = function () {
|
||||
@ -39,12 +55,17 @@
|
||||
};
|
||||
|
||||
ns.ImportController.prototype.onOpenPiskelChange_ = function (evt) {
|
||||
var files = this.hiddenOpenPiskelInput.get(0).files;
|
||||
var files = this.hiddenOpenPiskelInput.files;
|
||||
if (files.length == 1) {
|
||||
this.openPiskelFile_(files[0]);
|
||||
}
|
||||
};
|
||||
|
||||
ns.ImportController.prototype.openPiskelDesktop_ = function (evt) {
|
||||
this.closeDrawer_();
|
||||
pskl.app.desktopStorageService.openPiskel();
|
||||
};
|
||||
|
||||
ns.ImportController.prototype.onOpenPiskelClick_ = function (evt) {
|
||||
this.hiddenOpenPiskelInput.click();
|
||||
};
|
||||
@ -55,18 +76,18 @@
|
||||
};
|
||||
|
||||
ns.ImportController.prototype.openPiskelFile_ = function (file) {
|
||||
if (this.isPiskel_(file)){
|
||||
if (this.isPiskel_(file)) {
|
||||
pskl.utils.PiskelFileUtils.loadFromFile(file, function (piskel, descriptor, fps) {
|
||||
piskel.setDescriptor(descriptor);
|
||||
pskl.app.piskelController.setPiskel(piskel);
|
||||
pskl.app.animationController.setFPS(fps);
|
||||
pskl.app.previewController.setFPS(fps);
|
||||
});
|
||||
this.closeDrawer_();
|
||||
}
|
||||
};
|
||||
|
||||
ns.ImportController.prototype.importPictureFromFile_ = function () {
|
||||
var files = this.hiddenFileInput.get(0).files;
|
||||
var files = this.hiddenFileInput.files;
|
||||
if (files.length == 1) {
|
||||
var file = files[0];
|
||||
if (this.isImage_(file)) {
|
||||
@ -77,7 +98,7 @@
|
||||
this.closeDrawer_();
|
||||
} else {
|
||||
this.closeDrawer_();
|
||||
throw 'File is not an image : ' + file.type;
|
||||
console.error('File is not an image : ' + file.type);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -90,26 +111,10 @@
|
||||
return (/\.piskel$/).test(file.name);
|
||||
};
|
||||
|
||||
ns.ImportController.prototype.fillRestoreSession_ = function () {
|
||||
var previousInfo = pskl.app.backupService.getPreviousPiskelInfo();
|
||||
if (previousInfo) {
|
||||
var info = {
|
||||
name : previousInfo.name,
|
||||
date : pskl.utils.DateUtils.format(previousInfo.date, "{{H}}:{{m}} - {{Y}}/{{M}}/{{D}}")
|
||||
};
|
||||
|
||||
this.prevSessionContainer.html(pskl.utils.Template.replace(this.previousSessionTemplate_, info));
|
||||
$(".restore-session-button").click(this.onRestorePreviousSessionClick_.bind(this));
|
||||
} else {
|
||||
this.prevSessionContainer.html("No piskel backup was found on this browser.");
|
||||
}
|
||||
};
|
||||
|
||||
ns.ImportController.prototype.onRestorePreviousSessionClick_ = function () {
|
||||
if (window.confirm('This will erase your current workspace. Continue ?')) {
|
||||
pskl.app.backupService.load();
|
||||
$.publish(Events.CLOSE_SETTINGS_DRAWER);
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
@ -1,70 +0,0 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.controller.settings');
|
||||
|
||||
ns.ResizeController = function (piskelController) {
|
||||
this.piskelController = piskelController;
|
||||
};
|
||||
|
||||
ns.ResizeController.prototype.init = function () {
|
||||
this.resizeWidth = $('[name=resize-width]');
|
||||
this.resizeHeight = $('[name=resize-height]');
|
||||
|
||||
this.resizeWidth.val(this.piskelController.getWidth());
|
||||
this.resizeHeight.val(this.piskelController.getHeight());
|
||||
|
||||
this.cancelButton = $('.resize-cancel-button');
|
||||
this.cancelButton.click(this.onCancelButtonClicked_.bind(this));
|
||||
|
||||
this.resizeForm = $("[name=resize-form]");
|
||||
this.resizeForm.submit(this.onResizeFormSubmit_.bind(this));
|
||||
|
||||
this.resizeContentCheckbox = $(".resize-content-checkbox");
|
||||
};
|
||||
|
||||
ns.ResizeController.prototype.onResizeFormSubmit_ = function (evt) {
|
||||
evt.originalEvent.preventDefault();
|
||||
|
||||
var width = parseInt(this.resizeWidth.val(), 10);
|
||||
var height = parseInt(this.resizeHeight.val(), 10);
|
||||
|
||||
var resizeContentEnabled = this.isResizeContentEnabled_();
|
||||
var resizedLayers = this.piskelController.getLayers().map(this.resizeLayer_.bind(this));
|
||||
|
||||
var piskel = pskl.model.Piskel.fromLayers(resizedLayers, this.piskelController.getPiskel().getDescriptor());
|
||||
|
||||
pskl.app.piskelController.setPiskel(piskel, true);
|
||||
$.publish(Events.CLOSE_SETTINGS_DRAWER);
|
||||
};
|
||||
|
||||
ns.ResizeController.prototype.resizeLayer_ = function (layer) {
|
||||
var resizedFrames = layer.getFrames().map(this.resizeFrame_.bind(this));
|
||||
return pskl.model.Layer.fromFrames(layer.getName(), resizedFrames);
|
||||
};
|
||||
|
||||
ns.ResizeController.prototype.resizeFrame_ = function (frame) {
|
||||
var width = parseInt(this.resizeWidth.val(), 10);
|
||||
var height = parseInt(this.resizeHeight.val(), 10);
|
||||
|
||||
var resizedFrame;
|
||||
if (this.isResizeContentEnabled_()) {
|
||||
resizedFrame = pskl.utils.FrameUtils.resize(frame, width, height, false);
|
||||
} else {
|
||||
resizedFrame = new pskl.model.Frame(width, height);
|
||||
frame.forEachPixel(function (color, x, y) {
|
||||
if (x < resizedFrame.getWidth() && y < resizedFrame.getHeight()) {
|
||||
resizedFrame.setPixel(x, y, color);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return resizedFrame;
|
||||
};
|
||||
|
||||
ns.ResizeController.prototype.isResizeContentEnabled_ = function () {
|
||||
return !!this.resizeContentCheckbox.prop('checked');
|
||||
};
|
||||
|
||||
ns.ResizeController.prototype.onCancelButtonClicked_ = function (evt) {
|
||||
$.publish(Events.CLOSE_SETTINGS_DRAWER);
|
||||
};
|
||||
})();
|
@ -5,63 +5,84 @@
|
||||
this.piskelController = piskelController;
|
||||
};
|
||||
|
||||
pskl.utils.inherit(ns.SaveController, pskl.controller.settings.AbstractSettingController);
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
ns.SaveController.prototype.init = function () {
|
||||
|
||||
// Only available in app-engine mode ...
|
||||
this.piskelName = document.querySelector('.piskel-name');
|
||||
|
||||
this.saveOnlineStatus = $('#save-online-status');
|
||||
|
||||
this.saveFileStatus = $('#save-file-status');
|
||||
// timestamp used to generate unique name when saving as .piskel
|
||||
this.timestamp = new Date();
|
||||
|
||||
this.insertPartials_();
|
||||
|
||||
// Only available in app-engine mode
|
||||
this.piskelName = document.querySelector('.piskel-name');
|
||||
this.saveOnlineStatus = document.querySelector('#save-online-status');
|
||||
this.saveFileStatus = document.querySelector('#save-file-status');
|
||||
this.descriptionInput = document.querySelector('#save-description');
|
||||
this.nameInput = document.querySelector('#save-name');
|
||||
this.saveOnlineButton = document.querySelector('#save-online-button');
|
||||
this.isPublicCheckbox = document.querySelector('input[name=save-public-checkbox]');
|
||||
|
||||
var descriptor = this.piskelController.getPiskel().getDescriptor();
|
||||
this.descriptionInput = $('#save-description');
|
||||
this.descriptionInput.val(descriptor.description);
|
||||
|
||||
this.isPublicCheckbox = $('input[name=save-public-checkbox]');
|
||||
this.isPublicCheckbox.prop('checked', descriptor.isPublic);
|
||||
|
||||
this.saveFileButton = $('#save-file-button');
|
||||
this.saveFileButton.click(this.saveFile_.bind(this));
|
||||
|
||||
this.saveLocalButton = $('#save-browser-button');
|
||||
this.saveLocalButton.click(this.saveLocal_.bind(this));
|
||||
|
||||
this.saveOnlineButton = $('#save-online-button');
|
||||
this.saveOnlineButton.click(this.saveOnline_.bind(this));
|
||||
|
||||
this.saveForm = $('form[name=save-form]');
|
||||
this.saveForm.submit(this.onSaveFormSubmit_.bind(this));
|
||||
|
||||
this.nameInput = $('#save-name');
|
||||
this.nameInput.val(descriptor.name);
|
||||
this.nameInput.keyup(this.updateLocalStatusFilename_.bind(this));
|
||||
|
||||
if (!pskl.app.isLoggedIn()) {
|
||||
this.saveOnlineButton.hide();
|
||||
$('.save-public-section').hide();
|
||||
this.saveOnlineStatus.html(pskl.utils.Template.get('save-please-login-partial'));
|
||||
} else {
|
||||
this.saveOnlineStatus.html(pskl.utils.Template.get('save-online-status-partial'));
|
||||
this.descriptionInput.value = descriptor.description;
|
||||
this.nameInput.value = descriptor.name;
|
||||
if (descriptor.isPublic) {
|
||||
this.isPublicCheckbox.setAttribute('checked', true);
|
||||
}
|
||||
|
||||
this.updateLocalStatusFilename_();
|
||||
if (pskl.utils.Environment.detectNodeWebkit()) {
|
||||
this.addEventListener('#save-as-button', 'click', this.saveAs_);
|
||||
}
|
||||
|
||||
this.addEventListener('#save-file-button', 'click', this.saveFile_);
|
||||
this.addEventListener('#save-browser-button', 'click', this.saveLocal_);
|
||||
this.addEventListener(this.saveOnlineButton, 'click', this.saveOnline_);
|
||||
this.addEventListener('form[name=save-form]', 'submit', this.onSaveFormSubmit_);
|
||||
|
||||
if (pskl.app.isLoggedIn()) {
|
||||
pskl.utils.Template.insert(this.saveOnlineStatus, 'beforeend', 'save-online-status-partial');
|
||||
} else {
|
||||
pskl.utils.Template.insert(this.saveOnlineStatus, 'beforeend', 'save-please-login-partial');
|
||||
var container = document.querySelector('.setting-save-section');
|
||||
container.classList.add('anonymous');
|
||||
}
|
||||
};
|
||||
|
||||
ns.SaveController.prototype.updateLocalStatusFilename_ = function () {
|
||||
this.saveFileStatus.html(pskl.utils.Template.getAndReplace('save-file-status-template', {
|
||||
name : this.getLocalFilename_()
|
||||
}));
|
||||
ns.SaveController.prototype.insertPartials_ = function () {
|
||||
var partials = [];
|
||||
if (pskl.utils.Environment.detectNodeWebkit()) {
|
||||
partials = [
|
||||
'save-file-nw-partial',
|
||||
'save-localstorage-partial',
|
||||
'save-online-partial'
|
||||
];
|
||||
} else if (pskl.app.isLoggedIn()) {
|
||||
partials = [
|
||||
'save-online-partial',
|
||||
'save-localstorage-partial',
|
||||
'save-file-partial'
|
||||
];
|
||||
} else {
|
||||
partials = [
|
||||
'save-file-partial',
|
||||
'save-localstorage-partial',
|
||||
'save-online-partial'
|
||||
];
|
||||
}
|
||||
|
||||
var container = document.querySelector('.save-form');
|
||||
partials.forEach(function (partial) {
|
||||
pskl.utils.Template.insert(container, 'beforeend', partial);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
ns.SaveController.prototype.getLocalFilename_ = function () {
|
||||
var piskelName = this.getName();
|
||||
var timestamp = pskl.utils.DateUtils.format(this.timestamp, "{{Y}}{{M}}{{D}}-{{H}}{{m}}{{s}}");
|
||||
return piskelName + "-" + timestamp + ".piskel";
|
||||
var timestamp = pskl.utils.DateUtils.format(this.timestamp, '{{Y}}{{M}}{{D}}-{{H}}{{m}}{{s}}');
|
||||
return piskelName + '-' + timestamp + '.piskel';
|
||||
};
|
||||
|
||||
ns.SaveController.prototype.onSaveFormSubmit_ = function (evt) {
|
||||
@ -85,15 +106,15 @@
|
||||
|
||||
if (name) {
|
||||
var description = this.getDescription();
|
||||
var isPublic = !!this.isPublicCheckbox.prop('checked');
|
||||
var isPublic = this.isPublic_();
|
||||
|
||||
var descriptor = new pskl.model.piskel.Descriptor(name, description, isPublic);
|
||||
this.piskelController.getPiskel().setDescriptor(descriptor);
|
||||
|
||||
this.beforeSaving_();
|
||||
|
||||
this.saveOnlineButton.attr('disabled', true);
|
||||
this.saveOnlineStatus.html('Saving ...');
|
||||
this.saveOnlineButton.setAttribute('disabled', true);
|
||||
this.saveOnlineStatus.innerHTML = 'Saving ...';
|
||||
|
||||
pskl.app.storageService.store({
|
||||
success : this.onSaveSuccess_.bind(this),
|
||||
@ -123,20 +144,37 @@
|
||||
};
|
||||
|
||||
ns.SaveController.prototype.saveFile_ = function () {
|
||||
// detect if this is running in NodeWebkit
|
||||
if (pskl.utils.Environment.detectNodeWebkit()) {
|
||||
pskl.app.desktopStorageService.save();
|
||||
} else {
|
||||
this.saveFileBrowser_();
|
||||
}
|
||||
};
|
||||
|
||||
ns.SaveController.prototype.saveAs_ = function () {
|
||||
pskl.app.desktopStorageService.savePiskelAs();
|
||||
};
|
||||
|
||||
ns.SaveController.prototype.saveFileBrowser_ = function () {
|
||||
this.beforeSaving_();
|
||||
pskl.utils.BlobUtils.stringToBlob(pskl.app.piskelController.serialize(), function(blob) {
|
||||
pskl.utils.FileUtils.downloadAsFile(blob, this.getLocalFilename_());
|
||||
this.onSaveSuccess_();
|
||||
this.afterSaving_();
|
||||
}.bind(this), "application/piskel+json");
|
||||
}.bind(this), 'application/piskel+json');
|
||||
};
|
||||
|
||||
ns.SaveController.prototype.getName = function () {
|
||||
return this.nameInput.val();
|
||||
return this.nameInput.value;
|
||||
};
|
||||
|
||||
ns.SaveController.prototype.getDescription = function () {
|
||||
return this.descriptionInput.val();
|
||||
return this.descriptionInput.value;
|
||||
};
|
||||
|
||||
ns.SaveController.prototype.isPublic_ = function () {
|
||||
return !!this.isPublicCheckbox.checked;
|
||||
};
|
||||
|
||||
ns.SaveController.prototype.beforeSaving_ = function () {
|
||||
@ -150,7 +188,7 @@
|
||||
ns.SaveController.prototype.updatePiskelDescriptor_ = function () {
|
||||
var name = this.getName();
|
||||
var description = this.getDescription();
|
||||
var isPublic = !!this.isPublicCheckbox.prop('checked');
|
||||
var isPublic = this.isPublic_();
|
||||
|
||||
var descriptor = new pskl.model.piskel.Descriptor(name, description, isPublic);
|
||||
this.piskelController.getPiskel().setDescriptor(descriptor);
|
||||
@ -158,17 +196,17 @@
|
||||
|
||||
ns.SaveController.prototype.onSaveSuccess_ = function () {
|
||||
$.publish(Events.CLOSE_SETTINGS_DRAWER);
|
||||
$.publish(Events.SHOW_NOTIFICATION, [{"content": "Successfully saved !"}]);
|
||||
$.publish(Events.SHOW_NOTIFICATION, [{'content': 'Successfully saved !'}]);
|
||||
$.publish(Events.PISKEL_SAVED);
|
||||
};
|
||||
|
||||
ns.SaveController.prototype.onSaveError_ = function (status) {
|
||||
$.publish(Events.SHOW_NOTIFICATION, [{"content": "Saving failed ("+status+")"}]);
|
||||
$.publish(Events.SHOW_NOTIFICATION, [{'content': 'Saving failed (' + status + ')'}]);
|
||||
};
|
||||
|
||||
ns.SaveController.prototype.afterOnlineSaving_ = function () {
|
||||
this.saveOnlineButton.attr('disabled', false);
|
||||
this.saveOnlineStatus.html('');
|
||||
this.saveOnlineButton.setAttribute('disabled', false);
|
||||
this.saveOnlineStatus.innerHTML = '';
|
||||
this.afterSaving_();
|
||||
};
|
||||
|
||||
@ -179,4 +217,4 @@
|
||||
|
||||
window.setTimeout($.publish.bind($, Events.HIDE_NOTIFICATION), 5000);
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -8,11 +8,11 @@
|
||||
},
|
||||
'resize' : {
|
||||
template : 'templates/settings/resize.html',
|
||||
controller : ns.ResizeController
|
||||
controller : ns.resize.ResizeController
|
||||
},
|
||||
'export' : {
|
||||
template : 'templates/settings/export.html',
|
||||
controller : ns.ImageExportController
|
||||
controller : ns.exportimage.ImageExportController
|
||||
},
|
||||
'import' : {
|
||||
template : 'templates/settings/import.html',
|
||||
@ -73,16 +73,22 @@
|
||||
};
|
||||
|
||||
ns.SettingsController.prototype.loadSetting = function (setting) {
|
||||
if (this.currentController && this.currentController.destroy) {
|
||||
this.currentController.destroy();
|
||||
}
|
||||
|
||||
this.drawerContainer.innerHTML = pskl.utils.Template.get(settings[setting].template);
|
||||
(new settings[setting].controller(this.piskelController)).init();
|
||||
|
||||
this.currentSetting = setting;
|
||||
this.currentController = new settings[setting].controller(this.piskelController);
|
||||
this.currentController.init();
|
||||
|
||||
this.settingsContainer.addClass(EXP_DRAWER_CLS);
|
||||
|
||||
$('.' + SEL_SETTING_CLS).removeClass(SEL_SETTING_CLS);
|
||||
$('[data-setting='+setting+']').addClass(SEL_SETTING_CLS);
|
||||
$('[data-setting=' + setting + ']').addClass(SEL_SETTING_CLS);
|
||||
|
||||
this.isExpanded = true;
|
||||
this.currentSetting = setting;
|
||||
};
|
||||
|
||||
ns.SettingsController.prototype.closeDrawer = function () {
|
||||
@ -94,5 +100,4 @@
|
||||
|
||||
document.activeElement.blur();
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
176
src/js/controller/settings/exportimage/GifExportController.js
Normal file
@ -0,0 +1,176 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.controller.settings.exportimage');
|
||||
|
||||
var URL_MAX_LENGTH = 30;
|
||||
var MAX_GIF_COLORS = 256;
|
||||
var MAX_EXPORT_ZOOM = 20;
|
||||
var DEFAULT_EXPORT_ZOOM = 10;
|
||||
var MAGIC_PINK = '#FF00FF';
|
||||
|
||||
ns.GifExportController = function (piskelController) {
|
||||
this.piskelController = piskelController;
|
||||
};
|
||||
|
||||
pskl.utils.inherit(ns.GifExportController, pskl.controller.settings.AbstractSettingController);
|
||||
|
||||
/**
|
||||
* List of Resolutions applicable for Gif export
|
||||
* @static
|
||||
* @type {Array} array of Objects {zoom:{Number}, default:{Boolean}}
|
||||
*/
|
||||
ns.GifExportController.RESOLUTIONS = [];
|
||||
for (var i = 1 ; i <= MAX_EXPORT_ZOOM ; i++) {
|
||||
ns.GifExportController.RESOLUTIONS.push({
|
||||
zoom : i
|
||||
});
|
||||
}
|
||||
|
||||
ns.GifExportController.prototype.init = function () {
|
||||
|
||||
this.uploadStatusContainerEl = document.querySelector('.gif-upload-status');
|
||||
this.previewContainerEl = document.querySelector('.gif-export-preview');
|
||||
this.widthInput = document.querySelector('.export-gif-resize-width');
|
||||
this.heightInput = document.querySelector('.export-gif-resize-height');
|
||||
this.uploadButton = document.querySelector('.gif-upload-button');
|
||||
this.downloadButton = document.querySelector('.gif-download-button');
|
||||
|
||||
this.sizeInputWidget = new pskl.widgets.SizeInput(
|
||||
this.widthInput, this.heightInput,
|
||||
this.piskelController.getWidth(), this.piskelController.getHeight());
|
||||
|
||||
this.addEventListener(this.uploadButton, 'click', this.onUploadButtonClick_);
|
||||
this.addEventListener(this.downloadButton, 'click', this.onDownloadButtonClick_);
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.destroy = function () {
|
||||
this.sizeInputWidget.destroy();
|
||||
this.superclass.destroy.call(this);
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.onUploadButtonClick_ = function (evt) {
|
||||
evt.preventDefault();
|
||||
var zoom = this.getZoom_();
|
||||
var fps = this.piskelController.getFPS();
|
||||
|
||||
this.renderAsImageDataAnimatedGIF(zoom, fps, this.uploadImageData_.bind(this));
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.onDownloadButtonClick_ = function (evt) {
|
||||
var zoom = this.getZoom_();
|
||||
var fps = this.piskelController.getFPS();
|
||||
|
||||
this.renderAsImageDataAnimatedGIF(zoom, fps, this.downloadImageData_.bind(this));
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.downloadImageData_ = function (imageData) {
|
||||
var fileName = this.piskelController.getPiskel().getDescriptor().name + '.gif';
|
||||
pskl.utils.BlobUtils.dataToBlob(imageData, 'image/gif', function(blob) {
|
||||
pskl.utils.FileUtils.downloadAsFile(blob, fileName);
|
||||
});
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.uploadImageData_ = function (imageData) {
|
||||
this.updatePreview_(imageData);
|
||||
this.previewContainerEl.classList.add('preview-upload-ongoing');
|
||||
|
||||
pskl.app.imageUploadService.upload(imageData,
|
||||
this.onImageUploadCompleted_.bind(this),
|
||||
this.onImageUploadFailed_.bind(this));
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.onImageUploadCompleted_ = function (imageUrl) {
|
||||
this.updatePreview_(imageUrl);
|
||||
this.updateStatus_(imageUrl);
|
||||
this.previewContainerEl.classList.remove('preview-upload-ongoing');
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.onImageUploadFailed_ = function (event, xhr) {
|
||||
if (xhr.status === 500) {
|
||||
$.publish(Events.SHOW_NOTIFICATION, [{
|
||||
'content': 'Upload failed : ' + xhr.responseText,
|
||||
'hideDelay' : 5000
|
||||
}]);
|
||||
}
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.updatePreview_ = function (src) {
|
||||
this.previewContainerEl.innerHTML = '<div><img style="max-width:32px;"src="' + src + '"/></div>';
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.getZoom_ = function () {
|
||||
return parseInt(this.widthInput.value, 10) / this.piskelController.getWidth();
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.renderAsImageDataAnimatedGIF = function(zoom, fps, cb) {
|
||||
var currentColors = pskl.app.currentColorsService.getCurrentColors();
|
||||
|
||||
var preserveColors = currentColors.length < MAX_GIF_COLORS;
|
||||
var transparentColor = this.getTransparentColor(currentColors);
|
||||
|
||||
var gif = new window.GIF({
|
||||
workers: 5,
|
||||
quality: 1,
|
||||
width: this.piskelController.getWidth() * zoom,
|
||||
height: this.piskelController.getHeight() * zoom,
|
||||
preserveColors : preserveColors,
|
||||
transparent : parseInt(transparentColor.substring(1), 16)
|
||||
});
|
||||
|
||||
for (var i = 0 ; i < this.piskelController.getFrameCount() ; i++) {
|
||||
var frame = this.piskelController.getFrameAt(i);
|
||||
var canvasRenderer = new pskl.rendering.CanvasRenderer(frame, zoom);
|
||||
canvasRenderer.drawTransparentAs(transparentColor);
|
||||
var canvas = canvasRenderer.render();
|
||||
gif.addFrame(canvas.getContext('2d'), {
|
||||
delay: 1000 / fps
|
||||
});
|
||||
}
|
||||
|
||||
$.publish(Events.SHOW_PROGRESS, [{'name': 'Building animated GIF ...'}]);
|
||||
gif.on('progress', function(percentage) {
|
||||
$.publish(Events.UPDATE_PROGRESS, [{'progress': (percentage * 100).toFixed(1)}]);
|
||||
}.bind(this));
|
||||
|
||||
gif.on('finished', function(blob) {
|
||||
$.publish(Events.HIDE_PROGRESS);
|
||||
pskl.utils.FileUtils.readFile(blob, cb);
|
||||
}.bind(this));
|
||||
|
||||
gif.render();
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.getTransparentColor = function(currentColors) {
|
||||
var transparentColor = pskl.utils.ColorUtils.getUnusedColor(currentColors);
|
||||
|
||||
if (!transparentColor) {
|
||||
console.error('Unable to find unused color to use as transparent color in the current sprite');
|
||||
transparentColor = MAGIC_PINK;
|
||||
}
|
||||
|
||||
return transparentColor;
|
||||
};
|
||||
|
||||
// FIXME : JD : HORRIBLE COPY/PASTA (JD later : where???)
|
||||
ns.GifExportController.prototype.updateStatus_ = function (imageUrl, error) {
|
||||
if (imageUrl) {
|
||||
var linkTpl = '<a class="image-link" href="{{link}}" target="_blank">{{shortLink}}</a>';
|
||||
var linkHtml = pskl.utils.Template.replace(linkTpl, {
|
||||
link : imageUrl,
|
||||
shortLink : this.shorten_(imageUrl, URL_MAX_LENGTH, '...')
|
||||
});
|
||||
this.uploadStatusContainerEl.innerHTML = 'Your image is now available at : ' + linkHtml;
|
||||
} else {
|
||||
// FIXME : Should display error message instead
|
||||
}
|
||||
};
|
||||
|
||||
ns.GifExportController.prototype.shorten_ = function (url, maxLength, suffix) {
|
||||
if (url.length > maxLength) {
|
||||
var index = Math.round((maxLength - suffix.length) / 2);
|
||||
var part1 = url.substring(0, index);
|
||||
var part2 = url.substring(url.length - index, url.length);
|
||||
url = part1 + suffix + part2;
|
||||
}
|
||||
return url;
|
||||
};
|
||||
})();
|
@ -1,5 +1,5 @@
|
||||
(function () {
|
||||
var ns = $.namespace("pskl.controller.settings");
|
||||
var ns = $.namespace('pskl.controller.settings.exportimage');
|
||||
|
||||
ns.ImageExportController = function (piskelController) {
|
||||
this.piskelController = piskelController;
|
||||
@ -11,4 +11,9 @@
|
||||
this.pngExportController.init();
|
||||
this.gifExportController.init();
|
||||
};
|
||||
})();
|
||||
|
||||
ns.ImageExportController.prototype.destroy = function () {
|
||||
this.pngExportController.destroy();
|
||||
this.gifExportController.destroy();
|
||||
};
|
||||
})();
|
@ -1,5 +1,5 @@
|
||||
(function () {
|
||||
var ns = $.namespace("pskl.controller.settings");
|
||||
var ns = $.namespace('pskl.controller.settings.exportimage');
|
||||
|
||||
var URL_MAX_LENGTH = 60;
|
||||
|
||||
@ -7,16 +7,19 @@
|
||||
this.piskelController = piskelController;
|
||||
};
|
||||
|
||||
pskl.utils.inherit(ns.PngExportController, pskl.controller.settings.AbstractSettingController);
|
||||
|
||||
ns.PngExportController.prototype.init = function () {
|
||||
this.previewContainerEl = document.querySelector(".png-export-preview");
|
||||
this.pngFilePrefixInput = document.getElementById('zip-prefix-name');
|
||||
this.pngFilePrefixInput = document.querySelector('.zip-prefix-name');
|
||||
this.pngFilePrefixInput.value = 'sprite_';
|
||||
|
||||
document.querySelector(".png-download-button").addEventListener('click', this.onPngDownloadButtonClick_.bind(this));
|
||||
this.splitByLayersCheckbox = document.querySelector('.zip-split-layers-checkbox');
|
||||
|
||||
document.querySelector(".zip-generate-button").addEventListener('click', this.onZipButtonClick_.bind(this));
|
||||
var downloadButton = document.querySelector('.png-download-button');
|
||||
this.addEventListener(downloadButton, 'click', this.onPngDownloadButtonClick_);
|
||||
|
||||
this.updatePreview_(this.getFramesheetAsCanvas().toDataURL("image/png"));
|
||||
var zipButton = document.querySelector('.zip-generate-button');
|
||||
this.addEventListener(zipButton, 'click', this.onZipButtonClick_);
|
||||
};
|
||||
|
||||
ns.PngExportController.prototype.onPngDownloadButtonClick_ = function (evt) {
|
||||
@ -29,20 +32,45 @@
|
||||
ns.PngExportController.prototype.onZipButtonClick_ = function () {
|
||||
var zip = new window.JSZip();
|
||||
|
||||
for (var i = 0; i < this.piskelController.getFrameCount(); i++) {
|
||||
var frame = this.piskelController.getFrameAt(i);
|
||||
var canvas = this.getFrameAsCanvas_(frame);
|
||||
var basename = this.pngFilePrefixInput.value;
|
||||
var filename = basename + (i+1) + ".png";
|
||||
zip.file(filename, pskl.utils.CanvasUtils.getBase64FromCanvas(canvas) + '\n', {base64: true});
|
||||
if (this.splitByLayersCheckbox.checked) {
|
||||
this.splittedExport_(zip);
|
||||
} else {
|
||||
this.mergedExport_(zip);
|
||||
}
|
||||
|
||||
var fileName = this.getPiskelName_() + '.zip';
|
||||
|
||||
var blob = zip.generate({type:"blob"});
|
||||
var blob = zip.generate({
|
||||
type : 'blob'
|
||||
});
|
||||
|
||||
pskl.utils.FileUtils.downloadAsFile(blob, fileName);
|
||||
};
|
||||
|
||||
ns.PngExportController.prototype.mergedExport_ = function (zip) {
|
||||
for (var i = 0; i < this.piskelController.getFrameCount(); i++) {
|
||||
var frame = this.piskelController.getFrameAt(i);
|
||||
var canvas = this.getFrameAsCanvas_(frame);
|
||||
var basename = this.pngFilePrefixInput.value;
|
||||
var filename = basename + (i + 1) + '.png';
|
||||
zip.file(filename, pskl.utils.CanvasUtils.getBase64FromCanvas(canvas) + '\n', {base64: true});
|
||||
}
|
||||
};
|
||||
|
||||
ns.PngExportController.prototype.splittedExport_ = function (zip) {
|
||||
var layers = this.piskelController.getLayers();
|
||||
for (var j = 0; this.piskelController.hasLayerAt(j); j++) {
|
||||
var layer = this.piskelController.getLayerAt(j);
|
||||
for (var i = 0; i < this.piskelController.getFrameCount(); i++) {
|
||||
var frame = layer.getFrameAt(i);
|
||||
var canvas = this.getFrameAsCanvas_(frame);
|
||||
var basename = this.pngFilePrefixInput.value;
|
||||
var filename = 'l' + j + '_' + basename + (i + 1) + '.png';
|
||||
zip.file(filename, pskl.utils.CanvasUtils.getBase64FromCanvas(canvas) + '\n', {base64: true});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ns.PngExportController.prototype.getFrameAsCanvas_ = function (frame) {
|
||||
var canvasRenderer = new pskl.rendering.CanvasRenderer(frame, 1);
|
||||
canvasRenderer.drawTransparentAs(Constants.TRANSPARENT_COLOR);
|
||||
@ -58,15 +86,9 @@
|
||||
return renderer.renderAsCanvas();
|
||||
};
|
||||
|
||||
ns.PngExportController.prototype.onImageUploadCompleted_ = function (imageUrl) {
|
||||
this.updatePreview_(imageUrl);
|
||||
this.updateStatus_(imageUrl);
|
||||
this.previewContainerEl.classList.remove("preview-upload-ongoing");
|
||||
};
|
||||
|
||||
ns.PngExportController.prototype.updateStatus_ = function (imageUrl, error) {
|
||||
if (imageUrl) {
|
||||
var linkTpl = "<a class='image-link' href='{{link}}' target='_blank'>{{shortLink}}</a>";
|
||||
var linkTpl = '<a class="image-link" href="{{link}}" target="_blank">{{shortLink}}</a>';
|
||||
var linkHtml = pskl.utils.Template.replace(linkTpl, {
|
||||
link : imageUrl,
|
||||
shortLink : this.shorten_(imageUrl, URL_MAX_LENGTH, '...')
|
||||
@ -77,10 +99,6 @@
|
||||
}
|
||||
};
|
||||
|
||||
ns.PngExportController.prototype.updatePreview_ = function (src) {
|
||||
this.previewContainerEl.innerHTML = "<img class='light-picker-background' style='max-width:240px;' src='"+src+"'/>";
|
||||
};
|
||||
|
||||
ns.PngExportController.prototype.shorten_ = function (url, maxLength, suffix) {
|
||||
if (url.length > maxLength) {
|
||||
url = url.substring(0, maxLength);
|
87
src/js/controller/settings/resize/AnchorWidget.js
Normal file
@ -0,0 +1,87 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.controller.settings.resize');
|
||||
|
||||
var OPTION_CLASSNAME = 'resize-origin-option';
|
||||
|
||||
ns.AnchorWidget = function (container) {
|
||||
this.container = container;
|
||||
this.disabled = false;
|
||||
pskl.utils.Event.addEventListener(this.container, 'click', this.onResizeOriginClick_, this);
|
||||
};
|
||||
|
||||
ns.AnchorWidget.ORIGIN = {
|
||||
TOPLEFT : 'TOPLEFT',
|
||||
TOP : 'TOP',
|
||||
TOPRIGHT : 'TOPRIGHT',
|
||||
MIDDLELEFT : 'MIDDLELEFT',
|
||||
MIDDLE : 'MIDDLE',
|
||||
MIDDLERIGHT : 'MIDDLERIGHT',
|
||||
BOTTOMLEFT : 'BOTTOMLEFT',
|
||||
BOTTOM : 'BOTTOM',
|
||||
BOTTOMRIGHT : 'BOTTOMRIGHT'
|
||||
};
|
||||
|
||||
ns.AnchorWidget.prototype.destroy = function (evt) {
|
||||
pskl.utils.Event.removeAllEventListeners(this);
|
||||
this.container = null;
|
||||
};
|
||||
|
||||
ns.AnchorWidget.prototype.onResizeOriginClick_ = function (evt) {
|
||||
var origin = evt.target.dataset.origin;
|
||||
if (origin && ns.AnchorWidget.ORIGIN[origin] && !this.disabled) {
|
||||
this.setOrigin(origin);
|
||||
}
|
||||
};
|
||||
|
||||
ns.AnchorWidget.prototype.setOrigin = function (origin) {
|
||||
this.origin = origin;
|
||||
var previous = document.querySelector('.' + OPTION_CLASSNAME + '.selected');
|
||||
if (previous) {
|
||||
previous.classList.remove('selected');
|
||||
}
|
||||
|
||||
var selected = document.querySelector('.' + OPTION_CLASSNAME + '[data-origin="' + origin + '"]');
|
||||
if (selected) {
|
||||
selected.classList.add('selected');
|
||||
this.refreshNeighbors_(selected);
|
||||
}
|
||||
};
|
||||
|
||||
ns.AnchorWidget.prototype.getOrigin = function () {
|
||||
return this.origin;
|
||||
};
|
||||
|
||||
ns.AnchorWidget.prototype.disable = function () {
|
||||
this.disabled = true;
|
||||
this.container.classList.add('transition');
|
||||
this.container.classList.add('disabled');
|
||||
};
|
||||
|
||||
ns.AnchorWidget.prototype.enable = function () {
|
||||
this.disabled = false;
|
||||
this.container.classList.remove('disabled');
|
||||
window.setTimeout(this.container.classList.remove.bind(this.container.classList, 'transition'), 250);
|
||||
};
|
||||
|
||||
ns.AnchorWidget.prototype.refreshNeighbors_ = function (selected) {
|
||||
var options = document.querySelectorAll('.' + OPTION_CLASSNAME);
|
||||
for (var i = 0 ; i < options.length ; i++) {
|
||||
options[i].removeAttribute('data-neighbor');
|
||||
}
|
||||
|
||||
var selectedIndex = Array.prototype.indexOf.call(options, selected);
|
||||
|
||||
this.setNeighborhood_(options[selectedIndex - 1], 'left');
|
||||
this.setNeighborhood_(options[selectedIndex + 1], 'right');
|
||||
this.setNeighborhood_(options[selectedIndex - 3], 'top');
|
||||
this.setNeighborhood_(options[selectedIndex + 3], 'bottom');
|
||||
};
|
||||
|
||||
ns.AnchorWidget.prototype.setNeighborhood_ = function (el, neighborhood) {
|
||||
var origin = this.origin.toLowerCase();
|
||||
var isNeighborhoodValid = origin.indexOf(neighborhood) === -1;
|
||||
if (isNeighborhoodValid) {
|
||||
el.setAttribute('data-neighbor', neighborhood);
|
||||
}
|
||||
};
|
||||
})();
|
47
src/js/controller/settings/resize/DefaultSizeController.js
Normal file
@ -0,0 +1,47 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.controller.settings.resize');
|
||||
|
||||
ns.DefaultSizeController = function (piskelController) {
|
||||
this.piskelController = piskelController;
|
||||
};
|
||||
|
||||
pskl.utils.inherit(ns.DefaultSizeController, pskl.controller.settings.AbstractSettingController);
|
||||
|
||||
ns.DefaultSizeController.prototype.init = function () {
|
||||
this.container = document.querySelector('.settings-default-size');
|
||||
|
||||
var defaultSize = pskl.UserSettings.get(pskl.UserSettings.DEFAULT_SIZE);
|
||||
|
||||
this.widthInput = this.container.querySelector('[name="default-width"]');
|
||||
this.heightInput = this.container.querySelector('[name="default-height"]');
|
||||
|
||||
this.widthInput.value = defaultSize.width;
|
||||
this.heightInput.value = defaultSize.height;
|
||||
|
||||
this.defaultSizeForm = this.container.querySelector('form');
|
||||
this.addEventListener(this.defaultSizeForm, 'submit', this.onFormSubmit_);
|
||||
};
|
||||
|
||||
ns.DefaultSizeController.prototype.onFormSubmit_ = function (evt) {
|
||||
evt.preventDefault();
|
||||
|
||||
var defaultSize = pskl.UserSettings.get(pskl.UserSettings.DEFAULT_SIZE);
|
||||
|
||||
var width = this.toNumber_(this.widthInput.value, defaultSize.width);
|
||||
var height = this.toNumber_(this.heightInput.value, defaultSize.height);
|
||||
|
||||
pskl.UserSettings.set(pskl.UserSettings.DEFAULT_SIZE, {
|
||||
width : width,
|
||||
height : height
|
||||
});
|
||||
$.publish(Events.CLOSE_SETTINGS_DRAWER);
|
||||
};
|
||||
|
||||
ns.DefaultSizeController.prototype.toNumber_ = function (strValue, defaultValue) {
|
||||
var value = parseInt(strValue, 10);
|
||||
if (value === 0 || isNaN(value)) {
|
||||
value = defaultValue;
|
||||
}
|
||||
return value;
|
||||
};
|
||||
})();
|
129
src/js/controller/settings/resize/ResizeController.js
Normal file
@ -0,0 +1,129 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.controller.settings.resize');
|
||||
|
||||
ns.ResizeController = function (piskelController) {
|
||||
this.piskelController = piskelController;
|
||||
|
||||
this.container = document.querySelector('.resize-canvas');
|
||||
|
||||
var anchorWidgetContainer = this.container.querySelector('.resize-origin-container');
|
||||
this.anchorWidget = new ns.AnchorWidget(anchorWidgetContainer);
|
||||
this.defaultSizeController = new ns.DefaultSizeController(piskelController);
|
||||
};
|
||||
|
||||
pskl.utils.inherit(ns.ResizeController, pskl.controller.settings.AbstractSettingController);
|
||||
|
||||
ns.ResizeController.prototype.init = function () {
|
||||
this.widthInput = this.container.querySelector('[name="resize-width"]');
|
||||
this.heightInput = this.container.querySelector('[name="resize-height"]');
|
||||
this.resizeForm = this.container.querySelector('form');
|
||||
this.resizeContentCheckbox = this.container.querySelector('.resize-content-checkbox');
|
||||
this.maintainRatioCheckbox = this.container.querySelector('.resize-ratio-checkbox');
|
||||
|
||||
var initWidth = this.piskelController.getWidth();
|
||||
var initHeight = this.piskelController.getHeight();
|
||||
this.sizeInputWidget = new pskl.widgets.SizeInput(this.widthInput, this.heightInput, initWidth, initHeight);
|
||||
|
||||
this.anchorWidget.setOrigin(ns.AnchorWidget.ORIGIN.TOPLEFT);
|
||||
|
||||
this.addEventListener(this.resizeForm, 'submit', this.onResizeFormSubmit_);
|
||||
this.addEventListener(this.resizeContentCheckbox, 'change', this.onResizeContentChange_);
|
||||
this.addEventListener(this.maintainRatioCheckbox, 'change', this.onMaintainRatioChange_);
|
||||
|
||||
this.defaultSizeController.init();
|
||||
};
|
||||
|
||||
ns.ResizeController.prototype.destroy = function () {
|
||||
this.anchorWidget.destroy();
|
||||
this.sizeInputWidget.destroy();
|
||||
this.superclass.destroy.call(this);
|
||||
};
|
||||
|
||||
ns.ResizeController.prototype.onResizeFormSubmit_ = function (evt) {
|
||||
evt.preventDefault();
|
||||
|
||||
var resizedLayers = this.piskelController.getLayers().map(this.resizeLayer_.bind(this));
|
||||
|
||||
var piskel = pskl.model.Piskel.fromLayers(resizedLayers, this.piskelController.getPiskel().getDescriptor());
|
||||
|
||||
// propagate savepath to new Piskel
|
||||
piskel.savePath = pskl.app.piskelController.getSavePath();
|
||||
pskl.app.piskelController.setPiskel(piskel, true);
|
||||
|
||||
$.publish(Events.CLOSE_SETTINGS_DRAWER);
|
||||
};
|
||||
|
||||
ns.ResizeController.prototype.resizeLayer_ = function (layer) {
|
||||
var resizedFrames = layer.getFrames().map(this.resizeFrame_.bind(this));
|
||||
return pskl.model.Layer.fromFrames(layer.getName(), resizedFrames);
|
||||
};
|
||||
|
||||
ns.ResizeController.prototype.onResizeContentChange_ = function (evt) {
|
||||
var target = evt.target;
|
||||
if (target.checked) {
|
||||
this.anchorWidget.disable();
|
||||
} else {
|
||||
this.anchorWidget.enable();
|
||||
}
|
||||
};
|
||||
|
||||
ns.ResizeController.prototype.onMaintainRatioChange_ = function (evt) {
|
||||
var target = evt.target;
|
||||
if (target.checked) {
|
||||
this.sizeInputWidget.enableSync();
|
||||
} else {
|
||||
this.sizeInputWidget.disableSync();
|
||||
}
|
||||
};
|
||||
|
||||
/***********************/
|
||||
/* RESIZE LOGIC */
|
||||
/***********************/
|
||||
|
||||
ns.ResizeController.prototype.resizeFrame_ = function (frame) {
|
||||
var width = parseInt(this.widthInput.value, 10);
|
||||
var height = parseInt(this.heightInput.value, 10);
|
||||
if (this.resizeContentCheckbox.checked) {
|
||||
return pskl.utils.FrameUtils.resize(frame, width, height, false);
|
||||
} else {
|
||||
var resizedFrame = new pskl.model.Frame(width, height);
|
||||
frame.forEachPixel(function (color, x, y) {
|
||||
var translated = this.translateCoordinates_(x, y, frame, resizedFrame);
|
||||
if (resizedFrame.containsPixel(translated.x, translated.y)) {
|
||||
resizedFrame.setPixel(translated.x, translated.y, color);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
return resizedFrame;
|
||||
}
|
||||
};
|
||||
|
||||
ns.ResizeController.prototype.translateCoordinates_ = function (x, y, frame, resizedFrame) {
|
||||
return {
|
||||
x : this.translateX_(x, frame.width, resizedFrame.width),
|
||||
y : this.translateY_(y, frame.height, resizedFrame.height)
|
||||
};
|
||||
};
|
||||
|
||||
ns.ResizeController.prototype.translateX_ = function (x, width, resizedWidth) {
|
||||
var origin = this.anchorWidget.getOrigin();
|
||||
if (origin.indexOf('LEFT') != -1) {
|
||||
return x;
|
||||
} else if (origin.indexOf('RIGHT') != -1) {
|
||||
return x - (width - resizedWidth);
|
||||
} else {
|
||||
return x - Math.round((width - resizedWidth) / 2);
|
||||
}
|
||||
};
|
||||
|
||||
ns.ResizeController.prototype.translateY_ = function (y, height, resizedHeight) {
|
||||
var origin = this.anchorWidget.getOrigin();
|
||||
if (origin.indexOf('TOP') != -1) {
|
||||
return y;
|
||||
} else if (origin.indexOf('BOTTOM') != -1) {
|
||||
return y - (height - resizedHeight);
|
||||
} else {
|
||||
return y - Math.round((height - resizedHeight) / 2);
|
||||
}
|
||||
};
|
||||
})();
|
@ -1,194 +0,0 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.controller.widgets');
|
||||
|
||||
ns.HslRgbColorPicker = function (container, colorUpdatedCallback) {
|
||||
this.container = container;
|
||||
this.colorUpdatedCallback = colorUpdatedCallback;
|
||||
this.lastInputTimestamp_ = 0;
|
||||
};
|
||||
|
||||
ns.HslRgbColorPicker.prototype.init = function () {
|
||||
var isChromeOrFirefox = pskl.utils.UserAgent.isChrome || pskl.utils.UserAgent.isFirefox;
|
||||
var changeEvent = isChromeOrFirefox ? 'input' : 'change';
|
||||
this.container.addEventListener(changeEvent, this.onPickerChange_.bind(this));
|
||||
this.container.addEventListener('keydown', this.onKeydown_.bind(this));
|
||||
|
||||
this.spectrumEl = this.container.querySelector('.color-picker-spectrum');
|
||||
|
||||
$(this.spectrumEl).spectrum({
|
||||
flat: true,
|
||||
showInput: true,
|
||||
showButtons: false,
|
||||
move : this.setColor.bind(this),
|
||||
change : this.setColor.bind(this),
|
||||
preferredFormat: 'hex'
|
||||
});
|
||||
|
||||
this.setColor("#000000");
|
||||
};
|
||||
|
||||
ns.HslRgbColorPicker.prototype.destroy = function () {
|
||||
this.container = null;
|
||||
this.spectrumEl = null;
|
||||
};
|
||||
|
||||
ns.HslRgbColorPicker.prototype.onPickerChange_ = function (evt) {
|
||||
var target = evt.target;
|
||||
|
||||
var model = target.dataset.model;
|
||||
var dimension = target.dataset.dimension;
|
||||
|
||||
var value = parseInt(target.value, 10);
|
||||
if (dimension === 'v' || dimension === 's') {
|
||||
value = value/100;
|
||||
}
|
||||
|
||||
var color;
|
||||
if (model === 'rgb') {
|
||||
color = this.tinyColor.toRgb();
|
||||
} else if (model === 'hsv') {
|
||||
color = this.hsvColor;
|
||||
}
|
||||
|
||||
if (isNaN(value)) {
|
||||
value = color[dimension];
|
||||
} else {
|
||||
color[dimension] = value;
|
||||
}
|
||||
|
||||
this.setColor(color);
|
||||
};
|
||||
|
||||
ns.HslRgbColorPicker.prototype.onKeydown_ = function (evt) {
|
||||
var target = evt.target;
|
||||
|
||||
if (target.getAttribute('type').toLowerCase() === 'text') {
|
||||
var value = parseInt(target.value, 10);
|
||||
var dimension = target.dataset.dimension;
|
||||
|
||||
var key = pskl.service.keyboard.KeycodeTranslator.toChar(evt.keyCode);
|
||||
if (key === 'up') {
|
||||
value = value + 1;
|
||||
} else if (key === 'down') {
|
||||
value = value - 1;
|
||||
}
|
||||
|
||||
value = this.normalizeDimension_(value, dimension);
|
||||
|
||||
target.value = value;
|
||||
this.onPickerChange_(evt);
|
||||
}
|
||||
};
|
||||
|
||||
ns.HslRgbColorPicker.prototype.setColor = function (inputColor) {
|
||||
if (!this.unplugged) {
|
||||
this.unplugged = true;
|
||||
|
||||
this.hsvColor = this.toHsvColor_(inputColor);
|
||||
this.tinyColor = this.toTinyColor_(inputColor);
|
||||
|
||||
this.updateInputs();
|
||||
$(".color-picker-spectrum").spectrum("set", this.tinyColor);
|
||||
|
||||
this.colorUpdatedCallback(this.tinyColor);
|
||||
|
||||
this.unplugged = false;
|
||||
}
|
||||
};
|
||||
|
||||
ns.HslRgbColorPicker.prototype.updateInputs = function () {
|
||||
var inputs = this.container.querySelectorAll('input');
|
||||
var rgb = this.tinyColor.toRgb();
|
||||
|
||||
|
||||
for (var i = 0 ; i < inputs.length ; i++) {
|
||||
var input = inputs[i];
|
||||
var dimension = input.dataset.dimension;
|
||||
var model = input.dataset.model;
|
||||
|
||||
if (model === 'rgb') {
|
||||
input.value = rgb[dimension];
|
||||
} else if (model === 'hsv') {
|
||||
var value = this.hsvColor[dimension];
|
||||
if (dimension === 'v' || dimension === 's') {
|
||||
value = 100 * value;
|
||||
}
|
||||
input.value = Math.round(value);
|
||||
}
|
||||
|
||||
if (input.getAttribute('type') === 'range') {
|
||||
this.updateSliderBackground(input);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ns.HslRgbColorPicker.prototype.updateSliderBackground = function (slider) {
|
||||
var dimension = slider.dataset.dimension;
|
||||
var model = slider.dataset.model;
|
||||
|
||||
var start, end;
|
||||
var isHueSlider = dimension === 'h';
|
||||
if (!isHueSlider) {
|
||||
var colors = this.getSliderBackgroundColors_(model, dimension);
|
||||
slider.style.backgroundImage = "linear-gradient(to right, " + colors.start + " 0, " + colors.end + " 100%)";
|
||||
}
|
||||
};
|
||||
|
||||
ns.HslRgbColorPicker.prototype.getSliderBackgroundColors_ = function (model, dimension) {
|
||||
var start, end;
|
||||
if (model === 'hsv') {
|
||||
start = JSON.parse(JSON.stringify(this.hsvColor));
|
||||
start[dimension] = 0;
|
||||
|
||||
end = JSON.parse(JSON.stringify(this.hsvColor));
|
||||
end[dimension] = 1;
|
||||
} else {
|
||||
start = this.tinyColor.toRgb();
|
||||
start[dimension] = 0;
|
||||
|
||||
end = this.tinyColor.toRgb();
|
||||
end[dimension] = 255;
|
||||
}
|
||||
|
||||
return {
|
||||
start : window.tinycolor(start).toRgbString(),
|
||||
end : window.tinycolor(end).toRgbString()
|
||||
};
|
||||
};
|
||||
|
||||
ns.HslRgbColorPicker.prototype.toTinyColor_ = function (color) {
|
||||
if (typeof color == "object" && color.hasOwnProperty("_tc_id")) {
|
||||
return color;
|
||||
} else {
|
||||
return window.tinycolor(JSON.parse(JSON.stringify(color)));
|
||||
}
|
||||
};
|
||||
|
||||
ns.HslRgbColorPicker.prototype.toHsvColor_ = function (color) {
|
||||
var isHsvColor = ['h','s','v'].every(color.hasOwnProperty.bind(color));
|
||||
if (isHsvColor) {
|
||||
return {
|
||||
h : Math.max(0, Math.min(359, color.h)),
|
||||
s : Math.max(0, Math.min(1, color.s)),
|
||||
v : Math.max(0, Math.min(1, color.v))
|
||||
};
|
||||
} else {
|
||||
return this.toTinyColor_(color).toHsv();
|
||||
}
|
||||
};
|
||||
|
||||
ns.HslRgbColorPicker.prototype.normalizeDimension_ = function (value, dimension) {
|
||||
var ranges = {
|
||||
'h' : [0, 359],
|
||||
's' : [0, 100],
|
||||
'v' : [0, 100],
|
||||
'r' : [0, 255],
|
||||
'g' : [0, 255],
|
||||
'b' : [0, 255]
|
||||
};
|
||||
var range = ranges[dimension];
|
||||
return Math.max(range[0], Math.min(range[1], value));
|
||||
} ;
|
||||
|
||||
|
||||
})();
|
@ -33,7 +33,7 @@
|
||||
ns.DrawingTestPlayer.prototype.createPiskel_ = function (width, height) {
|
||||
var descriptor = new pskl.model.piskel.Descriptor('TestPiskel', '');
|
||||
var piskel = new pskl.model.Piskel(width, height, descriptor);
|
||||
var layer = new pskl.model.Layer("Layer 1");
|
||||
var layer = new pskl.model.Layer('Layer 1');
|
||||
var frame = new pskl.model.Frame(width, height);
|
||||
|
||||
layer.addFrame(frame);
|
||||
@ -88,8 +88,8 @@
|
||||
this.playInstrumentedEvent_(recordEvent);
|
||||
}
|
||||
|
||||
if (this.events[index+1]) {
|
||||
this.playEvent_(index+1);
|
||||
if (this.events[index + 1]) {
|
||||
this.playEvent_(index + 1);
|
||||
} else {
|
||||
this.onTestEnd_();
|
||||
}
|
||||
@ -102,7 +102,7 @@
|
||||
event.clientX = screenCoordinates.x;
|
||||
event.clientY = screenCoordinates.y;
|
||||
if (pskl.utils.UserAgent.isMac && event.ctrlKey) {
|
||||
event.metaKey = true;
|
||||
event.metaKey = true;
|
||||
}
|
||||
|
||||
if (event.type == 'mousedown') {
|
||||
@ -148,4 +148,4 @@
|
||||
this.callbacks.push(callback);
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
@ -105,11 +105,11 @@
|
||||
ns.DrawingTestRecorder.prototype.recordMouseEvent_ = function (mouseEvent) {
|
||||
var coords = pskl.app.drawingController.getSpriteCoordinates(mouseEvent.clientX, mouseEvent.clientY);
|
||||
var recordEvent = new ns.MouseEvent(mouseEvent, coords);
|
||||
var lastEvent = this.events[this.events.length-1];
|
||||
var lastEvent = this.events[this.events.length - 1];
|
||||
|
||||
if (!recordEvent.equals(lastEvent)) {
|
||||
this.events.push(recordEvent);
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
@ -18,8 +18,7 @@
|
||||
var testResult = document.createElement('div');
|
||||
testResult.id = 'drawing-test-result';
|
||||
testResult.setAttribute('data-test-name', this.testName);
|
||||
testResult.innerHTML = success ? 'OK' : ('KO:'+png);
|
||||
testResult.innerHTML = success ? 'OK' : ('KO:' + png);
|
||||
document.body.appendChild(testResult);
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
@ -60,7 +60,7 @@
|
||||
ns.DrawingTestSuiteController.prototype.onTestSuiteEnd_ = function (evt, status) {
|
||||
console.log('on test suite end');
|
||||
var elapsed = Date.now() - this.startTime_;
|
||||
elapsed = (elapsed/1000).toFixed(4);
|
||||
elapsed = (elapsed / 1000).toFixed(4);
|
||||
|
||||
var testSuiteStatus = document.createElement('li');
|
||||
testSuiteStatus.innerHTML = pskl.utils.Template.replace(
|
||||
@ -74,4 +74,4 @@
|
||||
// keep only the part after the last '/'
|
||||
return path.replace(/^.*\/([^\/]+.json$)/, '$1');
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -60,4 +60,4 @@
|
||||
this.status = success ? ns.DrawingTestSuiteRunner.STATUS.SUCCESS : ns.DrawingTestSuiteRunner.STATUS.ERROR;
|
||||
$.publish(Events.TEST_SUITE_END, [this.status]);
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -22,5 +22,4 @@
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
@ -27,7 +27,7 @@
|
||||
var stopInput = document.createElement('button');
|
||||
stopInput.innerHTML = 'Stop record';
|
||||
stopInput.addEventListener('click', this.onStopInputClick_.bind(this));
|
||||
stopInput.setAttribute('disabled','disabled');
|
||||
stopInput.setAttribute('disabled', 'disabled');
|
||||
|
||||
this.container = container;
|
||||
this.fileInput = this.container.appendChild(fileInput);
|
||||
@ -43,9 +43,9 @@
|
||||
ns.TestRecordController.prototype.onFileInputChange_ = function () {
|
||||
var files = this.fileInput.files;
|
||||
if (files.length == 1) {
|
||||
var file =files[0];
|
||||
var file = files[0];
|
||||
pskl.utils.FileUtils.readFile(file, function (content) {
|
||||
var testRecord = JSON.parse(window.atob(content.replace(/data\:.*?\;base64\,/,'')));
|
||||
var testRecord = JSON.parse(window.atob(content.replace(/data\:.*?\;base64\,/, '')));
|
||||
var testPlayer = new ns.DrawingTestPlayer(testRecord);
|
||||
testPlayer.start();
|
||||
}.bind(this));
|
||||
@ -54,7 +54,7 @@
|
||||
|
||||
ns.TestRecordController.prototype.onStartInputClick_ = function () {
|
||||
this.testRecorder.startRecord();
|
||||
this.startInput.setAttribute('disabled','disabled');
|
||||
this.startInput.setAttribute('disabled', 'disabled');
|
||||
this.stopInput.removeAttribute('disabled');
|
||||
};
|
||||
|
||||
@ -63,14 +63,14 @@
|
||||
|
||||
pskl.utils.BlobUtils.stringToBlob(testRecord, function(blob) {
|
||||
pskl.utils.FileUtils.downloadAsFile(blob, 'record_piskel.json');
|
||||
}.bind(this), "application/json");
|
||||
}.bind(this), 'application/json');
|
||||
|
||||
this.startInput.removeAttribute('disabled');
|
||||
this.stopInput.setAttribute('disabled','disabled');
|
||||
this.stopInput.setAttribute('disabled', 'disabled');
|
||||
};
|
||||
|
||||
ns.TestRecordController.prototype.onTestRecordEnd_ = function (evt, success) {
|
||||
window.alert('Test finished : ', success);
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
@ -31,4 +31,4 @@
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
195
src/js/devtools/lib/Blob.js
Normal file
@ -0,0 +1,195 @@
|
||||
(function (view) {
|
||||
"use strict";
|
||||
|
||||
view.URL = view.URL || view.webkitURL;
|
||||
|
||||
if (view.Blob && view.URL) {
|
||||
try {
|
||||
new Blob;
|
||||
return;
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// Internally we use a BlobBuilder implementation to base Blob off of
|
||||
// in order to support older browsers that only have BlobBuilder
|
||||
var BlobBuilder = view.BlobBuilder || view.WebKitBlobBuilder || view.MozBlobBuilder || (function(view) {
|
||||
var
|
||||
get_class = function(object) {
|
||||
return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
|
||||
}
|
||||
, FakeBlobBuilder = function BlobBuilder() {
|
||||
this.data = [];
|
||||
}
|
||||
, FakeBlob = function Blob(data, type, encoding) {
|
||||
this.data = data;
|
||||
this.size = data.length;
|
||||
this.type = type;
|
||||
this.encoding = encoding;
|
||||
}
|
||||
, FBB_proto = FakeBlobBuilder.prototype
|
||||
, FB_proto = FakeBlob.prototype
|
||||
, FileReaderSync = view.FileReaderSync
|
||||
, FileException = function(type) {
|
||||
this.code = this[this.name = type];
|
||||
}
|
||||
, file_ex_codes = (
|
||||
"NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR "
|
||||
+ "NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR"
|
||||
).split(" ")
|
||||
, file_ex_code = file_ex_codes.length
|
||||
, real_URL = view.URL || view.webkitURL || view
|
||||
, real_create_object_URL = real_URL.createObjectURL
|
||||
, real_revoke_object_URL = real_URL.revokeObjectURL
|
||||
, URL = real_URL
|
||||
, btoa = view.btoa
|
||||
, atob = view.atob
|
||||
|
||||
, ArrayBuffer = view.ArrayBuffer
|
||||
, Uint8Array = view.Uint8Array
|
||||
|
||||
, origin = /^[\w-]+:\/*\[?[\w\.:-]+\]?(?::[0-9]+)?/
|
||||
;
|
||||
FakeBlob.fake = FB_proto.fake = true;
|
||||
while (file_ex_code--) {
|
||||
FileException.prototype[file_ex_codes[file_ex_code]] = file_ex_code + 1;
|
||||
}
|
||||
// Polyfill URL
|
||||
if (!real_URL.createObjectURL) {
|
||||
URL = view.URL = function(uri) {
|
||||
var
|
||||
uri_info = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
|
||||
, uri_origin
|
||||
;
|
||||
uri_info.href = uri;
|
||||
if (!("origin" in uri_info)) {
|
||||
if (uri_info.protocol.toLowerCase() === "data:") {
|
||||
uri_info.origin = null;
|
||||
} else {
|
||||
uri_origin = uri.match(origin);
|
||||
uri_info.origin = uri_origin && uri_origin[1];
|
||||
}
|
||||
}
|
||||
return uri_info;
|
||||
};
|
||||
}
|
||||
URL.createObjectURL = function(blob) {
|
||||
var
|
||||
type = blob.type
|
||||
, data_URI_header
|
||||
;
|
||||
if (type === null) {
|
||||
type = "application/octet-stream";
|
||||
}
|
||||
if (blob instanceof FakeBlob) {
|
||||
data_URI_header = "data:" + type;
|
||||
if (blob.encoding === "base64") {
|
||||
return data_URI_header + ";base64," + blob.data;
|
||||
} else if (blob.encoding === "URI") {
|
||||
return data_URI_header + "," + decodeURIComponent(blob.data);
|
||||
} if (btoa) {
|
||||
return data_URI_header + ";base64," + btoa(blob.data);
|
||||
} else {
|
||||
return data_URI_header + "," + encodeURIComponent(blob.data);
|
||||
}
|
||||
} else if (real_create_object_URL) {
|
||||
return real_create_object_URL.call(real_URL, blob);
|
||||
}
|
||||
};
|
||||
URL.revokeObjectURL = function(object_URL) {
|
||||
if (object_URL.substring(0, 5) !== "data:" && real_revoke_object_URL) {
|
||||
real_revoke_object_URL.call(real_URL, object_URL);
|
||||
}
|
||||
};
|
||||
FBB_proto.append = function(data/*, endings*/) {
|
||||
var bb = this.data;
|
||||
// decode data to a binary string
|
||||
if (Uint8Array && (data instanceof ArrayBuffer || data instanceof Uint8Array)) {
|
||||
var
|
||||
str = ""
|
||||
, buf = new Uint8Array(data)
|
||||
, i = 0
|
||||
, buf_len = buf.length
|
||||
;
|
||||
for (; i < buf_len; i++) {
|
||||
str += String.fromCharCode(buf[i]);
|
||||
}
|
||||
bb.push(str);
|
||||
} else if (get_class(data) === "Blob" || get_class(data) === "File") {
|
||||
if (FileReaderSync) {
|
||||
var fr = new FileReaderSync;
|
||||
bb.push(fr.readAsBinaryString(data));
|
||||
} else {
|
||||
// async FileReader won't work as BlobBuilder is sync
|
||||
throw new FileException("NOT_READABLE_ERR");
|
||||
}
|
||||
} else if (data instanceof FakeBlob) {
|
||||
if (data.encoding === "base64" && atob) {
|
||||
bb.push(atob(data.data));
|
||||
} else if (data.encoding === "URI") {
|
||||
bb.push(decodeURIComponent(data.data));
|
||||
} else if (data.encoding === "raw") {
|
||||
bb.push(data.data);
|
||||
}
|
||||
} else {
|
||||
if (typeof data !== "string") {
|
||||
data += ""; // convert unsupported types to strings
|
||||
}
|
||||
// decode UTF-16 to binary string
|
||||
bb.push(unescape(encodeURIComponent(data)));
|
||||
}
|
||||
};
|
||||
FBB_proto.getBlob = function(type) {
|
||||
if (!arguments.length) {
|
||||
type = null;
|
||||
}
|
||||
return new FakeBlob(this.data.join(""), type, "raw");
|
||||
};
|
||||
FBB_proto.toString = function() {
|
||||
return "[object BlobBuilder]";
|
||||
};
|
||||
FB_proto.slice = function(start, end, type) {
|
||||
var args = arguments.length;
|
||||
if (args < 3) {
|
||||
type = null;
|
||||
}
|
||||
return new FakeBlob(
|
||||
this.data.slice(start, args > 1 ? end : this.data.length)
|
||||
, type
|
||||
, this.encoding
|
||||
);
|
||||
};
|
||||
FB_proto.toString = function() {
|
||||
return "[object Blob]";
|
||||
};
|
||||
FB_proto.close = function() {
|
||||
this.size = 0;
|
||||
delete this.data;
|
||||
};
|
||||
return FakeBlobBuilder;
|
||||
}(view));
|
||||
|
||||
view.Blob = function(blobParts, options) {
|
||||
var type = options ? (options.type || "") : "";
|
||||
var builder = new BlobBuilder();
|
||||
if (blobParts) {
|
||||
for (var i = 0, len = blobParts.length; i < len; i++) {
|
||||
if (Uint8Array && blobParts[i] instanceof Uint8Array) {
|
||||
builder.append(blobParts[i].buffer);
|
||||
}
|
||||
else {
|
||||
builder.append(blobParts[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
var blob = builder.getBlob(type);
|
||||
if (!blob.slice && blob.webkitSlice) {
|
||||
blob.slice = blob.webkitSlice;
|
||||
}
|
||||
return blob;
|
||||
};
|
||||
|
||||
var getPrototypeOf = Object.getPrototypeOf || function(object) {
|
||||
return object.__proto__;
|
||||
};
|
||||
view.Blob.prototype = getPrototypeOf(new view.Blob());
|
||||
}(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this.content || this));
|
1986
src/js/lib/q.js
Normal file
@ -1,5 +1,5 @@
|
||||
(function () {
|
||||
var ns = $.namespace("pskl.model");
|
||||
var ns = $.namespace('pskl.model');
|
||||
var __idCounter = 0;
|
||||
ns.Frame = function (width, height) {
|
||||
if (width && height) {
|
||||
@ -16,7 +16,8 @@
|
||||
|
||||
ns.Frame.fromPixelGrid = function (pixels) {
|
||||
if (pixels.length && pixels[0].length) {
|
||||
var w = pixels.length, h = pixels[0].length;
|
||||
var w = pixels.length;
|
||||
var h = pixels[0].length;
|
||||
var frame = new pskl.model.Frame(w, h);
|
||||
frame.setPixels(pixels);
|
||||
return frame;
|
||||
@ -26,10 +27,10 @@
|
||||
};
|
||||
|
||||
ns.Frame.createEmptyPixelGrid_ = function (width, height) {
|
||||
var pixels = []; //new Array(width);
|
||||
for (var columnIndex=0; columnIndex < width; columnIndex++) {
|
||||
var pixels = [];
|
||||
for (var columnIndex = 0 ; columnIndex < width ; columnIndex++) {
|
||||
var columnArray = [];
|
||||
for(var heightIndex = 0; heightIndex < height; heightIndex++) {
|
||||
for (var heightIndex = 0 ; heightIndex < height ; heightIndex++) {
|
||||
columnArray.push(Constants.TRANSPARENT_COLOR);
|
||||
}
|
||||
pixels[columnIndex] = columnArray;
|
||||
@ -126,4 +127,4 @@
|
||||
ns.Frame.prototype.isSameSize = function (otherFrame) {
|
||||
return this.getHeight() == otherFrame.getHeight() && this.getWidth() == otherFrame.getWidth();
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -56,7 +56,7 @@
|
||||
if (this.frames[index]) {
|
||||
this.frames.splice(index, 1);
|
||||
} else {
|
||||
throw 'Invalid index in removeFrameAt : ' + index + ' (size : ' + this.size() + ')';
|
||||
console.error('Invalid index in removeFrameAt : %s (size : %s)', index, this.size());
|
||||
}
|
||||
};
|
||||
|
||||
@ -72,9 +72,7 @@
|
||||
this.frames[toIndex] = fromFrame;
|
||||
this.frames[fromIndex] = toFrame;
|
||||
} else {
|
||||
console.log('frames', this.frames);
|
||||
console.log('fromIndex', fromIndex, 'toIndex', toIndex);
|
||||
throw 'Frame not found in moveFrameAt';
|
||||
console.error('Frame not found in moveFrameAt (from %s, to %s)', fromIndex, toIndex);
|
||||
}
|
||||
};
|
||||
|
||||
@ -89,7 +87,7 @@
|
||||
var clone = frame.clone();
|
||||
this.addFrameAt(clone, index);
|
||||
} else {
|
||||
throw 'Frame not found in duplicateFrameAt';
|
||||
console.error('Frame not found in duplicateFrameAt (at %s)', index);
|
||||
}
|
||||
};
|
||||
|
||||
@ -102,4 +100,4 @@
|
||||
return frame.getHash();
|
||||
}).join('-');
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -43,4 +43,4 @@
|
||||
ns.Palette.prototype.move = function (oldIndex, newIndex) {
|
||||
this.colors.splice(newIndex, 0, this.colors.splice(oldIndex, 1)[0]);
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -20,8 +20,12 @@
|
||||
this.height = height;
|
||||
|
||||
this.descriptor = descriptor;
|
||||
|
||||
/** @type {String} */
|
||||
this.savePath = null;
|
||||
|
||||
} else {
|
||||
throw 'Missing arguments in Piskel constructor : ' + Array.prototype.join.call(arguments, ",");
|
||||
throw 'Missing arguments in Piskel constructor : ' + Array.prototype.join.call(arguments, ',');
|
||||
}
|
||||
};
|
||||
|
||||
@ -79,17 +83,17 @@
|
||||
|
||||
ns.Piskel.prototype.moveLayerUp = function (layer) {
|
||||
var index = this.layers.indexOf(layer);
|
||||
if (index > -1 && index < this.layers.length-1) {
|
||||
this.layers[index] = this.layers[index+1];
|
||||
this.layers[index+1] = layer;
|
||||
if (index > -1 && index < this.layers.length - 1) {
|
||||
this.layers[index] = this.layers[index + 1];
|
||||
this.layers[index + 1] = layer;
|
||||
}
|
||||
};
|
||||
|
||||
ns.Piskel.prototype.moveLayerDown = function (layer) {
|
||||
var index = this.layers.indexOf(layer);
|
||||
if (index > 0) {
|
||||
this.layers[index] = this.layers[index-1];
|
||||
this.layers[index-1] = layer;
|
||||
this.layers[index] = this.layers[index - 1];
|
||||
this.layers[index - 1] = layer;
|
||||
}
|
||||
};
|
||||
|
||||
@ -119,4 +123,4 @@
|
||||
}).join('-');
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
57
src/js/model/frame/AsyncCachedFrameProcessor.js
Normal file
@ -0,0 +1,57 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.model.frame');
|
||||
|
||||
ns.AsyncCachedFrameProcessor = function (cacheResetInterval) {
|
||||
ns.CachedFrameProcessor.call(this, cacheResetInterval);
|
||||
};
|
||||
|
||||
pskl.utils.inherit(ns.AsyncCachedFrameProcessor, ns.CachedFrameProcessor);
|
||||
|
||||
/**
|
||||
* Retrieve the processed frame from the cache, in the (optional) namespace
|
||||
* If the first level cache is empty, attempt to clone it from 2nd level cache.
|
||||
* If second level cache is empty process the frame.
|
||||
* @param {pskl.model.Frame} frame
|
||||
* @param {String} namespace
|
||||
* @return {Object} the processed frame
|
||||
*/
|
||||
ns.AsyncCachedFrameProcessor.prototype.get = function (frame, namespace) {
|
||||
var processedFrame = null;
|
||||
namespace = namespace || this.defaultNamespace;
|
||||
|
||||
if (!this.cache_[namespace]) {
|
||||
this.cache_[namespace] = {};
|
||||
}
|
||||
|
||||
var deferred = Q.defer();
|
||||
|
||||
var cache = this.cache_[namespace];
|
||||
|
||||
var key1 = frame.getHash();
|
||||
if (cache[key1]) {
|
||||
processedFrame = cache[key1];
|
||||
} else {
|
||||
var framePixels = JSON.stringify(frame.getPixels());
|
||||
var key2 = pskl.utils.hashCode(framePixels);
|
||||
if (cache[key2]) {
|
||||
processedFrame = this.outputCloner(cache[key2], frame);
|
||||
cache[key1] = processedFrame;
|
||||
} else {
|
||||
var callback = this.onProcessorComplete_.bind(this, deferred, cache, key1, key2);
|
||||
this.frameProcessor(frame, callback);
|
||||
}
|
||||
}
|
||||
|
||||
if (processedFrame) {
|
||||
deferred.resolve(processedFrame);
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
ns.AsyncCachedFrameProcessor.prototype.onProcessorComplete_ = function (deferred, cache, key1, key2, result) {
|
||||
cache[key1] = result;
|
||||
cache[key2] = result;
|
||||
deferred.resolve(result);
|
||||
};
|
||||
})();
|
@ -1,8 +1,8 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.model.frame');
|
||||
|
||||
|
||||
var DEFAULT_CLEAR_INTERVAL = 10 * 60 *1000;
|
||||
// 10 * 60 * 1000 = 10 minutes
|
||||
var DEFAULT_CLEAR_INTERVAL = 10 * 60 * 1000;
|
||||
|
||||
var DEFAULT_FRAME_PROCESSOR = function (frame) {
|
||||
return pskl.utils.FrameUtils.toImage(frame);
|
||||
@ -17,6 +17,7 @@
|
||||
this.cacheResetInterval = cacheResetInterval || DEFAULT_CLEAR_INTERVAL;
|
||||
this.frameProcessor = DEFAULT_FRAME_PROCESSOR;
|
||||
this.outputCloner = DEFAULT_OUTPUT_CLONER;
|
||||
this.defaultNamespace = DEFAULT_NAMESPACE;
|
||||
|
||||
window.setInterval(this.clear.bind(this), this.cacheResetInterval);
|
||||
};
|
||||
@ -46,7 +47,8 @@
|
||||
|
||||
/**
|
||||
* Retrieve the processed frame from the cache, in the (optional) namespace
|
||||
* If the first level cache is empty, attempt to clone it from 2nd level cache. If second level cache is empty process the frame.
|
||||
* If the first level cache is empty, attempt to clone it from 2nd level cache.
|
||||
* If second level cache is empty process the frame.
|
||||
* @param {pskl.model.Frame} frame
|
||||
* @param {String} namespace
|
||||
* @return {Object} the processed frame
|
||||
@ -65,7 +67,8 @@
|
||||
if (cache[cacheKey]) {
|
||||
processedFrame = cache[cacheKey];
|
||||
} else {
|
||||
var frameAsString = JSON.stringify(frame.getPixels());
|
||||
var framePixels = JSON.stringify(frame.getPixels());
|
||||
var frameAsString = pskl.utils.hashCode(framePixels);
|
||||
if (cache[frameAsString]) {
|
||||
processedFrame = this.outputCloner(cache[frameAsString], frame);
|
||||
} else {
|
||||
@ -76,4 +79,4 @@
|
||||
}
|
||||
return processedFrame;
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -6,4 +6,4 @@
|
||||
this.description = description;
|
||||
this.isPublic = isPublic;
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -19,4 +19,4 @@
|
||||
|
||||
ns.AbstractRenderer.prototype.setDisplaySize = Constants.ABSTRACT_FUNCTION;
|
||||
ns.AbstractRenderer.prototype.getDisplaySize = Constants.ABSTRACT_FUNCTION;
|
||||
})();
|
||||
})();
|
||||
|
@ -1,6 +1,6 @@
|
||||
(function () {
|
||||
|
||||
var ns = $.namespace("pskl.rendering");
|
||||
var ns = $.namespace('pskl.rendering');
|
||||
ns.CanvasRenderer = function (frame, zoom) {
|
||||
this.frame = frame;
|
||||
this.zoom = zoom;
|
||||
@ -19,9 +19,18 @@
|
||||
ns.CanvasRenderer.prototype.render = function () {
|
||||
var canvas = this.createCanvas_();
|
||||
var context = canvas.getContext('2d');
|
||||
this.frame.forEachPixel(function (color, x, y) {
|
||||
this.renderPixel_(color, x, y, context);
|
||||
}.bind(this));
|
||||
|
||||
for (var x = 0, width = this.frame.getWidth(); x < width; x++) {
|
||||
for (var y = 0, height = this.frame.getHeight(); y < height; y++) {
|
||||
var color = this.frame.getPixel(x, y);
|
||||
var w = 1;
|
||||
while (color === this.frame.getPixel(x, y + w)) {
|
||||
w++;
|
||||
}
|
||||
this.renderLine_(color, x, y, w, context);
|
||||
y = y + w - 1;
|
||||
}
|
||||
}
|
||||
|
||||
var scaledCanvas = this.createCanvas_(this.zoom);
|
||||
var scaledContext = scaledCanvas.getContext('2d');
|
||||
@ -33,17 +42,25 @@
|
||||
};
|
||||
|
||||
ns.CanvasRenderer.prototype.renderPixel_ = function (color, x, y, context) {
|
||||
if(color == Constants.TRANSPARENT_COLOR) {
|
||||
if (color == Constants.TRANSPARENT_COLOR) {
|
||||
color = this.transparentColor_;
|
||||
}
|
||||
context.fillStyle = color;
|
||||
context.fillRect(x, y, 1, 1);
|
||||
};
|
||||
|
||||
ns.CanvasRenderer.prototype.renderLine_ = function (color, x, y, width, context) {
|
||||
if (color == Constants.TRANSPARENT_COLOR) {
|
||||
color = this.transparentColor_;
|
||||
}
|
||||
context.fillStyle = color;
|
||||
context.fillRect(x, y, 1, width);
|
||||
};
|
||||
|
||||
ns.CanvasRenderer.prototype.createCanvas_ = function (zoom) {
|
||||
zoom = zoom || 1;
|
||||
var width = this.frame.getWidth() * zoom;
|
||||
var height = this.frame.getHeight() * zoom;
|
||||
return pskl.utils.CanvasUtils.createCanvas(width, height);
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -48,7 +48,6 @@
|
||||
return this.getSampleRenderer_().getOffset();
|
||||
};
|
||||
|
||||
|
||||
ns.CompositeRenderer.prototype.setGridWidth = function (b) {
|
||||
this.renderers.forEach(function (renderer) {
|
||||
renderer.setGridWidth(b);
|
||||
@ -66,4 +65,4 @@
|
||||
throw 'Renderer manager is empty';
|
||||
}
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -1,5 +1,5 @@
|
||||
(function () {
|
||||
var ns = $.namespace("pskl.rendering");
|
||||
var ns = $.namespace('pskl.rendering');
|
||||
|
||||
ns.DrawingLoop = function () {
|
||||
this.requestAnimationFrame = this.getRequestAnimationFrameShim_();
|
||||
@ -54,8 +54,8 @@
|
||||
window.mozRequestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.msRequestAnimationFrame ||
|
||||
function (callback) { window.setTimeout(callback, 1000/60); };
|
||||
function (callback) { window.setTimeout(callback, 1000 / 60); };
|
||||
|
||||
return requestAnimationFrame;
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
@ -25,7 +25,7 @@
|
||||
ns.FramesheetRenderer.prototype.drawFrameInCanvas_ = function (frame, canvas, offsetWidth, offsetHeight) {
|
||||
var context = canvas.getContext('2d');
|
||||
frame.forEachPixel(function (color, x, y) {
|
||||
if(color != Constants.TRANSPARENT_COLOR) {
|
||||
if (color != Constants.TRANSPARENT_COLOR) {
|
||||
context.fillStyle = color;
|
||||
context.fillRect(x + offsetWidth, y + offsetHeight, 1, 1);
|
||||
}
|
||||
@ -39,5 +39,4 @@
|
||||
var height = sampleFrame.getHeight();
|
||||
return pskl.utils.CanvasUtils.createCanvas(width, height);
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|