|
@@ -108,7 +108,8 @@ UI::UI(Context* context) :
|
|
|
uiRendered_(false),
|
|
uiRendered_(false),
|
|
|
nonModalBatchSize_(0),
|
|
nonModalBatchSize_(0),
|
|
|
dragElementsCount_(0),
|
|
dragElementsCount_(0),
|
|
|
- dragConfirmedCount_(0)
|
|
|
|
|
|
|
+ dragConfirmedCount_(0),
|
|
|
|
|
+ uiScale_(1.0f)
|
|
|
{
|
|
{
|
|
|
rootElement_->SetTraversalMode(TM_DEPTH_FIRST);
|
|
rootElement_->SetTraversalMode(TM_DEPTH_FIRST);
|
|
|
rootModalElement_->SetTraversalMode(TM_DEPTH_FIRST);
|
|
rootModalElement_->SetTraversalMode(TM_DEPTH_FIRST);
|
|
@@ -362,7 +363,10 @@ void UI::Update(float timeStep)
|
|
|
for (unsigned i = 0; i < numTouches; ++i)
|
|
for (unsigned i = 0; i < numTouches; ++i)
|
|
|
{
|
|
{
|
|
|
TouchState* touch = input->GetTouch(i);
|
|
TouchState* touch = input->GetTouch(i);
|
|
|
- ProcessHover(touch->position_, TOUCHID_MASK(touch->touchID_), 0, 0);
|
|
|
|
|
|
|
+ IntVector2 touchPos = touch->position_;
|
|
|
|
|
+ touchPos.x_ = (int)(touchPos.x_ / uiScale_);
|
|
|
|
|
+ touchPos.y_ = (int)(touchPos.y_ / uiScale_);
|
|
|
|
|
+ ProcessHover(touchPos, TOUCHID_MASK(touch->touchID_), 0, 0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// End hovers that expired without refreshing
|
|
// End hovers that expired without refreshing
|
|
@@ -404,7 +408,7 @@ void UI::RenderUpdate()
|
|
|
batches_.Clear();
|
|
batches_.Clear();
|
|
|
vertexData_.Clear();
|
|
vertexData_.Clear();
|
|
|
const IntVector2& rootSize = rootElement_->GetSize();
|
|
const IntVector2& rootSize = rootElement_->GetSize();
|
|
|
- IntRect currentScissor = IntRect(0, 0, rootSize.x_, rootSize.y_);
|
|
|
|
|
|
|
+ IntRect currentScissor = IntRect(0, 0, (int)(rootSize.x_ / uiScale_), (int)(rootSize.y_ / uiScale_));
|
|
|
if (rootElement_->IsVisible())
|
|
if (rootElement_->IsVisible())
|
|
|
GetBatches(rootElement_, currentScissor);
|
|
GetBatches(rootElement_, currentScissor);
|
|
|
|
|
|
|
@@ -756,9 +760,9 @@ void UI::Render(bool resetRenderTargets, VertexBuffer* buffer, const PODVector<U
|
|
|
Vector2 offset(-1.0f, 1.0f);
|
|
Vector2 offset(-1.0f, 1.0f);
|
|
|
|
|
|
|
|
Matrix4 projection(Matrix4::IDENTITY);
|
|
Matrix4 projection(Matrix4::IDENTITY);
|
|
|
- projection.m00_ = scale.x_;
|
|
|
|
|
|
|
+ projection.m00_ = scale.x_ * uiScale_;
|
|
|
projection.m03_ = offset.x_;
|
|
projection.m03_ = offset.x_;
|
|
|
- projection.m11_ = scale.y_;
|
|
|
|
|
|
|
+ projection.m11_ = scale.y_ * uiScale_;
|
|
|
projection.m13_ = offset.y_;
|
|
projection.m13_ = offset.y_;
|
|
|
projection.m22_ = 1.0f;
|
|
projection.m22_ = 1.0f;
|
|
|
projection.m23_ = 0.0f;
|
|
projection.m23_ = 0.0f;
|
|
@@ -819,8 +823,14 @@ void UI::Render(bool resetRenderTargets, VertexBuffer* buffer, const PODVector<U
|
|
|
if (graphics_->NeedParameterUpdate(SP_MATERIAL, this))
|
|
if (graphics_->NeedParameterUpdate(SP_MATERIAL, this))
|
|
|
graphics_->SetShaderParameter(PSP_MATDIFFCOLOR, Color(1.0f, 1.0f, 1.0f, 1.0f));
|
|
graphics_->SetShaderParameter(PSP_MATDIFFCOLOR, Color(1.0f, 1.0f, 1.0f, 1.0f));
|
|
|
|
|
|
|
|
|
|
+ IntRect scissor = batch.scissor_;
|
|
|
|
|
+ scissor.left_ = (int)(scissor.left_ * uiScale_);
|
|
|
|
|
+ scissor.top_ = (int)(scissor.top_ * uiScale_);
|
|
|
|
|
+ scissor.right_ = (int)(scissor.right_ * uiScale_);
|
|
|
|
|
+ scissor.bottom_ = (int)(scissor.bottom_ * uiScale_);
|
|
|
|
|
+
|
|
|
graphics_->SetBlendMode(batch.blendMode_);
|
|
graphics_->SetBlendMode(batch.blendMode_);
|
|
|
- graphics_->SetScissorTest(true, batch.scissor_);
|
|
|
|
|
|
|
+ graphics_->SetScissorTest(true, scissor);
|
|
|
graphics_->SetTexture(0, batch.texture_);
|
|
graphics_->SetTexture(0, batch.texture_);
|
|
|
graphics_->Draw(TRIANGLE_LIST, batch.vertexStart_ / UI_VERTEX_SIZE,
|
|
graphics_->Draw(TRIANGLE_LIST, batch.vertexStart_ / UI_VERTEX_SIZE,
|
|
|
(batch.vertexEnd_ - batch.vertexStart_) / UI_VERTEX_SIZE);
|
|
(batch.vertexEnd_ - batch.vertexStart_) / UI_VERTEX_SIZE);
|
|
@@ -979,6 +989,9 @@ void UI::GetCursorPositionAndVisible(IntVector2& pos, bool& visible)
|
|
|
if (!visible && cursor_)
|
|
if (!visible && cursor_)
|
|
|
pos = cursor_->GetPosition();
|
|
pos = cursor_->GetPosition();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ pos.x_ = (int)(pos.x_ / uiScale_);
|
|
|
|
|
+ pos.y_ = (int)(pos.y_ / uiScale_);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void UI::SetCursorShape(CursorShape shape)
|
|
void UI::SetCursorShape(CursorShape shape)
|
|
@@ -1506,6 +1519,8 @@ void UI::HandleTouchBegin(StringHash eventType, VariantMap& eventData)
|
|
|
using namespace TouchBegin;
|
|
using namespace TouchBegin;
|
|
|
|
|
|
|
|
IntVector2 pos(eventData[P_X].GetInt(), eventData[P_Y].GetInt());
|
|
IntVector2 pos(eventData[P_X].GetInt(), eventData[P_Y].GetInt());
|
|
|
|
|
+ pos.x_ = int(pos.x_ / uiScale_);
|
|
|
|
|
+ pos.y_ = int(pos.y_ / uiScale_);
|
|
|
usingTouchInput_ = true;
|
|
usingTouchInput_ = true;
|
|
|
|
|
|
|
|
int touchId = TOUCHID_MASK(eventData[P_TOUCHID].GetInt());
|
|
int touchId = TOUCHID_MASK(eventData[P_TOUCHID].GetInt());
|
|
@@ -1525,6 +1540,8 @@ void UI::HandleTouchEnd(StringHash eventType, VariantMap& eventData)
|
|
|
using namespace TouchEnd;
|
|
using namespace TouchEnd;
|
|
|
|
|
|
|
|
IntVector2 pos(eventData[P_X].GetInt(), eventData[P_Y].GetInt());
|
|
IntVector2 pos(eventData[P_X].GetInt(), eventData[P_Y].GetInt());
|
|
|
|
|
+ pos.x_ = int(pos.x_ / uiScale_);
|
|
|
|
|
+ pos.y_ = int(pos.y_ / uiScale_);
|
|
|
|
|
|
|
|
// Get the touch index
|
|
// Get the touch index
|
|
|
int touchId = TOUCHID_MASK(eventData[P_TOUCHID].GetInt());
|
|
int touchId = TOUCHID_MASK(eventData[P_TOUCHID].GetInt());
|
|
@@ -1554,6 +1571,10 @@ void UI::HandleTouchMove(StringHash eventType, VariantMap& eventData)
|
|
|
|
|
|
|
|
IntVector2 pos(eventData[P_X].GetInt(), eventData[P_Y].GetInt());
|
|
IntVector2 pos(eventData[P_X].GetInt(), eventData[P_Y].GetInt());
|
|
|
IntVector2 deltaPos(eventData[P_DX].GetInt(), eventData[P_DY].GetInt());
|
|
IntVector2 deltaPos(eventData[P_DX].GetInt(), eventData[P_DY].GetInt());
|
|
|
|
|
+ pos.x_ = int(pos.x_ / uiScale_);
|
|
|
|
|
+ pos.y_ = int(pos.y_ / uiScale_);
|
|
|
|
|
+ deltaPos.x_ = int(deltaPos.x_ / uiScale_);
|
|
|
|
|
+ deltaPos.y_ = int(deltaPos.y_ / uiScale_);
|
|
|
usingTouchInput_ = true;
|
|
usingTouchInput_ = true;
|
|
|
|
|
|
|
|
int touchId = TOUCHID_MASK(eventData[P_TOUCHID].GetInt());
|
|
int touchId = TOUCHID_MASK(eventData[P_TOUCHID].GetInt());
|
|
@@ -1676,6 +1697,9 @@ void UI::HandleDropFile(StringHash eventType, VariantMap& eventData)
|
|
|
if (input->IsMouseVisible())
|
|
if (input->IsMouseVisible())
|
|
|
{
|
|
{
|
|
|
IntVector2 screenPos = input->GetMousePosition();
|
|
IntVector2 screenPos = input->GetMousePosition();
|
|
|
|
|
+ screenPos.x_ = int(screenPos.x_ / uiScale_);
|
|
|
|
|
+ screenPos.y_ = int(screenPos.y_ / uiScale_);
|
|
|
|
|
+
|
|
|
UIElement* element = GetElementAt(screenPos);
|
|
UIElement* element = GetElementAt(screenPos);
|
|
|
|
|
|
|
|
using namespace UIDropFile;
|
|
using namespace UIDropFile;
|
|
@@ -1759,8 +1783,8 @@ IntVector2 UI::SumTouchPositions(UI::DragData* dragData, const IntVector2& oldSe
|
|
|
if (!ts)
|
|
if (!ts)
|
|
|
break;
|
|
break;
|
|
|
IntVector2 pos = ts->position_;
|
|
IntVector2 pos = ts->position_;
|
|
|
- dragData->sumPos.x_ += pos.x_;
|
|
|
|
|
- dragData->sumPos.y_ += pos.y_;
|
|
|
|
|
|
|
+ dragData->sumPos.x_ += (int)(pos.x_ / uiScale_);
|
|
|
|
|
+ dragData->sumPos.y_ += (int)(pos.y_ / uiScale_);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
sendPos.x_ = dragData->sumPos.x_ / dragData->numDragButtons;
|
|
sendPos.x_ = dragData->sumPos.x_ / dragData->numDragButtons;
|
|
@@ -1769,6 +1793,24 @@ IntVector2 UI::SumTouchPositions(UI::DragData* dragData, const IntVector2& oldSe
|
|
|
return sendPos;
|
|
return sendPos;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void UI::SetWidth(float size)
|
|
|
|
|
+{
|
|
|
|
|
+ Graphics* g = GetSubsystem<Graphics>();
|
|
|
|
|
+ if (g)
|
|
|
|
|
+ {
|
|
|
|
|
+ uiScale_ = g->GetWidth() / size;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void UI::SetHeight(float size)
|
|
|
|
|
+{
|
|
|
|
|
+ Graphics* g = GetSubsystem<Graphics>();
|
|
|
|
|
+ if (g)
|
|
|
|
|
+ {
|
|
|
|
|
+ uiScale_ = g->GetHeight() / size;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void RegisterUILibrary(Context* context)
|
|
void RegisterUILibrary(Context* context)
|
|
|
{
|
|
{
|
|
|
Font::RegisterObject(context);
|
|
Font::RegisterObject(context);
|