Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Geokureli committed Dec 9, 2024
2 parents 822c55f + b94d693 commit f5fa45a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 21 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,8 @@ A Check Box is a FlxUIGroup which contains three objects: a "box" image, a "chec

Attributes:
* ```x```/```y```, ```use_def```, ```group```
* ```check_src``` - source image for box (not 9-sliceable, not scaleable)
* ```box_src``` - source image for check mark (not 9-sliceable, not scaleable)
* ```check_src``` - source image for check mark (not 9-sliceable, not scaleable)
* ```box_src``` - source image for box (not 9-sliceable, not scaleable)
* ```text_x``` / ```text_y``` - label offsets
* ```label``` - text to show
* ```context``` - FireTongue context (see Button)
Expand All @@ -624,8 +624,8 @@ Child tags:
*If you supply ```<check>``` or ```<box>``` child tags instead of their attribute equivalents, FlxUI will treat them as full-fledged ```<sprite>``` or ```<chrome>``` tags to load for the checkmark and box assets. You'll want to use this method if you want to do something complicated, like load a scaled sprite, or a 9-slice-scaled sprite, that you can't normally accomplish with the src attributes, which just load a static image as-is.

Event:
* name - "click_checkbox"
* params - as defined by user, but with this one automatically added to the list at the end: "checked:true" or "checked:false"
* name - "click_check_box"
* params - as defined by user, but with this one automatically added to the list at the end: ```{name:"checked", value:false}``` or ```{name:"checked", value:true}```

## 7. Text (FlxUIText) ```<text>```

Expand Down
73 changes: 57 additions & 16 deletions flixel/addons/ui/FlxInputText.hx
Original file line number Diff line number Diff line change
Expand Up @@ -272,22 +272,49 @@ class FlxInputText extends FlxText
}

/**
* Draw the caret in addition to the text.
* Draw the background, border and caret in addition to the text.
*/
override public function draw():Void
{
regenGraphic();
checkEmptyFrame();

if (alpha == 0 || _frame.type == EMPTY)
return;

if (dirty) // rarely
calcFrame(useFramePixels);

drawSprite(fieldBorderSprite);
drawSprite(backgroundSprite);

super.draw();


for (camera in getCamerasLegacy())
{
if (!camera.visible || !camera.exists || !isOnScreen(camera))
continue;

if (isSimpleRender(camera))
drawSimple(camera);
else
drawComplex(camera);

#if FLX_DEBUG
FlxBasic.visibleCount++;
#end
}

// In case caretColor was changed
if (caretColor != caret.color || caret.height != size + 2)
{
caret.color = caretColor;
}

drawSprite(caret);

#if FLX_DEBUG
if (FlxG.debugger.drawDebug)
drawDebug();
#end
}

/**
Expand Down Expand Up @@ -690,8 +717,9 @@ class FlxInputText extends FlxText
// Generate the properly sized caret and also draw a border that matches that of the textfield (if a border style is set)
// borderQuality can be safely ignored since the caret is always a rectangle

final caretHeight = Std.int(size + 2);
var cw:Int = caretWidth; // Basic size of the caret
var ch:Int = Std.int(size + 2);
var ch:Int = caretHeight;

// Make sure alpha channels are correctly set
var borderC:Int = (0xff000000 | (borderColor & 0x00ffffff));
Expand All @@ -705,29 +733,42 @@ class FlxInputText extends FlxText
// No border, just make the caret
caret.makeGraphic(cw, ch, caretC, false, caretKey);
caret.offset.x = caret.offset.y = 0;

case SHADOW:
// Shadow offset to the lower-right
cw += Std.int(borderSize);
ch += Std.int(borderSize); // expand canvas on one side for shadow
final absSize = Math.abs(borderSize);
cw += Std.int(absSize);
ch += Std.int(absSize); // expand canvas on one side for shadow
caret.makeGraphic(cw, ch, FlxColor.TRANSPARENT, false, caretKey); // start with transparent canvas
var r:Rectangle = new Rectangle(borderSize, borderSize, caretWidth, Std.int(size + 2));
final r:Rectangle = new Rectangle(absSize, absSize, caretWidth, caretHeight);
caret.pixels.fillRect(r, borderC); // draw shadow
r.x = r.y = 0;
caret.pixels.fillRect(r, caretC); // draw caret
caret.offset.x = caret.offset.y = 0;


case SHADOW_XY(shadowX, shadowY):
// Shadow offset to the lower-right
cw += Std.int(Math.abs(shadowX));
ch += Std.int(Math.abs(shadowY)); // expand canvas on one side for shadow
caret.makeGraphic(cw, ch, FlxColor.TRANSPARENT, false, caretKey); // start with transparent canvas
final r:Rectangle = new Rectangle(Math.max(0, shadowX), Math.max(0, shadowY), caretWidth, caretHeight);
caret.pixels.fillRect(r, borderC); // draw shadow
r.x -= shadowX;
r.y -= shadowY;
caret.pixels.fillRect(r, caretC); // draw caret
caret.offset.x = shadowX < 0 ? -shadowX : 0;
caret.offset.y = shadowY < 0 ? -shadowY : 0;

case OUTLINE_FAST, OUTLINE:
// Border all around it
cw += Std.int(borderSize * 2);
ch += Std.int(borderSize * 2); // expand canvas on both sides
final absSize = Math.abs(borderSize);
cw += Std.int(absSize * 2);
ch += Std.int(absSize * 2); // expand canvas on both sides
caret.makeGraphic(cw, ch, borderC, false, caretKey); // start with borderColor canvas
var r = new Rectangle(borderSize, borderSize, caretWidth, Std.int(size + 2));
final r = new Rectangle(absSize, absSize, caretWidth, caretHeight);
caret.pixels.fillRect(r, caretC); // draw caret
// we need to offset caret's drawing position since the caret is now larger than normal
caret.offset.x = caret.offset.y = borderSize;

case _: //temp fix for 5.9.0
caret.offset.x = caret.offset.y = absSize;
}
// Update width/height so caret's dimensions match its pixels
caret.width = cw;
Expand Down
2 changes: 1 addition & 1 deletion flixel/addons/ui/FlxUICheckBox.hx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class FlxUICheckBox extends FlxUIGroup implements ILabeled implements IFlxUIClic
{
params = [];
}
var nb:NamedBool = {name: "checked", value: false};
var nb:NamedBool = {name: "checked", value: checked};
params.push(nb);
return params;
}
Expand Down

0 comments on commit f5fa45a

Please sign in to comment.