]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/geometry.h
Rework how widget ownership works in Container
[libs/gltk.git] / source / geometry.h
index 7e59bd4936f7dc4f82797f9a97170532527b0a37..cb99cedecb8d6198e89bc869c633eb9a07d55f22 100644 (file)
@@ -1,19 +1,69 @@
 #ifndef MSP_GLTK_GEOMETRY_H_
 #define MSP_GLTK_GEOMETRY_H_
 
+#include <msp/datafile/objectloader.h>
+#include "mspgltk_api.h"
+
 namespace Msp {
 namespace GLtk {
 
 /**
 Specifies the position and size of a widget or graphic.
 */
-struct Geometry
+struct MSPGLTK_API Geometry
 {
-       int x, y;
-       unsigned w, h;
+       int x = 0;
+       int y = 0;
+       unsigned w = 1;
+       unsigned h = 1;
 
-       Geometry(): x(0), y(0), w(1), h(1) { }
+       Geometry() = default;
        Geometry(int x_, int y_, unsigned w_, unsigned h_): x(x_), y(y_), w(w_), h(h_) { }
+
+       bool is_inside(int, int) const;
+       bool is_inside_relative(int, int) const;
+};
+
+
+/**
+Specifies margins on the sides of an element.
+*/
+struct MSPGLTK_API Sides
+{
+       class Loader: public DataFile::ObjectLoader<Sides>
+       {
+       public:
+               Loader(Sides &);
+       private:
+               void horizontal(unsigned);
+               void vertical(unsigned);
+       };
+
+       unsigned top = 0;
+       unsigned right = 0;
+       unsigned bottom = 0;
+       unsigned left = 0;
+
+       Sides() = default;
+       Sides(unsigned);
+       Sides(unsigned, unsigned);
+       Sides(unsigned, unsigned, unsigned);
+       Sides(unsigned, unsigned, unsigned, unsigned);
+};
+
+
+/**
+Performs alignment of nested geometries, such as widgets and their parts.
+*/
+struct MSPGLTK_API Alignment
+{
+       float x = 0.0f;
+       float y = 0.0f;
+       float w = 1.0f;
+       float h = 1.0f;
+
+       void apply(Geometry &, const Geometry &) const;
+       void apply(Geometry &, const Geometry &, const Sides &) const;
 };
 
 } // namespace GLtk