-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* improve btimap tracking * add capitalizeFirstLetters and isRomanNumeral * fix window resizing * add FlxGraphicSource.resolveBitmapData * improve pointer selection * prevent debug cursors from blocking clicks * improve debug cursor hotspot * centralize debug icons * add shortcuts for tools and windows * handle FlxColors in watch window * add scroll bars to watch/tracker * add Tools to TrackObject and LogBitmap
- Loading branch information
Showing
10 changed files
with
608 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
package flixel.system.debug; | ||
|
||
import flixel.FlxG; | ||
import openfl.display.DisplayObject; | ||
import openfl.display.Sprite; | ||
import openfl.events.Event; | ||
import openfl.events.MouseEvent; | ||
import openfl.geom.Point; | ||
import openfl.geom.Rectangle; | ||
|
||
class ScrollSprite extends Sprite | ||
{ | ||
public var maxScrollY(get, never):Float; | ||
inline function get_maxScrollY():Float return this.height - scroll.height; | ||
|
||
public var viewHeight(get, never):Float; | ||
inline function get_viewHeight():Float return scroll.height; | ||
|
||
/** | ||
* The current amount of scrolling | ||
*/ | ||
public var scrollY(get, set):Float; | ||
inline function get_scrollY():Float return scroll.y; | ||
inline function set_scrollY(value):Float | ||
{ | ||
scroll.y = value; | ||
updateScroll(); | ||
return scroll.y; | ||
} | ||
|
||
var scroll = new Rectangle(); | ||
var scrollBar:ScrollBar = null; | ||
|
||
public function new () | ||
{ | ||
super(); | ||
|
||
addEventListener(Event.ADDED_TO_STAGE, function (e) | ||
{ | ||
final stage = this.stage; | ||
stage.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseScroll); | ||
addEventListener(Event.REMOVED_FROM_STAGE, (_)->stage.removeEventListener(MouseEvent.MOUSE_WHEEL, onMouseScroll)); | ||
}); | ||
} | ||
|
||
public function createScrollBar() | ||
{ | ||
return scrollBar = new ScrollBar(this); | ||
} | ||
|
||
function onMouseScroll(e:MouseEvent) | ||
{ | ||
if (mouseX > 0 && mouseX < scroll.width && mouseY - scroll.y > 0 && mouseY - scroll.y < scroll.height) | ||
{ | ||
scroll.y -= e.delta; | ||
updateScroll(); | ||
} | ||
} | ||
|
||
public function setScrollSize(width:Float, height:Float) | ||
{ | ||
scroll.width = width; | ||
scroll.height = height; | ||
|
||
updateScroll(); | ||
} | ||
|
||
function updateScroll() | ||
{ | ||
scrollRect = null; | ||
|
||
if (scroll.bottom > this.height) | ||
scroll.y = height - scroll.height; | ||
|
||
if (scroll.y < 0) | ||
scroll.y = 0; | ||
|
||
scrollRect = scroll; | ||
|
||
if (scrollBar != null) | ||
scrollBar.onViewChange(); | ||
} | ||
|
||
override function addChild(child) | ||
{ | ||
super.addChild(child); | ||
updateScroll(); | ||
return child; | ||
} | ||
|
||
public function isChildVisible(child:DisplayObject) | ||
{ | ||
if (getChildIndex(child) == -1) | ||
throw "Invalid child, not a child of this container"; | ||
|
||
return child.y < scroll.bottom && child.y + child.height > scroll.y; | ||
} | ||
} | ||
|
||
@:allow(flixel.system.debug.ScrollSprite) | ||
class ScrollBar extends Sprite | ||
{ | ||
static inline final WIDTH = 10; | ||
|
||
final target:ScrollSprite; | ||
|
||
final handle = new Sprite(); | ||
final bg = new Sprite(); | ||
|
||
var state:ScrollState = IDLE; | ||
|
||
public function new (target:ScrollSprite) | ||
{ | ||
this.target = target; | ||
super(); | ||
|
||
bg.mouseChildren = true; | ||
bg.mouseEnabled = true; | ||
bg.graphics.beginFill(0xFFFFFF, 0.1); | ||
bg.graphics.drawRect(0, 0, WIDTH, 1); | ||
bg.graphics.endFill(); | ||
addChild(bg); | ||
|
||
handle.mouseChildren = true; | ||
handle.mouseEnabled = true; | ||
handle.buttonMode = true; | ||
handle.graphics.beginFill(0xFFFFFF, 0.3); | ||
handle.graphics.drawRect(0, 0, WIDTH, 1); | ||
handle.graphics.endFill(); | ||
addChild(handle); | ||
|
||
function onAdded(_) | ||
{ | ||
removeEventListener(Event.ADDED_TO_STAGE, onAdded); | ||
final stage = this.stage; | ||
|
||
bg.addEventListener(MouseEvent.MOUSE_DOWN, onBgMouseDown); | ||
handle.addEventListener(MouseEvent.MOUSE_DOWN, onHandleMouse); | ||
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove); | ||
stage.addEventListener(MouseEvent.MOUSE_UP, onHandleMouse); | ||
|
||
function onRemoved(_) | ||
{ | ||
removeEventListener(Event.REMOVED_FROM_STAGE, onRemoved); | ||
|
||
bg.removeEventListener(MouseEvent.MOUSE_DOWN, onBgMouseDown); | ||
handle.removeEventListener(MouseEvent.MOUSE_DOWN, onHandleMouse); | ||
stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove); | ||
stage.removeEventListener(MouseEvent.MOUSE_UP, onHandleMouse); | ||
} | ||
addEventListener(Event.REMOVED_FROM_STAGE, onRemoved); | ||
} | ||
addEventListener(Event.ADDED_TO_STAGE, onAdded); | ||
} | ||
|
||
function onBgMouseDown(e:MouseEvent) | ||
{ | ||
if (state != IDLE) | ||
throw "expected state: IDLE"; | ||
|
||
state = DRAG_BG; | ||
mouseMoveHelper(e.stageY); | ||
} | ||
|
||
function onHandleMouse(e:MouseEvent) | ||
{ | ||
if (e.type == MouseEvent.MOUSE_DOWN) | ||
{ | ||
if (state != IDLE) | ||
throw "expected state: IDLE"; | ||
|
||
state = DRAG_HANDLE(getLocalY(e.stageY) - handle.y); | ||
} | ||
else | ||
state = IDLE; | ||
} | ||
|
||
function onMouseMove(e:MouseEvent) | ||
{ | ||
mouseMoveHelper(e.stageY); | ||
} | ||
|
||
function getLocalY(stageY:Float) | ||
{ | ||
return globalToLocal(new Point (0, stageY)).y; | ||
} | ||
|
||
function mouseMoveHelper(stageY:Float) | ||
{ | ||
final localY = getLocalY(stageY); | ||
switch state | ||
{ | ||
case IDLE: | ||
case DRAG_HANDLE(offsetY): | ||
handle.y = localY - offsetY; | ||
onHandleMove(); | ||
case DRAG_BG: | ||
handle.y = localY - handle.height / 2; | ||
onHandleMove(); | ||
} | ||
} | ||
|
||
function onHandleMove() | ||
{ | ||
if (handle.y < 0) | ||
handle.y = 0; | ||
|
||
if (handle.y > bg.height - handle.height) | ||
handle.y = bg.height - handle.height; | ||
|
||
target.scrollY = handle.y / (bg.height - handle.height) * target.maxScrollY; | ||
} | ||
|
||
public function resize(height:Float) | ||
{ | ||
bg.height = height; | ||
handle.height = height / target.height * target.viewHeight; | ||
onViewChange(); | ||
} | ||
|
||
function onViewChange() | ||
{ | ||
mouseEnabled = mouseChildren = visible = target.maxScrollY > 0 && target.maxScrollY < target.height; | ||
handle.y = (target.scrollY / target.maxScrollY) * (bg.height - handle.height); | ||
} | ||
} | ||
|
||
private enum ScrollState | ||
{ | ||
IDLE; | ||
DRAG_HANDLE(offsetY:Float); | ||
DRAG_BG; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package flixel.system.debug.interaction.tools; | ||
|
||
import flixel.FlxG; | ||
import flixel.FlxG; | ||
import openfl.display.Graphics; | ||
import openfl.display.BitmapData; | ||
import flixel.system.debug.interaction.Interaction; | ||
// import flixel.system.debug.Tooltip; | ||
|
||
using flixel.util.FlxArrayUtil; | ||
|
||
|
||
/** | ||
* A tool to add selected sprites to the BitmapLog window | ||
* | ||
* @author George | ||
*/ | ||
class LogBitmap extends Tool | ||
{ | ||
override function init(brain:Interaction):Tool | ||
{ | ||
super.init(brain); | ||
|
||
_name = "Log selected bitmaps"; | ||
setButton(Icon.bitmapLog); | ||
button.toggleMode = false; | ||
|
||
// _tooltip = Tooltip.add(null, ""); | ||
// _tooltip.textField.wordWrap = false; | ||
|
||
return this; | ||
} | ||
|
||
override function update():Void | ||
{ | ||
button.enabled = _brain.selectedItems.countLiving() > 0; | ||
button.mouseEnabled = button.enabled; | ||
button.alpha = button.enabled ? 0.3 : 0.1; | ||
} | ||
|
||
override function onButtonClicked() | ||
{ | ||
#if FLX_DEBUG // needed for coverage tests | ||
// super.onButtonClicked(); | ||
if (_brain.selectedItems.length == 0) | ||
return; | ||
|
||
for (member in _brain.selectedItems) | ||
{ | ||
if (member != null && member is FlxSprite) | ||
{ | ||
final sprite:FlxSprite = cast member; | ||
FlxG.bitmapLog.add(sprite.graphic); | ||
} | ||
} | ||
#end | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package flixel.system.debug.interaction.tools; | ||
|
||
import flixel.FlxG; | ||
import flixel.math.FlxRect; | ||
import flixel.system.debug.interaction.Interaction; | ||
import openfl.display.Graphics; | ||
import openfl.display.BitmapData; | ||
|
||
using flixel.util.FlxArrayUtil; | ||
|
||
/** | ||
* A tool to open a tracker for the selected object | ||
* | ||
* @author George | ||
*/ | ||
class TrackObject extends Tool | ||
{ | ||
override function init(brain:Interaction):Tool | ||
{ | ||
super.init(brain); | ||
|
||
_name = "Track object"; | ||
setButton(Icon.watch); | ||
button.toggleMode = true; | ||
|
||
setCursor(Icon.watch, -5, -5); | ||
|
||
return this; | ||
} | ||
|
||
#if FLX_DEBUG | ||
override function update():Void | ||
{ | ||
if (isActive() && _brain.pointerJustPressed) | ||
{ | ||
final rect = FlxRect.get(_brain.flixelPointer.x, _brain.flixelPointer.y, 1, 1); | ||
final item = _brain.getTopItemWithinState(FlxG.state, rect); | ||
if (item != null) | ||
{ | ||
FlxG.debugger.track(item); | ||
_brain.selectedItems.clear(); | ||
_brain.selectedItems.add(item); | ||
} | ||
rect.put(); | ||
} | ||
} | ||
#end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.