windows can be moved!!

This commit is contained in:
Yoshman29
2022-10-21 23:37:28 +02:00
parent 3c0763edd1
commit 2ad07feba0
6 changed files with 76 additions and 14 deletions
+1 -1
View File
@@ -1 +1 @@
696
708
+20
View File
@@ -1,11 +1,15 @@
package funkin.desktop;
import openfl.geom.Rectangle;
import flixel.FlxObject;
import lime.app.Application;
import openfl.display.BitmapData;
import flixel.system.scaleModes.BaseScaleMode;
import flixel.system.scaleModes.FixedScaleAdjustSizeScaleMode;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxBasic;
import flixel.FlxCamera;
import flixel.math.FlxPoint;
import funkin.desktop.editors.HelloWorld;
import funkin.desktop.windows.*;
@@ -78,9 +82,11 @@ class MouseInput {
public var pressed:Bool = false;
public var justPressed:Bool = false;
public var justReleased:Bool = false;
private var __cancelled:Bool = false;
public function cancel() {
pressed = justPressed = justReleased = false;
__cancelled = true;
}
public function new() {}
@@ -89,5 +95,19 @@ class MouseInput {
this.pressed = pressed;
this.justPressed = justPressed;
this.justReleased = justReleased;
this.__cancelled = false;
}
public function overlaps(spr:FlxObject, ?camera:FlxCamera) {
return overlapsRect(spr, new Rectangle(spr.x, spr.y, spr.width, spr.height), camera);
// return FlxG.mouse.overlaps(spr, camera);
}
public function overlapsRect(spr:FlxBasic, rect:Rectangle, ?camera:FlxCamera) {
if (__cancelled) return false;
if (camera == null) camera = FlxG.camera;
var pos = FlxG.mouse.getScreenPosition(camera);
return ((pos.x > rect.x) && (pos.x < rect.x + rect.width)) && ((pos.y > rect.y) && (pos.y < rect.y + rect.height));
}
}
+9 -2
View File
@@ -2,6 +2,7 @@ package funkin.desktop.editors;
import flixel.util.FlxDestroyUtil.IFlxDestroyable;
import flixel.addons.ui.FlxUIText;
import flixel.FlxG;
class HelloWorld extends WindowContent {
public override function new() {
@@ -25,11 +26,17 @@ class HelloWorld extends WindowContent {
}
public var time:Float = 0;
public var coolAssMode:Bool = false;
public override function update(elapsed:Float) {
super.update(elapsed);
time += elapsed;
width = 500 + Std.int(Math.cos(time * Math.PI) * 250);
height = 500 + Std.int(Math.sin(time * Math.PI) * 250);
if (FlxG.keys.justPressed.M) coolAssMode = !coolAssMode;
if (coolAssMode) {
width = 500 + Std.int(Math.cos(time * Math.PI) * 250);
height = 500 + Std.int(Math.sin(time * Math.PI) * 250);
}
parent.updateWindowFrame();
}
}
+25 -2
View File
@@ -37,6 +37,7 @@ class Window extends FlxTypedGroup<FlxBasic> {
public var caption:FlxUIText;
public var icon:FlxSprite;
public var dragHitbox:WindowDragHitbox;
public var draggable:Bool = true;
public var resizeable:Bool = true;
@@ -59,6 +60,10 @@ class Window extends FlxTypedGroup<FlxBasic> {
}
add(caption);
dragHitbox = new WindowDragHitbox(4, 4, 4, 18);
dragHitbox.parent = this;
add(dragHitbox);
icon = new FlxSprite(4, 4);
add(icon);
loadIcon(content.icon);
@@ -74,6 +79,7 @@ class Window extends FlxTypedGroup<FlxBasic> {
windowCaptionCamera.bgColor = 0;
FlxG.cameras.add(windowCaptionCamera, false);
cameras = [windowCaptionCamera];
dragHitbox.cameras = [windowCaptionCamera];
for(btn in captionButtons.members)
btn.cameras = cameras; // so that buttons detects on the right camera
@@ -140,14 +146,31 @@ class Window extends FlxTypedGroup<FlxBasic> {
}
public function move(x:Float, y:Float) {
windowCaptionCamera.x = x;
windowCaptionCamera.y = y;
@:privateAccess content.__noParentUpdate = true;
content.winX = windowCaptionCamera.x = x;
content.winY = windowCaptionCamera.y = y;
@:privateAccess content.__noParentUpdate = false;
for(e in windowCameras) {
e.camera.x = x + 4;
e.camera.y = y + 23;
}
}
public override function update(elapsed:Float) {
var i = members.length;
var shouldCancel = DesktopMain.instance.mouseInput.overlapsRect(this, new Rectangle(0, 0, windowCaptionCamera.width, windowCaptionCamera.height), windowCaptionCamera);
// updates them backwards!!
while(i > 0) {
i--;
var spr = members[i];
if (spr == null || !spr.exists) continue;
spr.update(elapsed);
}
if (shouldCancel) DesktopMain.instance.mouseInput.cancel();
}
public function close() {
DesktopMain.instance.windows.remove(this, true);
destroy();
@@ -19,7 +19,7 @@ class WindowContent extends FlxTypedGroup<FlxSprite> {
private var __noParentUpdate:Bool = false;
private function set_width(w:Int):Int {
width = w;
if (parent != null) {
if (parent != null && !__noParentUpdate) {
parent.windowWidth = w;
if (!__noParentUpdate)
parent.updateWindowFrame();
@@ -28,7 +28,7 @@ class WindowContent extends FlxTypedGroup<FlxSprite> {
}
private function set_height(h:Int):Int {
height = h;
if (parent != null) {
if (parent != null && !__noParentUpdate) {
parent.windowHeight = h;
if (!__noParentUpdate)
parent.updateWindowFrame();
@@ -37,24 +37,24 @@ class WindowContent extends FlxTypedGroup<FlxSprite> {
}
private function set_winX(v:Float):Float {
winX = v;
if (parent != null) parent.move(winX, winY);
if (parent != null && !__noParentUpdate) parent.move(winX, winY);
return winX;
}
private function set_title(text:String):String {
title = text;
if (parent != null) parent.changeCaption(title);
if (parent != null && !__noParentUpdate) parent.changeCaption(title);
return title;
}
private function set_icon(text:String):String {
icon = text;
if (parent != null) parent.loadIcon(icon);
if (parent != null && !__noParentUpdate) parent.loadIcon(icon);
return icon;
}
private function set_winY(v:Float):Float {
winY = v;
if (parent != null) parent.move(winX, winY);
if (parent != null && !__noParentUpdate) parent.move(winX, winY);
return winY;
}
@@ -1,6 +1,8 @@
package funkin.desktop.windows;
import flixel.FlxG;
import flixel.FlxObject;
import flixel.math.FlxPoint;
class WindowDragHitbox extends FlxObject {
public var parent:Window;
@@ -11,7 +13,10 @@ class WindowDragHitbox extends FlxObject {
public var dragging:Bool = false;
public var offset:FlxPoint;
public function new(left:Float, top:Float, right:Float, height:Float) {
super();
x = left;
y = top;
this.left = left;
@@ -21,18 +26,25 @@ class WindowDragHitbox extends FlxObject {
}
public override function get_width() {
return parent.windowWidth - left - right;
return parent.windowCaptionCamera.width - left - right;
}
public override function update(elapsed:Float) {
super.update(elapsed);
if (dragging) {
if (DesktopMain.instance.mouseInput.justReleased)
var screenPos = FlxG.mouse.getScreenPosition(FlxG.camera);
if (DesktopMain.instance.mouseInput.justReleased) {
dragging = false;
offset.put();
return;
}
parent.move(screenPos.x + offset.x, screenPos.y + offset.y);
DesktopMain.instance.mouseInput.cancel();
} else {
if (FlxG.mouse.overlaps(this)) {
if (DesktopMain.instance.mouseInput.overlaps(this, camera)) {
if (DesktopMain.instance.mouseInput.justPressed) {
var screenPos = FlxG.mouse.getScreenPosition(FlxG.camera);
offset = FlxPoint.get(parent.content.winX - screenPos.x, parent.content.winY - screenPos.y);
dragging = true;
}
DesktopMain.instance.mouseInput.cancel();