mirror of
https://github.com/whoahq/whoa.git
synced 2026-02-01 00:02:45 +03:00
chore(ui): make ORIENTATION enum generic
This commit is contained in:
parent
32b5d6402b
commit
a6e93122a7
@ -88,9 +88,9 @@ enum PLURAL_RULE {
|
|||||||
PLURAL_RULE_2 = 2
|
PLURAL_RULE_2 = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
enum SLIDER_ORIENTATION {
|
enum ORIENTATION {
|
||||||
SLIDER_HORIZONTAL = 0,
|
ORIENTATION_HORIZONTAL = 0,
|
||||||
SLIDER_VERTICAL = 1,
|
ORIENTATION_VERTICAL = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum TextureImageMode {
|
enum TextureImageMode {
|
||||||
|
|||||||
@ -87,15 +87,15 @@ int32_t StringToFrameStrata(const char* string, FRAME_STRATA& strata) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t StringToOrientation(const char* string, SLIDER_ORIENTATION& orientation) {
|
int32_t StringToOrientation(const char* string, ORIENTATION& orientation) {
|
||||||
struct OrientationEntry {
|
struct OrientationEntry {
|
||||||
SLIDER_ORIENTATION value;
|
ORIENTATION value;
|
||||||
const char* string;
|
const char* string;
|
||||||
};
|
};
|
||||||
|
|
||||||
static OrientationEntry orientationMap[] = {
|
static OrientationEntry orientationMap[] = {
|
||||||
{ SLIDER_HORIZONTAL, "HORIZONTAL" },
|
{ ORIENTATION_HORIZONTAL, "HORIZONTAL" },
|
||||||
{ SLIDER_VERTICAL, "VERTICAL" },
|
{ ORIENTATION_VERTICAL, "VERTICAL" },
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto& entry : orientationMap) {
|
for (auto& entry : orientationMap) {
|
||||||
|
|||||||
@ -13,6 +13,6 @@ int32_t StringToFramePoint(const char* string, FRAMEPOINT& point);
|
|||||||
|
|
||||||
int32_t StringToFrameStrata(const char* string, FRAME_STRATA& strata);
|
int32_t StringToFrameStrata(const char* string, FRAME_STRATA& strata);
|
||||||
|
|
||||||
int32_t StringToOrientation(const char* string, SLIDER_ORIENTATION& orientation);
|
int32_t StringToOrientation(const char* string, ORIENTATION& orientation);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -111,7 +111,7 @@ void CSimpleSlider::LoadXML(XMLNode* node, CStatus* status) {
|
|||||||
|
|
||||||
auto orientationStr = node->GetAttributeByName("orientation");
|
auto orientationStr = node->GetAttributeByName("orientation");
|
||||||
if (orientationStr && *orientationStr) {
|
if (orientationStr && *orientationStr) {
|
||||||
SLIDER_ORIENTATION orientation;
|
ORIENTATION orientation;
|
||||||
|
|
||||||
if (StringToOrientation(orientationStr, orientation)) {
|
if (StringToOrientation(orientationStr, orientation)) {
|
||||||
this->SetOrientation(orientation);
|
this->SetOrientation(orientation);
|
||||||
@ -163,7 +163,7 @@ int32_t CSimpleSlider::OnLayerTrackUpdate(const CMouseEvent& evt) {
|
|||||||
float area;
|
float area;
|
||||||
float offset;
|
float offset;
|
||||||
|
|
||||||
if (this->m_orientation == SLIDER_VERTICAL) {
|
if (this->m_orientation == ORIENTATION_VERTICAL) {
|
||||||
area = this->m_rect.maxY - this->m_rect.minY - thumbTexture->GetHeight();
|
area = this->m_rect.maxY - this->m_rect.minY - thumbTexture->GetHeight();
|
||||||
offset = this->m_rect.maxY - (thumbTexture->GetHeight() / 2.0f) - evt.y;
|
offset = this->m_rect.maxY - (thumbTexture->GetHeight() / 2.0f) - evt.y;
|
||||||
} else {
|
} else {
|
||||||
@ -188,7 +188,7 @@ void CSimpleSlider::OnLayerUpdate(float elapsedSec) {
|
|||||||
? 0.0f
|
? 0.0f
|
||||||
: (this->m_value - this->m_baseValue) / valueRange;
|
: (this->m_value - this->m_baseValue) / valueRange;
|
||||||
|
|
||||||
if (this->m_orientation == SLIDER_VERTICAL) {
|
if (this->m_orientation == ORIENTATION_VERTICAL) {
|
||||||
auto rangeY = (this->m_rect.maxY - this->m_rect.minY) / this->m_layoutScale;
|
auto rangeY = (this->m_rect.maxY - this->m_rect.minY) / this->m_layoutScale;
|
||||||
auto offsetY = -((rangeY - this->m_thumbTexture->GetHeight()) * valueOffset);
|
auto offsetY = -((rangeY - this->m_thumbTexture->GetHeight()) * valueOffset);
|
||||||
|
|
||||||
@ -249,7 +249,7 @@ void CSimpleSlider::SetMinMaxValues(float min, float max) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimpleSlider::SetOrientation(SLIDER_ORIENTATION orientation) {
|
void CSimpleSlider::SetOrientation(ORIENTATION orientation) {
|
||||||
this->m_orientation = orientation;
|
this->m_orientation = orientation;
|
||||||
|
|
||||||
if (this->m_thumbTexture) {
|
if (this->m_thumbTexture) {
|
||||||
|
|||||||
@ -24,7 +24,7 @@ class CSimpleSlider : public CSimpleFrame {
|
|||||||
float m_value = 0.0f;
|
float m_value = 0.0f;
|
||||||
float m_valueStep = 0.0f;
|
float m_valueStep = 0.0f;
|
||||||
CSimpleTexture* m_thumbTexture = nullptr;
|
CSimpleTexture* m_thumbTexture = nullptr;
|
||||||
SLIDER_ORIENTATION m_orientation = SLIDER_VERTICAL;
|
ORIENTATION m_orientation = ORIENTATION_VERTICAL;
|
||||||
ScriptIx m_onValueChanged;
|
ScriptIx m_onValueChanged;
|
||||||
ScriptIx m_onMinMaxChanged;
|
ScriptIx m_onMinMaxChanged;
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ class CSimpleSlider : public CSimpleFrame {
|
|||||||
void RunOnMinMaxChangedScript();
|
void RunOnMinMaxChangedScript();
|
||||||
void RunOnValueChangedScript();
|
void RunOnValueChangedScript();
|
||||||
void SetMinMaxValues(float min, float max);
|
void SetMinMaxValues(float min, float max);
|
||||||
void SetOrientation(SLIDER_ORIENTATION orientation);
|
void SetOrientation(ORIENTATION orientation);
|
||||||
void SetThumbTexture(CSimpleTexture* texture, int32_t drawLayer);
|
void SetThumbTexture(CSimpleTexture* texture, int32_t drawLayer);
|
||||||
void SetValue(float value);
|
void SetValue(float value);
|
||||||
void SetValueStep(float valueStep);
|
void SetValueStep(float valueStep);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user