make point hitbox bigger

This commit is contained in:
marmare314 2023-07-23 10:15:01 +02:00
parent b57cd2e210
commit 862c0ca2fc
2 changed files with 131 additions and 49 deletions

View file

@ -1645,11 +1645,6 @@ void CEditor::DoQuad(CQuad *pQuad, int Index)
float CenterX = fx2f(pQuad->m_aPoints[4].x);
float CenterY = fx2f(pQuad->m_aPoints[4].y);
float dx = (CenterX - wx) / m_MouseWScale;
float dy = (CenterY - wy) / m_MouseWScale;
if(dx * dx + dy * dy < 50)
UI()->SetHotItem(pID);
const bool IgnoreGrid = Input()->AltIsPressed();
// draw selection background
@ -1936,11 +1931,6 @@ void CEditor::DoQuadPoint(CQuad *pQuad, int QuadIndex, int V)
float px = fx2f(pQuad->m_aPoints[V].x);
float py = fx2f(pQuad->m_aPoints[V].y);
float dx = (px - wx) / m_MouseWScale;
float dy = (py - wy) / m_MouseWScale;
if(dx * dx + dy * dy < 50)
UI()->SetHotItem(pID);
// draw selection background
if(IsQuadPointSelected(QuadIndex, V))
{
@ -2485,23 +2475,14 @@ void CEditor::DoQuadEnvPoint(const CQuad *pQuad, int QIndex, int PIndex)
float wy = UI()->MouseWorldY();
CEnvelope *pEnvelope = m_Map.m_vpEnvelopes[pQuad->m_PosEnv];
void *pID = &pEnvelope->m_vPoints[PIndex];
static int s_CurQIndex = -1;
// get pivot
float CenterX = fx2f(pQuad->m_aPoints[4].x) + fx2f(pEnvelope->m_vPoints[PIndex].m_aValues[0]);
float CenterY = fx2f(pQuad->m_aPoints[4].y) + fx2f(pEnvelope->m_vPoints[PIndex].m_aValues[1]);
float dx = (CenterX - wx) / m_MouseWScale;
float dy = (CenterY - wy) / m_MouseWScale;
if(dx * dx + dy * dy < 50.0f && UI()->CheckActiveItem(nullptr))
{
UI()->SetHotItem(pID);
s_CurQIndex = QIndex;
}
const bool IgnoreGrid = Input()->AltIsPressed();
if(UI()->CheckActiveItem(pID) && s_CurQIndex == QIndex)
if(UI()->CheckActiveItem(pID) && m_CurrentQuadIndex == QIndex)
{
if(s_Operation == OP_MOVE)
{
@ -2534,7 +2515,7 @@ void CEditor::DoQuadEnvPoint(const CQuad *pQuad, int QIndex, int PIndex)
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
}
else if(UI()->HotItem() == pID && s_CurQIndex == QIndex)
else if(UI()->HotItem() == pID && m_CurrentQuadIndex == QIndex)
{
ms_pUiGotContext = pID;
@ -3068,6 +3049,8 @@ void CEditor::DoMapEditor(CUIRect View)
DoQuadKnife(m_vSelectedQuads[m_SelectedQuadIndex]);
else
{
SetHotQuadPoint(pLayer);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
for(size_t i = 0; i < pLayer->m_vQuads.size(); i++)
@ -3377,6 +3360,51 @@ void CEditor::DoMapEditor(CUIRect View)
UI()->MapScreen();
}
void CEditor::SetHotQuadPoint(CLayerQuads *pLayer)
{
float wx = UI()->MouseWorldX();
float wy = UI()->MouseWorldY();
float MinDist = 500.0f;
void *pMinPoint = nullptr;
auto UpdateMinimum = [&](float px, float py, void *pID) {
float dx = (px - wx) / m_MouseWScale;
float dy = (py - wy) / m_MouseWScale;
float CurrDist = dx * dx + dy * dy;
if(CurrDist < MinDist)
{
MinDist = CurrDist;
pMinPoint = pID;
return true;
}
return false;
};
for(size_t i = 0; i < pLayer->m_vQuads.size(); i++)
{
CQuad &Quad = pLayer->m_vQuads.at(i);
if(m_ShowTileInfo != SHOW_TILE_OFF && m_ShowEnvelopePreview != SHOWENV_NONE && Quad.m_PosEnv >= 0)
{
for(auto &EnvPoint : m_Map.m_vpEnvelopes[Quad.m_PosEnv]->m_vPoints)
{
float px = fx2f(Quad.m_aPoints[4].x) + fx2f(EnvPoint.m_aValues[0]);
float py = fx2f(Quad.m_aPoints[4].y) + fx2f(EnvPoint.m_aValues[1]);
if(UpdateMinimum(px, py, &EnvPoint))
m_CurrentQuadIndex = i;
}
}
for(auto &Point : Quad.m_aPoints)
UpdateMinimum(fx2f(Point.x), fx2f(Point.y), &Point);
}
if(pMinPoint != nullptr)
UI()->SetHotItem(pMinPoint);
}
int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int *pNewVal, ColorRGBA Color)
{
int Change = -1;
@ -5933,6 +5961,57 @@ private:
}
};
void CEditor::SetHotEnvelopePoint(const CUIRect &View, CEnvelope *pEnvelope)
{
if(!UI()->MouseInside(&View))
return;
float mx = UI()->MouseX();
float my = UI()->MouseY();
float MinDist = 200.0f;
int *pMinPoint = nullptr;
auto UpdateMinimum = [&](float px, float py, int *pID) {
float dx = px - mx;
float dy = py - my;
float CurrDist = dx * dx + dy * dy;
if(CurrDist < MinDist)
{
MinDist = CurrDist;
pMinPoint = pID;
}
};
for(size_t i = 0; i < pEnvelope->m_vPoints.size(); i++)
{
for(int c = 0; c < pEnvelope->GetChannels(); c++)
{
if(i > 0 && pEnvelope->m_vPoints[i - 1].m_Curvetype == CURVETYPE_BEZIER)
{
float px = EnvelopeToScreenX(View, fxt2f(pEnvelope->m_vPoints[i].m_Time + pEnvelope->m_vPoints[i].m_Bezier.m_aInTangentDeltaX[c]));
float py = EnvelopeToScreenY(View, fx2f(pEnvelope->m_vPoints[i].m_aValues[c] + pEnvelope->m_vPoints[i].m_Bezier.m_aInTangentDeltaY[c]));
UpdateMinimum(px, py, &pEnvelope->m_vPoints[i].m_Bezier.m_aInTangentDeltaX[c]);
}
if(pEnvelope->m_vPoints[i].m_Curvetype == CURVETYPE_BEZIER)
{
float px = EnvelopeToScreenX(View, fxt2f(pEnvelope->m_vPoints[i].m_Time + pEnvelope->m_vPoints[i].m_Bezier.m_aOutTangentDeltaX[c]));
float py = EnvelopeToScreenY(View, fx2f(pEnvelope->m_vPoints[i].m_aValues[c] + pEnvelope->m_vPoints[i].m_Bezier.m_aOutTangentDeltaY[c]));
UpdateMinimum(px, py, &pEnvelope->m_vPoints[i].m_Bezier.m_aOutTangentDeltaX[c]);
}
float px = EnvelopeToScreenX(View, fxt2f(pEnvelope->m_vPoints[i].m_Time));
float py = EnvelopeToScreenY(View, fx2f(pEnvelope->m_vPoints[i].m_aValues[c]));
UpdateMinimum(px, py, &pEnvelope->m_vPoints[i].m_aValues[c]);
}
}
if(pMinPoint != nullptr)
UI()->SetHotItem(pMinPoint);
}
void CEditor::RenderEnvelopeEditor(CUIRect View)
{
if(m_SelectedEnvelope < 0)
@ -6198,8 +6277,30 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
UI()->DoLabel(&Button, "Sync.", 10.0f, TEXTALIGN_ML);
if(UI()->MouseInside(&View))
{
UI()->SetHotItem(&s_EnvelopeEditorID);
if(UI()->MouseButton(2) || (UI()->MouseButton(0) && Input()->ModifierIsPressed()))
{
m_OffsetEnvelopeX += UI()->MouseDeltaX() / Graphics()->ScreenWidth() * UI()->Screen()->w / View.w;
m_OffsetEnvelopeY -= UI()->MouseDeltaY() / Graphics()->ScreenHeight() * UI()->Screen()->h / View.h;
}
if(Input()->ShiftIsPressed())
{
if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN))
m_ZoomEnvelopeY.ChangeZoom(0.1f * m_ZoomEnvelopeY.GetZoom());
if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP))
m_ZoomEnvelopeY.ChangeZoom(-0.1f * m_ZoomEnvelopeY.GetZoom());
}
else
{
if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN))
m_ZoomEnvelopeX.ChangeZoom(0.1f * m_ZoomEnvelopeX.GetZoom());
if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP))
m_ZoomEnvelopeX.ChangeZoom(-0.1f * m_ZoomEnvelopeX.GetZoom());
}
}
if(UI()->HotItem() == &s_EnvelopeEditorID)
{
// do stuff
@ -6220,25 +6321,6 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
RemoveTimeOffsetEnvelope(pEnvelope);
m_Map.OnModify();
}
else if(UI()->MouseButton(2) || (UI()->MouseButton(0) && Input()->ModifierIsPressed()))
{
m_OffsetEnvelopeX += UI()->MouseDeltaX() / Graphics()->ScreenWidth() * UI()->Screen()->w / View.w;
m_OffsetEnvelopeY -= UI()->MouseDeltaY() / Graphics()->ScreenHeight() * UI()->Screen()->h / View.h;
}
if(Input()->ShiftIsPressed())
{
if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN))
m_ZoomEnvelopeY.ChangeZoom(0.1f * m_ZoomEnvelopeY.GetZoom());
if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP))
m_ZoomEnvelopeY.ChangeZoom(-0.1f * m_ZoomEnvelopeY.GetZoom());
}
else
{
if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN))
m_ZoomEnvelopeX.ChangeZoom(0.1f * m_ZoomEnvelopeX.GetZoom());
if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP))
m_ZoomEnvelopeX.ChangeZoom(-0.1f * m_ZoomEnvelopeX.GetZoom());
}
m_ShowEnvelopePreview = SHOWENV_SELECTED;
m_pTooltip = "Double-click to create a new point. Use shift to change the zoom axis.";
@ -6505,6 +6587,8 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
}
{
SetHotEnvelopePoint(View, pEnvelope);
UI()->ClipEnable(&View);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
@ -6527,9 +6611,6 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
const void *pID = &pEnvelope->m_vPoints[i].m_aValues[c];
if(UI()->MouseInside(&Final) && UI()->MouseInside(&View))
UI()->SetHotItem(pID);
if(IsEnvPointSelected(i, c))
{
Graphics()->SetColor(1, 1, 1, 1);
@ -6741,9 +6822,6 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
Graphics()->QuadsDrawFreeform(&FreeformItem, 1);
}
if(UI()->MouseInside(&Final) && UI()->MouseInside(&View))
UI()->SetHotItem(pID);
if(UI()->CheckActiveItem(pID))
{
m_ShowEnvelopePreview = SHOWENV_SELECTED;
@ -6876,9 +6954,6 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
Graphics()->QuadsDrawFreeform(&FreeformItem, 1);
}
if(UI()->MouseInside(&Final) && UI()->MouseInside(&View))
UI()->SetHotItem(pID);
if(UI()->CheckActiveItem(pID))
{
m_ShowEnvelopePreview = SHOWENV_SELECTED;

View file

@ -949,10 +949,12 @@ public:
m_ShowEnvelopePreview = SHOWENV_NONE;
m_SelectedQuadEnvelope = -1;
m_vSelectedEnvelopePoints = {};
m_UpdateEnvPointInfo = false;
m_SelectedTangentInPoint = std::pair(-1, -1);
m_SelectedTangentOutPoint = std::pair(-1, -1);
m_CurrentQuadIndex = -1;
m_QuadKnifeActive = false;
m_QuadKnifeCount = 0;
@ -1292,6 +1294,7 @@ public:
int m_SelectedEnvelope;
std::vector<std::pair<int, int>> m_vSelectedEnvelopePoints;
int m_SelectedQuadEnvelope;
int m_CurrentQuadIndex;
int m_SelectedImage;
int m_SelectedSound;
int m_SelectedSource;
@ -1407,6 +1410,7 @@ public:
void DoQuadEnvelopes(const std::vector<CQuad> &vQuads, IGraphics::CTextureHandle Texture = IGraphics::CTextureHandle());
void DoQuadEnvPoint(const CQuad *pQuad, int QIndex, int pIndex);
void DoQuadPoint(CQuad *pQuad, int QuadIndex, int v);
void SetHotQuadPoint(CLayerQuads *pLayer);
float TriangleArea(vec2 A, vec2 B, vec2 C);
bool IsInTriangle(vec2 Point, vec2 A, vec2 B, vec2 C);
@ -1442,8 +1446,11 @@ public:
void RenderEnvelopeEditor(CUIRect View);
void RenderServerSettingsEditor(CUIRect View, bool ShowServerSettingsEditorLast);
void RenderExtraEditorDragBar(CUIRect View, CUIRect DragBar);
void SetHotEnvelopePoint(const CUIRect &View, CEnvelope *pEnvelope);
void RenderMenubar(CUIRect Menubar);
void RenderFileDialog();