1
1
package com.lambda.client.gui.rgui
2
2
3
3
import com.lambda.client.commons.interfaces.Nameable
4
+ import com.lambda.client.module.modules.client.ClickGUI.gridSize
4
5
import com.lambda.client.setting.GuiConfig.setting
5
6
import com.lambda.client.setting.configs.AbstractConfig
6
7
import com.lambda.client.util.graphics.AnimationUtils
7
8
import com.lambda.client.util.graphics.font.HAlign
8
9
import com.lambda.client.util.graphics.font.VAlign
9
10
import com.lambda.client.util.math.Vec2f
11
+ import org.lwjgl.input.Keyboard
10
12
import kotlin.math.max
11
13
import kotlin.math.min
14
+ import kotlin.math.roundToInt
12
15
13
16
open class WindowComponent (
14
17
name : String ,
@@ -106,38 +109,41 @@ open class WindowComponent(
106
109
else -> null
107
110
}
108
111
109
- val centerSplitterVCenter = if (draggableHeight != height && horizontalSide == HAlign .CENTER ) 2.5 else min(15.0 , preDragSize.x / 3.0 )
112
+ val centerSplitterVCenter = if (draggableHeight != height && horizontalSide == HAlign .CENTER ) {
113
+ 2.5
114
+ } else {
115
+ min(15.0 , preDragSize.x / 3.0 )
116
+ }
117
+
110
118
val verticalSide = when (relativeClickPos.y) {
111
119
in - 2.0 .. centerSplitterVCenter -> VAlign .TOP
112
120
in centerSplitterVCenter.. preDragSize.y - centerSplitterV -> VAlign .CENTER
113
121
in preDragSize.y - centerSplitterV.. preDragSize.y + 2.0 -> VAlign .BOTTOM
114
122
else -> null
115
123
}
116
124
125
+ if (horizontalSide == null || verticalSide == null ) return
126
+
117
127
val draggedDist = mousePos.minus(clickPos)
118
128
119
- if (horizontalSide != null && verticalSide != null ) {
120
- if (resizable && ! minimized && (horizontalSide != HAlign .CENTER || verticalSide != VAlign .CENTER )) {
121
- handleResizeX(horizontalSide, draggedDist)
122
- handleResizeY(verticalSide, draggedDist)
129
+ if (resizable && ! minimized && (horizontalSide != HAlign .CENTER || verticalSide != VAlign .CENTER )) {
130
+ handleResizeX(horizontalSide, draggedDist)
131
+ handleResizeY(verticalSide, draggedDist)
123
132
124
- onResize()
125
- } else if (draggableHeight == height || relativeClickPos.y <= draggableHeight) {
126
- posX = (preDragPos.x + draggedDist.x).coerceIn(1 .0f , mc.displayWidth - width - 1.0f )
127
- posY = (preDragPos.y + draggedDist.y).coerceIn(1 .0f , mc.displayHeight - height - 1.0f )
133
+ onResize()
134
+ } else if (draggableHeight == height || relativeClickPos.y <= draggableHeight) {
135
+ posX = roundOnGrid (preDragPos.x + draggedDist.x).coerceIn(.0f , mc.displayWidth - width)
136
+ posY = roundOnGrid (preDragPos.y + draggedDist.y).coerceIn(.0f , mc.displayHeight - height)
128
137
129
- onReposition()
130
- } else {
131
- // TODO
132
- }
138
+ onReposition()
133
139
}
134
140
}
135
141
136
142
private fun handleResizeX (horizontalSide : HAlign , draggedDist : Vec2f ) {
137
143
when (horizontalSide) {
138
144
HAlign .LEFT -> {
139
- val draggedX = max(draggedDist.x, 1.0f - preDragPos.x)
140
- var newWidth = max(preDragSize.x - draggedX, minWidth)
145
+ val draggedX = max(roundOnGrid( draggedDist.x) , 1.0f - preDragPos.x)
146
+ var newWidth = max(roundOnGrid( preDragSize.x - draggedX) , minWidth)
141
147
142
148
if (maxWidth != - 1.0f ) newWidth = min(newWidth, maxWidth)
143
149
newWidth = min(newWidth, scaledDisplayWidth - 2.0f )
@@ -147,25 +153,25 @@ open class WindowComponent(
147
153
posX + = prevWidth - newWidth
148
154
}
149
155
HAlign .RIGHT -> {
150
- val draggedX = min(draggedDist.x, preDragPos.x + preDragSize.x - 1.0f )
151
- var newWidth = max(preDragSize.x + draggedX, minWidth)
156
+ val draggedX = min(roundOnGrid( draggedDist.x) , preDragPos.x + preDragSize.x - 1.0f )
157
+ var newWidth = max(roundOnGrid( preDragSize.x + draggedX) , minWidth)
152
158
153
159
if (maxWidth != - 1.0f ) newWidth = min(newWidth, maxWidth)
154
160
newWidth = min(newWidth, scaledDisplayWidth - posX - 2.0f )
155
161
156
162
width = newWidth
157
163
}
158
164
else -> {
159
- // Nothing lol
165
+ // Ignored
160
166
}
161
167
}
162
168
}
163
169
164
170
private fun handleResizeY (verticalSide : VAlign , draggedDist : Vec2f ) {
165
171
when (verticalSide) {
166
172
VAlign .TOP -> {
167
- val draggedY = max(draggedDist.y, 1.0f - preDragPos.y)
168
- var newHeight = max(preDragSize.y - draggedY, minHeight)
173
+ val draggedY = max(roundOnGrid( draggedDist.y) , 1.0f - preDragPos.y)
174
+ var newHeight = max(roundOnGrid( preDragSize.y - draggedY) , minHeight)
169
175
170
176
if (maxHeight != - 1.0f ) newHeight = min(newHeight, maxHeight)
171
177
newHeight = min(newHeight, scaledDisplayHeight - 2.0f )
@@ -175,20 +181,26 @@ open class WindowComponent(
175
181
posY + = prevHeight - newHeight
176
182
}
177
183
VAlign .BOTTOM -> {
178
- val draggedY = min(draggedDist.y, preDragPos.y + preDragSize.y - 1.0f )
179
- var newHeight = max(preDragSize.y + draggedY, minHeight)
184
+ val draggedY = min(roundOnGrid( draggedDist.y) , preDragPos.y + preDragSize.y - 1.0f )
185
+ var newHeight = max(roundOnGrid( preDragSize.y + draggedY) , minHeight)
180
186
181
187
if (maxHeight != - 1.0f ) newHeight = min(newHeight, maxHeight)
182
188
newHeight = min(newHeight, scaledDisplayHeight - posY - 2.0f )
183
189
184
190
height = newHeight
185
191
}
186
- else -> {
187
- // Nothing lol
192
+ VAlign . CENTER -> {
193
+ // Ignored
188
194
}
189
195
}
190
196
}
191
197
198
+ private fun roundOnGrid (delta : Float ) =
199
+ if (gridSize == .0f
200
+ || Keyboard .isKeyDown(Keyboard .KEY_LSHIFT )
201
+ || Keyboard .isKeyDown(Keyboard .KEY_RSHIFT )
202
+ ) delta else (delta / gridSize).roundToInt() * gridSize
203
+
192
204
fun isInWindow (mousePos : Vec2f ): Boolean {
193
205
return visible && mousePos.x in preDragPos.x - 2.0f .. preDragPos.x + preDragSize.x + 2.0f
194
206
&& mousePos.y in preDragPos.y - 2.0f .. preDragPos.y + max(preDragSize.y * renderMinimizeProgress, draggableHeight) + 2.0f
0 commit comments