public override void OnAwake() { base.OnAwake(); var outerContainer = Library.New <DisplayObjectContainer>("OuterContainer"); AddChild(outerContainer); outerContainer.X = outerContainer.Y = 1f; _container = Library.New <DisplayObjectContainer>("Container"); outerContainer.AddChild(_container); _container.Rotation = 30f; var offsetX = ViewportWidth / 50f; var offsetY = ViewportHeight / 50f; for (var suit = 0; suit < 4; suit++) { for (var number = 0; number < 5; number++) { var card = Library.New(_cardSuits[suit] + (number + 1).ToString()); Assert(!_container.Contains(card), "_container should not contain " + card.Name); _container.AddChild(card); Assert(_container.Contains(card), "_container should contain " + card.Name); card.X = offsetX * (suit * 5 + number); card.Y = offsetY * (suit * 5 + number); card.MouseEnabled = true; card.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, onCardPress); card.AddEventListener <MouseEvent>(MouseEvent.MOUSE_UP, onCardRelease); } } }
public override void OnAwake() { base.OnAwake(); var outerContainer = Library.New<DisplayObjectContainer>("OuterContainer"); AddChild (outerContainer); outerContainer.X = outerContainer.Y = 1f; _container = Library.New<DisplayObjectContainer>("Container"); outerContainer.AddChild(_container); _container.Rotation = 30f; var offsetX = ViewportWidth/50f; var offsetY = ViewportHeight/50f; for (var suit = 0; suit < 4; suit++) { for (var number = 0; number < 5; number++) { var card = Library.New (_cardSuits[suit] + (number+1).ToString()); Assert (!_container.Contains(card), "_container should not contain " + card.Name); _container.AddChild(card); Assert (_container.Contains(card), "_container should contain " + card.Name); card.X = offsetX * (suit * 5 + number); card.Y = offsetY * (suit * 5 + number); card.MouseEnabled = true; card.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, onCardPress); card.AddEventListener<MouseEvent>(MouseEvent.MOUSE_UP, onCardRelease); } } }
public override void OnAwake() { base.OnAwake(); var cardContainer = Library.New <DisplayObjectContainer>("CardContainer"); AddEventListener <MouseEvent>(MouseEvent.MOUSE_MOVE, onMouseMove); cardContainer.Y = ViewportHeight * .4f; cardContainer.X = ViewportWidth * -.4f; AddChild(cardContainer); var offsetX = ViewportWidth / 30f; var offsetY = -ViewportHeight / 30f; DisplayObjectContainer lastParent = cardContainer; for (var suit = 0; suit < 4; suit++) { for (var number = 0; number < 5; number++) { var card = Library.New(_cardSuits[suit] + (number + 1).ToString(), "Card" + _cardSuits[suit] + (number + 1).ToString()); lastParent.AddChild(card); lastParent = card; card.X = offsetX; card.Y = offsetY; card.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, onCardPress); card.AddEventListener <MouseEvent>(MouseEvent.MOUSE_MOVE, onCardMouseMove); card.AddEventListener <MouseEvent>(MouseEvent.RELEASE_OUTSIDE, onCardReleaseOutside); } } this.Name = "Mouse Events Stage"; }
private void onCardPress(MouseEvent e) { var me = (MouseEvent)e; var target = (CinchSprite)me.Target; _container.AddChild(target); target.StartDrag(); }
public void Move() { #if DEBUG if (DebugMode) { Debug.Log(string.Format(@"Moving: {0} ", DescribeMoves())); } #endif // TODO: CreatingContentPane pane has already been set from the outside (the caller of this method) // that is because this flag has to be set not only for mover operations, but also for "manual" aditions // so we must rethink if this is to be used also here (it's redundant) List <DisplayListMember> childrenToTransfer = new List <DisplayListMember>(); for (int i = 0; i < _numberOfChildrenToMove; i++) { childrenToTransfer.Add(_docFrom.QChildren[i]); } foreach (DisplayListMember child in childrenToTransfer) { /** * Note: we have to use container's AddChild/RemoveChild stuff, because else the control won't initialize properly and its Visible will be false! // 20130507 * */ if (null != _docFrom) { _docFrom.RemoveChild(child); } if (null != _docTo) { _docTo.AddChild(child); } } #if DEBUG if (DebugMode) { Debug.Log(string.Format(@"Moved: {0} ", DescribeMoves())); } #endif if (null != _docFrom) { _docFrom.InvalidateDrawingList(); } if (null != _docTo) { _docTo.InvalidateDrawingList(); } }
public override void OnAwake() { base.OnAwake(); VerifySizingForEmptyObject(); VerifySizingForEmptyParent(); if (ViewportWidth > ViewportHeight) { ViewportWidth = 10f; } else { ViewportHeight = 10f; } _sizeChart = CinchSprite.NewFromImage("SizeChart", 100f, RegistrationPoint.BottomLeft); _sizeChart.Name = "SizeChart"; _sizeChart.X = ViewportWidth / -2; _sizeChart.Y = ViewportHeight / -2; AddChild(_sizeChart); //give it a weird pixels-per-meter to make sure it's not an even width in meters _earthContainer = Library.New <DisplayObjectContainer>("EarthContainer"); _earthContainer.SetPosition(3, 7); AddChild(_earthContainer); var innerContainer = Library.New <DisplayObjectContainer>("InnerContainer"); _earthContainer.AddChild(innerContainer); var yetAnotherContainer = Library.New <DisplayObjectContainer>("YetAnotherContainer"); innerContainer.AddChild(yetAnotherContainer); var earth = CinchSprite.NewFromImage("Earth", 158f, RegistrationPoint.Center); earth.MouseEnabled = true; earth.Name = "Earth"; earth.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, onEarthPress); yetAnotherContainer.AddChild(earth); //give it a weird pixels-per-meter to make sure it's not an even width in meters _mars = CinchSprite.NewFromImage("Mars", 212f, RegistrationPoint.BottomLeft); _mars.MouseEnabled = true; _mars.Name = "Mars"; _mars.SetPosition(.5f, .5f); _mars.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, onMarsPress); AddChild(_mars); }
private void StartHandler(Event e) { #if DEBUG if (DebugMode) { Debug.Log("StartHandler " + _component.Width + ", " + _component.Height); } #endif if (null != _maskGraphics) { return; // already masking this component } _parent = _component.Parent ?? (_component is Stage ? _component : null); if (null == _parent) { return; // we are not on the display list, so we have nothing to mask indeed } _maskGraphics = new LoadingMaskAnimator { IncludeInLayout = false, X = _component.X, Y = _component.Y, Width = _component.Width, Height = _component.Height, //Bounds = (Rectangle) _component.Bounds.Clone() // BEWARE! This was the reference bug (without Clone())!!!!!!!!! }; _parent.AddChild(_maskGraphics); LoadingEvent le = e as LoadingEvent; if (null != le) { _maskGraphics.Message = le.Message; } // critical! //_maskGraphics.Transform.Apply(); _maskGraphics.InvalidateTransform(); // subscribe to MOVE and RESIZE events of the component // we shall be levitating just over the component _component.AddEventListener(MoveEvent.MOVE, MoveHandler, EventPhase.Target); _component.AddEventListener(ResizeEvent.RESIZE, ResizeHandler, EventPhase.Target); _maskGraphics.Play(); }
public override void OnAwake() { base.OnAwake(); VerifySizingForEmptyObject(); VerifySizingForEmptyParent(); if (ViewportWidth > ViewportHeight) ViewportWidth = 10f; else ViewportHeight = 10f; _sizeChart = CinchSprite.NewFromImage("SizeChart", 100f, RegistrationPoint.BottomLeft); _sizeChart.Name = "SizeChart"; _sizeChart.X = ViewportWidth/-2; _sizeChart.Y = ViewportHeight/-2; AddChild(_sizeChart); //give it a weird pixels-per-meter to make sure it's not an even width in meters _earthContainer = Library.New<DisplayObjectContainer>("EarthContainer"); _earthContainer.SetPosition(3, 7); AddChild(_earthContainer); var innerContainer = Library.New<DisplayObjectContainer>("InnerContainer"); _earthContainer.AddChild(innerContainer); var yetAnotherContainer = Library.New<DisplayObjectContainer>("YetAnotherContainer"); innerContainer.AddChild(yetAnotherContainer); var earth = CinchSprite.NewFromImage("Earth", 158f, RegistrationPoint.Center); earth.MouseEnabled = true; earth.Name = "Earth"; earth.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, onEarthPress); yetAnotherContainer.AddChild(earth); //give it a weird pixels-per-meter to make sure it's not an even width in meters _mars = CinchSprite.NewFromImage("Mars", 212f, RegistrationPoint.BottomLeft); _mars.MouseEnabled = true; _mars.Name = "Mars"; _mars.SetPosition(.5f, .5f); _mars.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, onMarsPress); AddChild(_mars); }
public override void OnAwake() { base.OnAwake(); CinchOptions.UseTopLeftSpriteSheetCoordinates = true; CinchOptions.DefaultPixelsPerMeter = 100f; this.Name = "ParentingStage"; AddSymbolDefinitions(); AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, onStagePress); _everythingContainer = Library.New <DisplayObjectContainer>(); _everythingContainer.Name = "Everything container"; _everythingContainer.MouseEnabled = false; AddChild(_everythingContainer); _table = Library.New("Table"); _table.MouseEnabled = true; ValidateNumberMouseObjects(0); _everythingContainer.AddChild(_table); ValidateNumberMouseObjects(1); _table.Name = "Table"; _table.Width = ViewportWidth * .8f; _table.ScaleY = _table.ScaleX; var checkerBoard = Library.New("CheckerBoard"); _table.AddChild(checkerBoard); checkerBoard.MouseEnabled = true; ValidateNumberMouseObjects(2); checkerBoard.Rotation = 30; checkerBoard.Name = "Checkerboard"; checkerBoard.Y = checkerBoard.Height * .75f; var w = checkerBoard.Width; var h = checkerBoard.Height; var totalCheckers = 0; var isRed = false; for (var __x = -3.5f; __x <= 3f; __x += 1f) { isRed = !isRed; for (var __y = -3.5f; __y <= 3.5f; __y += 1f) { isRed = !isRed; var checker = Library.New(isRed ? "RedChecker" : "BlackChecker"); checker.Width = checker.Height = w / 8; checker.Name = "Checker" + totalCheckers++; checkerBoard.AddChild(checker); checker.MouseEnabled = true; checker.X = w * __x / 8f; checker.Y = h * __y / 8f; checker.AddEventListener <MouseEvent>(MouseEvent.MOUSE_OVER, onAnythingOver); checker.AddEventListener <MouseEvent>(MouseEvent.MOUSE_OUT, onAnythingOut); } } _everythingContainer.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, onAnythingPress); _everythingContainer.AddEventListener <MouseEvent>(MouseEvent.RELEASE_OUTSIDE, onAnythingUpOutside); AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, onStagePress); }
public override void OnAwake() { base.OnAwake(); CinchOptions.UseTopLeftSpriteSheetCoordinates = true; CinchOptions.DefaultPixelsPerMeter = 100f; this.Name = "ParentingStage"; AddSymbolDefinitions(); AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, onStagePress); _everythingContainer = Library.New<DisplayObjectContainer>(); _everythingContainer.Name = "Everything container"; _everythingContainer.MouseEnabled = false; AddChild(_everythingContainer); _table = Library.New ("Table"); _table.MouseEnabled = true; ValidateNumberMouseObjects(0); _everythingContainer.AddChild(_table); ValidateNumberMouseObjects(1); _table.Name = "Table"; _table.Width = ViewportWidth * .8f; _table.ScaleY = _table.ScaleX; var checkerBoard = Library.New ("CheckerBoard"); _table.AddChild(checkerBoard); checkerBoard.MouseEnabled = true; ValidateNumberMouseObjects(2); checkerBoard.Rotation = 30; checkerBoard.Name = "Checkerboard"; checkerBoard.Y = checkerBoard.Height * .75f; var w = checkerBoard.Width; var h = checkerBoard.Height; var totalCheckers = 0; var isRed = false; for (var __x = -3.5f; __x <= 3f; __x += 1f) { isRed = !isRed; for (var __y = -3.5f; __y <= 3.5f; __y += 1f) { isRed = !isRed; var checker = Library.New (isRed ? "RedChecker" : "BlackChecker"); checker.Width = checker.Height = w/8; checker.Name = "Checker" + totalCheckers++; checkerBoard.AddChild(checker); checker.MouseEnabled = true; checker.X = w * __x/8f; checker.Y = h * __y/8f; checker.AddEventListener<MouseEvent>(MouseEvent.MOUSE_OVER, onAnythingOver); checker.AddEventListener<MouseEvent>(MouseEvent.MOUSE_OUT, onAnythingOut); } } _everythingContainer.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, onAnythingPress); _everythingContainer.AddEventListener<MouseEvent>(MouseEvent.RELEASE_OUTSIDE, onAnythingUpOutside); AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, onStagePress); }
private void TestEventListeners() { _country = Library.New<CinchSprite>("Country"); _state = Library.New<CinchSprite>("Stage"); _city = Library.New<CinchSprite>("City"); _house = Library.New<CinchSprite>("House"); _country.Name = "Country"; _state.Name = "State"; _city.Name = "City"; _house.Name = "House"; _country.MouseEnabled = _state.MouseEnabled = _city.MouseEnabled = _house.MouseEnabled; _country.AddChild(_state); _state.AddChild(_city); _city.AddChild(_house); AssertEverybodyWillTrigger(MouseEvent.MOUSE_DOWN, false); AssertOnlyCityHasEventListener(MouseEvent.MOUSE_DOWN, false); _city.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler); _city.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler); _city.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler); AssertEverybodyWillTrigger(MouseEvent.MOUSE_DOWN, true); AssertOnlyCityHasEventListener(MouseEvent.MOUSE_DOWN, true); _city.RemoveEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler); AssertEverybodyWillTrigger(MouseEvent.MOUSE_DOWN, false); AssertOnlyCityHasEventListener(MouseEvent.MOUSE_DOWN, false); _eventRecord = new List<String>(); AssertEventRecordIs(""); _country.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, true); _state.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, false); _city.AddEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, true); _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs("CAP:Country,AT:City,BUB:State"); //removed the wrong handler, so should still do all the dispatching _country.RemoveEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler); //removed the right handler with wrong capture setting, so should still do all the dispatching _country.RemoveEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, false); _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs("CAP:Country,AT:City,BUB:State"); _state.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs("CAP:Country,AT:State"); //removed the right handler, so should do no the dispatching _country.RemoveEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, true); _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs("AT:City,BUB:State"); _state.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs("AT:State"); //removed the right handler with wrong capture setting, so should still do all the dispatching _state.RemoveEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, true); _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs("AT:City,BUB:State"); _state.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs("AT:State"); _state.RemoveEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler); _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs("AT:City"); _state.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs(""); Debug.Log("WIN: TestEventListeners"); }
private void TestEventListeners() { _country = Library.New <CinchSprite>("Country"); _state = Library.New <CinchSprite>("Stage"); _city = Library.New <CinchSprite>("City"); _house = Library.New <CinchSprite>("House"); _country.Name = "Country"; _state.Name = "State"; _city.Name = "City"; _house.Name = "House"; _country.MouseEnabled = _state.MouseEnabled = _city.MouseEnabled = _house.MouseEnabled; _country.AddChild(_state); _state.AddChild(_city); _city.AddChild(_house); AssertEverybodyWillTrigger(MouseEvent.MOUSE_DOWN, false); AssertOnlyCityHasEventListener(MouseEvent.MOUSE_DOWN, false); _city.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler); _city.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler); _city.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler); AssertEverybodyWillTrigger(MouseEvent.MOUSE_DOWN, true); AssertOnlyCityHasEventListener(MouseEvent.MOUSE_DOWN, true); _city.RemoveEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler); AssertEverybodyWillTrigger(MouseEvent.MOUSE_DOWN, false); AssertOnlyCityHasEventListener(MouseEvent.MOUSE_DOWN, false); _eventRecord = new List <String>(); AssertEventRecordIs(""); _country.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, true); _state.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, false); _city.AddEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, true); _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs("CAP:Country,AT:City,BUB:State"); //removed the wrong handler, so should still do all the dispatching _country.RemoveEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, GenericEventHandler); //removed the right handler with wrong capture setting, so should still do all the dispatching _country.RemoveEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, false); _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs("CAP:Country,AT:City,BUB:State"); _state.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs("CAP:Country,AT:State"); //removed the right handler, so should do no the dispatching _country.RemoveEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, true); _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs("AT:City,BUB:State"); _state.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs("AT:State"); //removed the right handler with wrong capture setting, so should still do all the dispatching _state.RemoveEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler, true); _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs("AT:City,BUB:State"); _state.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs("AT:State"); _state.RemoveEventListener <MouseEvent>(MouseEvent.MOUSE_DOWN, StackRecordingEventHandler); _city.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs("AT:City"); _state.DispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, _city, new Vector2(0, 0), new Vector2(0, 0))); AssertEventRecordIs(""); Debug.Log("WIN: TestEventListeners"); }