Skip to content

Commit

Permalink
Fix #66 "Make StablexUI working"
Browse files Browse the repository at this point in the history
  • Loading branch information
ngrebenshikov committed Oct 27, 2014
1 parent b32e312 commit 18320e6
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 95 deletions.
35 changes: 10 additions & 25 deletions openfl/Assets.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,7 @@ class Assets {

macro public static function embedBitmap ():Array<Field> {

#if (html5 && !openfl_html5_dom)
#if (html5 && !openfl_snapsvg)
var fields = embedData (":bitmap", true);
#else
var fields = embedData (":bitmap");
Expand All @@ -1527,14 +1527,13 @@ class Assets {
var constructor = macro {

#if html5
#if openfl_html5_dom
#if openfl_snapsvg

super (width, height, transparent, fillRGBA);

var currentType = Type.getClass (this);

if (preload != null) {

___textureBuffer.width = Std.int (preload.width);
___textureBuffer.height = Std.int (preload.height);
rect = new openfl.geom.Rectangle (0, 0, preload.width, preload.height);
Expand All @@ -1544,15 +1543,10 @@ class Assets {
} else {

var byteArray = openfl.utils.ByteArray.fromBytes (haxe.Resource.getBytes(resourceName));

if (onload != null && !Std.is (onload, Bool)) {

__loadFromBytes(byteArray, null, onload);

} else {

__loadFromBytes(byteArray);

}

}
Expand All @@ -1562,27 +1556,18 @@ class Assets {
super (0, 0, transparent, fillRGBA);

if (preload != null) {

__sourceImage = preload;
width = __sourceImage.width;
height = __sourceImage.height;

__sourceCanvas = preload.__sourceCanvas;
width = preload.__sourceCanvas.width;
height = preload.__sourceCanvas.height;
} else {

__loadFromBase64 (haxe.Resource.getString(resourceName), resourceType, function (b) {

if (preload == null) {

preload = b.__sourceImage;

}

if (onload != null) {

onload (b);

}

if (preload == null) {
preload = b;
}
});

}
Expand All @@ -1603,7 +1588,7 @@ class Assets {

#if html5
args.push ({ name: "onload", opt: true, type: macro :Dynamic, value: null });
#if openfl_html5_dom
#if openfl_snapsvg
fields.push ({ kind: FVar(macro :openfl.display.BitmapData, null), name: "preload", doc: null, meta: [], access: [ APublic, AStatic ], pos: Context.currentPos() });
#else
fields.push ({ kind: FVar(macro :js.html.Image, null), name: "preload", doc: null, meta: [], access: [ APublic, AStatic ], pos: Context.currentPos() });
Expand Down Expand Up @@ -1696,7 +1681,7 @@ class Assets {

super();

#if openfl_html5_dom
#if openfl_snapsvg
nmeFromBytes (haxe.Resource.getBytes (resourceName));
#else
__fromBytes (haxe.Resource.getBytes (resourceName));
Expand Down
24 changes: 12 additions & 12 deletions openfl/display/Bitmap.hx
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,13 @@ class Bitmap extends DisplayObject {

override public function __render (inMask:SnapElement = null, clipRect:Rectangle = null):Void {

if (!__combinedVisible) return;
if (bitmapData == null) return;

if (!__combinedVisible || bitmapData == null) return;

if (_matrixInvalid || _matrixChainInvalid) {

__validateMatrix ();

}
var imageDataLease = bitmapData.__getLease ();

var imageDataLease = bitmapData.__getLease ();
if (imageDataLease != null && (__currentLease == null || imageDataLease.seed != __currentLease.seed || imageDataLease.time != __currentLease.time)) {
var srcCanvas: CanvasElement = bitmapData.handle ();
var child = snap.select('*');
Expand All @@ -170,21 +167,24 @@ class Bitmap extends DisplayObject {
handleGraphicsUpdated (null);
}
//TODO: uncomment
if (inMask != null) {
// if (inMask != null) {
//
// __applyFilters (__graphics.__surface);
// var m = getBitmapSurfaceTransform (__graphics);
// Lib.__drawToSurface (__graphics.__surface, inMask, m, (parent != null ? parent.__combinedAlpha : 1) * alpha, clipRect, smoothing);
//
} else {
if (__testFlag (DisplayObject.TRANSFORM_INVALID)) {
// } else {
if (__testFlag(DisplayObject.TRANSFORM_INVALID)) {
var m = getSurfaceTransform ();
__setTransform (m);
__clearFlag (DisplayObject.TRANSFORM_INVALID);
__clearFlag(DisplayObject.TRANSFORM_INVALID);
}
var el: Element = cast(snap.node);
el.setAttribute('opacity', Std.string(alpha));
}
var alphaStr = Std.string(alpha);
if (el.getAttribute('opacity') != alphaStr) {
el.setAttribute('opacity', alphaStr);
}
// }
//updateClipRect();
}

Expand Down
27 changes: 8 additions & 19 deletions openfl/display/BitmapData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1362,9 +1362,7 @@ class BitmapData implements IBitmapDrawable {


public inline function __getLease ():ImageDataLease {

return __lease;

}


Expand All @@ -1374,19 +1372,19 @@ class BitmapData implements IBitmapDrawable {
var canvas = ___textureBuffer;

var drawImage = function (_) {

canvas.width = img.width;
canvas.height = img.height;

var ctx = canvas.getContext ('2d');
ctx.drawImage (img, 0, 0);

rect = new Rectangle (0, 0, canvas.width, canvas.height);

__buildLease ();

__sourceImage = cast(img);

if (onload != null) {

onload (this);

}

}
Expand Down Expand Up @@ -1530,15 +1528,10 @@ class BitmapData implements IBitmapDrawable {
if (image.complete) { }

}





// Event Handlers





private function __onLoad (data:LoadData, e) {

var canvas:CanvasElement = cast data.texture;
Expand All @@ -1551,6 +1544,8 @@ class BitmapData implements IBitmapDrawable {

var ctx:CanvasRenderingContext2D = canvas.getContext ("2d");
ctx.drawImage (data.image, 0, 0, width, height);

__sourceImage = cast(data.image);

data.bitmapData.width = width;
data.bitmapData.height = height;
Expand All @@ -1569,14 +1564,8 @@ class BitmapData implements IBitmapDrawable {

}




// Getters & Setters




private inline function get_height ():Int {

if ( ___textureBuffer != null ) {
Expand Down
14 changes: 7 additions & 7 deletions openfl/display/DisplayObject.hx
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,7 @@ class DisplayObject extends EventDispatcher implements IBitmapDrawable {


private inline function __clearFlag (mask:Int):Void {

___renderFlags &= ~mask;

}


Expand Down Expand Up @@ -626,21 +624,23 @@ class DisplayObject extends EventDispatcher implements IBitmapDrawable {

var fullAlpha:Float = (parent != null ? parent.__combinedAlpha : 1) * alpha;

if (inMask != null) {
// if (inMask != null) {
//TODO: uncomment
// var m = getSurfaceTransform (gfx);
// Lib.__drawToSurface (gfx.__surface, inMask, m, fullAlpha, clipRect);
} else {
// } else {

if (__testFlag (TRANSFORM_INVALID)) {

var m = getSurfaceTransform ();
__setTransform (m);
__clearFlag (TRANSFORM_INVALID);
}
var el: Element = cast(snap.node);
el.setAttribute('opacity', Std.string(alpha));
}
var alphaStr = Std.string(alpha);
if (el.getAttribute('opacity') != alphaStr) {
el.setAttribute('opacity', alphaStr);
}
// }

if (null != clipRect) {
updateClipRect(clipRect);
Expand Down
1 change: 0 additions & 1 deletion openfl/display/DisplayObjectContainer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@ class DisplayObjectContainer extends InteractiveObject {
if (child.__visible) {
if (clipRect != null) {
if (child._matrixInvalid || child._matrixChainInvalid) {
//child.invalidateGraphics ();
child.__validateMatrix ();
}
}
Expand Down
13 changes: 9 additions & 4 deletions openfl/display/Graphics.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1092,11 +1092,12 @@ class Graphics {


private function __addStrokeAttribute(element: SnapElement, lineJob: LineJob):Void {
var htmlElement: Element = cast(element.node);
if(lineJob != null){
if(lineJob.grad == null){
element.attr({stroke: createCanvasColor(lineJob.colour, lineJob.alpha)});
if (lineJob.grad == null) {
htmlElement.setAttribute('stroke', createCanvasColor(lineJob.colour, lineJob.alpha));
} else {
element.attr({stroke: createCanvasGradient(lineJob.grad)});
element.attr({ stroke: createCanvasGradient(lineJob.grad)});
}
element.attr({
'stroke-width': lineJob.thickness,
Expand All @@ -1122,7 +1123,7 @@ class Graphics {
}
});
} else {
element.attr({ stroke: "none" });
htmlElement.setAttribute('stroke', 'none');
}
}

Expand Down Expand Up @@ -1240,6 +1241,10 @@ class Graphics {

__snap.append(circle);
case SnapDrawable.RECT(x, y, width, height, rx, ry):
if (x < 0) x = 0;
if (y < 0) y = 0;
if (width < 0) width = 0;
if (height < 0) height = 0;
var rect: SnapElement = Lib.snap.rect(x, y, width, height, rx, ry);

__addStrokeAttribute(rect, d.lineJobs.length == 1 ? d.lineJobs[0] : null);
Expand Down
4 changes: 2 additions & 2 deletions openfl/display/Stage.hx
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,10 @@ class Stage extends DisplayObjectContainer {
}
__uIEventsQueueIndex = 0;

this.dispatchEvent(new Event(Event.ENTER_FRAME));
__broadcast(new Event(Event.ENTER_FRAME));

if (__invalid) {
this.dispatchEvent(new Event(Event.RENDER));
__broadcast(new Event(Event.RENDER));
}
this.__renderAll ();
this.dispatchEvent(new Event(Event.STAGE_RENDERED));
Expand Down
8 changes: 4 additions & 4 deletions openfl/events/EventDispatcher.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class EventDispatcher implements IEventDispatcher {


public function addEventListener (type:String, inListener:Dynamic -> Void, useCapture:Bool = false, inPriority:Int = 0, useWeakReference:Bool = false):Void {
var stage = Lib.__getStage();
if ((type == Event.RENDER || type == Event.ENTER_FRAME || type == Event.STAGE_RENDERED) && null != stage && this != stage) {
return stage.addEventListener(type, inListener, useCapture, inPriority, useWeakReference);
}
// var stage = Lib.__getStage();
// if ((type == Event.RENDER || type == Event.ENTER_FRAME || type == Event.STAGE_RENDERED) && null != stage && this != stage) {
// return stage.addEventListener(type, inListener, useCapture, inPriority, useWeakReference);
// }

var capture:Bool = (useCapture == null ? false : useCapture);
var priority:Int = (inPriority==null ? 0 : inPriority);
Expand Down
24 changes: 15 additions & 9 deletions openfl/text/TextField.hx
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,11 @@ class TextField extends InteractiveObject {
char_idx = wrapParagraph(paragraph, wrap, char_idx, mSelStart, mSelEnd);
}

mTextSnap.selectAll("tspan").forEach(function (s) {
s.remove();
}, this);
var textNode = mTextSnap.node;
var spans = [for (i in 0...textNode.childNodes.length) textNode.childNodes.item(i)];
for (s in spans) {
textNode.removeChild(s);
}

var svgBuf: StringBuf = new StringBuf();
var firstParagraph = true;
Expand Down Expand Up @@ -675,7 +677,7 @@ class TextField extends InteractiveObject {
lineWidth += s.rect.width;
}
}
if (paragraph.align == TextFormatAlign.CENTER) {
if (paragraph.align == TextFormatAlign.CENTER && null != startSpan) {
startSpan.startX = Math.floor((mUserWidth - lineWidth)/2);
}

Expand Down Expand Up @@ -1324,11 +1326,11 @@ class TextField extends InteractiveObject {
}


private function get_maxScrollH ():Int { return 0; }
private function get_maxScrollV ():Int { return 0; }
private function get_maxScrollH ():Int { return scrollH; }
private function get_maxScrollV ():Int { return scrollV; }
private function get_multiline ():Bool { return multiline; }
private function set_multiline (value:Bool):Bool { return multiline = value; }
private function get_numLines ():Int { return 0; }
private function get_numLines ():Int { return if (null != mText) 1 else 0; }
private function get_scrollH ():Int { return scrollH; }
private function set_scrollH (value:Int):Int { return scrollH = value; }
private function get_scrollV ():Int { return scrollV; }
Expand All @@ -1349,16 +1351,20 @@ class TextField extends InteractiveObject {


public function set_text (inText:String):String {
mText = Std.string(inText);
if (mText == inText) return inText;

mText = inText;
if (!multiline) {
mText = StringTools.replace(mText, '\n', '');
}

//mHTMLText = inText;
mHTMLMode = false;
RebuildText ();
__invalidateBounds ();
dispatchEvent(new Event(Event.CHANGE));
return mText;

return mText;
}


Expand Down
Loading

0 comments on commit 18320e6

Please sign in to comment.