Improve UI
This commit is contained in:
parent
96eb91ff78
commit
fd71242a42
@ -82,6 +82,52 @@ int UIElement::uiToScreen(UIValue val) {
|
||||
return px;
|
||||
}
|
||||
|
||||
int UIElement::offsetX(int w, Origin origin) {
|
||||
switch(origin) {
|
||||
case Origin::TOP_LEFT:
|
||||
case Origin::BOTTOM_LEFT:
|
||||
case Origin::LEFT_CENTER:
|
||||
return 0;
|
||||
|
||||
case Origin::TOP_RIGHT:
|
||||
case Origin::BOTTOM_RIGHT:
|
||||
case Origin::RIGHT_CENTER:
|
||||
return -w;
|
||||
|
||||
case Origin::TOP_CENTER:
|
||||
case Origin::BOTTOM_CENTER:
|
||||
case Origin::CENTER:
|
||||
return -w / 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int UIElement::offsetY(int h, Origin origin) {
|
||||
switch(origin) {
|
||||
case Origin::TOP_LEFT:
|
||||
case Origin::TOP_CENTER:
|
||||
case Origin::TOP_RIGHT:
|
||||
return 0;
|
||||
|
||||
case Origin::BOTTOM_LEFT:
|
||||
case Origin::BOTTOM_CENTER:
|
||||
case Origin::BOTTOM_RIGHT:
|
||||
return -h;
|
||||
|
||||
case Origin::LEFT_CENTER:
|
||||
case Origin::RIGHT_CENTER:
|
||||
case Origin::CENTER:
|
||||
return -h / 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
UIBounds UIElement::offsetUIBounds(int w, int h, Origin origin) {
|
||||
return UIBounds(offsetX(w, origin), offsetY(h, origin), w, h);
|
||||
}
|
||||
|
||||
void UIElement::drawAll(UIPoint screenPos, glm::mat4 projection) {
|
||||
if(!visible) return;
|
||||
draw(screenPos, projection);
|
||||
|
@ -6,52 +6,6 @@
|
||||
|
||||
namespace kek {
|
||||
|
||||
static inline int offsetX(int w, Origin origin) {
|
||||
switch(origin) {
|
||||
case Origin::TOP_LEFT:
|
||||
case Origin::BOTTOM_LEFT:
|
||||
case Origin::LEFT_CENTER:
|
||||
return 0;
|
||||
|
||||
case Origin::TOP_RIGHT:
|
||||
case Origin::BOTTOM_RIGHT:
|
||||
case Origin::RIGHT_CENTER:
|
||||
return -w;
|
||||
|
||||
case Origin::TOP_CENTER:
|
||||
case Origin::BOTTOM_CENTER:
|
||||
case Origin::CENTER:
|
||||
return -w / 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int offsetY(int h, Origin origin) {
|
||||
switch(origin) {
|
||||
case Origin::TOP_LEFT:
|
||||
case Origin::TOP_CENTER:
|
||||
case Origin::TOP_RIGHT:
|
||||
return 0;
|
||||
|
||||
case Origin::BOTTOM_LEFT:
|
||||
case Origin::BOTTOM_CENTER:
|
||||
case Origin::BOTTOM_RIGHT:
|
||||
return -h;
|
||||
|
||||
case Origin::LEFT_CENTER:
|
||||
case Origin::RIGHT_CENTER:
|
||||
case Origin::CENTER:
|
||||
return -h / 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline UIBounds offsetUIBounds(int w, int h, Origin origin) {
|
||||
return UIBounds(offsetX(w, origin), offsetY(h, origin), w, h);
|
||||
}
|
||||
|
||||
TextElement::TextElement(UIValue x, UIValue y, Font *font): UIElement(x, y) {
|
||||
this->text = new TextObject(font, "Text");
|
||||
this->sizePixels = KEK_DEFAULT_FONT_SIZE_PIXELS;
|
||||
|
@ -41,23 +41,6 @@ enum class UIElementType {
|
||||
GROUP
|
||||
};
|
||||
|
||||
enum class TextMode {
|
||||
// Draw with y as baseline, disables vertical offset from the origin position specified using setOrigin()
|
||||
BASELINE,
|
||||
// Draw from the set origin
|
||||
ORIGIN
|
||||
};
|
||||
|
||||
enum class TextBounds {
|
||||
SMALLEST,
|
||||
LINE
|
||||
};
|
||||
|
||||
enum class SliderDirection {
|
||||
HORIZONTAL,
|
||||
VERTICAL
|
||||
};
|
||||
|
||||
enum class Origin {
|
||||
TOP_LEFT,
|
||||
TOP_CENTER,
|
||||
@ -150,6 +133,9 @@ public:
|
||||
|
||||
protected:
|
||||
int uiToScreen(UIValue val);
|
||||
static int offsetX(int w, Origin origin);
|
||||
static int offsetY(int h, Origin origin);
|
||||
static UIBounds offsetUIBounds(int w, int h, Origin origin);
|
||||
|
||||
public:
|
||||
// Returns the bounds of the element relative to its origin
|
||||
|
@ -16,6 +16,18 @@ class UIWindow: public UIElement {
|
||||
|
||||
};
|
||||
|
||||
enum class TextMode {
|
||||
// Draw with y as baseline, disables vertical offset from the origin position specified using setOrigin()
|
||||
BASELINE,
|
||||
// Draw from the set origin
|
||||
ORIGIN
|
||||
};
|
||||
|
||||
enum class TextBounds {
|
||||
SMALLEST,
|
||||
LINE
|
||||
};
|
||||
|
||||
class TextElement: public UIElement {
|
||||
|
||||
protected:
|
||||
|
Loading…
Reference in New Issue
Block a user