Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. function Toolbar(){
  2. this.loc = new Location(850, 50);
  3.  
  4. this.buttons = []
  5. this.buttons.push(new Button("POINTER", this.loc.x +5, this.loc.y + 20, this.buttons.length));
  6. this.buttons.push(new Button("LINE", this.loc.x + 45, this.loc.y+20, this.buttons.length));
  7. this.buttons.push(new Button("5SLINE", this.loc.x + 85, this.loc.y+20, this.buttons.length));
  8. this.buttons.push(new Button("CLEAR", this.loc.x + 125, this.loc.y+20, this.buttons.length));
  9. this.buttons.push(new Button("VIDEO", this.loc.x + 165, this.loc.y+20, this.buttons.length));
  10.  
  11.  
  12.  
  13. // Old button layout
  14. // this.buttons.push(new Button("TEXT", this.loc.x + 125, this.loc.y+20, this.buttons.length));
  15. // this.buttons.push(new Button("CLEAR", this.loc.x + 165, this.loc.y+20, this.buttons.length));
  16. // this.buttons.push(new Button("VIDEO", this.loc.x + 205, this.loc.y+20, this.buttons.length));
  17.  
  18. this.draw = toolbar_draw;
  19. this.update = toolbar_update;
  20. this.mousedown = toolbar_mousedown;
  21. this.mouseup = toolbar_mouseup;
  22. this.click = toolbar_click;
  23. this.mousemove = toolbar_mousemove;
  24. this.hitcheck = toolbar_hitcheck;
  25.  
  26. this.highlight_dragbar = false;
  27. this.is_dragging = false;
  28. this.cur_selected = "POINTER";
  29. this.get_lowest_point = function(){
  30. // Toolbar doesn't affect how far we can scroll
  31. return 0;
  32. }
  33. this.last_move = new Location(0,0);
  34. }
  35.  
  36. function toolbar_draw(ctx){
  37. if(this.highlight_dragbar === false){
  38. ctx.fillStyle = "#222222";
  39. }else{
  40. ctx.fillStyle = "#444444";
  41. }
  42.  
  43. var tb_width = (this.buttons.length * 40) + 5;
  44. ctx.beginPath();
  45. ctx.fillRect(this.loc.x, this.loc.y, tb_width , 20);
  46. ctx.stroke();
  47. ctx.closePath();
  48.  
  49. ctx.beginPath();
  50. ctx.fillStyle = "#777777";
  51. ctx.fillRect(this.loc.x, this.loc.y + 20, tb_width , 45);
  52. ctx.stroke();
  53. ctx.closePath();
  54.  
  55. for(var i=0; i<this.buttons.length; i++){
  56. this.buttons[i].draw(ctx);
  57. }
  58. }
  59. function toolbar_hitcheck(_x, _y){
  60. var tb_width = this.buttons.length * 40;
  61.  
  62. if(_x > this.loc.x && _x < this.loc.x + tb_width){
  63. if(_y > this.loc.y && _y < this.loc.y + 20){
  64. return true;
  65. }
  66. }
  67.  
  68. return false
  69. }
  70. function toolbar_update(){
  71.  
  72. }
  73.  
  74. function toolbar_click(_x, _y){
  75.  
  76. }
  77.  
  78. function toolbar_mousedown(_x, _y){
  79. if(this.hitcheck(_x, _y)){
  80. this.is_dragging = true;
  81. this.last_move = new Location(_x,_y);
  82. return true;
  83. }
  84. var hit = false;
  85. for(var i=0; i<this.buttons.length; i++){
  86. var btn = this.buttons[i];
  87. if(btn.mousedown(_x, _y)){
  88. hit = true;
  89. this.cur_selected = btn.type;
  90. }
  91. }
  92. return hit;
  93. }
  94.  
  95. function toolbar_mouseup(_x, _y){
  96. this.is_dragging = false;
  97. }
  98.  
  99. function toolbar_mousemove(_x, _y){
  100. this.highlight_dragbar = false;
  101. if(this.is_dragging){
  102. var new_x = _x - this.last_move.x;
  103. var new_y = _y - this.last_move.y;
  104. this.last_move.x = _x;
  105. this.last_move.y = _y;
  106. this.loc.x += new_x;
  107. this.loc.y += new_y;
  108.  
  109. for(var i=0; i<this.buttons.length; i++){
  110. this.buttons[i].loc.x += new_x;
  111. this.buttons[i].loc.y += new_y;
  112. }
  113. }else if(this.hitcheck(_x, _y)){
  114. this.highlight_dragbar = true;
  115. }else{
  116. for(var i=0; i<this.buttons.length; i++){
  117. this.buttons[i].mousemove(_x, _y);
  118. }
  119. }
  120.  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement