Skip to content

Commit

Permalink
ImageEditor: fixed appearance of font size edit control and step init…
Browse files Browse the repository at this point in the history
…ial value edit control

Set busy timeout for sqlite in HistoryManager
  • Loading branch information
zenden2k committed Jun 27, 2019
1 parent e7367f0 commit 6b665c5
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 44 deletions.
10 changes: 5 additions & 5 deletions README.MD
@@ -1,25 +1,25 @@
# Image Uploader
Free program for Windows that allows you to upload images, screenshots, or any other files to over 30 different file hosting services.
Official website: http://zenden2k.atwebpages.com/imageuploader
Official website: http://zenden2k.com/imageuploader

![Image Uploader main window](https://lh3.googleusercontent.com/-Cn0FbMwNmME/VXvtHdBlKgI/AAAAAAAAF0A/r7soROnyqrg/s0/clipboard_5956_12792.png)

[![Download Image Uploader](https://lh4.googleusercontent.com/-D6wvBfMHonw/VQHgBb9ZFzI/AAAAAAAAD1s/Hq1uUei_C-s/s0/download-button-en.png)](http://zenden2k.atwebpages.com/imageuploader_downloads)

Supported operating systems: Windows 10/8/7/Vista/XP SP2+ (also server versions starting with Windows Server 2003 SP1)
Supported operating systems: Windows 10/8/7/Vista/XP SP3+ (also server versions starting with Windows Server 2003 SP1)

## Main Features

### Uploading files to image hostings and file hostings
It can upload to more than [20 image hostings sites](http://zenden2k.atwebpages.com/imageuploader_servers). After uploading, Image Uploader generates HTML code or BBCode for forums.
It can upload to more than [20 image hostings sites](http://zenden2k.com/imageuploader_servers). After uploading, Image Uploader generates HTML code, BBCode for forums and Markdown code.

It is also possible to specify your own output format template.

### Grabbing Frames from a Video Clip
Image Uploader can grab frames from various types of video formats, e.g. AVI, MPG, VOB, WMV, MKV (it depends on DirectShow codecs you have installed on your system). It is recommended to install K-lite Codec Pack.

### Screen capturing
Image Uploader can do screenshots of entire screen or selected screen region.
Image Uploader can make screenshots of entire screen or selected screen region.

Image Uploader is available in the following languages: English, Russian, Swedish, Romanian, Turkish, Serbian, Hrvatski, Farsi

Expand All @@ -29,7 +29,7 @@ Image Uploader is available in the following languages: English, Russian, Swedis

Available options:

http://zenden2k.atwebpages.com/imageuploader-cli
http://zenden2k.com/imageuploader-cli

## Building from source

Expand Down
6 changes: 4 additions & 2 deletions Source/Core/HistoryManager.cpp
Expand Up @@ -65,6 +65,7 @@ bool CHistoryManager::openDatabase() {
LOG(ERROR) << "unable to open database: ";
return false;
}
sqlite3_busy_timeout(db_, 1000); // Wait 1 second before SQLITE_BUSY is returned
const char* sql = "CREATE TABLE IF NOT EXISTS upload_sessions(id PRIMARY KEY NOT NULL,created_at INT NOT NULL)";
char* err = nullptr;
if (sqlite3_exec(db_, sql, nullptr, nullptr, &err) != SQLITE_OK) {
Expand Down Expand Up @@ -108,8 +109,9 @@ bool CHistoryManager::saveSession(CHistorySession* session) {
/*if (sqlite3_bind_text(stmt, 3 , serverName.c_str(), -1, nullptr) != SQLITE_OK) {
LOG(ERROR) << "SQL error: Could not bind value.";
}*/
if (sqlite3_step(stmt) != SQLITE_DONE) {
LOG(ERROR) << "SQL error: Could not execute statement";
int retCode = sqlite3_step(stmt);
if (retCode != SQLITE_DONE) {
LOG(ERROR) << "SQL error: Could not execute statement, return code=" << retCode;
}
/*sqlite3_reset(stmt);
sqlite3_clear_bindings(stmt);*/
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Upload/ServerProfile.h
Expand Up @@ -53,7 +53,7 @@ class ServerProfile {
void setProfileName(const std::string& newProfileName);
std::string profileName() const;

void setServerName(const std::string& newProfileName);
void setServerName(const std::string& newServerName);
std::string serverName() const;

std::string folderTitle() const;
Expand Down
9 changes: 5 additions & 4 deletions Source/ImageEditor/Canvas.cpp
Expand Up @@ -18,16 +18,17 @@

#include "Canvas.h"

#include <cmath>
#include <cassert>
#include <algorithm>

#include "DrawingElement.h"
#include "Document.h"
#include "DrawingTool.h"
#include "InputBox.h"
#include "MovableElements.h"
#include <ImageEditor/Gui/InputBoxControl.h>
#include "ImageEditor/Gui/InputBoxControl.h"
#include "Core/Logging.h"
#include <cmath>
#include <cassert>
#include <algorithm>
#include "3rdpart/GdiplusH.h"
#include "Core/i18n/Translator.h"

Expand Down
52 changes: 31 additions & 21 deletions Source/ImageEditor/Gui/Toolbar.cpp
Expand Up @@ -19,7 +19,7 @@ Toolbar::Toolbar(Toolbar::Orientation orientation)
selectedItemIndex_ = -1;
trackMouse_ = false;
m_hWnd = 0;
dropDownIcon_ = ImageUtils::BitmapFromResource(GetModuleHandle(0), MAKEINTRESOURCE(IDB_DROPDOWNICONPNG),_T("PNG")); //(HICON)LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDI_DROPDOWN), IMAGE_ICON, 16,16,0);
dropDownIcon_ = ImageUtils::BitmapFromResource(GetModuleHandle(0), MAKEINTRESOURCE(IDB_DROPDOWNICONPNG),_T("PNG"));
dpiScaleX_ = 1.0f;
dpiScaleY_ = 1.0f;
transparentColor_ = Color(255,50,56);
Expand Down Expand Up @@ -72,7 +72,15 @@ bool Toolbar::Create(HWND parent, bool child )
::GetWindowRect(parent, parentRect);
OffsetRect(&rc, parentRect.left, parentRect.top);
}
HWND wnd = TParent::Create(parent, rc, _T("test"), (child ? WS_CHILD : WS_POPUP | WS_CLIPCHILDREN), child ? 0 : (WS_EX_LAYERED | WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST) /*|WS_EX_TOOLWINDOW*/);
DWORD style, exStyle;
if (child) {
style = WS_CHILD;
exStyle = 0;
} else {
style = WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
exStyle = WS_EX_LAYERED | WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
}
HWND wnd = TParent::Create(parent, rc, _T("ImageEditor Toolbar"), style, exStyle);
if ( !wnd ) {
LOG(ERROR) << WinUtils::GetLastErrorAsString();
return false;
Expand Down Expand Up @@ -147,7 +155,6 @@ void Toolbar::clickButton(int index)
}

InvalidateRect(&item.rect, FALSE);

}

LRESULT Toolbar::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
Expand All @@ -157,7 +164,6 @@ LRESULT Toolbar::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, B
transparentColor_.SetFromCOLORREF(GetSysColor(COLOR_APPWORKSPACE));
} else {
SetLayeredWindowAttributes(m_hWnd, RGB(transparentColor_.GetR(),transparentColor_.GetG(),transparentColor_.GetB()),225,LWA_COLORKEY/*| LWA_ALPHA*/);

}
//lStyle &= ~(WS_CAPTION /*| WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU*/);
//::SetWindowLong(m_hWnd, GWL_STYLE, lStyle);
Expand Down Expand Up @@ -206,24 +212,24 @@ LRESULT Toolbar::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, B
fontSizeLabel_.Create(m_hWnd, fontSizeLabelRect, TR("Font size:"), WS_CHILD);
fontSizeLabel_.SetFont(systemFont_);

RECT fontSizeEditRect = { 0, 0, static_cast<LONG>(63 * dpiScaleX_), static_cast<LONG>(subpanelHeight_ - 4 * dpiScaleY_) };
RECT fontSizeEditRect = { 0, 0, static_cast<LONG>(63 * dpiScaleX_), static_cast<LONG>(22 * dpiScaleY_) };

fontSizeEdit_.Create(m_hWnd, fontSizeEditRect, nullptr, WS_CHILD | ES_NUMBER | ES_AUTOHSCROLL, WS_EX_CLIENTEDGE, (HMENU)ID_FONTSIZEEDITCONTROL);
fontSizeEdit_.SetFont(systemFont_);

RECT fontSizeUpDownRect = { 0, 0, static_cast<LONG>(30 * dpiScaleX_), static_cast<LONG>(subpanelHeight_ - 4 * dpiScaleY_) };

fontSizeUpDownCtrl_.Create(m_hWnd, fontSizeUpDownRect, nullptr, WS_CHILD | UDS_AUTOBUDDY | UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_ARROWKEYS | UDS_HOTTRACK);
fontSizeUpDownCtrl_.Create(m_hWnd, fontSizeUpDownRect, _T(""), WS_CHILD | UDS_AUTOBUDDY | UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_ARROWKEYS | UDS_HOTTRACK);
fontSizeUpDownCtrl_.SetRange(1, 100);

RECT initialValueLabelRect { 0, 0, static_cast<LONG>(100 * dpiScaleX_), static_cast<LONG>(subpanelHeight_ - 4 * dpiScaleY_) };

initialValueLabel_.Create(m_hWnd, initialValueLabelRect, TR("Initial value:"), WS_CHILD);
initialValueLabel_.SetFont(systemFont_);

RECT initialValueEditRect{ 0, 0, static_cast<LONG>(40 * dpiScaleX_), static_cast<LONG>(subpanelHeight_ - 4 * dpiScaleY_) };
RECT initialValueEditRect{ 0, 0, static_cast<LONG>(40 * dpiScaleX_), static_cast<LONG>(22 * dpiScaleY_) };

initialValueEdit_.Create(m_hWnd, initialValueEditRect, nullptr, WS_CHILD | ES_NUMBER | ES_AUTOHSCROLL, WS_EX_CLIENTEDGE, ID_STEPINITIALVALUE);
initialValueEdit_.Create(m_hWnd, initialValueEditRect, _T(""), WS_CHILD | ES_NUMBER | ES_AUTOHSCROLL, WS_EX_CLIENTEDGE, ID_STEPINITIALVALUE);
initialValueEdit_.SetFont(systemFont_);
}
return 0;
Expand Down Expand Up @@ -440,8 +446,6 @@ LRESULT Toolbar::OnLButtonUp(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL&
selectedItemIndex_ = getItemAtPos(xPos, yPos);
Item& item = buttons_[selectedItemIndex_];



if ( item.itemDelegate ) {
clickButton(selectedItemIndex_);
item.itemDelegate->OnClick(xPos, yPos, dpiScaleX_, dpiScaleY_);
Expand Down Expand Up @@ -493,6 +497,7 @@ LRESULT Toolbar::OnNcHitTest(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/
{
bHandled = false;
if ( ::GetKeyState(VK_MENU) & 0x8000 ) {
// User can drag toolbars with ALT pressed
bHandled = true;
return HTCAPTION;
}
Expand Down Expand Up @@ -583,7 +588,6 @@ int Toolbar::AutoSize()
ScreenToClient(&penSizeSliderRect);
pixelLabel_.SetWindowPos(0, penSizeSliderRect.right, static_cast<int>(buttonsRect_.bottom + 3 * dpiScaleY_), 0, 0, SWP_NOSIZE);


roundRadiusSlider_.SetWindowPos(0, subpanelLeftOffset_ + static_cast<int>(150 * dpiScaleX_), static_cast<int>(buttonsRect_.bottom + 1 * dpiScaleY_), 0, 0, SWP_NOSIZE| SWP_NOZORDER);
roundRadiusSlider_.SetRange(1,Canvas::kMaxRoundingRadius);
RECT radiusSliderRect;
Expand All @@ -592,28 +596,31 @@ int Toolbar::AutoSize()
ScreenToClient(&radiusSliderRect);
roundRadiusLabel_.SetWindowPos(0, radiusSliderRect.right, buttonsRect_.bottom + static_cast<int>(3 * dpiScaleY_), 0, 0, SWP_NOSIZE| SWP_NOZORDER);


//RECT fontSizeLabelRect = { 0, 0, static_cast<LONG>(100 * dpiScaleX_), static_cast<LONG>(subpanelHeight_ - 2 * dpiScaleY_) };

fontSizeLabel_.SetWindowPos(0, subpanelLeftOffset_ + static_cast<int>(6 * dpiScaleX_), static_cast<int>(buttonsRect_.bottom + 3 * dpiScaleY_), 0, 0, SWP_NOSIZE | SWP_NOZORDER);
GuiTools::AutoSizeStaticControl(fontSizeLabel_);
RECT fontSizeLabelRect;
fontSizeLabel_.GetClientRect(&fontSizeLabelRect);
fontSizeLabel_.ClientToScreen(&fontSizeLabelRect);
fontSizeLabel_.GetWindowRect(&fontSizeLabelRect);
ScreenToClient(&fontSizeLabelRect);
fontSizeLabel_.SetWindowPos(0, subpanelLeftOffset_ + static_cast<int>(6 * dpiScaleX_), static_cast<int>(buttonsRect_.bottom + (subpanelHeight_ - fontSizeLabelRect.bottom + fontSizeLabelRect.top)/2), 0, 0, SWP_NOSIZE | SWP_NOZORDER);
fontSizeLabel_.GetWindowRect(&fontSizeLabelRect);
ScreenToClient(&fontSizeLabelRect);

fontSizeEdit_.SetWindowPos(0, fontSizeLabelRect.right + static_cast<int>(2 * dpiScaleX_), buttonsRect_.bottom + static_cast<int>(1 * dpiScaleY_), 0, 0, SWP_NOSIZE | SWP_NOZORDER);
fontSizeEdit_.SetWindowPos(0, fontSizeLabelRect.right + static_cast<int>(8 * dpiScaleX_), buttonsRect_.bottom + static_cast<int>(2 * dpiScaleY_), 0, 0, SWP_NOSIZE | SWP_NOZORDER);
fontSizeUpDownCtrl_.SetBuddy(fontSizeEdit_);

RECT rect;
fontSizeUpDownCtrl_.GetWindowRect(&rect);
ScreenToClient(&rect);
initialValueLabel_.SetWindowPos(nullptr, rect.right + static_cast<int>(5 * dpiScaleX_), buttonsRect_.bottom + static_cast<int>(3 * dpiScaleY_), 0, 0, SWP_NOSIZE | SWP_NOZORDER);
RECT upDownRect, rect;
fontSizeUpDownCtrl_.GetWindowRect(&upDownRect);
ScreenToClient(&upDownRect);
GuiTools::AutoSizeStaticControl(initialValueLabel_);
initialValueLabel_.GetWindowRect(&rect);
ScreenToClient(&rect);

initialValueEdit_.SetWindowPos(0, rect.right + static_cast<int>(2 * dpiScaleX_), buttonsRect_.bottom + static_cast<int>(1 * dpiScaleY_), 0, 0, SWP_NOSIZE | SWP_NOZORDER);
initialValueLabel_.SetWindowPos(nullptr, upDownRect.right + static_cast<int>(8 * dpiScaleX_), buttonsRect_.bottom + (subpanelHeight_ - rect.bottom + rect.top) / 2, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
initialValueLabel_.GetWindowRect(&rect);
ScreenToClient(&rect);

initialValueEdit_.SetWindowPos(0, rect.right + static_cast<int>(8 * dpiScaleX_), buttonsRect_.bottom + static_cast<int>(2 * dpiScaleY_), 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}

for (size_t i = 0; i < buttons_.size(); i++) {
Expand Down Expand Up @@ -820,4 +827,7 @@ LRESULT Toolbar::OnStepInitialValueChange(WORD /*wNotifyCode*/, WORD /*wID*/, HW
return 0;
}

LRESULT Toolbar::OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
return 0;
}
}
21 changes: 10 additions & 11 deletions Source/ImageEditor/Gui/Toolbar.h
Expand Up @@ -9,8 +9,8 @@
#define MTBM_DROPDOWNCLICKED (WM_USER + 400)
#define MTBM_FONTSIZECHANGE (WM_USER + 401)
#define MTBM_STEPINITIALVALUECHANGE (WM_USER + 402)
namespace ImageEditor {

namespace ImageEditor {

class Toolbar : public CWindowImpl<Toolbar> {
public:
Expand All @@ -19,7 +19,7 @@ class Toolbar : public CWindowImpl<Toolbar> {
enum ItemState { isNormal, isHover, isDown, isDropDown };
enum ItemType { itButton, itComboButton, itTinyCombo };
enum { kTinyComboDropdownTimer = 42, kSubpanelWidth = 300 };
enum {ID_FONTSIZEEDITCONTROL = 1201, ID_STEPINITIALVALUE};
enum {ID_FONTSIZEEDITCONTROL = 12001, ID_STEPINITIALVALUE};
class ToolbarItemDelegate;
struct Item {
CString title;
Expand Down Expand Up @@ -58,7 +58,7 @@ class Toolbar : public CWindowImpl<Toolbar> {
virtual void OnClick(int x, int y, float dpiScaleX, float dpiScaleY){};
};

Toolbar(Orientation orientation);
explicit Toolbar(Orientation orientation);
~Toolbar();
bool Create(HWND parent, bool child = false);
int addButton(const Item& item);
Expand Down Expand Up @@ -89,16 +89,13 @@ class Toolbar : public CWindowImpl<Toolbar> {
MESSAGE_HANDLER( WM_KEYUP, OnKeyUp )
MESSAGE_HANDLER( WM_ACTIVATE, OnActivate )
MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnColorStatic)
MESSAGE_HANDLER(WM_HSCROLL , OnHScroll)
MESSAGE_HANDLER(WM_TIMER , OnTimer)
MESSAGE_HANDLER(WM_HSCROLL, OnHScroll)
MESSAGE_HANDLER(WM_TIMER, OnTimer)
MESSAGE_HANDLER(WM_CLOSE, OnClose)
COMMAND_HANDLER(ID_FONTSIZEEDITCONTROL, EN_CHANGE, OnFontSizeEditControlChange)
COMMAND_HANDLER(ID_STEPINITIALVALUE, EN_CHANGE, OnStepInitialValueChange)

REFLECT_NOTIFICATIONS ()

END_MSG_MAP()


// Handler prototypes (uncomment arguments if needed):
// LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
// LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
Expand All @@ -120,10 +117,11 @@ class Toolbar : public CWindowImpl<Toolbar> {
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*/);

SIZE CalcItemSize(int index);
int AutoSize();
void CreateToolTipForItem(unsigned index);
void CreateToolTipForItem(size_t index);
CTrackBarCtrl penSizeSlider_;
CTrackBarCtrl roundRadiusSlider_;
CStatic pixelLabel_;
Expand All @@ -133,6 +131,7 @@ class Toolbar : public CWindowImpl<Toolbar> {
CUpDownCtrl fontSizeUpDownCtrl_;
CStatic initialValueLabel_;
CEdit initialValueEdit_;
CButton testButton_;
protected:
Orientation orientation_;
std::vector<Item> buttons_;
Expand Down
7 changes: 7 additions & 0 deletions Source/ImageEditor/MovableElements.cpp
Expand Up @@ -880,8 +880,12 @@ void StepNumber::render(Painter* gr) {
RectF textRect(static_cast<REAL>(x), static_cast<REAL>(y), static_cast<REAL>(width), static_cast<REAL>(height));
CString s;
s.Format(L"%d", number_);
auto oldTextHint = gr->GetTextRenderingHint();
gr->SetTextRenderingHint(TextRenderingHintAntiAlias);
gr->DrawString(s, -1, &font, textRect, &format, &textBrush );
gr->SetTextRenderingHint(oldTextHint);
gr->SetClip(canvas_->currentRenderingRect()); // restoring clip

}

RECT StepNumber::getPaintBoundingRect() {
Expand All @@ -895,12 +899,15 @@ ElementType StepNumber::getType() const {
int StepNumber::recalcRadius() {
using namespace Gdiplus;
Graphics* gr = canvas_->getGraphicsDevice();
auto oldTextHint = gr->GetTextRenderingHint();
gr->SetTextRenderingHint(TextRenderingHintAntiAlias);
FontFamily ff(L"Arial");
Font font(&ff, static_cast<REAL>(fontSize_), FontStyleBold);
CString s;
s.Format(L"%d", number_);
RectF boundingBox;
gr->MeasureString(s, -1, &font, PointF(static_cast<REAL>(startPoint_.x), static_cast<REAL>(startPoint_.y)), &boundingBox);
gr->SetTextRenderingHint(oldTextHint);
int radius = static_cast<int>(std::max<>(boundingBox.Width, boundingBox.Height) / 2 + 6);
return radius;
}
Expand Down

0 comments on commit 6b665c5

Please sign in to comment.