public override void tickUpdate() { InteractiveComponent comp = (InteractiveComponent)this.graphComponent; int state = -1; if (comp.GetType().IsSubclassOf(typeof(LinkComponent))) { state = ((LinkComponent)comp).getExtensionConnection().Value; } else if (comp.GetType().IsSubclassOf(typeof(LogicComponent))) { state = ((LogicComponent)comp).getState(); } else { throw new Exception(comp.GetType() + " was not found"); } for (int i = 0; i < this.senderControllers.Count; i++) { bool isActive = Convert.ToBoolean((state >> (this.senderControllers.Count - 1 - i)) & 1); this.senderControllers[i].updateSignal(isActive); } }
/// <summary> /// Gets a component from the adapter specified by ID /// </summary> /// <returns></returns> public static Component GetComponent(GameObject parentGameObject, string id) { ComponentAdapter adapter = GetAdapter(parentGameObject); if (null == adapter) { Debug.LogWarning("Cannot find component adapter on game object: " + parentGameObject); return(null); } if (null == adapter.Component) { Debug.LogWarning("Component not instantiated. Adapter: " + adapter); return(null); } Component parentComponent = adapter.Component; // TODO: create method ComponentManager.Instance.GetMultiple(id); and use it here! InteractiveComponent component = ComponentManager.Instance.Get(id); if (parentComponent.HasChild(component)) { return((Component)component); } return(null); }
/// <summary> /// Finds focusable parent or parent's parent /// </summary> /// <param name="component"></param> /// <returns></returns> internal static InteractiveComponent FindFocusableAncestor(InteractiveComponent component) { //Debug.Log("FindFocusableAncestor: " + component); InteractiveComponent ancestor = null; DisplayObjectContainer child = component; do { var ic = child as InteractiveComponent; if (null != ic) { if (ic.Enabled && ic.FocusEnabled || null != ic.FocusRouting) { ancestor = ic; break; } } //child = (InteractiveComponent) child.Parent; child = child.Parent; }while (null != child); #if DEBUG if (DebugMode) { Debug.Log(null != ancestor ? string.Format("Focusable ancestor found: {0}", ancestor) : "Focusable ancestor NOT found"); } #endif //Debug.Log("ancestor: " + ancestor); return(ancestor); }
internal void Register(/*ref */ string id, InteractiveComponent component) { //if (null == id) // throw new ComponentManagerException(ComponentManagerException.CannotRegisterNull); if (string.IsNullOrEmpty(id)) { return; // do not register an empty ID } if (_customDict.ContainsKey(id)) { return; // no multiple registration } if (_customDict.ContainsKey(id)) { #if DEBUG if (DebugMode) { Debug.Log(string.Format(ComponentManagerException.IdAlreadyRegistered, id)); Debug.Break(); } #endif throw new ComponentManagerException(string.Format(ComponentManagerException.IdAlreadyRegistered, id)); } _customDict.Add(id, component); #if DEBUG if (DebugMode) { Debug.Log(string.Format(@"Component registered: [{0}] => {1}", id, component)); } #endif }
// TODO: handle skipping non-focused components and circular changes private List <FocusableComponentDescriptor> GetFocusableComponents() { List <FocusableComponentDescriptor> list = new List <FocusableComponentDescriptor>(); ITabManagerClient fmc = _component as ITabManagerClient; if (null == fmc) { return(list); } _components = TabChildren ?? fmc.GetTabChildren(); int index = 0; _components.ForEach(delegate(DisplayListMember child) { InteractiveComponent comp = child as InteractiveComponent; // form item if (FocusManager.IsFocusCandidate(comp)) // visible & enabled & focus enabled? { list.Add(new FocusableComponentDescriptor(index, comp)); } index++; }); return(list); }
/// <summary> /// Blurs the referenced component but only if currently in focus /// Use this if you really know what you are doing; else you get en exception /// </summary> /// <param name="component"></param> public void Blur(InteractiveComponent component) { if (_focusedComponent == component) { Blur(); } else { throw new FocusManagerException(FocusManagerException.ComponentNotInFocus); } }
/// <summary> /// Blurs everything /// </summary> public void Blur() { //Debug.Log("Blur: " + _focusedComponent); //if (null != _focusedComponent) // _focusedComponent.DispatchEvent(new GuiEvent(GuiEvent.FOCUS_OUT)); //TextFieldFocusHelper.BlurUnityFocus(); if (null != _focusedComponent) { _focusedComponent.FocusOutHandler(new FocusEvent(FocusEvent.FOCUS_IN)); } _focusedComponent = null; }
/// <summary> /// Sets focus on a component /// </summary> /// <param name="component"></param> public void SetFocus(InteractiveComponent component) { DoSetFocus(component); /*if (component.Initialized) * { * //FocusManager.Instance.TabbedToFocus = true; * //Debug.Log("Setting focus: " + this); * DoSetFocus(component); * } * else * { * component.AddEventListener(FrameworkEvent.CREATION_COMPLETE, SetFocusDelayed); * }*/ }
protected void formBasicShape(InteractiveComponent comp) { Transform middle = this.transform.Find("MiddleBody"); Transform reciever = this.transform.Find("Reciever"); Transform sender = this.transform.Find("Sender"); GameObject.Destroy(sender.gameObject); GameObject.Destroy(reciever.gameObject); //makes the middle //GameObject currentMiddle = Instantiate(middle.gameObject); middle.transform.SetParent(this.transform); middle.transform.localScale = new Vector3(comp.Size.x - .2f, comp.Size.y - .4f); middle.transform.localPosition = Vector3.zero; middle.transform.rotation = this.transform.rotation; reciever.localPosition = new Vector3(((comp.Size.x - 1) / -2f), ((comp.Size.y - 1) / -2f) - .35f, 0); //makes the receivers for (int i = 0; i < comp.receiverCount(); i++) { GameObject currentReciever = Instantiate(reciever.gameObject); currentReciever.transform.SetParent(this.transform); currentReciever.transform.localPosition = new Vector3(((comp.Size.x - 1) / -2f) + i, ((comp.Size.y - 1) / -2f) - .35f, 0); currentReciever.transform.rotation = this.transform.rotation; BoxCollider2D bc = currentReciever.GetComponent <BoxCollider2D>(); //bc.enabled = true; } //makes the senders for (int i = 0; i < comp.senderCount(); i++) { GameObject currentSender = Instantiate(sender.gameObject); currentSender.transform.SetParent(this.transform); currentSender.transform.localPosition = new Vector3(((comp.Size.x - 1) / -2f) + i, ((comp.Size.y - 1) / 2f) + .35f, 0); currentSender.transform.rotation = this.transform.rotation; SenderController cs = currentSender.AddComponent <SenderController>(); BoxCollider2D bc = currentSender.GetComponent <BoxCollider2D>(); cs.setUp(comp.getSenderAt(i)); this.senderControllers.Add(cs); } }
public void connectGraph() { List <InteractiveComponent> interComps = this.lightGraph.getAllInteractiveComponents(); for (int i = 0; i < interComps.Count; i++) { InteractiveComponent currentComp = interComps[i]; for (int s = 0; s < currentComp.senderCount(); s++) { Sender sender = currentComp.getSenderAt(s); int direction = currentComp.Rotation; //gets the connections for the sender sender.setTargets(getConnections(sender, direction)); } } }
public override void SetFocus() { InteractiveComponent firstFocusableItem = Children.Find(delegate(DisplayListMember control) { return(((InteractiveComponent)control).FocusEnabled); }) as InteractiveComponent; //Debug.Log("firstFocusableItem == null: " + (firstFocusableItem == null)); if (null != firstFocusableItem) { firstFocusableItem.SetFocus(); } else { base.SetFocus(); } }
private void OnKeyDown(Event e) { #if DEBUG if (DebugMode) { Debug.Log("KeyEventDispatcher:OnKeyDown"); } #endif InteractiveComponent comp = FocusManager.Instance.FocusedComponent; if (null == comp || !comp.PassesKeyDownFilter(e)) { return; } e.Bubbles = true; RedispatchKeyEvent(comp, e); }
/// <summary> /// Fires when component clicked with a mouse /// The clicked component is obviously mouse enabled /// But not all the clickable components are focusable /// Thus we have to climb up the parent tree to find the first focusable component, or focus routing /// If such component exists, we should set focus on it or run the routing to other component /// </summary> /// <param name="e"></param> private void ComponentMouseDownHandler(Event e) { #if DEBUG if (DebugMode) { Debug.Log("FocusManager: ComponentMouseDownHandler: " + e.Target); } #endif //Debug.Log("FocusManager: ComponentMouseDownHandler: " + e.Target); //((InteractiveComponent)e.Target).SetFocus(); // breaks combobox! //return; InteractiveComponent component = FindFocusableAncestor((InteractiveComponent)e.Target); if (null == component) { return; } if (null != component.FocusRouting) { component.FocusRouting(); return; } if (component == _focusedComponent) { return; } // blur the old one //if (null != _focusedComponent) // commented 20130331 (redundant ?) //{ // Blur(_focusedComponent); //} //Debug.Log("Setting focus on component: " + component); //SetFocus(component); component.SetFocus(); // give the component a chance to handle its focus (pass to child etc.) }
override public List <DisplayListMember> GetTabChildren() { List <DisplayListMember> list = new List <DisplayListMember>(); /*_fieldGroup.*/ Children.ForEach(delegate(DisplayListMember child) // form items { Group itemGroup = child as Group; // form item if (null != itemGroup) { //Debug.Log("list: " + list.Count); list.AddRange( itemGroup.ContentChildren.FindAll(delegate(DisplayListMember child2) { InteractiveComponent c = child2 as InteractiveComponent; return(null != c && c.Enabled && c.Visible && c.FocusEnabled); }) ); } }); return(list); }
/// <summary> /// The focus at the Unity level could change with tabbing etc. /// It is important to correct this behaviour, because the FocusManager should handle all the focus logic /// This method is being called from StageManager, in each frame, from OnGUI() handler /// </summary> public static void HandleFocus() { /** * If this is the focused component and focus on this component already handled * our work is done, so return * */ if (string.IsNullOrEmpty(NextFocusId) && !_shouldHandleFocus && FocusManager.Instance.FocusedComponent == _previouslyFocusedComponent) { return; } /* Reset the "force" flag */ _shouldHandleFocus = false; _previouslyFocusedComponent = FocusManager.Instance.FocusedComponent; if (!string.IsNullOrEmpty(NextFocusId)) { #if DEBUG if (DebugMode) { Debug.Log("Handling focus DIRECTLY with NextFocusId = " + NextFocusId); } #endif DoFocusTextField(NextFocusId); NextFocusId = null; return; } //Debug.Log("GUIUtility.keyboardControl: " + GUIUtility.keyboardControl); _textField = FocusManager.Instance.FocusedComponent as TextFieldBase; if (null != _textField && _textField.FocusEnabled && _textField.Enabled) { #if DEBUG if (DebugMode) { Debug.Log("Handling focus on " + FocusManager.Instance.FocusedComponent + "(" + FocusManager.Instance.FocusedComponent.Uid + ")"); } #endif // @see http://answers.unity3d.com/questions/17169/select-text-in-gui-textfield.html // 'You must first focus something else (doesn't matter what, so long as it exists, "" or null will not suffice). Bit of an ugly kludge, but seems to work.' // A. Blur //BlurUnityFocus(); // BUG BUG BUG ??? Not needed! // B. Focus if (_textField.Rendered) { DoFocusTextField(); } else { _textField.AddEventListener(FrameworkEvent.FIRST_SHOW, delegate { DoFocusTextField(); }); } } else { BlurUnityFocus(); } FocusManager.Instance.TabbedToFocus = false; }
/// <summary> /// Sets focus to the component /// Blurs previously focused component /// Called internaly by InteractiveComponent /// </summary> /// <param name="component">Component to focus</param> private void DoSetFocus(InteractiveComponent component) { //Debug.Log("DoSetFocus: " + component); /** * Clicking everywhere outside the text field messes the editor (cursor) * However, if the host dialog clicked, and it's SetFocus() routes to the same text field, * the focus should stay intact (and the cursor working) * That's why we need to give TextFieldFocusHelper a chance to re-apply the focus * (it does it at the end of OnGUI) * */ if (component is TextFieldBase) { TextFieldFocusHelper.ShouldHandleFocus = true; } /** * 1) If component not focus enabled, go no further * */ if (!component.FocusEnabled) { #if DEBUG if (DebugMode) { Debug.Log(string.Format("FocusManager: Focus not set to [{0}] because component not FocusEnabled", component)); } #endif return; // else do nothing } #if DEBUG if (DebugMode) { Debug.Log("FocusManager: Trying to set focus to: " + component); } #endif //Debug.Log("_focusedComponent == component: " + (_focusedComponent == component)); //Debug.Log("component.FocusEnabled: " + (component.FocusEnabled)); /** * 2) If focusing the already focused component, do nothing * */ if (_focusedComponent == component) { #if DEBUG if (DebugMode) { Debug.Log(string.Format("FocusManager: Focus not set to [{0}] because it is the same component", component)); } #endif return; } /** * 3) Blur previuosly focused component * */ Blur(); //Debug.Log("component: " + component); /** * 4) Set current component as focused component * */ _focusedComponent = component; #if DEBUG if (DebugMode) { Debug.Log("FocusManager: Focus changed to: " + _focusedComponent); } #endif //Debug.Log("FocusManager: Focus changed to: " + _focusedComponent); //GUI.FocusControl(component.Uid); //if (0 != _focusedComponent.HotControlId) //{ // if (_focusedComponent is TextField) // { // GUIUtility.keyboardControl = _focusedComponent.HotControlId; // Debug.Log("GUIUtility.keyboardControl: " + GUIUtility.keyboardControl); // } //} /** * / * 5) Execute focus on the component * / * */ component.FocusInHandler(new FocusEvent(FocusEvent.FOCUS_IN)); //if (_focusedComponent is TextField) //{ // Debug.Log("Calling GUI.FocusControl: " + this); // GUI.FocusControl(_focusedComponent.Uid); // //TextEditor t = GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl) as TextEditor; // //if (null != t) // // t.SelectAll(); //} }
/// <summary> /// Removes a popup from popup stage /// </summary> /// <param name="popup">A popup to remove</param> public void RemovePopup(DisplayObject popup) { #if TRIAL /* HACK CHECK */ Acme acme = (Acme)Framework.GetComponent <Acme>(true); if (null == acme || !acme.gameObject.activeInHierarchy /*active*/ || !acme.enabled) { return; } #endif #if DEBUG if (DebugMode) { Debug.Log("RemovePopup"); } #endif if (!_descriptors.ContainsKey(popup)) { return; } var descriptor = _descriptors[popup]; //if (popup.HasFocus) // FocusManager.Instance.Blur(); if (HasEventListener(CLOSING)) { Event e = new Event(CLOSING, popup, false, true); // cancelable DispatchEvent(e); if (e.Canceled) { return; } } if (IsDefaultPrevented(CLOSING)) { return; } var stage = descriptor.Stage; //Debug.Log(string.Format(@"Removing {0} from {1}", descriptor.PopupRoot, stage)); // removing children //descriptor.PopupRoot.Parent.RemoveChild(descriptor.PopupRoot); stage.RemoveChild(descriptor.PopupRoot); //Debug.Log("Descriptors remove"); _descriptors.Remove(popup); //FocusManager.Instance.Blur(); // TEMP disabled 2.1.2012. _popups.Remove(popup); if (descriptor.FocusPreviousOnHide) { if (_popups.Count > 0) // we have more opened popups { DisplayObject lastPopup = _popups[_popups.Count - 1]; //Debug.Log("_popups.Count: " + _popups.Count); if (lastPopup is InteractiveComponent) { ((InteractiveComponent)lastPopup).SetFocus(); /*lastPopup.Defer(delegate * { * ((InteractiveComponent)lastPopup).SetFocus(); * }, 1);*/ //FocusManager.Instance.SetFocus((InteractiveComponent)lastPopup); } // TEMP disabled on 2.1.2012. because the overlay popup constantly // appears and dissapears and takes focus // and raises "ArgumentException: You can only call GUI functions from inside OnGUI." // should enable back when overlay will be in it's top stage, non run by popup manager } else // this was the only popup { if (popup is Dialog) { Dialog dlg = (Dialog)popup; if (null != dlg.Owner) { // if owner is defined, focus the owner InteractiveComponent ic = dlg.Owner as InteractiveComponent; /*if (null != ic) * ic.SetFocus();*/ if (null != ic) { //((InteractiveComponent)lastPopup).SetFocus(); /*ic.Defer(delegate * { * //ic.SetFocus(); * FocusManager.Instance.SetFocus(ic); * }, 1);*/ //FocusManager.Instance.SetFocus(ic); ic.SetFocus(); } } //else // FocusManager.Instance.Blur(); // else blur everything // commented 20130331 - because after closing th eallert, the SetFocus te TextField (via the callback) didn't work } } } // disconnect if (_descriptors.Count == 0) { SystemManager.Instance.ResizeSignal.Disconnect(ResizeSlot); SystemManager.Instance.MouseDownSignal.Disconnect(MouseDownSlot); SystemManager.Instance.MouseWheelSignal.Disconnect(MouseWheelSlot); stage.RemoveEventListener(MouseEvent.MOUSE_DOWN, MouseDownHandler); } //Debug.Log("_descriptors.Count: " + _descriptors.Count); //_stage.ValidateNow(); if (HasEventListener(CLOSE)) { DispatchEvent(new Event(CLOSE, popup)); } if (descriptor.Popup != descriptor.PopupRoot) { // this is a modal popup // the removed effect won't play on popup, because PopupRoot is being removed, not the popup // we have to handle this case and play the effect here Component component = popup as Component; if (null != component && component.HasStyle("removedEffect")) { ITweenFactory removeEffect = (ITweenFactory)component.GetStyle("removedEffect"); removeEffect.Play(popup); } } }
/// <summary> /// Gets the info if this is a focus candidate (for tabbing etc.) /// </summary> /// <param name="comp"></param> /// <returns></returns> public static bool IsFocusCandidate(InteractiveComponent comp) { return(null != comp && comp.Enabled && comp.Visible && comp.FocusEnabled); }
//private void RemoveHandler(Event e) //{ // DisplayObject popup = e.Target as DisplayObject; // if (null != popup) // { // popup.RemoveEventListener(MouseEvent.MOUSE_DOWN_OUTSIDE, RemoveHandler); // popup.RemoveEventListener(MouseEvent.MOUSE_WHEEL_OUTSIDE, RemoveHandler); // TerminatePopup(popup); // } // if (_popups.Count == 0 && SystemManager.Instance.HasEventListener(ResizeEvent.RESIZE)) // SystemManager.Instance.RemoveEventListener(ResizeEvent.RESIZE, RemoveHandler); //} //private static void TerminatePopup(DisplayObject popup) //{ // //Debug.Log("TerminatePopup"); // var dlm = popup as DisplayListMember; // if (null != dlm) // { // Instance.RemovePopup(dlm); // // TODO: SystemManager.Instance.RemoveEventListener(ResizeEvent.RESIZE, ...); // dlm.Dispose(); // } //} #endregion #region Add /// <summary> /// Adds a popup to popup stage /// </summary> /// <param name="popup">A popup to add</param> /// <param name="options">Popup options</param> public void AddPopup(DisplayListMember popup, params PopupOption[] options) { Event e = new Event(OPENING, popup, false, true); // cancelable DispatchEvent(e); if (e.Canceled) { return; } if (IsDefaultPrevented(OPENING)) { return; } if (_popups.Contains(popup)) { return; } #if DEBUG if (DebugMode) { Debug.Log("AddPopup"); } #endif DisplayObjectContainer parent = null; bool modal = true; bool centered = true; bool keepCenter = false; bool removeOnMouseDownOutside = false; bool removeOnMouseWheelOutside = false; bool removeOnScreenResize = false; bool autoFocus = true; bool focusPreviousOnHide = true; Stage stage = _stage; bool visibleFlag = popup.Visible; popup.Visible = false; int len = options.Length; for (int i = 0; i < len; i++) { PopupOption option = options[i]; switch (option.Type) { case PopupOptionType.Parent: parent = (DisplayObjectContainer)option.Value; break; case PopupOptionType.Modal: modal = (bool)option.Value; break; case PopupOptionType.Centered: centered = (bool)option.Value; break; case PopupOptionType.KeepCenter: keepCenter = (bool)option.Value; break; case PopupOptionType.RemoveOnMouseDownOutside: removeOnMouseDownOutside = (bool)option.Value; break; case PopupOptionType.RemoveOnMouseWheelOutside: removeOnMouseWheelOutside = (bool)option.Value; break; case PopupOptionType.RemoveOnScreenResize: removeOnScreenResize = (bool)option.Value; break; case PopupOptionType.AutoFocus: autoFocus = (bool)option.Value; break; case PopupOptionType.FocusPreviousOnHide: focusPreviousOnHide = (bool)option.Value; break; case PopupOptionType.Stage: //Debug.Log("Exotic stage: " + option.Value); stage = (Stage)option.Value; break; default: throw new Exception("Unknown option"); } } _popups.Add(popup); if (null == parent) { parent = stage; } DisplayListMember overlay = null; Group popupRoot = null; InvalidationManagerClient imc = popup as InvalidationManagerClient; Component comp = popup as Component; if (null != comp) { comp.IsPopUp = true; } if (modal) { overlay = (DisplayListMember)Activator.CreateInstance(ModalOverlayType); overlay.AddEventListener(MouseEvent.MOUSE_DOWN, OnOverlayMouseDown); // we are packing both the overlay and the popup to into an aditional container popupRoot = new Group(); stage.AddChild(popupRoot); // BUG BUG BUG! If we do _stage.AddChild(popupRoot); AFTER the children are added, we get a null exception // this is the major problem when adding children, started appearing since 10.1.2012 // solved. This had to to with the creationcomplete method, which has to be run after the complete invalidation pass popupRoot.AddChild(overlay); popupRoot.AddChild(popup); // popup has been added to popup stage // invalidation methods have been called upon the addition // now we want to run measure (to validate dimensions) // because we want to center the popup // now, the absolute layout won't do it on his own //overlay.Bounds = (Rectangle)parent.Bounds.Clone(); overlay.Width = PopupManagerStage.Instance.Width; overlay.Height = PopupManagerStage.Instance.Height; /*var client = overlay as InvalidationManagerClient; * if (client != null) * { * /*var imc2 = client; * imc2.SetActualSize( * PopupManagerStage.Instance.Width, * PopupManagerStage.Instance.Height/*, * Math.Max(imc2.GetExplicitOrMeasuredWidth(), imc2.MinWidth), * Math.Max(imc2.GetExplicitOrMeasuredHeight(), imc2.MinHeight)#2# * );#1# * client.Width = PopupManagerStage.Instance.Width; * client.Height = PopupManagerStage.Instance.Height; * //imc2.InvalidateTransform(); * } * else * { * overlay.X = parent.X; * overlay.Y = parent.Y; * /*overlay.X = parent.X; * overlay.Y = parent.Y;#1# * }*/ } else { stage.AddChild(popup); } if (null != imc) { //InvalidationManager.Instance.ValidateClient(imc, true); imc.ValidateNow(); //Debug.Log(string.Format("imc.Width:{0}, imc.Height:{1}", imc.Width, imc.Height)); //Debug.Log(string.Format("imc.GetExplicitOrMeasuredWidth():{0}, imc.GetExplicitOrMeasuredHeight():{1}", imc.GetExplicitOrMeasuredWidth(), imc.GetExplicitOrMeasuredHeight())); //imc.SetActualSize(imc.GetExplicitOrMeasuredWidth(), imc.GetExplicitOrMeasuredHeight()); imc.SetActualSize( Math.Min(Math.Max(imc.GetExplicitOrMeasuredWidth(), imc.MinWidth), imc.MaxWidth), Math.Min(Math.Max(imc.GetExplicitOrMeasuredHeight(), imc.MinHeight), imc.MaxHeight) ); } var descriptor = new PopupDescriptor(parent, overlay, popupRoot) { Popup = popup, PopupRoot = modal ? popupRoot : popup, Owner = parent, Modal = modal, Centered = centered, KeepCenter = keepCenter, RemoveOnMouseDownOutside = removeOnMouseDownOutside, RemoveOnMouseWheelOutside = removeOnMouseWheelOutside, RemoveOnScreenResize = removeOnScreenResize, FocusPreviousOnHide = focusPreviousOnHide, Stage = stage }; _descriptors.Add(popup, descriptor); if (centered) { CenterPopUp(popup); } InteractiveComponent ic = popup as InteractiveComponent; if (autoFocus && null != ic) { ic.SetFocus(); // TEMP disabled, 2.1.2012. //FocusManager.Instance.SetFocus(ic); /*ic.Defer(delegate * { * //ic.SetFocus(); * FocusManager.Instance.SetFocus(ic); * }, 1);*/ } // connect if not connected if (_descriptors.Count > 0) { SystemManager.Instance.ResizeSignal.Connect(ResizeSlot); SystemManager.Instance.MouseDownSignal.Connect(MouseDownSlot); SystemManager.Instance.RightMouseDownSignal.Connect(MouseDownSlot); SystemManager.Instance.MiddleMouseDownSignal.Connect(MouseDownSlot); SystemManager.Instance.MouseWheelSignal.Connect(MouseWheelSlot); // subscribe to stage to see if some component has been mouse-downed // NOTE: some components (i.e. window close button) could cancel the event, this is by design // note: it is safe ta call it multiple times, it is checked internally stage.AddEventListener(MouseEvent.MOUSE_DOWN, MouseDownHandler); } else { SystemManager.Instance.ResizeSignal.Disconnect(ResizeSlot); SystemManager.Instance.MouseDownSignal.Disconnect(MouseDownSlot); SystemManager.Instance.RightMouseDownSignal.Disconnect(MouseDownSlot); SystemManager.Instance.MiddleMouseDownSignal.Disconnect(MouseDownSlot); SystemManager.Instance.MouseWheelSignal.Disconnect(MouseWheelSlot); //MouseEventDispatcher.Instance.RemoveEventListener(MouseEvent.MOUSE_DOWN, MouseDownHandler); stage.RemoveEventListener(MouseEvent.MOUSE_DOWN, MouseDownHandler); } // NOTE: This is needed when having effects because of the flicker (?): //descriptor.PopupRoot.SkipRender(100); // bring the popup root to front descriptor.PopupRoot.BringToFront(); popup.Visible = visibleFlag; DispatchEvent(new Event(OPEN, popup)); }
public bool IsRegistered(InteractiveComponent component) { return(_customDict.ContainsValue(component)); }
/// <summary> /// Looks for a front-most component inside of the parent component /// Goes top-down, from parent to children /// Returns the front-most rendered component on given coordinates (on a single stage) /// NOTE: RECURSIVE!!! /// </summary> /// <param name="dlm"></param> /// <param name="coords">Coordinates to test</param> /// <param name="filter">Filter</param> /// <param name="stopOnDisabled">Should we stop on disabled component</param> /// <param name="stopOnInvisible">Should we stop on invisible component</param> /// <returns></returns> // ReSharper disable SuggestBaseTypeForParameter private static DisplayListMember GetComponentUnderCoordinates(DisplayListMember dlm, Point coords, Filter filter, bool stopOnDisabled, bool stopOnInvisible) // ReSharper restore SuggestBaseTypeForParameter { //Debug.Log("GetComponentUnderCoordinates: " + dlm); InteractiveComponent component = dlm as InteractiveComponent; if (null != component) { if (stopOnInvisible && !component.Visible) // invisible { return(null); } if (stopOnDisabled && !component.Enabled) // disabled { return(null); } } DisplayListMember output = null; _containsPoint = dlm.ContainsPoint(coords, false); if (_containsPoint && PassesFilter(dlm, filter)) { output = component; } GroupBase group = dlm as GroupBase; if (null != group) { if (!_containsPoint && group.ClipAndEnableScrolling) { return(output); } if (group.MouseChildren) { foreach (DisplayListMember d in group.QDrawingList) { /* Recursive call! */ DisplayListMember c = GetComponentUnderCoordinates(d, coords, filter, stopOnDisabled, stopOnInvisible); if (null != c) { output = c; } } } } else // simple component { var doc = dlm as DisplayObjectContainer; if (null != doc) { if (doc.MouseChildren /* && doc.QNumberOfChildren > 0*/) { foreach (DisplayListMember d in doc.QDrawingList) { /* Recursive call! */ DisplayListMember c = GetComponentUnderCoordinates(d, coords, filter, stopOnDisabled, stopOnInvisible); if (null != c) { output = c; } } } } } return(output); }
/// <summary> /// Checks if the specified component is in focus /// </summary> /// <param name="c"></param> /// <returns></returns> public bool HasFocusedComponent(InteractiveComponent c) { return(_focusedComponent == c); }
private void KeyDownHandler(Event e) { KeyboardEvent ke = (KeyboardEvent)e; int index = _components.IndexOf(FocusManager.Instance.FocusedComponent); if (-1 == index) { return; } bool keyRecognized = false; switch (ke.KeyCode) { case KeyCode.Tab: //Debug.Log("Tab"); keyRecognized = true; index = ke.Shift ? Previous(index, _circularTabs ?? false) : Next(index, _circularTabs ?? false); break; case KeyCode.LeftArrow: //Debug.Log("LeftArrow"); if (_arrowsEnabled) { keyRecognized = true; index = Previous(index, _circularTabs ?? false); } break; case KeyCode.RightArrow: //Debug.Log("CircularArrows: " + CircularArrows); if (_arrowsEnabled) { keyRecognized = true; index = Next(index, _circularTabs ?? false); } break; case KeyCode.UpArrow: //Debug.Log("LeftArrow"); if (_arrowsEnabled && _upDownArrowsEnabled) { keyRecognized = true; index = Previous(index, _circularTabs ?? false); } break; case KeyCode.DownArrow: //Debug.Log("CircularArrows: " + CircularArrows); if (_arrowsEnabled && _upDownArrowsEnabled) { keyRecognized = true; index = Next(index, _circularTabs ?? false); } break; default: break; } if (keyRecognized) { /** * Important: canceling the event alters with behavours of container children !!! * (for instance, TabManager set on Form swallows the key events needed by combo box) * */ e.CancelAndStopPropagation(); InteractiveComponent componentToFocus = _components[index] as InteractiveComponent; if (null != componentToFocus) { if (!componentToFocus.FocusEnabled) { #if DEBUG if (DebugMode) { Debug.Log("Component is not focus enabled: " + componentToFocus); return; } #endif } #if DEBUG if (DebugMode) { Debug.Log("Focusing component: " + componentToFocus); } #endif FocusManager.Instance.TabbedToFocus = true; componentToFocus.SetFocus(); } else { #if DEBUG if (DebugMode) { Debug.LogWarning("Component to focus not instantiated"); } #endif } } }