Moved scaling stuff into a module

This commit is contained in:
Devine Lu Linvega 2017-09-26 11:00:54 +13:00
parent c23b96ca3a
commit bbe469d29b
7 changed files with 48 additions and 9 deletions

View File

@ -1,17 +1,18 @@
<html> <html>
<head> <head>
<script type="text/javascript" src="scripts/module.js"></script>
<script type="text/javascript" src="scripts/modules/frame.js"></script>
<script type="text/javascript" src="scripts/modules/brush.js"></script>
<script type="text/javascript" src="scripts/modules/eraser.js"></script>
<script type="text/javascript" src="scripts/io.js"></script> <script type="text/javascript" src="scripts/io.js"></script>
<script type="text/javascript" src="scripts/query.js"></script> <script type="text/javascript" src="scripts/query.js"></script>
<script type="text/javascript" src="scripts/keyboard.js"></script> <script type="text/javascript" src="scripts/keyboard.js"></script>
<script type="text/javascript" src="scripts/cursor.js"></script> <script type="text/javascript" src="scripts/cursor.js"></script>
<script type="text/javascript" src="scripts/brush.js"></script>
<script type="text/javascript" src="scripts/eraser.js"></script>
<script type="text/javascript" src="scripts/hint.js"></script> <script type="text/javascript" src="scripts/hint.js"></script>
<script type="text/javascript" src="scripts/render.js"></script> <script type="text/javascript" src="scripts/render.js"></script>
<script type="text/javascript" src="scripts/commander.js"></script> <script type="text/javascript" src="scripts/commander.js"></script>
<script type="text/javascript" src="scripts/ronin.js"></script> <script type="text/javascript" src="scripts/ronin.js"></script>
<script type="text/javascript" src="scripts/modules/rescale.js"></script>
<link rel="stylesheet" type="text/css" href="links/reset.css"/> <link rel="stylesheet" type="text/css" href="links/reset.css"/>
<link rel="stylesheet" type="text/css" href="links/fonts.css"/> <link rel="stylesheet" type="text/css" href="links/fonts.css"/>

View File

@ -11,7 +11,13 @@ function Hint()
this.update = function(e = null) this.update = function(e = null)
{ {
this.el.innerHTML = this.pad(ronin.commander.input_el.value)+"brush:"+ronin.brush.settings.size+"&"+ronin.brush.settings.color+""; var html = ""
for(module_id in ronin.modules){
var module = ronin.modules[module_id];
html += module.hint()+" ";
}
this.el.innerHTML = this.pad(ronin.commander.input_el.value)+html;
} }
this.pad = function(input) this.pad = function(input)

16
sources/scripts/module.js Normal file
View File

@ -0,0 +1,16 @@
function Module(name)
{
this.name = name;
this.hint = function()
{
var html = "";
for(setting_id in this.settings){
var setting_value = this.settings[setting_id];
html += setting_id+"="+setting_value+" ";
}
return this.name+"["+html.trim()+"]";
}
}

View File

@ -1,5 +1,7 @@
function Brush() function Brush()
{ {
Module.call(this,"brush");
this.settings = {size:10,color:"#f00"}; this.settings = {size:10,color:"#f00"};
this.thickness = function(line) this.thickness = function(line)
@ -26,7 +28,12 @@ function Brush()
this.mod_size = function(mod) this.mod_size = function(mod)
{ {
this.settings.size += mod; this.settings.size = clamp(this.settings.size+mod,1,100);
}
function clamp(v, min, max)
{
return v < min ? min : v > max ? max : v;
} }
function distance_between(a,b) function distance_between(a,b)

View File

@ -1,5 +1,7 @@
function Eraser() function Eraser()
{ {
Module.call(this,"eraser");
this.thickness = function(line) this.thickness = function(line)
{ {
return ronin.brush.thickness(line); return ronin.brush.thickness(line);

View File

@ -0,0 +1,4 @@
function Frame()
{
Module.call(this,"frame");
}

View File

@ -8,13 +8,16 @@ function Ronin()
this.commander = new Commander(); this.commander = new Commander();
this.cursor = new Cursor(); this.cursor = new Cursor();
this.render = new Render(); this.render = new Render();
this.brush = new Brush();
this.eraser = new Eraser();
this.hint = new Hint(); this.hint = new Hint();
this.brush = new Brush();
this.eraser = new Eraser();
this.frame = new Frame();
this.modules = { this.modules = {
rescale : new Rescale(),
brush : this.brush, brush : this.brush,
eraser : this.eraser,
frame : this.frame,
}; };
this.install = function() this.install = function()