refactor editor map view logic

This commit is contained in:
msiglreith 2015-11-25 13:07:48 +01:00 committed by oy
parent a516935854
commit b960e7491a
2 changed files with 265 additions and 248 deletions

View file

@ -1107,14 +1107,18 @@ void CEditor::DoToolbar(CUIRect ToolBar)
m_GridFactor++;
}
TB_Bottom.VSplitLeft(30.0f, 0, &TB_Bottom);
TB_Bottom.VSplitLeft(10.0f, 0, &TB_Bottom);
// pipette / color picking
TB_Bottom.VSplitLeft(30.0f, &Button, &TB_Bottom);
TB_Bottom.VSplitLeft(40.0f, &Button, &TB_Bottom);
static int s_ColorPickingButton = 0;
if(DoButton_Editor(&s_ColorPickingButton, "Pick", m_PickColor, &Button, 0, "Pick color from view"))
if(DoButton_Editor(&s_ColorPickingButton, "Pipette", m_MouseEdMode == MOUSE_PIPETTE, &Button, 0, "Pick color from view"))
{
m_PickColor = !m_PickColor;
// toggle mouse mode
if(m_MouseEdMode == MOUSE_PIPETTE)
m_MouseEdMode = MOUSE_EDIT;
else
m_MouseEdMode = MOUSE_PIPETTE;
}
}
@ -1910,47 +1914,11 @@ void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar)
}
}
switch(m_MouseEdMode)
{
case MOUSE_EDIT:
{
if(UI()->HotItem() == s_pEditorID)
{
if(m_PickColor)
{
m_pTooltip = "Use left mouse button to pick a color from screen.";
if(UI()->CheckActiveItem(s_pEditorID))
{
if(s_Operation == OP_PIPETTE)
{
const int Width = Graphics()->ScreenWidth();
const int Height = Graphics()->ScreenHeight();
const int px = clamp(0, int(mx * Width/UI()->Screen()->w), Width);
const int py = clamp(0, int(my * Height/UI()->Screen()->h), Height);
unsigned char *pPixelData = 0x0;
Graphics()->ReadBackbuffer(&pPixelData, px, py, 1, 1); // get pixel at location (px, py)
vec3 PickedColor = vec3(pPixelData[0] / 255.0f, pPixelData[1] / 255.0f, pPixelData[2] / 255.0f);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(PickedColor.r, PickedColor.g, PickedColor.b, 1.0f);
IGraphics::CQuadItem QuadItem(0.0f, 0.0f, 20.0f, 20.0f);
Graphics()->QuadsDraw(&QuadItem, 1);
Graphics()->QuadsEnd();
mem_free(pPixelData);
}
}
else
{
if(UI()->MouseButton(0))
{
UI()->SetActiveItem(s_pEditorID);
s_Operation = OP_PIPETTE;
}
}
}
else
{
// brush editing
if(m_Brush.IsEmpty())
@ -2092,11 +2060,10 @@ void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar)
}
}
}
}
// quad editing
{
if(!m_ShowTilePicker && !m_PickColor && m_Brush.IsEmpty())
if(!m_ShowTilePicker && m_Brush.IsEmpty())
{
// fetch layers
CLayerGroup *g = GetSelectedGroup();
@ -2174,6 +2141,50 @@ void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar)
Graphics()->MapScreen(UI()->Screen()->x, UI()->Screen()->y, UI()->Screen()->w, UI()->Screen()->h);
}
}
} break;
case MOUSE_PIPETTE:
{
if(UI()->HotItem() == s_pEditorID)
{
m_pTooltip = "Use left mouse button to pick a color from screen.";
if(UI()->CheckActiveItem(s_pEditorID))
{
if(s_Operation == OP_PIPETTE)
{
const int Width = Graphics()->ScreenWidth();
const int Height = Graphics()->ScreenHeight();
const int px = clamp(0, int(mx * Width/UI()->Screen()->w), Width);
const int py = clamp(0, int(my * Height/UI()->Screen()->h), Height);
unsigned char *pPixelData = 0x0;
Graphics()->ReadBackbuffer(&pPixelData, px, py, 1, 1); // get pixel at location (px, py)
vec3 PickedColor = vec3(pPixelData[0] / 255.0f, pPixelData[1] / 255.0f, pPixelData[2] / 255.0f);
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(PickedColor.r, PickedColor.g, PickedColor.b, 1.0f);
IGraphics::CQuadItem QuadItem(0.0f, 0.0f, 20.0f, 20.0f);
Graphics()->QuadsDraw(&QuadItem, 1);
Graphics()->QuadsEnd();
mem_free(pPixelData);
}
}
else
{
if(UI()->MouseButton(0))
{
UI()->SetActiveItem(s_pEditorID);
s_Operation = OP_PIPETTE;
}
}
}
} break;
}
// do panning
if(UI()->CheckActiveItem(s_pEditorID))

View file

@ -532,7 +532,7 @@ public:
m_GridActive = false;
m_GridFactor = 1;
m_PickColor = false;
m_MouseEdMode = MOUSE_EDIT;
m_aFileName[0] = 0;
m_aFileSaveName[0] = 0;
@ -619,7 +619,13 @@ public:
bool m_GridActive;
int m_GridFactor;
bool m_PickColor; // TODO: rename: pointer/mouse mode
enum
{
MOUSE_EDIT=0,
MOUSE_PIPETTE,
};
int m_MouseEdMode;
char m_aFileName[512];
char m_aFileSaveName[512];