diff --git a/button.js b/button.js index e913ad7..dbeb56b 100644 --- a/button.js +++ b/button.js @@ -7,8 +7,8 @@ var button = function(p, spec) { // --- defaults --- - spec.rect.width = spec.rect.width || 100; - spec.rect.height = spec.rect.height || 35; + //spec.rect.width = spec.rect.width || 100; + //spec.rect.height = spec.rect.height || 35; // obj to return var obj = {}; @@ -16,7 +16,6 @@ var button = function(p, spec) { // --- private variables --- var next_state_fun = spec.state; - var rect = rectangle(p, spec.rect); var active = spec.active || true; var image = spec.rect.image ? @@ -24,6 +23,18 @@ var button = function(p, spec) { var over_image = spec.rect.over_image ? image_manager.get_image(spec.rect.over_image) : null; + // if no width is given but an image is + // use the image width + if (!spec.rect.width && image) { + spec.rect.width = image.width; + } + // and for height + if (!spec.rect.height && image) { + spec.rect.height = image.height; + } + + var rect = rectangle(p, spec.rect); + // --- public methods --- obj.draw = function() { diff --git a/help_state.js b/help_state.js index ecbd807..96f1787 100644 --- a/help_state.js +++ b/help_state.js @@ -495,11 +495,9 @@ var help_state = function (p, prev_state) { state : function() { sounds.play_button_back(); return prev_state; }, rect : { pos : new p.PVector(p.width/2, button_y), //box_x+box_w-80, box_y+box_h-30), - width: 120, - height: 50, - text: "Back", - text_x_offset: 5, - text_y_offset: -8, + //text: "Back", + //text_x_offset: 5, + //text_y_offset: -8, image: "back.png", } }); @@ -512,9 +510,9 @@ var help_state = function (p, prev_state) { }, rect: { pos: new p.PVector(p.width/2+120, button_y), - text: "Next", + //text: "Next", image: "next.png", - style: button_style + //style: button_style } }); @@ -526,9 +524,9 @@ var help_state = function (p, prev_state) { }, rect: { pos: new p.PVector(p.width/2-120, button_y), - text: "Previous", + //text: "Previous", image: "previous.png", - style: button_style + //style: button_style } }); previous_button.deactivate(); diff --git a/pause_state.js b/pause_state.js index cedae96..30e7767 100644 --- a/pause_state.js +++ b/pause_state.js @@ -29,10 +29,12 @@ var pause_state = function (p, prev_state) { }, rect : { pos : new p.PVector(button_x, button_top), - text: "Continue", + //text: "Continue", image: "continue.png", - image_x_offset: 5, - style: button_style + width: 120, + height: 50 + //image_x_offset: 5, + //style: button_style } }); @@ -43,9 +45,9 @@ var pause_state = function (p, prev_state) { }, rect : { pos : new p.PVector(button_x, button_top+button_sep), - text: "Settings", + //text: "Settings", image: "settings.png", - style: button_style + //style: button_style } }); @@ -56,11 +58,11 @@ var pause_state = function (p, prev_state) { }, rect : { pos : new p.PVector(button_x, button_top+2*button_sep), - text: "Instructions", + //text: "Instructions", //text_x_offset: 10, image: "instructions.png", - image_x_offset: 3, - style: button_style + //image_x_offset: 3, + //style: button_style } }); @@ -71,11 +73,11 @@ var pause_state = function (p, prev_state) { }, rect : { pos : new p.PVector(button_x, button_top+3*button_sep), - text: "Quit", + //text: "Quit", //text_x_offset: -5, image: "quit.png", - image_x_offset: -5, - style: button_style + //image_x_offset: -5, + //style: button_style } }); @@ -106,7 +108,7 @@ var pause_state = function (p, prev_state) { }; obj.key_pressed = function(k) { - if (k === 112 || p.keyCode == 13 || p.keyCode === 27) { //p, enter, esc + if (k === 112 || p.keyCode === 13 || p.keyCode === 27) { //p, enter, esc obj.exit_state();; } }; diff --git a/rectangle.js b/rectangle.js index 09637d0..2fbf7d3 100644 --- a/rectangle.js +++ b/rectangle.js @@ -43,6 +43,7 @@ var rectangle = function (p, spec) { if (spec.image) { rect_image = image_manager.get_image(spec.image);// p.loadImage(spec.image); } + spec.image_x_offset = spec.image_x_offset || 0; var rect_mode = p.CENTER; // tints background image for mouse over