Skip to content

Commit

Permalink
ImageEditor: fix hotkeys behavior; save delete link for imgbb.com
Browse files Browse the repository at this point in the history
  • Loading branch information
zenden2k committed Feb 21, 2024
1 parent c4e5568 commit 29b3567
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 59 deletions.
7 changes: 6 additions & 1 deletion Data/Scripts/imgbb.nut
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ function _UploadToAccount(FileName, options) {
options.setViewUrl(t.data.url_viewer);
options.setDirectUrl(t.data.url);
options.setThumbUrl(t.data.thumb.url);
//options.setDeleteUrl(t.data.delete_url);
if ("delete_url" in t.data) {
options.setDeleteUrl(t.data.delete_url);
}
return 1;
}
} else if ("error" in t) {
Expand Down Expand Up @@ -69,6 +71,9 @@ function UploadFile(FileName, options) {
options.setViewUrl(t.image.url_viewer);
options.setDirectUrl(t.image.url);
options.setThumbUrl(t.image.thumb.url);
if ("delete_url" in t.image) {
options.setDeleteUrl(t.image.delete_url);
}
return 1;
} else
return 0;
Expand Down
96 changes: 59 additions & 37 deletions Source/ImageEditor/Gui/ImageEditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,18 @@ void ImageEditorWindow::init()
selectedSubMenuItems_[ID_FILLEDRECTANGLE] = ID_FILLEDRECTANGLE;
selectedSubMenuItems_[ID_BLURRINGRECTANGLE] = ID_BLURRINGRECTANGLE;

drawingToolsHotkeys_[kMoveKey] = DrawingToolType::dtMove;
drawingToolsHotkeys_[kBrushKey] = DrawingToolType::dtBrush;
drawingToolsHotkeys_[kTextKey] = DrawingToolType::dtText;
drawingToolsHotkeys_[kRectangleKey] = DrawingToolType::dtRectangle;
drawingToolsHotkeys_[kColorPickerKey] = DrawingToolType::dtColorPicker;
drawingToolsHotkeys_[kCropKey] = DrawingToolType::dtCrop;
drawingToolsHotkeys_[kMarkerKey] = DrawingToolType::dtMarker;
drawingToolsHotkeys_[kBlurringRectangleKey] = DrawingToolType::dtBlurringRectangle;
drawingToolsHotkeys_[kArrowKey] = DrawingToolType::dtArrow;
drawingToolsHotkeys_[kLineKey] = DrawingToolType::dtLine;
drawingToolsHotkeys_[kFilledRectangle] = DrawingToolType::dtFilledRectangle;
drawingToolsHotkeys_[kStepNumber] = DrawingToolType::dtStepNumber;
drawingToolsHotkeys_[kMoveKey] = ID_MOVE /*DrawingToolType::dtMove*/;
drawingToolsHotkeys_[kBrushKey] = ID_BRUSH /*DrawingToolType::dtBrush*/;
drawingToolsHotkeys_[kTextKey] = ID_TEXT /*DrawingToolType::dtText*/;
drawingToolsHotkeys_[kRectangleKey] = ID_RECTANGLE /*DrawingToolType::dtRectangle*/;
drawingToolsHotkeys_[kColorPickerKey] = ID_COLORPICKER /*DrawingToolType::dtColorPicker*/;
drawingToolsHotkeys_[kCropKey] = ID_CROP;
drawingToolsHotkeys_[kMarkerKey] = ID_MARKER;
drawingToolsHotkeys_[kBlurringRectangleKey] = ID_BLURRINGRECTANGLE;
drawingToolsHotkeys_[kArrowKey] = ID_ARROW;
drawingToolsHotkeys_[kLineKey] = ID_LINE;
drawingToolsHotkeys_[kFilledRectangle] = ID_FILLEDRECTANGLE;
drawingToolsHotkeys_[kStepNumber] = ID_STEPNUMBER;

dialogResult_ = drCancel;
}
Expand Down Expand Up @@ -428,16 +428,25 @@ ImageEditorWindow::DialogResult ImageEditorWindow::DoModal(HWND parent, HMONITOR

SetIcon(icon_, TRUE);
SetIcon(iconSmall_, FALSE);
ACCEL accels[] = {
std::vector<ACCEL> accels = {
{ FVIRTKEY | FCONTROL, 'Z', ID_UNDO },
{ FVIRTKEY | FCONTROL, 'D', ID_UNSELECTALL },
{ FVIRTKEY | FCONTROL, 'S', ID_SAVE },
{ FVIRTKEY | FCONTROL, 'C', ID_COPYBITMAPTOCLIBOARD },
{ FVIRTKEY | FCONTROL, 'F', ID_SEARCHBYIMAGE },
{ FVIRTKEY | FCONTROL, 'P', ID_PRINTIMAGE },
{ FVIRTKEY, VK_ESCAPE, ID_CLOSE },
{ FVIRTKEY, VK_RETURN, IDOK },
{ FVIRTKEY, VK_DELETE, ID_DELETESELECTED },
};

accelerators_ = CreateAcceleratorTable(accels, ARRAY_SIZE(accels));
for(const auto& [k,v]: drawingToolsHotkeys_) {
accels.push_back(
{ FVIRTKEY, static_cast<WORD>(k), static_cast<WORD>(v) }
);
}

accelerators_ = CreateAcceleratorTable(&accels[0], accels.size());

//RECT rc;
GetClientRect(&rc);
Expand Down Expand Up @@ -678,23 +687,23 @@ LRESULT ImageEditorWindow::OnGetMinMaxInfo(UINT /*uMsg*/, WPARAM /*wParam*/, LPA
return 0;
}

LRESULT ImageEditorWindow::OnClickedOK(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
if (showUploadButton_ || showAddToWizardButton_ ) {
if (!sourceFileName_.IsEmpty()) {
outFileName_ = sourceFileName_;
}
if (saveDocument()) {
DialogResult dr = showUploadButton_ ? drUpload : drAddToWizard;
EndDialog(dr);
}
}
return 0;
}

LRESULT ImageEditorWindow::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
std::map<DrawingToolHotkey, DrawingToolType>::iterator it;
//HKL englishLayout = LoadKeyboardLayout(_T("00000409"),0);
if ( wParam == VK_ESCAPE ) {
onClose();
return 0;
} else if ( wParam == VK_RETURN && (showUploadButton_ || showAddToWizardButton_) ) {
if ( !sourceFileName_.IsEmpty() ) {
outFileName_ = sourceFileName_;
}
if ( saveDocument() ) {
DialogResult dr = showUploadButton_ ? drUpload : drAddToWizard;
EndDialog(dr);
}
}
else if (wParam == VK_OEM_6) { // ']'
if (wParam == VK_OEM_6) { // ']'
canvas_->beginPenSizeChanging();
canvas_->setPenSize(canvas_->getPenSize()+1);
horizontalToolbar_.penSizeSlider_.SetPos(canvas_->getPenSize());
Expand All @@ -707,15 +716,7 @@ LRESULT ImageEditorWindow::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BO
horizontalToolbar_.penSizeSlider_.SetPos(canvas_->getPenSize());
updatePixelLabels();
m_view.SendMessage(WM_SETCURSOR, reinterpret_cast<LPARAM>(m_view.m_hWnd), 0);
} else if ( (it = drawingToolsHotkeys_.find((DrawingToolHotkey)wParam)) != drawingToolsHotkeys_.end()
&& !(GetKeyState(VK_CONTROL) & 0x8000)
&& !(GetKeyState(VK_SHIFT) & 0x8000)
&& !(GetKeyState(VK_MENU) & 0x8000) ) {
canvas_->setDrawingToolType(it->second);
updateToolbarDrawingTool(it->second);
} else if ( wParam == VK_DELETE ) {
canvas_->deleteSelectedElements();
}
}
return 0;
}

Expand Down Expand Up @@ -1395,9 +1396,25 @@ bool ImageEditorWindow::CopyBitmapToClipboardAndClose(ClipboardFormat format) {
}

BOOL ImageEditorWindow::PreTranslateMessage(MSG* pMsg) {
HWND parent = ::GetParent(pMsg->hwnd);

if (parent) {
if (parent == m_view.m_hWnd) {
return FALSE;
}

if (parent == horizontalToolbar_.m_hWnd || parent == verticalToolbar_.m_hWnd) {
TCHAR className[MAX_PATH]{};
if (GetClassName(pMsg->hwnd, className, MAX_PATH) && !lstrcmp(className, _T("Edit"))) {
return FALSE;
}
}
}

if (TranslateAccelerator(m_hWnd, accelerators_, pMsg)) {
return TRUE;
}

return FALSE;
}

Expand Down Expand Up @@ -1602,4 +1619,9 @@ void ImageEditorWindow::repositionToolbar(Toolbar& toolbar, const CRect& otherTo
}
}

LRESULT ImageEditorWindow::OnDeleteSelected(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
canvas_->deleteSelectedElements();
return 0;
}

}
11 changes: 8 additions & 3 deletions Source/ImageEditor/Gui/ImageEditorWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <memory>
#include <map>
#include <unordered_map>

#include "atlheaders.h"
#include "resource.h"
Expand All @@ -29,7 +30,7 @@ class ImageEditorWindow : public CWindowImpl<ImageEditorWindow>, CMessageFilter
enum {
ID_UNDO = 1000, ID_CLOSE, ID_ADDTOWIZARD, ID_UPLOAD, ID_SHARE, ID_SAVE, ID_SAVEAS, ID_COPYBITMAPTOCLIBOARD, ID_COPYBITMAPTOCLIBOARDASDATAURI,
ID_COPYBITMAPTOCLIBOARDASDATAURIHTML, ID_UNSELECTALL, ID_INCREASEPENSIZE, ID_DECREASEPENSIZE, ID_PRINTIMAGE, ID_SEARCHBYIMAGE, ID_SEARCHBYIMAGEINGOOGLE,
ID_SEARCHBYIMAGEINYANDEX,
ID_SEARCHBYIMAGEINYANDEX, ID_DELETESELECTED,
ID_PEN = 1600,
ID_BRUSH, ID_MARKER,ID_BLUR, ID_BLURRINGRECTANGLE, ID_PIXELATERECTANGLE, ID_LINE, ID_ARROW, ID_RECTANGLE, ID_ROUNDEDRECTANGLE, ID_ELLIPSE,
ID_FILLEDRECTANGLE, ID_FILLEDROUNDEDRECTANGLE, ID_FILLEDELLIPSE, ID_COLORPICKER, ID_CROP , ID_SELECTION,ID_TEXT, ID_STEPNUMBER, ID_MOVE /* ID_MOVE should be last */
Expand Down Expand Up @@ -105,6 +106,7 @@ class ImageEditorWindow : public CWindowImpl<ImageEditorWindow>, CMessageFilter
MESSAGE_HANDLER(MTBM_CANCEL, OnCancelOperation)
MESSAGE_HANDLER( TextParamsWindow::TPWM_FONTCHANGED, OnTextParamWindowFontChanged);

COMMAND_ID_HANDLER(IDOK, OnClickedOK)
COMMAND_ID_HANDLER(ID_APP_EXIT, OnFileExit)
COMMAND_RANGE_HANDLER( ID_PEN, ID_MOVE, OnMenuItemClick)
COMMAND_ID_HANDLER( ID_UNDO, OnUndoClick )
Expand All @@ -122,9 +124,9 @@ class ImageEditorWindow : public CWindowImpl<ImageEditorWindow>, CMessageFilter
COMMAND_ID_HANDLER(ID_SEARCHBYIMAGE, OnSearchByImage)
COMMAND_ID_HANDLER(ID_SEARCHBYIMAGEINGOOGLE, OnSearchByImage)
COMMAND_ID_HANDLER(ID_SEARCHBYIMAGEINYANDEX, OnSearchByImage)
COMMAND_ID_HANDLER(ID_DELETESELECTED, OnDeleteSelected)
MESSAGE_HANDLER( WM_ERASEBKGND, OnEraseBackground )
MESSAGE_HANDLER( WM_ENABLE, OnEnable )

REFLECT_NOTIFICATIONS()
/*CHAIN_MSG_MAP(CUpdateUI<CMainFrame>)
CHAIN_MSG_MAP(CFrameWindowImpl<CMainFrame>)*/
Expand Down Expand Up @@ -174,14 +176,17 @@ class ImageEditorWindow : public CWindowImpl<ImageEditorWindow>, CMessageFilter
LRESULT OnEnable(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnApplyOperation(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnCancelOperation(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnClickedOK(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnDeleteSelected(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
//LRESULT ReflectedCommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

Toolbar horizontalToolbar_;
Toolbar verticalToolbar_;
std::unique_ptr<ImageEditor::Canvas> canvas_;
std::map<int, DrawingToolType> menuItems_;
std::map<DrawingToolType, SubMenuItem> subMenuItems_;
std::map<int,int> selectedSubMenuItems_;
std::map<DrawingToolHotkey, DrawingToolType> drawingToolsHotkeys_;
std::unordered_map<DrawingToolHotkey, int> drawingToolsHotkeys_;
DialogResult dialogResult_;
WindowDisplayMode displayMode_;
DrawingToolType initialDrawingTool_;
Expand Down
14 changes: 1 addition & 13 deletions Source/ImageEditor/Gui/Toolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,19 +450,6 @@ LRESULT Toolbar::OnTimer(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL&
return 0;
}


LRESULT Toolbar::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = true;
return ::SendMessage(GetParent(), uMsg, wParam, lParam);
}

LRESULT Toolbar::OnKeyUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = true;
return ::SendMessage(GetParent(), uMsg, wParam, lParam);
}

LRESULT Toolbar::OnLButtonUp(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
int xPos = GET_X_LPARAM(lParam);
Expand Down Expand Up @@ -938,4 +925,5 @@ void Toolbar::setShowButtonText(bool show) {
Toolbar::Orientation Toolbar::orientation() const {
return orientation_;
}

}
6 changes: 1 addition & 5 deletions Source/ImageEditor/Gui/Toolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Toolbar : public CWindowImpl<Toolbar> {
void showArrowTypeCombo(bool show);
bool isFillBackgroundChecked() const;
bool isInvertSelectionChecked() const;
void setInvertSelectionCheckbox(bool fill);
void setInvertSelectionCheckbox(bool invert);
int getArrowType() const;
void setArrowType(int type);
void setMovable(bool value);
Expand All @@ -106,8 +106,6 @@ class Toolbar : public CWindowImpl<Toolbar> {
MESSAGE_HANDLER( WM_LBUTTONUP, OnLButtonUp )
MESSAGE_HANDLER( WM_RBUTTONUP, OnRButtonUp )
MESSAGE_HANDLER( WM_ERASEBKGND, OnEraseBackground )
MESSAGE_HANDLER( WM_KEYDOWN, OnKeyDown )
MESSAGE_HANDLER( WM_KEYUP, OnKeyUp )
MESSAGE_HANDLER( WM_ACTIVATE, OnActivate )
MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic)
MESSAGE_HANDLER(WM_HSCROLL, OnHScroll)
Expand Down Expand Up @@ -139,8 +137,6 @@ class Toolbar : public CWindowImpl<Toolbar> {
LRESULT OnEraseBackground(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnNcHitTest(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnTimer(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnKeyDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnKeyUp(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnFontSizeEditControlChange(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnStepInitialValueChange(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
Expand Down

0 comments on commit 29b3567

Please sign in to comment.