Skip to content

Commit

Permalink
use screenLeft / screenTop from core
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Oct 7, 2024
1 parent fdd337f commit 3da709c
Showing 1 changed file with 29 additions and 38 deletions.
67 changes: 29 additions & 38 deletions haxe/ui/backend/ComponentImpl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -91,32 +91,19 @@ class ComponentImpl extends ComponentBase {
if (_cachedScreenX != null && _cachedScreenY != null) {
return;
}

var c:Component = asComponent;
var xpos:Float = 0;
var ypos:Float = 0;
while (c != null) {
xpos += c.left;
ypos += c.top;
if (c.componentClipRect != null) {
xpos -= c.componentClipRect.left;
ypos -= c.componentClipRect.top;
}
c = c.parentComponent;
}

_cachedScreenX = xpos * Toolkit.scaleX;
_cachedScreenY = ypos * Toolkit.scaleY;
var screenBounds = asComponent.screenBounds;
_cachedScreenX = screenBounds.left;
_cachedScreenY = screenBounds.top;
}

private var screenX(get, null):Float;
private function get_screenX():Float {
private var cachedScreenX(get, null):Float;
private function get_cachedScreenX():Float {
cacheScreenPos();
return _cachedScreenX;
}

private var screenY(get, null):Float;
private function get_screenY():Float {
private var cachedScreenY(get, null):Float;
private function get_cachedScreenY():Float {
cacheScreenPos();
return _cachedScreenY;
}
Expand Down Expand Up @@ -172,8 +159,8 @@ class ComponentImpl extends ComponentBase {
}

var b:Bool = false;
var sx = screenX;
var sy = screenY;
var sx = cachedScreenX;
var sy = cachedScreenY;
var cx = asComponent.componentWidth * Toolkit.scaleX;
var cy = asComponent.componentHeight * Toolkit.scaleY;

Expand All @@ -186,8 +173,8 @@ class ComponentImpl extends ComponentBase {
var clip:Component = findClipComponent();
if (clip != null) {
b = false;
var sx = (clip.screenX + (clip.componentClipRect.left * Toolkit.scaleX));
var sy = (clip.screenY + (clip.componentClipRect.top * Toolkit.scaleY));
var sx = (clip.cachedScreenX + (clip.componentClipRect.left * Toolkit.scaleX));
var sy = (clip.cachedScreenY + (clip.componentClipRect.top * Toolkit.scaleY));
var cx = clip.componentClipRect.width * Toolkit.scaleX;
var cy = clip.componentClipRect.height * Toolkit.scaleY;
if (x >= sx && y >= sy && x <= sx + cx && y < sy + cy) {
Expand All @@ -205,10 +192,10 @@ class ComponentImpl extends ComponentBase {

if (parentComponent == null) {
if (left != null) {
this.x = left;
//this.x = left;
}
if (top != null) {
this.y = top;
//this.y = top;
}
}
}
Expand Down Expand Up @@ -658,23 +645,25 @@ class ComponentImpl extends ComponentBase {
// Util
//***********************************************************************************************************
private function repositionChildren() {
var xpos = this.cachedScreenX;
var ypos = this.cachedScreenY;
if (_surface != null) {
_surface.x = this.screenX;
_surface.y = this.screenY;
_surface.x = xpos;
_surface.y = ypos;
}

if (_textDisplay != null) {
var offsetX = 2 / Toolkit.scaleX;
var offsetY = 2 / Toolkit.scaleY;
_textDisplay.tf.x = _surface.x + _textDisplay.left - offsetX;
_textDisplay.tf.y = _surface.y + _textDisplay.top - offsetY;
_textDisplay.tf.x = xpos + _textDisplay.left - offsetX;
_textDisplay.tf.y = ypos + _textDisplay.top - offsetY;
}

if (_textInput != null) {
var offsetX = 2 / Toolkit.scaleX;
var offsetY = 2 / Toolkit.scaleY;
_textInput.x = (_surface.x + _textInput.left - offsetX);
_textInput.y = (_surface.y + _textInput.top - offsetY);
_textInput.x = (xpos + _textInput.left - offsetX);
_textInput.y = (ypos + _textInput.top - offsetY);
_textInput.scaleX = FlxG.scaleMode.scale.x;
_textInput.scaleY = FlxG.scaleMode.scale.y;
_textInput.update();
Expand All @@ -683,14 +672,14 @@ class ComponentImpl extends ComponentBase {
if (_imageDisplay != null) {
var offsetX = 0;
var offsetY = 0;
_imageDisplay.x = _surface.x + _imageDisplay.left - offsetX;
_imageDisplay.y = _surface.y + _imageDisplay.top - offsetY;
_imageDisplay.x = xpos + _imageDisplay.left - offsetX;
_imageDisplay.y = ypos + _imageDisplay.top - offsetY;
}

if (_unsolicitedMembers != null) {
for (m in _unsolicitedMembers) {
m.sprite.x = m.originalX + this.screenX;
m.sprite.y = m.originalY + this.screenY;
m.sprite.x = m.originalX + this.cachedScreenX;
m.sprite.y = m.originalY + this.cachedScreenY;
}
}
}
Expand Down Expand Up @@ -921,19 +910,21 @@ class ComponentImpl extends ComponentBase {
_destroy = true;
}

/*
private override function set_x(value:Float):Float {
var r = super.set_x(value);
if (this.parentComponent == null && _surface != null) {
this.left = value;
//this.left = value;
}
return r;
}
private override function set_y(value:Float):Float {
var r = super.set_y(value);
if (this.parentComponent == null && _surface != null) {
this.top = value;
//this.top = value;
}
return r;
}
*/
}

0 comments on commit 3da709c

Please sign in to comment.