2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <base/math.h>
|
2008-08-14 17:19:13 +00:00
|
|
|
|
2010-08-17 22:06:00 +00:00
|
|
|
#include <engine/console.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <engine/graphics.h>
|
2009-10-27 14:38:53 +00:00
|
|
|
|
2011-04-19 08:34:51 +00:00
|
|
|
#include "editor.h"
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <game/generated/client_data.h>
|
|
|
|
#include <game/client/render.h>
|
2010-08-15 23:29:11 +00:00
|
|
|
#include <game/localization.h>
|
2008-01-12 12:27:55 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CLayerQuads::CLayerQuads()
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Type = LAYERTYPE_QUADS;
|
2019-03-24 01:44:33 +00:00
|
|
|
m_aName[0] = '\0';
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Image = -1;
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CLayerQuads::~CLayerQuads()
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-08-19 17:05:42 +00:00
|
|
|
void CLayerQuads::Render(bool QuadPicker)
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2009-10-27 14:38:53 +00:00
|
|
|
Graphics()->TextureSet(-1);
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_Image >= 0 && m_Image < m_pEditor->m_Map.m_lImages.size())
|
2011-02-12 10:40:36 +00:00
|
|
|
Graphics()->TextureSet(m_pEditor->m_Map.m_lImages[m_Image]->m_TexID);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2012-08-13 10:57:40 +00:00
|
|
|
Graphics()->BlendNone();
|
2014-01-11 21:57:23 +00:00
|
|
|
m_pEditor->RenderTools()->ForceRenderQuads(m_lQuads.base_ptr(), m_lQuads.size(), LAYERRENDERFLAG_OPAQUE, m_pEditor->EnvelopeEval, m_pEditor);
|
2012-08-13 10:57:40 +00:00
|
|
|
Graphics()->BlendNormal();
|
2014-01-11 21:57:23 +00:00
|
|
|
m_pEditor->RenderTools()->ForceRenderQuads(m_lQuads.base_ptr(), m_lQuads.size(), LAYERRENDERFLAG_TRANSPARENT, m_pEditor->EnvelopeEval, m_pEditor);
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
|
|
|
|
2019-03-28 12:41:07 +00:00
|
|
|
CQuad *CLayerQuads::NewQuad(int x, int y, int Width, int Height)
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2011-03-21 23:31:42 +00:00
|
|
|
m_pEditor->m_Map.m_Modified = true;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CQuad *q = &m_lQuads[m_lQuads.add(CQuad())];
|
2008-01-12 12:27:55 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
q->m_PosEnv = -1;
|
|
|
|
q->m_ColorEnv = -1;
|
|
|
|
q->m_PosEnvOffset = 0;
|
|
|
|
q->m_ColorEnvOffset = 0;
|
2019-03-28 12:41:07 +00:00
|
|
|
|
|
|
|
Width /= 2;
|
|
|
|
Height /= 2;
|
|
|
|
q->m_aPoints[0].x = x - Width;
|
|
|
|
q->m_aPoints[0].y = y - Height;
|
|
|
|
q->m_aPoints[1].x = x + Width;
|
|
|
|
q->m_aPoints[1].y = y - Height;
|
|
|
|
q->m_aPoints[2].x = x - Width;
|
|
|
|
q->m_aPoints[2].y = y + Height;
|
|
|
|
q->m_aPoints[3].x = x + Width;
|
|
|
|
q->m_aPoints[3].y = y + Height;
|
|
|
|
|
|
|
|
q->m_aPoints[4].x = x; // pivot
|
|
|
|
q->m_aPoints[4].y = y;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-12 12:27:55 +00:00
|
|
|
for(int i = 0; i < 5; i++)
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
q->m_aPoints[i].x <<= 10;
|
|
|
|
q->m_aPoints[i].y <<= 10;
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-12 12:27:55 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
q->m_aTexcoords[0].x = 0;
|
|
|
|
q->m_aTexcoords[0].y = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
q->m_aTexcoords[1].x = 1<<10;
|
|
|
|
q->m_aTexcoords[1].y = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
q->m_aTexcoords[2].x = 0;
|
|
|
|
q->m_aTexcoords[2].y = 1<<10;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
q->m_aTexcoords[3].x = 1<<10;
|
|
|
|
q->m_aTexcoords[3].y = 1<<10;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
q->m_aColors[0].r = 255; q->m_aColors[0].g = 255; q->m_aColors[0].b = 255; q->m_aColors[0].a = 255;
|
|
|
|
q->m_aColors[1].r = 255; q->m_aColors[1].g = 255; q->m_aColors[1].b = 255; q->m_aColors[1].a = 255;
|
|
|
|
q->m_aColors[2].r = 255; q->m_aColors[2].g = 255; q->m_aColors[2].b = 255; q->m_aColors[2].a = 255;
|
|
|
|
q->m_aColors[3].r = 255; q->m_aColors[3].g = 255; q->m_aColors[3].b = 255; q->m_aColors[3].a = 255;
|
2008-01-12 12:27:55 +00:00
|
|
|
|
|
|
|
return q;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CLayerQuads::BrushSelecting(CUIRect Rect)
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
|
|
|
// draw selection rectangle
|
2010-05-29 07:25:38 +00:00
|
|
|
IGraphics::CLineItem Array[4] = {
|
|
|
|
IGraphics::CLineItem(Rect.x, Rect.y, Rect.x+Rect.w, Rect.y),
|
|
|
|
IGraphics::CLineItem(Rect.x+Rect.w, Rect.y, Rect.x+Rect.w, Rect.y+Rect.h),
|
|
|
|
IGraphics::CLineItem(Rect.x+Rect.w, Rect.y+Rect.h, Rect.x, Rect.y+Rect.h),
|
|
|
|
IGraphics::CLineItem(Rect.x, Rect.y+Rect.h, Rect.x, Rect.y)};
|
2009-10-27 14:38:53 +00:00
|
|
|
Graphics()->TextureSet(-1);
|
|
|
|
Graphics()->LinesBegin();
|
2010-05-29 07:25:38 +00:00
|
|
|
Graphics()->LinesDraw(Array, 4);
|
2009-10-27 14:38:53 +00:00
|
|
|
Graphics()->LinesEnd();
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int CLayerQuads::BrushGrab(CLayerGroup *pBrush, CUIRect Rect)
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
|
|
|
// create new layers
|
2010-05-29 07:25:38 +00:00
|
|
|
CLayerQuads *pGrabbed = new CLayerQuads();
|
|
|
|
pGrabbed->m_pEditor = m_pEditor;
|
|
|
|
pGrabbed->m_Image = m_Image;
|
|
|
|
pBrush->AddLayer(pGrabbed);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-12 12:27:55 +00:00
|
|
|
//dbg_msg("", "%f %f %f %f", rect.x, rect.y, rect.w, rect.h);
|
2010-05-29 07:25:38 +00:00
|
|
|
for(int i = 0; i < m_lQuads.size(); i++)
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CQuad *q = &m_lQuads[i];
|
|
|
|
float px = fx2f(q->m_aPoints[4].x);
|
|
|
|
float py = fx2f(q->m_aPoints[4].y);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(px > Rect.x && px < Rect.x+Rect.w && py > Rect.y && py < Rect.y+Rect.h)
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CQuad n;
|
2008-01-12 12:27:55 +00:00
|
|
|
n = *q;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-12 12:27:55 +00:00
|
|
|
for(int p = 0; p < 5; p++)
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
n.m_aPoints[p].x -= f2fx(Rect.x);
|
|
|
|
n.m_aPoints[p].y -= f2fx(Rect.y);
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
pGrabbed->m_lQuads.add(n);
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
return pGrabbed->m_lQuads.size()?1:0;
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CLayerQuads::BrushPlace(CLayer *pBrush, float wx, float wy)
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CLayerQuads *l = (CLayerQuads *)pBrush;
|
|
|
|
for(int i = 0; i < l->m_lQuads.size(); i++)
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CQuad n = l->m_lQuads[i];
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-12 12:27:55 +00:00
|
|
|
for(int p = 0; p < 5; p++)
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
n.m_aPoints[p].x += f2fx(wx);
|
|
|
|
n.m_aPoints[p].y += f2fx(wy);
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_lQuads.add(n);
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
2011-03-21 23:31:42 +00:00
|
|
|
m_pEditor->m_Map.m_Modified = true;
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
|
|
|
|
2014-05-17 15:47:47 +00:00
|
|
|
void Swap(CPoint& a, CPoint& b)
|
|
|
|
{
|
2017-03-21 10:24:44 +00:00
|
|
|
CPoint Tmp;
|
|
|
|
Tmp.x = a.x;
|
|
|
|
Tmp.y = a.y;
|
2014-05-17 15:47:47 +00:00
|
|
|
|
|
|
|
a.x = b.x;
|
|
|
|
a.y = b.y;
|
|
|
|
|
2017-03-21 10:24:44 +00:00
|
|
|
b.x = Tmp.x;
|
|
|
|
b.y = Tmp.y;
|
2014-05-17 15:47:47 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CLayerQuads::BrushFlipX()
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2014-05-17 15:47:47 +00:00
|
|
|
for(int i = 0; i < m_lQuads.size(); i++)
|
|
|
|
{
|
|
|
|
CQuad *q = &m_lQuads[i];
|
|
|
|
|
|
|
|
Swap(q->m_aPoints[0], q->m_aPoints[1]);
|
|
|
|
Swap(q->m_aPoints[2], q->m_aPoints[3]);
|
|
|
|
}
|
|
|
|
m_pEditor->m_Map.m_Modified = true;
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CLayerQuads::BrushFlipY()
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2014-05-17 15:47:47 +00:00
|
|
|
for(int i = 0; i < m_lQuads.size(); i++)
|
|
|
|
{
|
|
|
|
CQuad *q = &m_lQuads[i];
|
|
|
|
|
|
|
|
Swap(q->m_aPoints[0], q->m_aPoints[2]);
|
|
|
|
Swap(q->m_aPoints[1], q->m_aPoints[3]);
|
|
|
|
}
|
|
|
|
m_pEditor->m_Map.m_Modified = true;
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void Rotate(vec2 *pCenter, vec2 *pPoint, float Rotation)
|
2008-02-05 19:11:34 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
float x = pPoint->x - pCenter->x;
|
|
|
|
float y = pPoint->y - pCenter->y;
|
|
|
|
pPoint->x = x * cosf(Rotation) - y * sinf(Rotation) + pCenter->x;
|
|
|
|
pPoint->y = x * sinf(Rotation) + y * cosf(Rotation) + pCenter->y;
|
2008-02-05 19:11:34 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CLayerQuads::BrushRotate(float Amount)
|
2008-02-05 19:11:34 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
vec2 Center;
|
|
|
|
GetSize(&Center.x, &Center.y);
|
|
|
|
Center.x /= 2;
|
|
|
|
Center.y /= 2;
|
2008-02-05 19:11:34 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
for(int i = 0; i < m_lQuads.size(); i++)
|
2008-02-05 19:11:34 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
CQuad *q = &m_lQuads[i];
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-02-05 19:11:34 +00:00
|
|
|
for(int p = 0; p < 5; p++)
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
vec2 Pos(fx2f(q->m_aPoints[p].x), fx2f(q->m_aPoints[p].y));
|
|
|
|
Rotate(&Center, &Pos, Amount);
|
|
|
|
q->m_aPoints[p].x = f2fx(Pos.x);
|
|
|
|
q->m_aPoints[p].y = f2fx(Pos.y);
|
2008-02-05 19:11:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CLayerQuads::GetSize(float *w, float *h)
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
|
|
|
*w = 0; *h = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
for(int i = 0; i < m_lQuads.size(); i++)
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
|
|
|
for(int p = 0; p < 5; p++)
|
|
|
|
{
|
2019-04-26 19:36:49 +00:00
|
|
|
*w = maximum(*w, fx2f(m_lQuads[i].m_aPoints[p].x));
|
|
|
|
*h = maximum(*h, fx2f(m_lQuads[i].m_aPoints[p].y));
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
extern int gs_SelectedPoints;
|
2008-01-12 12:27:55 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int CLayerQuads::RenderProperties(CUIRect *pToolBox)
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
|
|
|
// layer props
|
2008-01-17 23:09:49 +00:00
|
|
|
enum
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2008-01-17 23:09:49 +00:00
|
|
|
PROP_IMAGE=0,
|
|
|
|
NUM_PROPS,
|
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CProperty aProps[] = {
|
2011-03-20 16:04:03 +00:00
|
|
|
{"Image", m_Image, PROPTYPE_IMAGE, -1, 0},
|
2008-01-17 23:09:49 +00:00
|
|
|
{0},
|
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
static int s_aIds[NUM_PROPS] = {0};
|
|
|
|
int NewVal = 0;
|
2011-03-21 23:31:42 +00:00
|
|
|
int Prop = m_pEditor->DoProperties(pToolBox, aProps, s_aIds, &NewVal);
|
|
|
|
if(Prop != -1)
|
|
|
|
m_pEditor->m_Map.m_Modified = true;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(Prop == PROP_IMAGE)
|
2008-01-17 23:09:49 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(NewVal >= 0)
|
|
|
|
m_Image = NewVal%m_pEditor->m_Map.m_lImages.size();
|
2008-01-17 23:09:49 +00:00
|
|
|
else
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Image = -1;
|
2008-01-17 23:09:49 +00:00
|
|
|
}
|
|
|
|
|
2008-01-13 22:03:32 +00:00
|
|
|
return 0;
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CLayerQuads::ModifyImageIndex(INDEX_MODIFY_FUNC Func)
|
2008-01-19 12:32:08 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
Func(&m_Image);
|
2008-01-19 12:32:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CLayerQuads::ModifyEnvelopeIndex(INDEX_MODIFY_FUNC Func)
|
2008-01-19 12:32:08 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
for(int i = 0; i < m_lQuads.size(); i++)
|
2008-01-19 12:32:08 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
Func(&m_lQuads[i].m_PosEnv);
|
|
|
|
Func(&m_lQuads[i].m_ColorEnv);
|
2008-01-19 12:32:08 +00:00
|
|
|
}
|
|
|
|
}
|