| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  | MIT License | 
					
						
							|  |  |  | Copyright (c) 2024 - 2025 René Amthor (tobid7) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Permission is hereby granted, free of charge, to any person obtaining a copy | 
					
						
							|  |  |  | of this software and associated documentation files (the "Software"), to deal | 
					
						
							|  |  |  | in the Software without restriction, including without limitation the rights | 
					
						
							|  |  |  | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
					
						
							|  |  |  | copies of the Software, and to permit persons to whom the Software is | 
					
						
							|  |  |  | furnished to do so, subject to the following conditions: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The above copyright notice and this permission notice shall be included in all | 
					
						
							|  |  |  | copies or substantial portions of the Software. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
					
						
							|  |  |  | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
					
						
							|  |  |  | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
					
						
							|  |  |  | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 
					
						
							|  |  |  | SOFTWARE. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <pd/core/core.hpp>
 | 
					
						
							|  |  |  | #include <pd/ui7/io.hpp>
 | 
					
						
							|  |  |  | #include <pd/ui7/pd_p_api.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace PD { | 
					
						
							|  |  |  | namespace UI7 { | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Container base class all Objects are based on | 
					
						
							|  |  |  |  * @note this class can be used to create custom Objects as well | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  | class PD_UI7_API Container { | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  |  public: | 
					
						
							|  |  |  |   Container() = default; | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Constructor with pos and Size | 
					
						
							|  |  |  |    * @param pos Container Position | 
					
						
							|  |  |  |    * @param size Container Size | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   Container(const fvec2& pos, const fvec2& size) : pos(pos), size(size) {} | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Constructor by a vec4 box | 
					
						
							|  |  |  |    * @param box Box containing top left and bottom right coords | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   Container(const fvec4& box) | 
					
						
							|  |  |  |       : pos(fvec2(box.x, box.y)), size(fvec2(box.z - box.x, box.w - box.y)) {} | 
					
						
							|  |  |  |   ~Container() = default; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  |   PD_SHARED(Container); | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  |   /**
 | 
					
						
							|  |  |  |    * Init Function Required by every Object that uses | 
					
						
							|  |  |  |    * Render or Input functions | 
					
						
							|  |  |  |    * @param io IO Reference | 
					
						
							|  |  |  |    * @param l DrawList Reference | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  |   void Init(UI7::IO::Ref io, Li::DrawList::Ref l) { | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  |     list = l; | 
					
						
							|  |  |  |     this->io = io; | 
					
						
							|  |  |  |     // this->screen = io->Ren->CurrentScreen();
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-01 21:43:35 +02:00
										 |  |  |   void SetClipRect(fvec4 clip) { | 
					
						
							|  |  |  |     pClipRect = clip; | 
					
						
							|  |  |  |     pCLipRectUsed = true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  |   /** Setter for Position */ | 
					
						
							|  |  |  |   void SetPos(const fvec2& pos) { this->pos = pos; } | 
					
						
							|  |  |  |   /** Setter for Size */ | 
					
						
							|  |  |  |   void SetSize(const fvec2& size) { this->size = size; } | 
					
						
							|  |  |  |   /** Getter for Position */ | 
					
						
							|  |  |  |   fvec2 GetPos() { return pos; } | 
					
						
							|  |  |  |   /** Getter for Size */ | 
					
						
							|  |  |  |   fvec2 GetSize() { return size; } | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Get the Containers Final Position | 
					
						
							|  |  |  |    * for Rendering and Input (if it has a parent Object) | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   fvec2 FinalPos() { | 
					
						
							|  |  |  |     vec2 res = pos; | 
					
						
							|  |  |  |     if (parent) { | 
					
						
							|  |  |  |       /// Probably should use parant->FinalPos here
 | 
					
						
							|  |  |  |       res += parent->GetPos(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** Setter for Parent Container */ | 
					
						
							|  |  |  |   void SetParent(Container::Ref v) { parent = v; } | 
					
						
							|  |  |  |   /** Getter for Parent Container */ | 
					
						
							|  |  |  |   Container::Ref GetParent() { return parent; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** Check if Rendering can be skipped */ | 
					
						
							|  |  |  |   bool Skippable() const { return skippable; } | 
					
						
							|  |  |  |   /** Check if the Object got a timeout (ID OBJ Relevant) */ | 
					
						
							|  |  |  |   bool Removable() const { return rem; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Handles Scrolling by scrolling pos as well as | 
					
						
							|  |  |  |    * Time for Remove for ID Objects | 
					
						
							|  |  |  |    * @param scrolling Scrolling Position | 
					
						
							|  |  |  |    * @param viewport Viewport to check if the Object is skippable | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   void HandleScrolling(fvec2 scrolling, fvec4 viewport); | 
					
						
							|  |  |  |   /** Template function for Input Handling */ | 
					
						
							|  |  |  |   virtual void HandleInput() {} | 
					
						
							|  |  |  |   /** Tamplate function for Object rendering */ | 
					
						
							|  |  |  |   virtual void Draw() {} | 
					
						
							|  |  |  |   /** Template function to update internal data (if needed) */ | 
					
						
							|  |  |  |   virtual void Update() {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** Internal Input Handler */ | 
					
						
							|  |  |  |   void HandleInternalInput(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Function to unlock Input after Rendering is done in | 
					
						
							|  |  |  |    * Menu::Update | 
					
						
							|  |  |  |    * @note This is used if the Object got Input Handled directly after creation | 
					
						
							|  |  |  |    * to not check for Inputs twice | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   void UnlockInput() { inp_done = false; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** Get the Objects ID (if it is an ID object)*/ | 
					
						
							|  |  |  |   u32 GetID() const { return id; } | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Set ID for ID Objects | 
					
						
							|  |  |  |    * @param id Object ID (hashed prefix+objname+prefixed_counter) | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   void SetID(u32 id) { this->id = id; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** Get a reference to IO */ | 
					
						
							|  |  |  |   UI7::IO::Ref GetIO() { return io; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  protected: | 
					
						
							|  |  |  |   /** used to skip Input/Render preocessing ot not*/ | 
					
						
							|  |  |  |   bool skippable = false; | 
					
						
							|  |  |  |   /** value to check if an ID Object goes out of lifetime*/ | 
					
						
							|  |  |  |   bool rem = false; | 
					
						
							|  |  |  |   /** Time of the last use (set by HandleScrolling)*/ | 
					
						
							|  |  |  |   u64 last_use = 0; | 
					
						
							|  |  |  |   /** Input done or not for current frame*/ | 
					
						
							|  |  |  |   bool inp_done = false; | 
					
						
							|  |  |  |   /** Reference to the Screen to draw the Object on*/ | 
					
						
							|  |  |  |   // Screen::Ref screen;
 | 
					
						
							|  |  |  |   /** Container Position*/ | 
					
						
							|  |  |  |   fvec2 pos; | 
					
						
							|  |  |  |   /** Container Size*/ | 
					
						
							|  |  |  |   fvec2 size; | 
					
						
							|  |  |  |   /** Reference to the Drawlist to Draw to*/ | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  |   Li::DrawList::Ref list; | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  |   /** IO Reference for Renderer and Theme */ | 
					
						
							|  |  |  |   UI7::IO::Ref io; | 
					
						
							|  |  |  |   /** Reference to the parent container*/ | 
					
						
							|  |  |  |   Container::Ref parent; | 
					
						
							|  |  |  |   /** Object ID (0 if unused)*/ | 
					
						
							|  |  |  |   u32 id = 0; | 
					
						
							|  |  |  |   /** Internal Flags */ | 
					
						
							|  |  |  |   u32 pFlags = 0; | 
					
						
							|  |  |  |   /** Is Selected? */ | 
					
						
							|  |  |  |   bool pSelected = false; | 
					
						
							|  |  |  |   /** Was Pressed */ | 
					
						
							|  |  |  |   bool pPressed = false; | 
					
						
							|  |  |  |   /** Was Pressed Twice */ | 
					
						
							|  |  |  |   bool pPressedTwice = false; | 
					
						
							| 
									
										
										
										
											2025-07-01 21:43:35 +02:00
										 |  |  |   /** ClipRect */ | 
					
						
							|  |  |  |   fvec4 pClipRect; | 
					
						
							|  |  |  |   /** Clip Rect used */ | 
					
						
							|  |  |  |   bool pCLipRectUsed = false; | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | }  // namespace UI7
 | 
					
						
							|  |  |  | }  // namespace PD
 |