Skip to content

Commit

Permalink
Simplify and fix mouseEnabled logic. Add hitEnabled to allow easy blo…
Browse files Browse the repository at this point in the history
…cking of all hit tests.
  • Loading branch information
hughsando committed Jun 22, 2015
1 parent 74d4739 commit 9ba31ef
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 78 deletions.
3 changes: 3 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

* Respect the flash meaning of mouseEnabled, and add hitEnabled to ignore hit tests

--------------------------
* Use async callback to fill ogg buffers (stops sound stutter in ios)

5.4
Expand Down
2 changes: 1 addition & 1 deletion haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"tags": [ "cpp", "neko", "nme", "opengl", "sdl", "android", "ios" ],
"description": "NME provides a backend for native iOS, Android, Windows, Mac and Linux applications, using a Flash inspired API",
"version": "5.4.0",
"binaryversion": "65",
"binaryversion": "66",
"releasenote": "see Changes.md",
"contributors": [ "gamehaxe" ],
"dependencies": {}
Expand Down
11 changes: 11 additions & 0 deletions nme/display/DisplayObject.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class DisplayObject extends EventDispatcher implements IBitmapDrawable
public var filters(get_filters, set_filters):Array<Dynamic>;
public var graphics(get_graphics, null):Graphics;
public var height(get_height, set_height):Float;
public var hitEnabled(get,set):Bool;
public var loaderInfo:LoaderInfo;
public var mask(default, set_mask):DisplayObject;
public var mouseX(get_mouseX, null):Float;
Expand Down Expand Up @@ -76,6 +77,14 @@ class DisplayObject extends EventDispatcher implements IBitmapDrawable
return result;
}


private function get_hitEnabled():Bool { return nme_display_object_get_hit_enabled(nmeHandle); }
private function set_hitEnabled(inVal:Bool):Bool
{
nme_display_object_set_hit_enabled(nmeHandle, inVal);
return inVal;
}

public function getBounds(targetCoordinateSpace:DisplayObject):Rectangle
{
var result = new Rectangle();
Expand Down Expand Up @@ -601,6 +610,8 @@ class DisplayObject extends EventDispatcher implements IBitmapDrawable
private static var nme_display_object_get_pixel_bounds = Loader.load("nme_display_object_get_pixel_bounds", 2);
private static var nme_display_object_get_bounds = Loader.load("nme_display_object_get_bounds", 4);
private static var nme_display_object_hit_test_point = Loader.load("nme_display_object_hit_test_point", 5);
private static var nme_display_object_get_hit_enabled = Loader.load("nme_display_object_get_hit_enabled", 1);
private static var nme_display_object_set_hit_enabled = Loader.load("nme_display_object_set_hit_enabled", 2);
private static var nme_doc_add_child = Loader.load("nme_doc_add_child", 2);
}

Expand Down
3 changes: 3 additions & 0 deletions project/include/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class DisplayObject : public Object
uint32 getOpaqueBackground() { return opaqueBackground; }
bool getMouseEnabled() { return mouseEnabled; }
void setMouseEnabled(bool inVal) { mouseEnabled = inVal; }
bool getHitEnabled() { return hitEnabled; }
void setHitEnabled(bool inVal) { hitEnabled = inVal; }
bool getNeedsSoftKeyboard() { return needsSoftKeyboard; }
void setNeedsSoftKeyboard(bool inVal) { needsSoftKeyboard = inVal; }
bool getMovesForSoftKeyboard() { return movesForSoftKeyboard; }
Expand Down Expand Up @@ -156,6 +158,7 @@ class DisplayObject : public Object
int id;
bool visible;
bool mouseEnabled;
bool hitEnabled;
bool needsSoftKeyboard;
bool movesForSoftKeyboard;

Expand Down
3 changes: 3 additions & 0 deletions project/include/TextField.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class TextField : public DisplayObject
public:
TextField(bool inInitRef=false);

bool IsInteractive() const { return true; }


void appendText(WString inString);
Rect getCharBoundaries(int inCharIndex);
int getCharIndexAtPoint(double x, double y);
Expand Down
131 changes: 55 additions & 76 deletions project/src/common/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ DisplayObject::DisplayObject(bool inInitRef) : Object(inInitRef)
pixelSnapping = psNone;
opaqueBackground = 0;
mouseEnabled = true;
hitEnabled = true;
needsSoftKeyboard = false;
mMask = 0;
mIsMaskCount = 0;
Expand Down Expand Up @@ -199,7 +200,7 @@ void DisplayObject::SetBitmapCache(BitmapCache *inCache)

void DisplayObject::Render( const RenderTarget &inTarget, const RenderState &inState )
{
if (inState.mPhase==rpHitTest && !mouseEnabled )
if (inState.mPhase==rpHitTest && !hitEnabled )
return;

if (mGfx && inState.mPhase!=rpBitmap)
Expand All @@ -218,24 +219,14 @@ void DisplayObject::Render( const RenderTarget &inTarget, const RenderState &inS
state.mTransform.mMatrix = &unscaled;

hit = mGfx->Render(inTarget,state);

if (IsInteractive())
inState.mHitResult = state.mHitResult;
else
inState.mHitResult = state.mHitResult != NULL ? mParent : NULL;
}
else if (mGfx)
{
hit = mGfx->Render(inTarget,inState);
}

if (hit)
{
if (IsInteractive())
inState.mHitResult = this;
else
inState.mHitResult = mParent;
}
if (hit && inState.mPhase==rpHitTest)
inState.mHitResult = this;
}
else if (inState.mPhase==rpBitmap && inState.mWasDirtyPtr && !*inState.mWasDirtyPtr)
{
Expand Down Expand Up @@ -774,7 +765,7 @@ void SimpleButton::Render( const RenderTarget &inTarget, const RenderState &inSt
{
if (inState.mPhase==rpHitTest)
{
if (!mouseEnabled)
if (!hitEnabled)
return;
if (mState[stateHitTest])
{
Expand Down Expand Up @@ -1133,11 +1124,20 @@ void DisplayObjectContainer::Render( const RenderTarget &inTarget, const RenderS
BitmapCache *orig_mask = inState.mMask;
if (!inState.mRecurse)
last = first;


bool mouseDisabledObjectHit = false;

for(int i=first; i!=last; i+=dir)
{
DisplayObject *obj = mChildren[i];
//printf("Render phase = %d, parent = %d, child = %d\n", inState.mPhase, id, obj->id);
if (!obj->visible || (inState.mPhase!=rpCreateMask && obj->IsMask()) )
if (!obj->visible || (inState.mPhase!=rpCreateMask && obj->IsMask()) ||
(inState.mPhase==rpHitTest && !obj->hitEnabled) )
continue;

// Already found a diabled one - no need to look at others
if (mouseDisabledObjectHit && !obj->mouseEnabled)
continue;

RenderState *obj_state = &state;
Expand Down Expand Up @@ -1335,93 +1335,72 @@ void DisplayObjectContainer::Render( const RenderTarget &inTarget, const RenderS
obj->Render(inTarget,*obj_state);
}
}
// Not rpBitmap ...
else
{
if ( (obj->IsBitmapRender(inTarget.IsHardware()) && inState.mPhase!=rpHitTest) )
{
if (inState.mPhase==rpRender)
{
obj->RenderBitmap(inTarget,*obj_state);
}
/* HitTest is done on vector, not bitmap
else if (inState.mPhase==rpHitTest && obj->IsBitmapRender() )
{
if (obj->HitBitmap(inTarget,*obj_state))
{
inState.mHitResult = obj;
return;
}
}
*/
}
else
// Can just test the rect?
else if (obj->opaqueBackground && inState.mPhase==rpHitTest && !obj->scrollRect.HasPixels())
{
if (inState.mHitResult==this && !obj->IsInteractive())
continue;

if (obj->opaqueBackground)
Rect rect = clip_state.mClipRect;
if ( !obj->scrollRect.HasPixels() )
{
Rect rect = clip_state.mClipRect;
if ( !obj->scrollRect.HasPixels() )
{
// TODO: this should actually be a rectangle rotated like the object?
Extent2DF screen_extent;
obj->GetExtent(obj_state->mTransform,screen_extent,true,true);
// Get bounding pixel rect
rect = obj_state->mTransform.GetTargetRect(screen_extent);

// Intersect with clip rect ...
rect = rect.Intersect(obj_state->mClipRect);
}

if (rect.HasPixels())
{
if (inState.mPhase == rpHitTest && obj->mouseEnabled)
{
if (obj->IsInteractive())
{
inState.mHitResult = obj;
return;
}
else
{
inState.mHitResult = this;
continue;
}
}
else if (inState.mPhase == rpRender )
inTarget.Clear(obj->opaqueBackground,rect);
}
else if (inState.mPhase == rpHitTest)
{
continue;
}
// TODO: this should actually be a rectangle rotated like the object?
Extent2DF screen_extent;
obj->GetExtent(obj_state->mTransform,screen_extent,true,true);
// Get bounding pixel rect
rect = obj_state->mTransform.GetTargetRect(screen_extent);

// Intersect with clip rect ...
rect = rect.Intersect(obj_state->mClipRect);
}

if (rect.HasPixels())
obj_state->mHitResult = obj;
}
else
{
if (inState.mPhase==rpRender)
obj_state->CombineColourTransform(inState,&obj->colorTransform,&col_trans);

obj->Render(inTarget,*obj_state);
}

if (obj_state->mHitResult)
if (obj_state->mHitResult && inState.mPhase==rpHitTest)
{
if(mouseChildren && obj_state->mHitResult->mouseEnabled && obj_state->mHitResult != NULL)
inState.mHitResult = obj_state->mHitResult;
else if(mouseEnabled)
inState.mHitResult = this;

if (inState.mHitResult!=this)
if (!obj_state->mHitResult->mouseEnabled)
{
// Objects underneath a mouseEnabled=false object will register the hit
// first (hmm) - but if there is none, then the hit will be attributed to the
// parent object (this)
mouseDisabledObjectHit = true;
}
else
{
inState.mHitResult = obj_state->mHitResult;
// Child has been hit - should we steal the hit?
if (!inState.mHitResult->IsInteractive() || !mouseChildren)
inState.mHitResult = this;
return;
}
}
}
}

if (inState.mPhase==rpHitTest && inState.mHitResult==this)

if (mouseDisabledObjectHit)
{
inState.mHitResult = this;
return;
}

// Render parent at beginning or end...
if (!parent_first)
DisplayObject::Render(inTarget,inState);

}

void DisplayObjectContainer::GetExtent(const Transform &inTrans, Extent2DF &outExt,bool inForScreen,bool inIncludeStroke)
Expand Down
1 change: 1 addition & 0 deletions project/src/common/ExternalInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2306,6 +2306,7 @@ DO_DISPLAY_PROP(name,Name,alloc_wstring,val2stdwstr)
DO_DISPLAY_PROP(blend_mode,BlendMode,alloc_int,val_int)
DO_DISPLAY_PROP(needs_soft_keyboard,NeedsSoftKeyboard,alloc_bool,val_bool)
DO_DISPLAY_PROP(moves_for_soft_keyboard,MovesForSoftKeyboard,alloc_bool,val_bool)
DO_DISPLAY_PROP(hit_enabled,HitEnabled,alloc_bool,val_bool)
DO_PROP_READ(DisplayObject,display_object,mouse_x,MouseX,alloc_float)
DO_PROP_READ(DisplayObject,display_object,mouse_y,MouseY,alloc_float)

Expand Down
2 changes: 1 addition & 1 deletion project/src/common/TextField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ void TextField::Render( const RenderTarget &inTarget, const RenderState &inState
if (inTarget.mPixelFormat==pfAlpha || inState.mPhase==rpBitmap)
return;

if (inState.mPhase==rpHitTest && !mouseEnabled )
if (inState.mPhase==rpHitTest && !hitEnabled )
return;

const Matrix &matrix = *inState.mTransform.mMatrix;
Expand Down

0 comments on commit 9ba31ef

Please sign in to comment.