Permalink
Browse files

test flood fill algorithm

  • Loading branch information...
1 parent 9c5797c commit d08ceb5bd041d0bbc01760d8626946c15b62205f Daome committed Feb 20, 2012
Showing with 40 additions and 35 deletions.
  1. +7 −1 css/index.css
  2. +11 −13 js/faviconbuilder.coffee
  3. +22 −21 js/faviconbuilder.js
View
@@ -1,6 +1,7 @@
/* ksuFAVICON BUILDER stylecheet */
@import url('gradient.css'); /* fond dégradé */
@import url('messagebox.css'); /* message box */
+@import url('unselectable.css'); /*unselectable*/
h1,h2,h3,h4,h5,h6,div,p,img{
border:none;
margin:0;
@@ -127,12 +128,17 @@ canvas{
.emptyCell{
background:url("/lib/img/faviconbuilder/emptycell.gif");
}
-
+#toolSelector{
+ height:50px;
+}
#toolSelector img{
border:2px solid #666;
+ width:32px;
+ margin-right:6px;
}
#toolSelector img:hover{
border:2px dashed #666;
+ cursor: pointer;
}
#toolSelector img.selected{
border:2px dashed #666;
View
@@ -186,13 +186,13 @@ class App.Models.History
constructor:(@iterator = new App.Utils.Iterator())->
class App.Models.Toolbox
-constructor:(@tools)->
+ constructor:(@tools)->
+ @currentTool = {value:@tools[0].label}
### VIEWS ###
class View
render:->
for child of this
- console.log child,"render"
@[child].render?()
class App.Views.Cell extends View
@@ -388,11 +388,13 @@ class App.Views.Toolbox extends View
render:->
@el = ""
for tool in @model.tools
- @el += "<img title='#{tool.title}' name='#{tool.label}' #{if tool.title = @model.currentTool.value then "class='selected'" else "" } src='#{tool.src}'/>"
+ @el += "<img title='#{tool.title}' name='#{tool.label}' #{if tool.title == @model.currentTool.value then "class='selected'" else "" } src='#{tool.src}'/>"
+ @el+="<br/><h5>#{@model.currentTool.value}</h5>"
@targetId.onclick =(e)=>
name = e.target.getAttribute("name")
tagName = e.target.tagName
@eventDispatcher.dispatch(new App.Utils.Event("changetool"),name) unless not name? and tagName != "IMG"
+ return false
@targetId.innerHTML = @el
return this
@@ -404,6 +406,7 @@ class App.Controllers.Application
### MAIN ###
class Main
constructor:->
+ console.log "favicon builder at #{new Date()}"
"use strict"
@version = 0.1
# DOM
@@ -433,7 +436,7 @@ class Main
@applicationController = new App.Controllers.Application(@model)
### VIEWS ###
@view = new App.Views.Application(@applicationController,$app)
- #@view.toolbox = new App.Views.Toolbox(@model.toolbox,$toolbox)
+ @view.toolbox = new App.Views.Toolbox(@model.toolbox,$toolbox)
@view.colorSelector = new App.Views.ColorSelector($colorSelector,@model.colorSelector)
@view.colorSelector.eventDispatcher.addListener("colorchange",@oncolorchange)
@view.canvasPreview = new App.Views.CanvasPreview(@model.canvasPreview)
@@ -442,17 +445,9 @@ class Main
@view.title = new App.Views.Title(@model.title)
@view.grid.setPenColor(@model.currentColor)
@view.menu = new App.Views.Menu(@model.menu)
- ###
- @view.addChild(@view.toolbox)
- @view.addChild(@view.grid)
- @view.addChild(@view.title)
- @view.addChild(@view.colorSelector)
- @view.addChild(@view.canvasPreview)
- @view.addChild(@view.factorSelector)
- @view.addChild(@view.menu)
- ###
@view.render() # render all child views
### EVENTS ###
+ @view.toolbox.eventDispatcher.addListener("changetool",@changeTool)
@view.menu.eventDispatcher.addListener("exporttopng",@exportCanvas)
@view.menu.eventDispatcher.addListener("changegridsize",@changegridsize)
@view.menu.eventDispatcher.addListener("emptygrid",@emptygrid)
@@ -470,6 +465,9 @@ class Main
@pushInHistory()
+ changeTool:(e)=>
+ @model.toolbox.currentTool.value = e.datas
+ @view.render()
pushInHistory:(e)=>
if @model.history.iterator.hasNext()
@model.history.iterator.split(@model.history.iterator)
View
@@ -405,19 +405,19 @@ App.Models.History = (function() {
App.Models.Toolbox = (function() {
- function Toolbox() {}
+ function Toolbox(tools) {
+ this.tools = tools;
+ this.currentTool = {
+ value: this.tools[0].label
+ };
+ }
return Toolbox;
})();
-({
- constructor: function(tools) {
- this.tools = tools;
- }
- /* VIEWS
- */
-});
+/* VIEWS
+*/
View = (function() {
@@ -427,7 +427,6 @@ View = (function() {
var child, _base, _results;
_results = [];
for (child in this) {
- console.log(child, "render");
_results.push(typeof (_base = this[child]).render === "function" ? _base.render() : void 0);
}
return _results;
@@ -795,15 +794,17 @@ App.Views.Toolbox = (function(_super) {
_ref = this.model.tools;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
tool = _ref[_i];
- this.el += "<img title='" + tool.title + "' name='" + tool.label + "' " + ((tool.title = this.model.currentTool.value) ? "class='selected'" : "") + " src='" + tool.src + "'/>";
+ this.el += "<img title='" + tool.title + "' name='" + tool.label + "' " + (tool.title === this.model.currentTool.value ? "class='selected'" : "") + " src='" + tool.src + "'/>";
}
+ this.el += "<br/><h5>" + this.model.currentTool.value + "</h5>";
this.targetId.onclick = function(e) {
var name, tagName;
name = e.target.getAttribute("name");
tagName = e.target.tagName;
if (!(!(name != null) && tagName !== "IMG")) {
- return _this.eventDispatcher.dispatch(new App.Utils.Event("changetool"), name);
+ _this.eventDispatcher.dispatch(new App.Utils.Event("changetool"), name);
}
+ return false;
};
this.targetId.innerHTML = this.el;
return this;
@@ -848,8 +849,10 @@ Main = (function() {
this.redo = __bind(this.redo, this);
this.undo = __bind(this.undo, this);
this.pushInHistory = __bind(this.pushInHistory, this);
- "use strict";
+ this.changeTool = __bind(this.changeTool, this);
var $app, $canvasPreview, $colorSelector, $factorSelector, $menu, $target, $title, $toolbox, defaultColor, title;
+ console.log("favicon builder at " + (new Date()));
+ "use strict";
this.version = 0.1;
this.thickbox = document.getElementById("thickbox");
$app = document.getElementById("app");
@@ -879,6 +882,7 @@ Main = (function() {
/* VIEWS
*/
this.view = new App.Views.Application(this.applicationController, $app);
+ this.view.toolbox = new App.Views.Toolbox(this.model.toolbox, $toolbox);
this.view.colorSelector = new App.Views.ColorSelector($colorSelector, this.model.colorSelector);
this.view.colorSelector.eventDispatcher.addListener("colorchange", this.oncolorchange);
this.view.canvasPreview = new App.Views.CanvasPreview(this.model.canvasPreview);
@@ -887,18 +891,10 @@ Main = (function() {
this.view.title = new App.Views.Title(this.model.title);
this.view.grid.setPenColor(this.model.currentColor);
this.view.menu = new App.Views.Menu(this.model.menu);
- /*
- @view.addChild(@view.toolbox)
- @view.addChild(@view.grid)
- @view.addChild(@view.title)
- @view.addChild(@view.colorSelector)
- @view.addChild(@view.canvasPreview)
- @view.addChild(@view.factorSelector)
- @view.addChild(@view.menu)
- */
this.view.render();
/* EVENTS
*/
+ this.view.toolbox.eventDispatcher.addListener("changetool", this.changeTool);
this.view.menu.eventDispatcher.addListener("exporttopng", this.exportCanvas);
this.view.menu.eventDispatcher.addListener("changegridsize", this.changegridsize);
this.view.menu.eventDispatcher.addListener("emptygrid", this.emptygrid);
@@ -916,6 +912,11 @@ Main = (function() {
this.pushInHistory();
}
+ Main.prototype.changeTool = function(e) {
+ this.model.toolbox.currentTool.value = e.datas;
+ return this.view.render();
+ };
+
Main.prototype.pushInHistory = function(e) {
if (this.model.history.iterator.hasNext()) {
this.model.history.iterator.split(this.model.history.iterator);

0 comments on commit d08ceb5

Please sign in to comment.