Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Toolbar(){
- this.loc = new Location(850, 50);
- this.buttons = []
- this.buttons.push(new Button("POINTER", this.loc.x +5, this.loc.y + 20, this.buttons.length));
- this.buttons.push(new Button("LINE", this.loc.x + 45, this.loc.y+20, this.buttons.length));
- this.buttons.push(new Button("5SLINE", this.loc.x + 85, this.loc.y+20, this.buttons.length));
- this.buttons.push(new Button("CLEAR", this.loc.x + 125, this.loc.y+20, this.buttons.length));
- this.buttons.push(new Button("VIDEO", this.loc.x + 165, this.loc.y+20, this.buttons.length));
- // Old button layout
- // this.buttons.push(new Button("TEXT", this.loc.x + 125, this.loc.y+20, this.buttons.length));
- // this.buttons.push(new Button("CLEAR", this.loc.x + 165, this.loc.y+20, this.buttons.length));
- // this.buttons.push(new Button("VIDEO", this.loc.x + 205, this.loc.y+20, this.buttons.length));
- this.draw = toolbar_draw;
- this.update = toolbar_update;
- this.mousedown = toolbar_mousedown;
- this.mouseup = toolbar_mouseup;
- this.click = toolbar_click;
- this.mousemove = toolbar_mousemove;
- this.hitcheck = toolbar_hitcheck;
- this.highlight_dragbar = false;
- this.is_dragging = false;
- this.cur_selected = "POINTER";
- this.get_lowest_point = function(){
- // Toolbar doesn't affect how far we can scroll
- return 0;
- }
- this.last_move = new Location(0,0);
- }
- function toolbar_draw(ctx){
- if(this.highlight_dragbar === false){
- ctx.fillStyle = "#222222";
- }else{
- ctx.fillStyle = "#444444";
- }
- var tb_width = (this.buttons.length * 40) + 5;
- ctx.beginPath();
- ctx.fillRect(this.loc.x, this.loc.y, tb_width , 20);
- ctx.stroke();
- ctx.closePath();
- ctx.beginPath();
- ctx.fillStyle = "#777777";
- ctx.fillRect(this.loc.x, this.loc.y + 20, tb_width , 45);
- ctx.stroke();
- ctx.closePath();
- for(var i=0; i<this.buttons.length; i++){
- this.buttons[i].draw(ctx);
- }
- }
- function toolbar_hitcheck(_x, _y){
- var tb_width = this.buttons.length * 40;
- if(_x > this.loc.x && _x < this.loc.x + tb_width){
- if(_y > this.loc.y && _y < this.loc.y + 20){
- return true;
- }
- }
- return false
- }
- function toolbar_update(){
- }
- function toolbar_click(_x, _y){
- }
- function toolbar_mousedown(_x, _y){
- if(this.hitcheck(_x, _y)){
- this.is_dragging = true;
- this.last_move = new Location(_x,_y);
- return true;
- }
- var hit = false;
- for(var i=0; i<this.buttons.length; i++){
- var btn = this.buttons[i];
- if(btn.mousedown(_x, _y)){
- hit = true;
- this.cur_selected = btn.type;
- }
- }
- return hit;
- }
- function toolbar_mouseup(_x, _y){
- this.is_dragging = false;
- }
- function toolbar_mousemove(_x, _y){
- this.highlight_dragbar = false;
- if(this.is_dragging){
- var new_x = _x - this.last_move.x;
- var new_y = _y - this.last_move.y;
- this.last_move.x = _x;
- this.last_move.y = _y;
- this.loc.x += new_x;
- this.loc.y += new_y;
- for(var i=0; i<this.buttons.length; i++){
- this.buttons[i].loc.x += new_x;
- this.buttons[i].loc.y += new_y;
- }
- }else if(this.hitcheck(_x, _y)){
- this.highlight_dragbar = true;
- }else{
- for(var i=0; i<this.buttons.length; i++){
- this.buttons[i].mousemove(_x, _y);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement