#134 Extender layer 4.x-dev

Mon, 02 Nov 2020 18:53:00 +0200

author
cemkalyoncu
date
Mon, 02 Nov 2020 18:53:00 +0200
branch
4.x-dev
changeset 1482
427bb870e024
parent 1481
00c4b8cec518
child 1483
4dbbdae925b4

#134 Extender layer

Source/Gorgon/Containers/Collection.h file | annotate | diff | comparison | revisions
Source/Gorgon/UI/Window.h file | annotate | diff | comparison | revisions
Source/Gorgon/Window.cpp file | annotate | diff | comparison | revisions
--- a/Source/Gorgon/Containers/Collection.h	Sun Nov 01 20:45:20 2020 +0200
+++ b/Source/Gorgon/Containers/Collection.h	Mon Nov 02 18:53:00 2020 +0200
@@ -369,7 +369,7 @@
 			/// Creates a new item and inserts it before the given reference. You may use the size of the collection
 			/// for this function to behave like Add.
 			template<typename... Args_>
-			T_ &InsertNew(unsigned before, Args_... args) {
+			T_ &InsertNew(long before, Args_... args) {
 				auto t=new T_(args...);
 				Insert(t, before);
 
@@ -377,7 +377,9 @@
 			}
 
 			/// this method moves the given object in the collection in front of the reference
-			void MoveBefore(unsigned index, unsigned before) {
+			void MoveBefore(long index, long before) {
+                if(before == -1)
+                    before = list.size();
 				if(index>=list.size())
 					throw std::out_of_range("Invalid location");
 				if(before>list.size())
@@ -388,7 +390,7 @@
 
 				if(index>before) {
 					T_ *t=list[index];
-					for(unsigned i=index; i>before; i--)
+					for(long i=index; i>before; i--)
 						list[i]=list[i-1];
 
 					list[before]=t;
@@ -396,14 +398,14 @@
 				else if(before==list.size()) {
 					T_ *t=list[index];
 
-					for(unsigned i=index; i<list.size()-1; i++)
+					for(long i=index; i<list.size()-1; i++)
 						list[i]=list[i+1];
 
 					list[list.size()-1]=t;
 				}
 				else {
 					T_ *t=list[index];
-					for(unsigned i=index; i<before; i++)
+					for(long i=index; i<before; i++)
 						list[i]=list[i+1];
 
 					list[before]=t;
@@ -411,12 +413,12 @@
 			}
 
 			/// this method moves the given object in the collection in front of the reference
-			void MoveBefore(unsigned index, const T_ &before) {
+			void MoveBefore(long index, const T_ &before) {
 				MoveBefore(index, FindLocation(before));
 			}
 
 			/// this method moves the given object in the collection in front of the reference
-			void MoveBefore(const T_ &index, unsigned before) {
+			void MoveBefore(const T_ &index, long before) {
 				MoveBefore(FindLocation(index), before);
 			}
 
--- a/Source/Gorgon/UI/Window.h	Sun Nov 01 20:45:20 2020 +0200
+++ b/Source/Gorgon/UI/Window.h	Mon Nov 02 18:53:00 2020 +0200
@@ -17,9 +17,9 @@
 namespace Gorgon { namespace UI {
 
     /**
-     * UI window allows programmers to create an OS window that will accept
-     * widgets and has the ability to run by its own.
-     */
+    * UI window allows programmers to create an OS window that will accept
+    * widgets and has the ability to run by its own.
+    */
     class Window : public Gorgon::Window, public Runner, public WidgetContainer {
     public:
         using Gorgon::Window::Window;
@@ -30,6 +30,7 @@
         ~Window() {
             KeyEvent.Unregister(inputtoken);
             CharacterEvent.Unregister(chartoken);
+            delete extenderlayer;
         }
         
         Window(Window &&other) : Gorgon::Window(std::move(other)), WidgetContainer(std::move(other)) {
@@ -38,6 +39,11 @@
             
             inputtoken = keyinit();
             chartoken  = charinit();
+            
+            delete extenderlayer;
+            extenderlayer = other.extenderlayer;
+            Add(extenderlayer);
+            other.extenderlayer = other.layerinit();
         }
         
         Window &operator=(Window &&other) {
@@ -54,6 +60,11 @@
             inputtoken = keyinit();
             chartoken  = charinit();
             
+            delete extenderlayer;
+            extenderlayer = other.extenderlayer;
+            Add(extenderlayer);
+            other.extenderlayer = other.layerinit();
+            
             return *this;
         }
         
@@ -103,12 +114,12 @@
             Gorgon::Window::Resize(size);
             
             return GetSize() == size;
-		}
+        }
 
-		decltype(KeyEvent)::Token keyinit() {
-			inputtoken = KeyEvent.Register([this](Input::Key key, float amount) {
+        decltype(KeyEvent)::Token keyinit() {
+            inputtoken = KeyEvent.Register([this](Input::Key key, float amount) {
                 return WidgetContainer::KeyEvent(key, amount);
-			});
+            });
             
             KeyEvent.NewHandler = [this]{
                 RegisterOnce([this] {
@@ -116,13 +127,13 @@
                 });
             };
 
-			return inputtoken;
-		}
+            return inputtoken;
+        }
 
-		decltype(CharacterEvent)::Token charinit() {
-			chartoken = CharacterEvent.Register([this](Char c) {
-				return WidgetContainer::CharacterEvent(c);
-			});
+        decltype(CharacterEvent)::Token charinit() {
+            chartoken = CharacterEvent.Register([this](Char c) {
+                return WidgetContainer::CharacterEvent(c);
+            });
             
             CharacterEvent.NewHandler = [this]{
                 RegisterOnce([this] {
@@ -130,15 +141,31 @@
                 });
             };
 
-			return chartoken;
-		}
+            return chartoken;
+        }
+        
+        Graphics::Layer *layerinit() {
+            auto l = new Graphics::Layer;
+            Add(l);
+            return l;
+        }
 
+        void added(Layer &l) override {
+            long ind = children.FindLocation(extenderlayer);
+            if(ind != -1) {
+                children.MoveBefore(ind, children.GetSize());
+            }
+            
+            Gorgon::Window::added(l);
+        }
+        
 
     private:
-		bool quiting = false;
+        bool quiting = false;
+        Graphics::Layer *extenderlayer = layerinit();
 
-		decltype(KeyEvent)::Token inputtoken = keyinit(); //to initialize token after window got constructed
-		decltype(CharacterEvent)::Token chartoken = charinit(); //to initialize token after window got constructed
+        decltype(KeyEvent)::Token inputtoken = keyinit(); //to initialize token after window got constructed
+        decltype(CharacterEvent)::Token chartoken = charinit(); //to initialize token after window got constructed
     };
     
 } }
--- a/Source/Gorgon/Window.cpp	Sun Nov 01 20:45:20 2020 +0200
+++ b/Source/Gorgon/Window.cpp	Mon Nov 02 18:53:00 2020 +0200
@@ -214,7 +214,9 @@
 	}
 	
 	void Window::added(Layer &) {
-        children.MoveBefore(*pointerlayer, children.GetSize());
+        long ind = children.FindLocation(pointerlayer);
+        if(ind != -1)
+            children.MoveBefore(ind, children.GetSize());
     }
     
     void Window::SwitchToLocalPointers() {

mercurial