put SimpleWindow controls in a bounded camera
This commit is contained in:
@@ -3,6 +3,7 @@ package kiss_flixel;
|
|||||||
import kiss.Prelude;
|
import kiss.Prelude;
|
||||||
import kiss.List;
|
import kiss.List;
|
||||||
import flixel.FlxG;
|
import flixel.FlxG;
|
||||||
|
import flixel.FlxCamera;
|
||||||
import flixel.ui.FlxButton;
|
import flixel.ui.FlxButton;
|
||||||
import flixel.text.FlxText;
|
import flixel.text.FlxText;
|
||||||
import flixel.FlxSprite;
|
import flixel.FlxSprite;
|
||||||
|
@@ -3,6 +3,8 @@
|
|||||||
(var :kiss.List<SimpleWindow> windowStack [])
|
(var :kiss.List<SimpleWindow> windowStack [])
|
||||||
(var &mut :flixel.FlxCamera defaultCamera null)
|
(var &mut :flixel.FlxCamera defaultCamera null)
|
||||||
|
|
||||||
|
(prop :FlxCamera controlCamera)
|
||||||
|
|
||||||
(prop &mut keyboardEnabled true)
|
(prop &mut keyboardEnabled true)
|
||||||
|
|
||||||
// TODO tooltip support with left-click and right-click action
|
// TODO tooltip support with left-click and right-click action
|
||||||
@@ -30,8 +32,13 @@
|
|||||||
(Std.int (* FlxG.height (or percentHeight 0.5)))
|
(Std.int (* FlxG.height (or percentHeight 0.5)))
|
||||||
(or bgColor FlxColor.BLACK))
|
(or bgColor FlxColor.BLACK))
|
||||||
(screenCenter)
|
(screenCenter)
|
||||||
(set nextControlX x)
|
|
||||||
(set nextControlY y)
|
(set controlCamera (new FlxCamera (Std.int x) (Std.int y) (Std.int width) (Std.int height)))
|
||||||
|
(set controlCamera.bgColor FlxColor.TRANSPARENT)
|
||||||
|
|
||||||
|
// Top-left corner for controls is (0,0) because a camera displays them
|
||||||
|
(set nextControlX 0)
|
||||||
|
(set nextControlY 0)
|
||||||
|
|
||||||
(let [textHeight
|
(let [textHeight
|
||||||
.height (new FlxText 0 0 0 "a" textSize)]
|
.height (new FlxText 0 0 0 "a" textSize)]
|
||||||
@@ -54,7 +61,7 @@
|
|||||||
// TODO could make a camera on the window so the controls are clipped by the camera
|
// TODO could make a camera on the window so the controls are clipped by the camera
|
||||||
|
|
||||||
(method addControl [:FlxSprite control]
|
(method addControl [:FlxSprite control]
|
||||||
(set control.cameras this.cameras)
|
(set control.cameras [controlCamera])
|
||||||
(set control.x nextControlX)
|
(set control.x nextControlX)
|
||||||
(set control.y nextControlY)
|
(set control.y nextControlY)
|
||||||
(controls.add control)
|
(controls.add control)
|
||||||
@@ -99,6 +106,7 @@
|
|||||||
|
|
||||||
(method :Void show []
|
(method :Void show []
|
||||||
(unless _shown
|
(unless _shown
|
||||||
|
(FlxG.cameras.add controlCamera)
|
||||||
(FlxG.state.add this)
|
(FlxG.state.add this)
|
||||||
(FlxG.state.add controls)
|
(FlxG.state.add controls)
|
||||||
(windowStack.push this)
|
(windowStack.push this)
|
||||||
@@ -107,6 +115,7 @@
|
|||||||
|
|
||||||
(method :Void hide []
|
(method :Void hide []
|
||||||
(when _shown
|
(when _shown
|
||||||
|
(FlxG.cameras.remove controlCamera)
|
||||||
(FlxG.state.remove this)
|
(FlxG.state.remove this)
|
||||||
(FlxG.state.remove controls)
|
(FlxG.state.remove controls)
|
||||||
(windowStack.remove this)
|
(windowStack.remove this)
|
||||||
@@ -128,12 +137,11 @@
|
|||||||
(when keyboardEnabled
|
(when keyboardEnabled
|
||||||
(keyHandler.update))
|
(keyHandler.update))
|
||||||
// Handle mouse input
|
// Handle mouse input
|
||||||
(let [camera (first (or cameras []))
|
(let [mousePos (FlxG.mouse.getScreenPosition controlCamera)]
|
||||||
mousePos (FlxG.mouse.getScreenPosition camera)]
|
|
||||||
(controls.forEach ->text
|
(controls.forEach ->text
|
||||||
(whenLet [onClick (dictGet _actions text)]
|
(whenLet [onClick (dictGet _actions text)]
|
||||||
(let [color (dictGet _colors text)]
|
(let [color (dictGet _colors text)]
|
||||||
(if (and !otherIsSelected (.containsPoint (text.getScreenBounds camera) mousePos))
|
(if (and !otherIsSelected (.containsPoint (text.getScreenBounds controlCamera) mousePos))
|
||||||
{
|
{
|
||||||
(when FlxG.mouse.justPressed
|
(when FlxG.mouse.justPressed
|
||||||
(onClick text))
|
(onClick text))
|
||||||
|
Reference in New Issue
Block a user