@usman404/crowjs 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,185 @@
1
+ import { Component } from "../Core/Component.js";
2
+
3
+ export class DummyFrame extends Component{
4
+ static RESIZE_DF = "ResizeDF";
5
+ static REPOSITION_DF = "RepositionDF";
6
+
7
+ /**
8
+ * Creates a temporary frame used during resize/reposition operations
9
+ * @param {number} x - The x-coordinate
10
+ * @param {number} y - The y-coordinate
11
+ * @param {number} width - The width
12
+ * @param {number} height - The height
13
+ * @param {string} type - Type of dummy frame (RESIZE_DF or REPOSITION_DF)
14
+ */
15
+ constructor(x, y, width, height, type){
16
+ super(x, y, width, height, {type: type});
17
+ //parent will store reference to the attached frame
18
+ //root will store the ref of root
19
+
20
+ if(this.type === "ResizeDF"){
21
+ this.nearestBorder = null;
22
+ } else if(this.type === "RepositionDF"){
23
+ this.prevX = null;
24
+ this.prevY = null;
25
+ this.xDist = null;
26
+ this.yDist = null;
27
+ }
28
+
29
+ this.addEventListener("hover", (event)=> this.onMouseHover(event));
30
+ this.addEventListener("drag", (event)=> this.onMouseDrag(event));
31
+ this.addEventListener("release", (event) => this.onMouseRelease(event));
32
+ }
33
+
34
+ /**
35
+ * Handles mouse hover events on the dummy frame
36
+ * @param {GUIEvent} event - The hover event
37
+ */
38
+ onMouseHover(event){
39
+ // console.log("hovering ...");
40
+ event.stopPropagation();
41
+ }
42
+
43
+ /**
44
+ * Handles mouse drag events for resizing or repositioning
45
+ * @param {GUIEvent} event - The drag event
46
+ */
47
+ onMouseDrag(event){
48
+ if(this.type === "ResizeDF"){
49
+ this.updateDimensions();
50
+ } else if(this.type === "RepositionDF"){
51
+ this.updatePosition();
52
+ }
53
+
54
+ event.stopPropagation();
55
+ }
56
+
57
+ /**
58
+ * Updates position during repositioning operations
59
+ */
60
+ updatePosition(){
61
+ // console.log("updating position...");
62
+ this.prevX = this.x;
63
+ this.prevY = this.y;
64
+
65
+ this.x = mouseX - abs(this.xDist);
66
+ this.y = mouseY - abs(this.yDist);
67
+ }
68
+
69
+ /**
70
+ * Updates dimensions during resizing operations
71
+ */
72
+ updateDimensions(){
73
+ // console.log("updating dimensions...");
74
+
75
+ switch(this.nearestBorder){
76
+ case "left":
77
+ if(this.x+this.width-mouseX>=this.parent.bannerHeight){
78
+ this.width = this.x + this.width - mouseX;
79
+ this.x = mouseX;
80
+ }
81
+
82
+ break;
83
+ case "right":
84
+ if(mouseX-this.x>=this.parent.bannerHeight){
85
+ this.width = mouseX - this.x;
86
+ }
87
+
88
+ break;
89
+ case "top":
90
+ if(this.y+this.height-mouseY>=this.parent.bannerHeight){
91
+ this.height =this.y + this.height - mouseY;
92
+ this.y = mouseY;
93
+ }
94
+
95
+ break;
96
+ case "bottom":
97
+ if(mouseY-this.y>=this.parent.bannerHeight){
98
+ this.height = mouseY - this.y;
99
+ }
100
+
101
+ break;
102
+ case "top-left":
103
+ if(this.x+this.width-mouseX>=this.parent.bannerHeight){
104
+ this.width = this.x + this.width - mouseX;
105
+ this.x = mouseX;
106
+ }
107
+
108
+ if(this.y+this.height-mouseY>=this.parent.bannerHeight){
109
+ this.height =this.y + this.height - mouseY;
110
+ this.y = mouseY;
111
+ }
112
+
113
+ break;
114
+ case "top-right":
115
+ if(mouseX-this.x>=this.parent.bannerHeight){
116
+ this.width = mouseX - this.x;
117
+ }
118
+
119
+ if(this.y+this.height-mouseY>=this.parent.bannerHeight){
120
+ this.height =this.y + this.height - mouseY;
121
+ this.y = mouseY;
122
+ }
123
+
124
+ break;
125
+ case "bottom-left":
126
+ if(this.x+this.width-mouseX>=this.parent.bannerHeight){
127
+ this.width = this.x + this.width - mouseX;
128
+ this.x = mouseX;
129
+ }
130
+
131
+ if(mouseY-this.y>=this.parent.bannerHeight){
132
+ this.height = mouseY - this.y;
133
+ }
134
+
135
+ break;
136
+ case "bottom-right":
137
+ if(mouseX-this.x>=this.parent.bannerHeight){
138
+ this.width = mouseX - this.x;
139
+ }
140
+
141
+ if(mouseY-this.y>=this.parent.bannerHeight){
142
+ this.height = mouseY - this.y;
143
+ }
144
+
145
+ break;
146
+ default:
147
+ console.log("wrong data in nearestBorder!");
148
+
149
+ break;
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Handles mouse release to finalize operations and transfer values to parent
155
+ * @param {GUIEvent} event - The release event
156
+ */
157
+ onMouseRelease(event){
158
+ // console.log("mouse released...");
159
+ this.parent.x = this.x;
160
+ this.parent.y = this.y;
161
+ this.parent.width = this.width;
162
+ this.parent.height = this.height;
163
+ this.parent.isBannerShown = false;
164
+ this.parent.redraw();
165
+
166
+ this.root.activeElement = this.parent;
167
+ this.root.remove(this);
168
+
169
+ // event.stopPropagation();
170
+ }
171
+
172
+ /**
173
+ * Renders the dummy frame outline during operations
174
+ */
175
+ show(){
176
+ push();
177
+ if(this.parent.borderColor){
178
+ stroke(this.parent.borderColor);
179
+ }
180
+ strokeWeight(this.parent.borderWidth);
181
+ noFill();
182
+ rect(this.x, this.y, this.width, this.height, this.parent.cornerRadius);
183
+ pop();
184
+ }
185
+ }