Differential D825 Diff 9982 source/tools/atlas/AtlasUI/CustomControls/MapResizeDialog/PseudoMiniMapPanel.cpp
Changeset View
Changeset View
Standalone View
Standalone View
source/tools/atlas/AtlasUI/CustomControls/MapResizeDialog/PseudoMiniMapPanel.cpp
Show All 13 Lines | |||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "PseudoMiniMapPanel.h" | #include "PseudoMiniMapPanel.h" | ||||
#include "GameInterface/Messages.h" | |||||
#include "GameInterface/MessagePasser.h" | #include "GameInterface/MessagePasser.h" | ||||
#include "GameInterface/Messages.h" | |||||
vladislavbelov: I think it's not alphabetical order. | |||||
#include "ScenarioEditor/Tools/Common/Tools.h" | #include "ScenarioEditor/Tools/Common/Tools.h" | ||||
#include "math.h" | #include <cmath> | ||||
Done Inline Actions<cmath> and should be together with the ones below. vladislavbelov: `<cmath>` and should be together with the ones below. | |||||
#include <wx/dcbuffer.h> | #include <wx/dcbuffer.h> | ||||
#include <wx/dcgraph.h> | #include <wx/dcgraph.h> | ||||
#include <wx/defs.h> | #include <wx/defs.h> | ||||
#include <wx/event.h> | #include <wx/event.h> | ||||
namespace | namespace | ||||
{ | { | ||||
const int PanelRadius = 64 + 1; | const int PanelRadius = 64 + 1; | ||||
Show All 17 Lines | |||||
} | } | ||||
PseudoMiniMapPanel::PseudoMiniMapPanel(wxWindow* parent, int currentSize) | PseudoMiniMapPanel::PseudoMiniMapPanel(wxWindow* parent, int currentSize) | ||||
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(PanelRadius * 2 + 1, PanelRadius * 2 + 1)), | : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(PanelRadius * 2 + 1, PanelRadius * 2 + 1)), | ||||
m_CurrentSize(currentSize), m_ScreenTones(), | m_CurrentSize(currentSize), m_ScreenTones(), | ||||
m_LastMousePos(-1, -1), m_Dragging(false), | m_LastMousePos(-1, -1), m_Dragging(false), | ||||
m_SelectionRadius(PanelRadius), m_SelectionCenter(PanelCenter), m_SameOrGrowing(true), m_NewSize(currentSize) | m_SelectionRadius(PanelRadius), m_SelectionCenter(PanelCenter), m_SameOrGrowing(true), m_NewSize(currentSize) | ||||
{ | { | ||||
Done Inline ActionsNot needed line. vladislavbelov: Not needed line. | |||||
AtlasMessage::qGetMiniMapDisplay qryBackground; | AtlasMessage::qRasterizeMinimap qryBackground; | ||||
qryBackground.Post(); | qryBackground.Post(); | ||||
int dim = qryBackground.dimension; | int dim = qryBackground.dimension; | ||||
std::vector<unsigned char> imageBytes = *qryBackground.imageBytes; | std::vector<uint8_t> imageBytes = *qryBackground.imageBytes; | ||||
Done Inline ActionsMaybe imageBytes = std::move(*qryBackground.imageBytes)? vladislavbelov: Maybe `imageBytes = std::move(*qryBackground.imageBytes)`? | |||||
Done Inline ActionsCan you explain? I'm always struggling with this. Stan: Can you explain? I'm always struggling with this. | |||||
Done Inline ActionsReverted because ../../../source/tools/atlas/AtlasUI/CustomControls/MapResizeDialog/PseudoMiniMapPanel.cpp:63:36: warning: moving a temporary object prevents copy elision [-Wpessimizing-move] std::vector<uint8_t> imageBytes = std::move(*qryBackground.imageBytes); Stan: Reverted because
```
../../../source/tools/atlas/AtlasUI/CustomControls/MapResizeDialog/PseudoM… | |||||
Done Inline ActionsI'd prefer to store image data in u8/uint8t_ and only cast it if needed. vladislavbelov: I'd prefer to store image data in `u8`/`uint8t_` and only cast it if needed. | |||||
// Data is destined for a wxImage, which uses free. | // Data is destined for a wxImage, which uses free. | ||||
unsigned char* data = static_cast<unsigned char*>(malloc(imageBytes.size())); | uint8_t* data = static_cast<uint8_t*>(malloc(imageBytes.size())); | ||||
Done Inline ActionsIt'd be good in future to not know how wxWidgets frees the pointer. vladislavbelov: It'd be good in future to not know how wxWidgets frees the pointer. | |||||
Done Inline ActionsWe use new, no? vladislavbelov: We use `new`, no? | |||||
Done Inline ActionsDunno? You're the expert. Stan: Dunno? You're the expert. | |||||
std::copy(imageBytes.cbegin(), imageBytes.cend(), data); | std::copy(imageBytes.cbegin(), imageBytes.cend(), data); | ||||
m_Background = wxImage(dim, dim, data); | m_Background = wxImage(dim, dim, data); | ||||
m_Background.Rescale(PanelRadius * 2, PanelRadius * 2, wxIMAGE_QUALITY_BOX_AVERAGE); | m_Background.Rescale(PanelRadius * 2, PanelRadius * 2, wxIMAGE_QUALITY_BOX_AVERAGE); | ||||
m_Backgrounds[PanelRadius] = wxBitmap(m_Background); | m_Backgrounds[PanelRadius] = wxBitmap(m_Background); | ||||
SetBackgroundStyle(wxBG_STYLE_PAINT); | SetBackgroundStyle(wxBG_STYLE_PAINT); | ||||
} | } | ||||
Show All 11 Lines | |||||
void PseudoMiniMapPanel::OnNewSize(wxCommandEvent& evt) | void PseudoMiniMapPanel::OnNewSize(wxCommandEvent& evt) | ||||
{ | { | ||||
if (!evt.IsSelection()) | if (!evt.IsSelection()) | ||||
return; | return; | ||||
evt.Skip(); | evt.Skip(); | ||||
m_NewSize = wxAtoi(static_cast<wxStringClientData*>(evt.GetClientObject())->GetData()); | m_NewSize = wxAtoi(static_cast<wxStringClientData*>(evt.GetClientObject())->GetData()); | ||||
Done Inline ActionsWe have duplication here. We need only one place to parse the size. vladislavbelov: We have duplication here. We need only one place to parse the size. | |||||
Done Inline ActionsDuplication with where? Stan: Duplication with where? | |||||
m_SameOrGrowing = m_NewSize >= m_CurrentSize; | m_SameOrGrowing = m_NewSize >= m_CurrentSize; | ||||
m_SelectionRadius = std::min(m_NewSize, m_CurrentSize) * PanelRadius / std::max(m_NewSize, m_CurrentSize); | m_SelectionRadius = std::min(m_NewSize, m_CurrentSize) * PanelRadius / std::max(m_NewSize, m_CurrentSize); | ||||
if (!m_SameOrGrowing && m_ScreenTones.find(m_SelectionRadius) == m_ScreenTones.cend()) | if (!m_SameOrGrowing && m_ScreenTones.find(m_SelectionRadius) == m_ScreenTones.cend()) | ||||
{ | { | ||||
wxImage overlay = wxImage(PanelRadius * 4, PanelRadius * 4); | wxImage overlay = wxImage(PanelRadius * 4, PanelRadius * 4); | ||||
overlay.InitAlpha(); | overlay.InitAlpha(); | ||||
Done Inline ActionsMagic numbers and I didn't figure out why we need to multiply the size instead of scaling. vladislavbelov: Magic numbers and I didn't figure out why we need to multiply the size instead of scaling. | |||||
wxGraphicsContext* gc = wxGraphicsContext::Create(overlay); | wxGraphicsContext* gc = wxGraphicsContext::Create(overlay); | ||||
gc->SetBrush(*wxGREY_BRUSH); | gc->SetBrush(*wxGREY_BRUSH); | ||||
gc->DrawRectangle(0, 0, PanelRadius * 4, PanelRadius * 4); | gc->DrawRectangle(0, 0, PanelRadius * 4, PanelRadius * 4); | ||||
gc->SetBrush(*wxBLACK_BRUSH); | gc->SetBrush(*wxBLACK_BRUSH); | ||||
gc->DrawEllipse(PanelRadius * 2 - m_SelectionRadius, PanelRadius * 2 - m_SelectionRadius, m_SelectionRadius * 2, m_SelectionRadius * 2); | gc->DrawEllipse(PanelRadius * 2 - m_SelectionRadius, PanelRadius * 2 - m_SelectionRadius, m_SelectionRadius * 2, m_SelectionRadius * 2); | ||||
gc->SetPen(*wxWHITE_PEN); | gc->SetPen(*wxWHITE_PEN); | ||||
gc->DrawEllipse(PanelRadius * 2 - m_SelectionRadius, PanelRadius * 2 - m_SelectionRadius, m_SelectionRadius * 2, m_SelectionRadius * 2); | gc->DrawEllipse(PanelRadius * 2 - m_SelectionRadius, PanelRadius * 2 - m_SelectionRadius, m_SelectionRadius * 2, m_SelectionRadius * 2); | ||||
delete gc; | delete gc; | ||||
▲ Show 20 Lines • Show All 122 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
I think it's not alphabetical order.