]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/item/container.c
Merge branch 'master' into terencehill/music_player
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / item / container.c
index 5e924a0eebf7726cc10825984f6e3563e352b312..8bc925f1ca1d8594c768d75f719dd15eaf238e54 100644 (file)
@@ -15,6 +15,7 @@ CLASS(Container) EXTENDS(Item)
        METHOD(Container, moveItemAfter, void(entity, entity, entity))
        METHOD(Container, removeItem, void(entity, entity))
        METHOD(Container, setFocus, void(entity, entity))
+       METHOD(Container, saveFocus, void(entity))
        METHOD(Container, setAlphaOf, void(entity, entity, float))
        METHOD(Container, itemFromPoint, entity(entity, vector))
        METHOD(Container, showNotify, void(entity))
@@ -24,6 +25,7 @@ CLASS(Container) EXTENDS(Item)
        ATTRIB(Container, firstChild, entity, NULL)
        ATTRIB(Container, lastChild, entity, NULL)
        ATTRIB(Container, focusedChild, entity, NULL)
+       ATTRIB(Container, savedFocus, entity, NULL)
        ATTRIB(Container, shown, float, 0)
 
        METHOD(Container, enterSubitem, void(entity, entity))
@@ -85,7 +87,7 @@ void Container_showNotify(entity me)
 void Container_hideNotify(entity me)
 {
        entity e;
-       if not(me.shown)
+       if (!me.shown)
                return;
        me.shown = 0;
        for(e = me.firstChild; e; e = e.nextSibling)
@@ -177,6 +179,8 @@ void Container_draw(entity me)
                e.draw(e);
                me.leaveSubitem(me);
        }
+
+       SUPER(Container).draw(me);
 }
 
 void Container_focusLeave(entity me)
@@ -302,8 +306,7 @@ void Container_addItem(entity me, entity other, vector theOrigin, vector theSize
        other.Container_size = theSize;
        me.setAlphaOf(me, other, theAlpha);
 
-       entity f, l;
-       f = me.firstChild;
+       entity l;
        l = me.lastChild;
 
        if(l)
@@ -314,8 +317,6 @@ void Container_addItem(entity me, entity other, vector theOrigin, vector theSize
        other.prevSibling = l;
        other.nextSibling = NULL;
        me.lastChild = other;
-
-       draw_NeedResizeNotify = 1;
 }
 
 void Container_removeItem(entity me, entity other)
@@ -328,9 +329,7 @@ void Container_removeItem(entity me, entity other)
 
        other.parent = NULL;
 
-       entity n, p, f, l;
-       f = me.firstChild;
-       l = me.lastChild;
+       entity n, p;
        n = other.nextSibling;
        p = other.prevSibling;
 
@@ -347,35 +346,56 @@ void Container_removeItem(entity me, entity other)
 
 void Container_setFocus(entity me, entity other)
 {
-       if(other)
-               if not(me.focused)
-                       error("Trying to set focus in a non-focused control!");
        if(me.focusedChild == other)
                return;
-       //print(etos(me), ": focus changes from ", etos(me.focusedChild), " to ", etos(other), "\n");
+
        if(me.focusedChild)
        {
                me.focusedChild.focused = 0;
                me.focusedChild.focusLeave(me.focusedChild);
+               me.focusedChild = NULL;
        }
+
        if(other)
        {
-               other.focused = 1;
-               other.focusEnter(other);
+               if(!me.focused)
+                       error("Trying to set focus in a non-focused control!");
+
+               if(me.savedFocus)
+               {
+                       me.focusedChild = me.savedFocus;
+                       me.savedFocus = NULL;
+                       me.focusedChild.focused = 1;
+                       me.focusedChild.focusEnter(me.focusedChild);
+
+                       if(me.focusedChild.instanceOfContainer)
+                               me.focusedChild.setFocus(me.focusedChild, me.focusedChild.savedFocus);
+               }
+               else
+               {
+                       me.focusedChild = other;
+                       me.focusedChild.focused = 1;
+                       me.focusedChild.focusEnter(me.focusedChild);
+               }
        }
-       me.focusedChild = other;
+}
+
+void Container_saveFocus(entity me)
+{
+       me.savedFocus = me.focusedChild;
+
+       if(me.focusedChild.instanceOfContainer)
+               me.focusedChild.saveFocus(me.focusedChild);
 }
 
 void Container_moveItemAfter(entity me, entity other, entity dest)
 {
        // first: remove other from the chain
-       entity n, p, f, l;
+       entity n, p;
 
        if(other.parent != me)
                error("Can't move in wrong container!");
 
-       f = me.firstChild;
-       l = me.lastChild;
        n = other.nextSibling;
        p = other.prevSibling;
 
@@ -388,7 +408,7 @@ void Container_moveItemAfter(entity me, entity other, entity dest)
                n.prevSibling = p;
        else
                me.lastChild = p;
-       
+
        // now other got removed. Insert it behind dest now.
        other.prevSibling = dest;
        if(dest)