コード例 #1
0
        /**
         * Activates the widget w, and deactivates the previously active widget. (if exists)
         */
        public void setActiveWidget(Widget w)
        {
            if ((w.getInstanceName() == mActiveWidget.getInstanceName()) || (!w.enabled()) || (w == null))
            {
                return;
            }

            if (mActiveWidget != null)
            {
                WidgetEventArgs e = new WidgetEventArgs(mActiveWidget);
                e.handled = false;
                mActiveWidget.Deactivate(e);
            }

            mActiveWidget = w;
            WidgetEventArgs e2 = new WidgetEventArgs(mActiveWidget);

            e2.handled = false;
            mActiveWidget.Activate(e2);
        }
コード例 #2
0
        public bool injectMouseButtonDown(MouseButtonID button)
        {
            if ((mMouseCursor == null) || (!mMouseCursor.isVisible()))
            {
                return(false);
            }

            MouseEventArgs args = new MouseEventArgs(null);

            args.position.x = mMouseCursor.getPixelPosition().x;
            args.position.y = mMouseCursor.getPixelPosition().y;
            args.button     = button;
            args.handled    = false;

            if (mWidgetContainingMouse != null)
            {
                // mActiveWidget is the last widget the user clicked on, ie TextBox, ComboBox, etc.
                if ((mActiveWidget != null) && (!mActiveWidget.getInstanceName().Equals(mWidgetContainingMouse.getInstanceName())))
                {
                    args.widget = mActiveWidget;
                    mActiveWidget.Deactivate(args);
                    // reset to false, becase within this context, the event (mouseButtonDown) has not been handled
                    args.handled  = false;
                    mActiveWidget = null;
                }

                mActiveWidget = mWidgetContainingMouse;

                args.widget = mActiveWidget;
                mWidgetContainingMouse.MouseButtonDown(args);
                // Gaurds against the scenario where a handler changes game state (clears GUI)
                if (mWidgetContainingMouse == null)
                {
                    return(args.handled);
                }

                // When a window becomes active, activates all its child widgets (except textboxes)
                Window w = mWidgetContainingMouse.getWindow();
                if (w != null)
                {
                    w.Activate(args);
                }
                else
                {
                    mWidgetContainingMouse.getSheet().Activate(args);
                }

                // Only one textbox can be active at a time.  In the event that the clicked widget
                // is a textbox, activate it!
                if (mActiveWidget.getWidgetType() == Widget.WidgetType.QGUI_TYPE_TEXTBOX)
                {
                    mActiveWidget.Activate(args);
                }

                // Record that the mouse button went down on this widget (non-window)
                mMouseButtonDown[args.button] = mWidgetContainingMouse;
            }
            else
            {
                if (mActiveWidget != null)
                {
                    args.widget = mActiveWidget;
                    mActiveWidget.Deactivate(args);
                    mActiveWidget = null;
                }

                mMouseButtonDown[args.button] = null;
            }

            mMouseButtonTimings[button] = Timer.time(null);
            return(args.handled);
        }