X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fmenu%2Fitem%2Finputcontainer.qc;h=cda342677262206dd8afb2bcdb011f136ed2edc9;hp=90ca719dce9e25326e54a700df5799f7a5a83189;hb=58032876ef7ef5d8978989144dfa20e84457ee37;hpb=e090603a32c8cba598f2c54e355cdb5b32b0d986 diff --git a/qcsrc/menu/item/inputcontainer.qc b/qcsrc/menu/item/inputcontainer.qc index 90ca719dc..cda342677 100644 --- a/qcsrc/menu/item/inputcontainer.qc +++ b/qcsrc/menu/item/inputcontainer.qc @@ -1,168 +1,134 @@ -#ifndef ITEM_INPUTCONTAINER_H -#define ITEM_INPUTCONTAINER_H -#include "container.qc" -CLASS(InputContainer, Container) - METHOD(InputContainer, keyDown, float(entity, float, float, float)) - METHOD(InputContainer, mouseMove, float(entity, vector)) - METHOD(InputContainer, mousePress, float(entity, vector)) - METHOD(InputContainer, mouseRelease, float(entity, vector)) - METHOD(InputContainer, mouseDrag, float(entity, vector)) - METHOD(InputContainer, focusLeave, void(entity)) - METHOD(InputContainer, resizeNotify, void(entity, vector, vector, vector, vector)) +#include "inputcontainer.qh" - METHOD(InputContainer, _changeFocusXY, float(entity, vector)) - ATTRIB(InputContainer, mouseFocusedChild, entity, NULL) - ATTRIB(InputContainer, isTabRoot, float, 0) -ENDCLASS(InputContainer) -#endif - -#ifdef IMPLEMENTATION -void InputContainer_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) -{ - SUPER(InputContainer).resizeNotify(me, relOrigin, relSize, absOrigin, absSize); - /* - if(me.parent.instanceOfInputContainer) - me.isTabRoot = 0; - else - me.isTabRoot = 1; - */ -} + void InputContainer_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize) + { + SUPER(InputContainer).resizeNotify(me, relOrigin, relSize, absOrigin, absSize); + /* + if(me.parent.instanceOfInputContainer) + me.isTabRoot = 0; + else + me.isTabRoot = 1; + */ + } -void InputContainer_focusLeave(entity me) -{ - SUPER(InputContainer).focusLeave(me); - me.mouseFocusedChild = NULL; -} + void InputContainer_focusLeave(entity me) + { + SUPER(InputContainer).focusLeave(me); + me.mouseFocusedChild = NULL; + } -float InputContainer_keyDown(entity me, float scan, float ascii, float shift) -{ - entity f, ff; - if(SUPER(InputContainer).keyDown(me, scan, ascii, shift)) - return 1; - if(scan == K_ESCAPE) + float InputContainer_keyDown(entity me, float scan, float ascii, float shift) { - f = me.focusedChild; - if(f) - { - me.setFocus(me, NULL); + entity f, ff; + if (SUPER(InputContainer).keyDown(me, scan, ascii, shift)) return 1; + if (scan == K_ESCAPE) + { + f = me.focusedChild; + if (f) + { + me.setFocus(me, NULL); + return 1; + } + return 0; } - return 0; - } - if(scan == K_TAB) - { - f = me.focusedChild; - if(shift & S_SHIFT) + if (scan == K_TAB) { - if(f) + f = me.focusedChild; + if (shift & S_SHIFT) { - for(ff = f.prevSibling; ff; ff = ff.prevSibling) + if (f) { - if (!ff.focusable) - continue; - me.setFocus(me, ff); - return 1; + for (ff = f.prevSibling; ff; ff = ff.prevSibling) + { + if (!ff.focusable) continue; + me.setFocus(me, ff); + return 1; + } } - } - if(!f || me.isTabRoot) - { - for(ff = me.lastChild; ff; ff = ff.prevSibling) + if (!f || me.isTabRoot) { - if (!ff.focusable) - continue; - me.setFocus(me, ff); - return 1; + for (ff = me.lastChild; ff; ff = ff.prevSibling) + { + if (!ff.focusable) continue; + me.setFocus(me, ff); + return 1; + } + return 0; // AIIIIEEEEE! } - return 0; // AIIIIEEEEE! } - } - else - { - if(f) + else { - for(ff = f.nextSibling; ff; ff = ff.nextSibling) + if (f) { - if (!ff.focusable) - continue; - me.setFocus(me, ff); - return 1; + for (ff = f.nextSibling; ff; ff = ff.nextSibling) + { + if (!ff.focusable) continue; + me.setFocus(me, ff); + return 1; + } } - } - if(!f || me.isTabRoot) - { - for(ff = me.firstChild; ff; ff = ff.nextSibling) + if (!f || me.isTabRoot) { - if (!ff.focusable) - continue; - me.setFocus(me, ff); - return 1; + for (ff = me.firstChild; ff; ff = ff.nextSibling) + { + if (!ff.focusable) continue; + me.setFocus(me, ff); + return 1; + } + return 0; // AIIIIEEEEE! } - return 0; // AIIIIEEEEE! } } + return 0; } - return 0; -} -float InputContainer__changeFocusXY(entity me, vector pos) -{ - entity e, ne; - e = me.mouseFocusedChild; - ne = me.itemFromPoint(me, pos); - if(ne) - if (!ne.focusable) - ne = NULL; - me.mouseFocusedChild = ne; - if(ne) - if(ne != e) + bool InputContainer__changeFocusXY(entity this, vector pos) + { + entity e = this.itemFromPoint(this, pos); + if (e && !e.focusable) e = NULL; + entity prev = this.mouseFocusedChild; + this.mouseFocusedChild = e; + if (e != prev) { - me.setFocus(me, ne); - if(ne.instanceOfInputContainer) + this.setFocus(this, e); + if (e && e.instanceOfInputContainer) { - ne.focusedChild = NULL; - ne._changeFocusXY(e, globalToBox(pos, ne.Container_origin, ne.Container_size)); + e.focusedChild = NULL; + e._changeFocusXY(e, globalToBox(pos, e.Container_origin, e.Container_size)); } } - return (ne != NULL); -} + return true; // have focus + } -float InputContainer_mouseDrag(entity me, vector pos) -{ - if(SUPER(InputContainer).mouseDrag(me, pos)) - return 1; - if(pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1) - return 1; - return 0; -} -float InputContainer_mouseMove(entity me, vector pos) -{ - if(me.mouseFocusedChild != me.focusedChild) // if the keyboard moved the focus away - me.mouseFocusedChild = NULL; // force focusing - if(me._changeFocusXY(me, pos)) - if(SUPER(InputContainer).mouseMove(me, pos)) - return 1; - if(pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1) - return 1; - return 0; -} -float InputContainer_mousePress(entity me, vector pos) -{ - me.mouseFocusedChild = NULL; // force focusing - if(me._changeFocusXY(me, pos)) - if(SUPER(InputContainer).mousePress(me, pos)) - return 1; - if(pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1) - return 1; - return 0; -} -float InputContainer_mouseRelease(entity me, vector pos) -{ - SUPER(InputContainer).mouseRelease(me, pos); // return value? - if(me.focused) // am I still eligible for this? (UGLY HACK, but a mouse event could have changed focus away) - if(me._changeFocusXY(me, pos)) - return 1; - if(pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1) - return 1; - return 0; -} -#endif + float InputContainer_mouseDrag(entity me, vector pos) + { + if (SUPER(InputContainer).mouseDrag(me, pos)) return 1; + if (pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1) return 1; + return 0; + } + float InputContainer_mouseMove(entity me, vector pos) + { + if (me.mouseFocusedChild != me.focusedChild) // if the keyboard moved the focus away + me.mouseFocusedChild = NULL; // force focusing + if (me._changeFocusXY(me, pos)) + if (SUPER(InputContainer).mouseMove(me, pos)) return 1; + if (pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1) return 1; + return 0; + } + METHOD(InputContainer, mousePress, bool(InputContainer this, vector pos)) + { + this.mouseFocusedChild = NULL; // force focusing + if (this._changeFocusXY(this, pos)) + if (SUPER(InputContainer).mousePress(this, pos)) return true; + if (pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1) return true; + return false; + } + float InputContainer_mouseRelease(entity me, vector pos) + { + SUPER(InputContainer).mouseRelease(me, pos); // return value? + if (me.focused) // am I still eligible for this? (UGLY HACK, but a mouse event could have changed focus away) + if (me._changeFocusXY(me, pos)) return 1; + if (pos.x >= 0 && pos.y >= 0 && pos.x < 1 && pos.y < 1) return 1; + return 0; + }