Skip to content

Commit

Permalink
ImageEditor: reposition toolbars in fullscreen mode
Browse files Browse the repository at this point in the history
  • Loading branch information
zenden2k committed May 15, 2023
1 parent 1a3b07a commit bfb0d5e
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 32 deletions.
56 changes: 29 additions & 27 deletions Source/Gui/Dialogs/RegionSelect.cpp
Expand Up @@ -138,27 +138,22 @@ LRESULT CRegionSelect::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOO
return 0; // Let the system set the focus
}

LRESULT CRegionSelect::OnPaint(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
{
PAINTSTRUCT ps;
BeginPaint(&ps);

HDC dc = ps.hdc;
LRESULT CRegionSelect::OnPaint(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled) {
CPaintDC dc(m_hWnd);

int w = ps.rcPaint.right - ps.rcPaint.left;
int h = ps.rcPaint.bottom - ps.rcPaint.top;
int w = dc.m_ps.rcPaint.right - dc.m_ps.rcPaint.left;
int h = dc.m_ps.rcPaint.bottom - dc.m_ps.rcPaint.top;

if (m_bPictureChanged) {
if (Down) {
EndPaint(&ps);
return 0;
}
RECT rc;
GetClientRect(&rc);
CRgn newRegion;
newRegion.CreateRectRgn(0, 0, rc.right, rc.bottom);
SelectClipRgn(doubleDC, newRegion);
BitBlt(doubleDC, ps.rcPaint.left, ps.rcPaint.top, w, h, memDC2, ps.rcPaint.left, ps.rcPaint.top,SRCCOPY);
BitBlt(doubleDC, dc.m_ps.rcPaint.left, dc.m_ps.rcPaint.top, w, h, memDC2, dc.m_ps.rcPaint.left, dc.m_ps.rcPaint.top,SRCCOPY);
newRegion.CombineRgn(m_SelectionRegion,RGN_DIFF);
CBrush br;
SelectClipRgn(doubleDC, newRegion);
Expand All @@ -171,7 +166,7 @@ LRESULT CRegionSelect::OnPaint(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/,
bf.AlphaFormat = 0; ///*0 */ /*AC_SRC_ALPHA*/0;

if (RectCount)
if (AlphaBlend(doubleDC, ps.rcPaint.left, ps.rcPaint.top, w, h, alphaDC, ps.rcPaint.left, ps.rcPaint.top, w,
if (AlphaBlend(doubleDC, dc.m_ps.rcPaint.left, dc.m_ps.rcPaint.top, w, h, alphaDC, dc.m_ps.rcPaint.left, dc.m_ps.rcPaint.top, w,
h, bf) == FALSE) {
}
newRegion.DeleteObject();
Expand All @@ -192,9 +187,9 @@ LRESULT CRegionSelect::OnPaint(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/,
}
m_bPictureChanged = false;
}
BitBlt(dc, ps.rcPaint.left, ps.rcPaint.top, w, h, doubleDC, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY);
dc.BitBlt(dc.m_ps.rcPaint.left, dc.m_ps.rcPaint.top, w, h, doubleDC, dc.m_ps.rcPaint.left, dc.m_ps.rcPaint.top, SRCCOPY);


EndPaint(&ps);
m_bPainted = true;
return 0;
}
Expand Down Expand Up @@ -463,7 +458,7 @@ LRESULT CRegionSelect::OnRButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BO
return 1;
}

bool CRegionSelect::Execute(HBITMAP screenshot, int width, int height)
bool CRegionSelect::Execute(HBITMAP screenshot, int width, int height, HMONITOR monitor)
{
auto* settings = ServiceLocator::instance()->settings<WtlGuiSettings>();
m_bPictureChanged = false;
Expand All @@ -487,15 +482,6 @@ bool CRegionSelect::Execute(HBITMAP screenshot, int width, int height)
Create(nullptr, r, _T("ImageUploader_RegionWnd"), WS_POPUP, WS_EX_TOPMOST);
}

BITMAPINFOHEADER bmi;
memset(&bmi, 0, sizeof(bmi));
bmi.biSize = sizeof(bmi);
bmi.biWidth = m_Width;
bmi.biHeight = m_Height;
bmi.biPlanes = 1;
bmi.biBitCount = 4 * 8;
bmi.biCompression = BI_RGB;

HDC dstDC = ::GetDC(m_hWnd);
//doubleBm.
///* m_hBitmap = */CreateDIBSection(dstDC, (BITMAPINFO*)&bmi, DIB_RGB_COLORS, 0, NULL, NULL);
Expand Down Expand Up @@ -531,11 +517,27 @@ bool CRegionSelect::Execute(HBITMAP screenshot, int width, int height)

alphaDC.FillRect(&r, br2);
m_bPictureChanged = true;


//RECT screenBounds;
::ReleaseDC(m_hWnd, dstDC);

CRect windowRc;
GuiTools::GetScreenBounds(m_screenBounds);
MoveWindow(m_screenBounds.left, m_screenBounds.top,m_screenBounds.Width(), m_screenBounds.Height());
if (monitor) {
MONITORINFO mi;
memset(&mi, 0, sizeof(mi));
mi.cbSize = sizeof(mi);
if (!GetMonitorInfo(monitor, &mi)) {
LOG(ERROR) << "Unable get info about monitor";
return false;
}

windowRc = mi.rcMonitor;
} else {
windowRc = m_screenBounds;
}

//RECT screenBounds;
MoveWindow(windowRc.left, windowRc.top, windowRc.Width(), windowRc.Height());
topLeft.x = 0;
topLeft.y = 0;
ScreenToClient(&topLeft);
Expand All @@ -561,7 +563,7 @@ bool CRegionSelect::Execute(HBITMAP screenshot, int width, int height)

alphaBm.DeleteObject();

::ReleaseDC(m_hWnd, dstDC);

ShowWindow(SW_HIDE);
return m_bResult;
}
Expand Down
3 changes: 1 addition & 2 deletions Source/Gui/Dialogs/RegionSelect.h
Expand Up @@ -24,7 +24,6 @@
#include "atlheaders.h"
#include <atlcrack.h>
#include "resource.h" // main symbols
#include "Gui/Controls/myimage.h"
#include "Core/ScreenCapture.h"

class CRegionSelectCallback
Expand All @@ -44,7 +43,7 @@ class CRegionSelect: public CWindowImpl<CRegionSelect>

bool wasImageEdited() const;
std::shared_ptr<ScreenCapture::CScreenshotRegion> region() const;
bool Execute(HBITMAP screenshot, int width, int height);
bool Execute(HBITMAP screenshot, int width, int height, HMONITOR monitor = nullptr);

DECLARE_WND_CLASS(_T("CRegionSelect"))

Expand Down
2 changes: 1 addition & 1 deletion Source/Gui/Dialogs/WizardDlg.cpp
Expand Up @@ -1968,7 +1968,7 @@ bool CWizardDlg::CommonScreenshot(ScreenCapture::CaptureMode mode)
{
HBITMAP gdiBitmap=0;
res->GetHBITMAP(Color(255,255,255), &gdiBitmap);
if(RegionSelect.Execute(gdiBitmap, res->GetWidth(), res->GetHeight()))
if(RegionSelect.Execute(gdiBitmap, res->GetWidth(), res->GetHeight(), monitor))
{
if(RegionSelect.wasImageEdited() || (mode!=cmWindowHandles /*|| !Settings.ScreenshotSettings.ShowForeground*/) )
engine.setSource(gdiBitmap);
Expand Down
47 changes: 45 additions & 2 deletions Source/ImageEditor/Gui/ImageEditorWindow.cpp
Expand Up @@ -12,7 +12,7 @@
#include "ImageEditor/MovableElements.h"
#include "Gui/Dialogs/SearchByImageDlg.h"
#include "Gui/Components/MyFileDialog.h"

#include "Core/ScreenCapture/MonitorEnumerator.h"

namespace ImageEditor {

Expand Down Expand Up @@ -482,6 +482,9 @@ ImageEditorWindow::DialogResult ImageEditorWindow::DoModal(HWND parent, HMONITOR
if (displayMode_ == wdmWindowed) {
horizontalToolbar_.SetWindowPos(0, rc.left, 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
verticalToolbar_.SetWindowPos(0, 0, rc.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
} else {
repositionToolbar(horizontalToolbar_, vertToolbarRect);
repositionToolbar(verticalToolbar_, horToolbarRect);
}

m_view.SetWindowPos(0, &rc, SWP_NOSIZE);
Expand Down Expand Up @@ -1311,7 +1314,7 @@ bool ImageEditorWindow::createTooltip() {
// Set up "tool" information. In this case, the "tool" is the entire parent window.


TOOLINFO ti = { 0 };
TOOLINFO ti = {};
CString title = TR("Select region");
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
Expand Down Expand Up @@ -1555,4 +1558,44 @@ void ImageEditorWindow::showApplyButtons() {
horizontalToolbar_.showApplyButtons(currentDrawingTool_ == DrawingToolType::dtCrop && displayMode_ == wdmWindowed && canvas_->hasElementOfType(ElementType::etCrop));
}

void ImageEditorWindow::repositionToolbar(Toolbar& toolbar, const CRect& otherToolbarRect) {
if (displayMode_ != wdmFullscreen) {
return;
}
MONITORINFO mi = {};
mi.cbSize = sizeof(mi);
::GetMonitorInfo(::MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST), &mi);
CRect workArea = mi.rcWork;

MonitorEnumerator enumerator;
CRect toolbarRc;
toolbar.GetClientRect(toolbarRc);
toolbar.ClientToScreen(toolbarRc);

bool needRepos = false;

if (enumerator.enumDisplayMonitors(nullptr, nullptr)) {
needRepos = true;
for (const auto& mon : enumerator) {
CRect r = mon.rect;
CRect intersected;
intersected.IntersectRect(r, toolbarRc);
if (intersected == toolbarRc) {
needRepos = false;
break;
}
}
}

if (needRepos) {
CPoint newPos;
if (toolbar.orientation() == Toolbar::orHorizontal) {
newPos = CPoint(workArea.left + otherToolbarRect.Width() + kCanvasMargin, workArea.top);
} else {
newPos = CPoint(workArea.left, workArea.top + otherToolbarRect.Height() + kCanvasMargin);
}
toolbar.SetWindowPos(nullptr, newPos.x, newPos.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
}

}
5 changes: 5 additions & 0 deletions Source/ImageEditor/Gui/ImageEditorWindow.h
Expand Up @@ -236,6 +236,11 @@ class ImageEditorWindow : public CWindowImpl<ImageEditorWindow>, CMessageFilter
void enableToolbarsIfNecessary(bool enable);
void updateWindowTitle();
void showApplyButtons();

/**
* Reposition toolbar in full screen mode so it becomes fully visible
*/
void repositionToolbar(Toolbar& toolbar, const CRect& otherToolbarRect);
};

class ConfigurationProvider {
Expand Down
4 changes: 4 additions & 0 deletions Source/ImageEditor/Gui/Toolbar.cpp
Expand Up @@ -908,4 +908,8 @@ void Toolbar::setFillBackgroundCheckbox(bool fill) {
void Toolbar::setShowButtonText(bool show) {
showButtonText_ = show;
}

Toolbar::Orientation Toolbar::orientation() const {
return orientation_;
}
}
1 change: 1 addition & 0 deletions Source/ImageEditor/Gui/Toolbar.h
Expand Up @@ -86,6 +86,7 @@ class Toolbar : public CWindowImpl<Toolbar> {
void setArrowType(int type);
void setMovable(bool value);
void setShowButtonText(bool show);
Orientation orientation() const;

BEGIN_MSG_MAP(Toolbar)
MESSAGE_HANDLER( WM_CREATE, OnCreate )
Expand Down

0 comments on commit bfb0d5e

Please sign in to comment.