2 var canvas_keyup_temp; |
2 var canvas_keyup_temp; |
3 var CANVAS_KEY_ESC = 27; |
3 var CANVAS_KEY_ESC = 27; |
4 |
4 |
5 function canvas_click(obj) |
5 function canvas_click(obj) |
6 { |
6 { |
7 var click_x = mouseX - $(obj).Left(); |
7 var click_x = mouseX - $dynano(obj).Left(); |
8 var click_y = mouseY - $(obj).Top() + getScrollOffset(); |
8 var click_y = mouseY - $dynano(obj).Top() + getScrollOffset(); |
9 |
9 |
10 if ( obj.canvas_in_draw ) |
10 if ( obj.canvas_in_draw ) |
11 { |
11 { |
12 canvas_close_draw(obj, click_x, click_y); |
12 canvas_close_draw(obj, click_x, click_y); |
13 } |
13 } |
61 |
61 |
62 function canvas_create_box(obj, x, y, width, height) |
62 function canvas_create_box(obj, x, y, width, height) |
63 { |
63 { |
64 var inner_width = width - 2; |
64 var inner_width = width - 2; |
65 var inner_height = height - 2; |
65 var inner_height = height - 2; |
66 var top = $(obj).Top() + y; |
66 var top = $dynano(obj).Top() + y; |
67 var left = $(obj).Left() + x; |
67 var left = $dynano(obj).Left() + x; |
68 |
68 |
69 // draw outer box |
69 // draw outer box |
70 var div_outer = document.createElement('div'); |
70 var div_outer = document.createElement('div'); |
71 div_outer.className = 'canvasbox'; |
71 div_outer.className = 'canvasbox'; |
72 div_outer.style.border = '1px solid #000000'; |
72 div_outer.style.border = '1px solid #000000'; |
100 |
100 |
101 function canvas_redraw_box(obj) |
101 function canvas_redraw_box(obj) |
102 { |
102 { |
103 if ( !obj.canvas_box_obj ) |
103 if ( !obj.canvas_box_obj ) |
104 return false; |
104 return false; |
105 var rel_x = mouseX - $(obj).Left(); |
105 var rel_x = mouseX - $dynano(obj).Left(); |
106 var rel_y = mouseY - $(obj).Top() + getScrollOffset(); |
106 var rel_y = mouseY - $dynano(obj).Top() + getScrollOffset(); |
107 var new_width = rel_x - obj.canvas_box_obj.rootX; |
107 var new_width = rel_x - obj.canvas_box_obj.rootX; |
108 var new_height = rel_y - obj.canvas_box_obj.rootY; |
108 var new_height = rel_y - obj.canvas_box_obj.rootY; |
109 var rootX = obj.canvas_box_obj.rootX; |
109 var rootX = obj.canvas_box_obj.rootX; |
110 var rootY = obj.canvas_box_obj.rootY; |
110 var rootY = obj.canvas_box_obj.rootY; |
111 // Limit dimensions to width - origin_x and height - origin_y |
111 // Limit dimensions to width - origin_x and height - origin_y |
112 if ( new_width + rootX > $(obj).Width() ) |
112 if ( new_width + rootX > $dynano(obj).Width() ) |
113 new_width = $(obj).Width() - rootX; |
113 new_width = $dynano(obj).Width() - rootX; |
114 if ( new_height + rootY > $(obj).Height() ) |
114 if ( new_height + rootY > $dynano(obj).Height() ) |
115 new_height = $(obj).Height() - rootY; |
115 new_height = $dynano(obj).Height() - rootY; |
116 // If going to the top or left of the origin, avoid negative width/height by moving the box |
116 // If going to the top or left of the origin, avoid negative width/height by moving the box |
117 if ( new_width < 1 ) |
117 if ( new_width < 1 ) |
118 { |
118 { |
119 new_width = rootX - rel_x; |
119 new_width = rootX - rel_x; |
120 obj.canvas_box_obj.style.left = String(mouseX + 2) + 'px'; |
120 obj.canvas_box_obj.style.left = String(mouseX + 2) + 'px'; |
145 function canvas_close_draw(obj, x, y) |
145 function canvas_close_draw(obj, x, y) |
146 { |
146 { |
147 canvas_restore_mousemove(); |
147 canvas_restore_mousemove(); |
148 obj.canvas_in_draw = false; |
148 obj.canvas_in_draw = false; |
149 obj.canvas = { |
149 obj.canvas = { |
150 top: $(obj.canvas_box_obj).Top() - $(obj).Top(), |
150 top: $dynano(obj.canvas_box_obj).Top() - $dynano(obj).Top(), |
151 left: $(obj.canvas_box_obj).Left() - $(obj).Left(), |
151 left: $dynano(obj.canvas_box_obj).Left() - $dynano(obj).Left(), |
152 width: $(obj.canvas_box_obj).Width(), |
152 width: $dynano(obj.canvas_box_obj).Width(), |
153 height: $(obj.canvas_box_obj).Height() |
153 height: $dynano(obj.canvas_box_obj).Height() |
154 } |
154 } |
155 obj.onclick = function(e) |
155 obj.onclick = function(e) |
156 { |
156 { |
157 canvas_click(this); |
157 canvas_click(this); |
158 } |
158 } |