Skip to content

Instantly share code, notes, and snippets.

@stpettersens
Created July 5, 2012 09:48
Show Gist options
  • Save stpettersens/3052675 to your computer and use it in GitHub Desktop.
Save stpettersens/3052675 to your computer and use it in GitHub Desktop.
Caption class
// Define a Caption 'class'.
function Caption(message, color, x, y) {
// Properties.
this.message = message;
this.color = color;
this.x = x;
this.y = y;
// Methods.
this.draw = function() {
// Draw the caption, using the parameters provided.
gContextOverlay.beginPath();
gContextOverlay.rect(this.x, this.y, 180, 40);
gContextOverlay.fillStyle = this.color;
gContextOverlay.fill();
gContextOverlay.lineWidth = 0.5;
gContextOverlay.strokeStyle = "#505050";
gContextOverlay.stroke();
gContextOverlay.font = "10pt Verdana";
gContextOverlay.fillStyle = "#000000";
gContextOverlay.fillText(this.message, this.x + 10, this.y + 25);
/*console.log(gContextOverlay + " Drew caption: "
+ "\'" + this.message + "\' in "
+ this.color + " at " + x + "," + this.y + ".");*/
};
this.remove = function() {
// This actually clears the entire overlay canvas,
// but this is invoked with {button}.remove() in showCaption(event).
gContextOverlay.clearRect(0, 0, gDemoOverlay.width, gDemoOverlay.height);
};
}
/* A new Caption is defined like this: */
var y = new Caption("Y button - Show caption", "#FFFF66", 270, 90);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment