Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ypujante committed Jan 20, 2023
1 parent 66b651b commit dacd8c5
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 195 deletions.
118 changes: 0 additions & 118 deletions src/cpp/re/edit/AppContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,124 +491,6 @@ void AppContext::toggleRails()
}
}

//------------------------------------------------------------------------
// AppContext::TextureItem
//------------------------------------------------------------------------
void AppContext::TextureItem(Texture const *iTexture,
ImVec2 const &iPosition,
ImVec2 const &iSize,
int iFrameNumber,
ImU32 iBorderColor,
ImU32 iTextureColor) const
{
iTexture->Item(iPosition, iSize, getZoom(), iFrameNumber, iBorderColor, iTextureColor);
}

//------------------------------------------------------------------------
// AppContext::drawTexture
//------------------------------------------------------------------------
void AppContext::drawTexture(Texture const *iTexture,
ImVec2 const &iPosition,
int iFrameNumber,
ImU32 iBorderColor,
ImU32 iTextureColor) const
{
iTexture->draw(iPosition, getZoom(), iFrameNumber, iBorderColor, iTextureColor);
}

//------------------------------------------------------------------------
// AppContext::drawRect
//------------------------------------------------------------------------
void AppContext::drawRect(ImVec2 const &iPosition, ImVec2 const &iSize, ImU32 iColor) const
{
auto const cp = ImGui::GetCursorScreenPos();
ImVec2 pos(cp + iPosition * getZoom());
auto drawList = ImGui::GetWindowDrawList();
drawList->AddRect(pos, {pos.x + (iSize.x * getZoom()), pos.y + (iSize.y * getZoom())}, iColor);
}

//------------------------------------------------------------------------
// AppContext::RectFilledItem
//------------------------------------------------------------------------
void AppContext::RectFilledItem(ImVec2 const &iPosition,
ImVec2 const &iSize,
ImU32 iColor,
float iRounding,
ImDrawFlags iFlags) const
{
auto const cp = ImGui::GetCursorScreenPos() + iPosition * getZoom();

const ImRect rect{cp, cp + iSize * getZoom()};

ImGui::ItemSize(rect);
if(!ImGui::ItemAdd(rect, 0))
return;

ImGui::SetCursorScreenPos(cp);
auto drawList = ImGui::GetWindowDrawList();
drawList->AddRectFilled(cp, {cp.x + (iSize.x * getZoom()), cp.y + (iSize.y * getZoom())}, iColor, iRounding, iFlags);
}

//------------------------------------------------------------------------
// AppContext::RectItem
//------------------------------------------------------------------------
void AppContext::RectItem(ImVec2 const &iPosition,
ImVec2 const &iSize,
ImU32 iColor,
float iRounding,
ImDrawFlags iFlags) const
{
auto const cp = ImGui::GetCursorScreenPos() + iPosition * getZoom();

const ImRect rect{cp, cp + iSize * getZoom()};

ImGui::ItemSize(rect);
if(!ImGui::ItemAdd(rect, 0))
return;

ImGui::SetCursorScreenPos(cp);
auto drawList = ImGui::GetWindowDrawList();
drawList->AddRect(cp, {cp.x + (iSize.x * getZoom()), cp.y + (iSize.y * getZoom())}, iColor, iRounding, iFlags);
}

//------------------------------------------------------------------------
// AppContext::Dummy
//------------------------------------------------------------------------
void AppContext::Dummy(ImVec2 const &iPosition, ImVec2 const &iSize) const
{
auto const cp = ImGui::GetCursorScreenPos() + iPosition * getZoom();
const ImRect rect{cp, cp + iSize * getZoom()};
ImGui::SetCursorScreenPos(cp);
ImGui::ItemSize(rect);
ImGui::ItemAdd(rect, 0);
}


//------------------------------------------------------------------------
// AppContext::drawRectFilled
//------------------------------------------------------------------------
void AppContext::drawRectFilled(ImVec2 const &iPosition,
ImVec2 const &iSize,
ImU32 iColor,
float iRounding,
ImDrawFlags iFlags) const
{
auto const cp = ImGui::GetCursorScreenPos();
ImVec2 pos(cp + iPosition * getZoom());
auto drawList = ImGui::GetWindowDrawList();
drawList->AddRectFilled(pos, {pos.x + (iSize.x * getZoom()), pos.y + (iSize.y * getZoom())}, iColor, iRounding, iFlags);
}

//------------------------------------------------------------------------
// AppContext::drawLine
//------------------------------------------------------------------------
void AppContext::drawLine(const ImVec2& iP1, const ImVec2& iP2, ImU32 iColor, float iThickness) const
{
auto const cp = ImGui::GetCursorScreenPos();
auto drawList = ImGui::GetWindowDrawList();
drawList->AddLine(cp + iP1 * getZoom(), cp + iP2 * getZoom(), iColor, iThickness);
}

//------------------------------------------------------------------------
// AppContext::addUndoAction
//------------------------------------------------------------------------
Expand Down
20 changes: 0 additions & 20 deletions src/cpp/re/edit/AppContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,26 +151,6 @@ class AppContext
std::optional<FilmStrip::key_t> importTextureBlocking();
std::size_t importTexturesBlocking();

void TextureItem(Texture const *iTexture,
ImVec2 const &iPosition = {0,0},
ImVec2 const &iSize = {0,0},
int iFrameNumber = 0,
ImU32 iBorderColor = ReGui::kTransparentColorU32,
ImU32 iTextureColor = ReGui::kWhiteColorU32) const;

void drawTexture(Texture const *iTexture,
ImVec2 const &iPosition = {0,0},
int iFrameNumber = 0,
ImU32 iBorderColor = ReGui::kTransparentColorU32,
ImU32 iTextureColor = ReGui::kWhiteColorU32) const;

void drawRect(ImVec2 const &iPosition, ImVec2 const &iSize, ImU32 iColor) const;
void RectFilledItem(ImVec2 const &iPosition, ImVec2 const &iSize, ImU32 iColor, float iRounding = 0.0f, ImDrawFlags iFlags = 0) const;
void RectItem(ImVec2 const &iPosition, ImVec2 const &iSize, ImU32 iColor, float iRounding = 0.0f, ImDrawFlags iFlags = 0) const;
void drawRectFilled(ImVec2 const &iPosition, ImVec2 const &iSize, ImU32 iColor, float iRounding = 0.0f, ImDrawFlags iFlags = 0) const;
void drawLine(const ImVec2& iP1, const ImVec2& iP2, ImU32 iColor, float iThickness = 1.0f) const;
void Dummy(ImVec2 const &iPosition, ImVec2 const &iSize) const;

public: // Undo
constexpr bool isUndoEnabled() const { return fUndoManager->isEnabled(); }
constexpr void enableUndo() { fUndoManager->enable(); }
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/re/edit/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ void Application::renderLogoBox(float iPadding)
ReGui::Box(logoModifier, [this, textSizeHeight, newVersion]() {
auto logo = getLogo();
auto computedHeight = 2.0f * textSizeHeight + (ImGui::GetStyle().ItemSpacing.y);
logo->Item({}, {computedHeight, computedHeight});
logo->Item({computedHeight, computedHeight});

ImGui::SameLine();

Expand Down Expand Up @@ -932,7 +932,7 @@ void Application::renderWelcome()
ImGui::BeginGroup();
{
ImGui::AlignTextToFramePadding();
icon->Item({}, {buttonHeight, buttonHeight}, 1.0f, impl::getFrameNumberFromDeviceType(item.fType));
icon->Item({buttonHeight, buttonHeight}, impl::getFrameNumberFromDeviceType(item.fType));
ImGui::SameLine();
if(ImGui::Button(fmt::printf("%s\n%s", item.fName, item.fPath).c_str()))
loadProjectDeferred(fs::path(item.fPath));
Expand Down
36 changes: 3 additions & 33 deletions src/cpp/re/edit/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,37 +67,16 @@ class Texture

std::shared_ptr<FilmStrip> getFilmStrip() const { return fFilmStrip; }

inline void Item(ImVec2 const &iPosition,
ImVec2 const &iSize = {},
float iZoom = 1.0f,
inline void Item(ImVec2 const &iSize = {},
int iFrameNumber = 0,
ImU32 iBorderColor = ReGui::kTransparentColorU32,
ImU32 iTextureColor = ReGui::kWhiteColorU32) const
{
doDraw(true, iPosition, iSize, iZoom, iZoom, iFrameNumber, iBorderColor, iTextureColor);
}

inline void draw(ImVec2 const &iPosition,
float iZoom,
int iFrameNumber,
ImU32 iBorderColor = ReGui::kTransparentColorU32,
ImU32 iTextureColor = ReGui::kWhiteColorU32) const
{
doDraw(false, iPosition, {}, iZoom, iZoom, iFrameNumber, iBorderColor, iTextureColor);
}

inline void draw(ImVec2 const &iPosition,
float iPositionZoom,
float iTextureZoom,
int iFrameNumber,
ImU32 iBorderColor = ReGui::kTransparentColorU32,
ImU32 iTextureColor = ReGui::kWhiteColorU32) const
{
doDraw(false, iPosition, {}, iPositionZoom, iTextureZoom, iFrameNumber, iBorderColor, iTextureColor);
doDraw(true, ImGui::GetCursorScreenPos(), iSize, iFrameNumber, iBorderColor, iTextureColor);
}

inline void draw(ImVec2 const &iScreenPosition,
ImVec2 const &iSize,
ImVec2 const &iSize = {},
int iFrameNumber = 0,
ImU32 iBorderColor = ReGui::kTransparentColorU32,
ImU32 iTextureColor = ReGui::kWhiteColorU32) const
Expand All @@ -111,15 +90,6 @@ class Texture
friend class TextureManager;

protected:
void doDraw(bool iAddItem,
ImVec2 const &iPosition,
ImVec2 const &iSize,
float iPositionZoom,
float iTextureZoom,
int iFrameNumber,
ImU32 iBorderColor,
ImU32 iTextureColor) const;

void doDraw(bool iAddItem,
ImVec2 const &iScreenPosition,
ImVec2 const &iSize,
Expand Down
25 changes: 3 additions & 22 deletions src/cpp/re/edit/TextureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,27 +156,6 @@ void TextureManager::overrideNumFrames(std::string const &iKey, int iNumFrames)
getTexture(iKey)->fFilmStrip->overrideNumFrames(iNumFrames);
}


//------------------------------------------------------------------------
// Texture::doDraw
//------------------------------------------------------------------------
void Texture::doDraw(bool iAddItem,
ImVec2 const &iPosition,
ImVec2 const &iSize,
float iPositionZoom,
float iTextureZoom,
int iFrameNumber,
ImU32 iBorderColor,
ImU32 iTextureColor) const
{
if(fData.empty())
return;
auto const cp = ImGui::GetCursorScreenPos() + iPosition * iPositionZoom;
auto const size = ImVec2{(iSize.x == 0 ? frameWidth() : iSize.x) * iTextureZoom,
(iSize.y == 0 ? frameHeight() : iSize.y) * iTextureZoom};
doDraw(iAddItem, cp, size, iFrameNumber, iBorderColor, iTextureColor);
}

//------------------------------------------------------------------------
// Texture::doDraw
//------------------------------------------------------------------------
Expand All @@ -190,7 +169,9 @@ void Texture::doDraw(bool iAddItem,
if(fData.empty())
return;

const ImRect rect{iScreenPosition, iScreenPosition + iSize};
auto const size = ImVec2{iSize.x == 0 ? frameWidth() : iSize.x, iSize.y == 0 ? frameHeight() : iSize.y};

const ImRect rect{iScreenPosition, iScreenPosition + size};

// do we treat the texture as a ImGui item (clickable, etc...)
if(iAddItem)
Expand Down

0 comments on commit dacd8c5

Please sign in to comment.