Skip to content

Commit 63fb6ad

Browse files
Add ctrl image viewer
1 parent 9d6dac3 commit 63fb6ad

17 files changed

+642
-103
lines changed

CMakeLists.txt

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# --------------------------------------------------------------------
2-
31
cmake_minimum_required(VERSION 3.13)
42
project("K_and_M_recorder_player")
53

@@ -14,22 +12,15 @@ find_package(Threads REQUIRED)
1412
#---------------------------------------------------------------------
1513
## Please set your wxWidgets configuration here
1614
#---------------------------------------------------------------------
17-
18-
# Here you can define what libraries of wxWidgets you need for your
19-
# application. You can figure out what libraries you need here;
20-
# https://www.wxwidgets.org/manuals/2.8/wx_librarieslist.html
21-
# We need the Find package for wxWidgets to work
22-
# NOTE: if you're using aui, include aui in this required components list.
23-
24-
# It was noticed that when using MinGW gcc it is essential that 'core' is mentioned before 'base'.
25-
find_package(wxWidgets COMPONENTS core base REQUIRED)
26-
27-
#---------------------------------------------------------------------
28-
## Actual config file starts here
29-
#---------------------------------------------------------------------
30-
31-
# wxWidgets include (this will do all the magic to configure everything)
32-
include("${wxWidgets_USE_FILE}")
15+
if(DEFINED "ENV{WXWIDGETS_PATH}")
16+
find_package(wxWidgets REQUIRED
17+
PATHS "$ENV{WXWIDGETS_PATH}" NO_DEFAULT_PATH
18+
COMPONENTS core base
19+
)
20+
else()
21+
find_package(wxWidgets COMPONENTS core base REQUIRED)
22+
include("${wxWidgets_USE_FILE}")
23+
endif()
3324

3425
#---------------------------------------------------------------------
3526

@@ -104,6 +95,7 @@ set(SOURCES1
10495
src/key_conversion.cpp
10596
src/progress_bar.cpp
10697
src/wx_worker.cpp
98+
src/light_image_panel.cpp
10799
)
108100

109101
add_executable(

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ kmRecorderAndPlayer:
8888
- [Startup](https://odysee.com/@volatilflerovium:3/Quick_start_setup:c)
8989
- [Claudflare turnstile](https://odysee.com/@volatilflerovium:3/captchat_example:f)
9090
- [Image comparison tool](https://odysee.com/@volatilflerovium:3/image_comparison_tool_example:7)
91-
- [GUI testing](https://odysee.com/@volatilflerovium:3/GUI_testing:4)
91+
- [GUI testing](https://odysee.com/@volatilflerovium:3/testing_gui:6)
92+
- [Another GUI testing](https://odysee.com/@volatilflerovium:3/GUI_testing:4)
9293
- [Download images](https://odysee.com/@volatilflerovium:3/download_imgs:c)
9394

9495
## Interface Method

include/command_wrapper.h

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class BasePanel : public wxPanel
6666
virtual bool isPanel(PanelType panelType) const=0;
6767

6868
virtual int getHeight() const=0;
69+
70+
virtual void reset()
71+
{}
6972

7073
virtual void enableStatus()
7174
{}
@@ -184,7 +187,7 @@ class CommandPanel : public WrapperPanel<CommandPanel, 10, 2, WX::DELETE_CMD, Ba
184187
{
185188
public:
186189
CommandPanel(wxWindow* parent, uint posY, uint width, BaseCommand* cmd)
187-
:WrapperPanel<CommandPanel, 10, 2, WX::DELETE_CMD, BasePanel>(parent, posY, width)
190+
: WrapperPanel<CommandPanel, 10, 2, WX::DELETE_CMD, BasePanel>(parent, posY, width)
188191
{
189192
m_baseCommandPtr=cmd;
190193
}
@@ -223,7 +226,13 @@ class CommandPanel : public WrapperPanel<CommandPanel, 10, 2, WX::DELETE_CMD, Ba
223226
}
224227

225228
virtual void enableStatus() override;
226-
229+
230+
virtual void reset() override
231+
{
232+
m_statusBtn->SetBackgroundColour(wxColour("#FFFFFF"));
233+
SetBackgroundColour(wxColour("#FFFFFF"));
234+
}
235+
227236
protected:
228237
BaseCommand* m_baseCommandPtr{nullptr};
229238
wxBoxSizer* m_mainCol;
@@ -237,15 +246,16 @@ class CommandPanel : public WrapperPanel<CommandPanel, 10, 2, WX::DELETE_CMD, Ba
237246

238247
bool m_isIndented{false};
239248

240-
virtual void setSelected() override
249+
/*virtual void setSelected() override
241250
{
242251
s_lastSelected=this;
243-
}
252+
}// */
244253

245254
static constexpr int c_padding=30;
246255

247256
virtual void setTimeoutCtrl()=0;
248257
virtual void OnCheck(wxCommandEvent& event);
258+
virtual void OnCheckStatus(wxCommandEvent& event);
249259

250260
DECLARE_EVENT_TABLE()
251261

@@ -270,10 +280,13 @@ class InputCommandWrapper : public CommandPanel
270280
static wxFloatingPointValidator<float> s_floatValidator;
271281
static bool s_isValidatorSet;
272282

283+
DECLARE_EVENT_TABLE()
273284
};
274285

275286
//====================================================================
276287

288+
class ResultPopup;
289+
277290
class ControlCommandWrapper : public CommandPanel
278291
{
279292
public:
@@ -283,18 +296,18 @@ class ControlCommandWrapper : public CommandPanel
283296

284297
virtual void init(bool indentation=false);
285298

286-
virtual void enableCommand(bool enable);
287-
288299
void updateTimeout(int timeout)
289300
{
290301
m_timeoutInput->ChangeValue(wxString::Format("%i", timeout));
291302
}
292303

293304
protected:
294305
virtual void setTimeoutCtrl() override;
306+
virtual void OnCheckStatus(wxCommandEvent& event) override;
307+
virtual void mkContextMenu();
295308

296309
private:
297-
wxButton* m_edit;
310+
ResultPopup* m_imgCtrlViewrPtr;
298311

299312
DECLARE_EVENT_TABLE()
300313
};

include/dedicated_popups.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
#include "utilities.h"
2424

2525
#include <wx/wx.h>
26+
#include <string>
2627

2728
class CtrlCommand;
2829
class WX_TextCtrl;
2930
class wxSpinCtrl;
3031
class ImagePanel;
32+
class LightImagePanel;
3133

3234
//====================================================================
3335

@@ -50,7 +52,7 @@ class AddCmdPopup : public ExtendedPopup
5052

5153
wxSpinCtrl* m_timeoutInput;
5254
wxRadioBox* m_ctrlCmdModeSetRadio;
53-
ImagePanel* m_previewPanel;
55+
LightImagePanel* m_previewPanel;
5456
wxCheckBox* m_strictRunCheck;
5557

5658
wxStaticText* m_instructions;
@@ -210,4 +212,26 @@ class FileListPopup : public WX_Popup
210212

211213
//====================================================================
212214

215+
class ResultPopup : public ExtendedPopup
216+
{
217+
public:
218+
ResultPopup(wxWindow* parent, const char* title, const std::string& baseImg);
219+
virtual ~ResultPopup()=default;
220+
221+
void loadBaseImg(const std::string& baseImg);
222+
223+
protected:
224+
std::string m_baseImg;
225+
std::string m_sampleImg;
226+
wxRadioBox* m_swapScreenshotRadio;
227+
ImagePanel* m_previewPanel;
228+
wxBoxSizer* m_bodySizer;
229+
wxBoxSizer* m_row;
230+
uint m_perc;
231+
232+
void setLayout();
233+
};
234+
235+
//====================================================================
236+
213237
#endif

include/enumerations.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ namespace WX
5252
SETTINGS,
5353
DELETE_FILE,
5454
PROGRESS_TIMER,
55+
CMD_STATUS,
56+
CTRL_CMD_MENU_EDIT,
5557
_LAST,
5658
};
5759

include/extended_popup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class BasicPopup : public wxFrame
8989
inline void BasicPopup::setSizer(wxBoxSizer* box, bool deleteOld)
9090
{
9191
wxBoxSizer* boxWrapper = new wxBoxSizer(wxHORIZONTAL);
92-
boxWrapper->Add(box, 0, wxALL, FromDIP(10));
92+
boxWrapper->Add(box, 1, wxEXPAND | wxALL, FromDIP(10));
9393
this->SetSizerAndFit(boxWrapper, deleteOld);
9494
}
9595

include/file_scrolled_window.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ class FilePanel : public WrapperPanel<FilePanel, 10, 2, WX::DELETE_FILE>
4545
wxString m_fileName;
4646
WX_TextCtrl* m_fileNameInput;
4747

48-
virtual void setSelected() override
49-
{
50-
s_lastSelected=this;
51-
}
52-
5348
DECLARE_EVENT_TABLE()
5449

5550
friend class FileScrolledWindow;

include/image_panel.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,16 @@ class wxBackgroundBitmap : public wxEvtHandler
4747
* the bitmap explicitly, the bitmap will be destroyed automatically
4848
* by wxWidgets when the application exits.
4949
* */
50-
virtual ~wxBackgroundBitmap()=default;
50+
virtual ~wxBackgroundBitmap()
51+
{
52+
delete m_bitmap;
53+
}
54+
5155
virtual bool ProcessEvent(wxEvent& Event);
5256

5357
void loadImage(wxBitmap* bitmap);
5458
void loadImage(const char* imagePath, wxBitmapType bitmapType, uint rWidth, uint rHeight);
59+
void loadImage(const char* imagePath, wxBitmapType bitmapType, uint perc);
5560
void loadImage(const char* imagePath, wxBitmapType bitmapType);
5661
int getWidth() const;
5762
int getHeight() const;
@@ -208,6 +213,7 @@ class ImagePanel : public BaseBackground<wxPanel>
208213
virtual ~ImagePanel()=default;
209214

210215
virtual void loadBackground(const char* imagePath, wxBitmapType bitmapType=wxBITMAP_TYPE_PNG);
216+
virtual void loadBackground(const char* imagePath, wxBitmapType bitmapType, uint percent);
211217

212218
protected:
213219
wxString m_path;

include/input_command.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class ExitCode
9393
BASE_IMAGE_MISSING=1<<3,
9494
TARGET_WINDOW_CLOSED=1<<4,
9595
CV_EXCEPTION=1<<5,
96-
OUT_OF_BOUND=1<<6,// when pointer is trying to get to a position outside of the screen
96+
OUT_OF_BOUND=1<<6,// when mouse pointer is trying to get to a position outside of the screen
9797
SYSTEM_FAILED=1<<7,
9898
UNKNOWN=1<<8,
9999
LAST=1<<9

include/light_image_panel.h

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*********************************************************************
2+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
6+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
7+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
8+
* THE SOFTWARE.
9+
*
10+
* LightImagePanel class *
11+
* *
12+
* Version: 1.0 *
13+
* Date: 22-06-2021 (Reviewed 03/2015) *
14+
* Author: Dan Machado *
15+
* Note: partially taken from https://wiki.wxwidgets.org/An_image_panel *
16+
**********************************************************************/
17+
#ifndef LIGHT_IMAGE_PANEL_H
18+
#define LIGHT_IMAGE_PANEL_H
19+
20+
#include <wx/panel.h>
21+
#include <wx/string.h>
22+
23+
//====================================================================
24+
25+
class wxBitmap;
26+
27+
class LightImagePanel : public wxPanel
28+
{
29+
public:
30+
LightImagePanel(wxWindow* parent, const char* file, const wxPoint& pos, int width);
31+
32+
LightImagePanel(wxWindow* parent, const wxSize& size=wxDefaultSize);
33+
34+
virtual ~LightImagePanel();
35+
36+
void loadImage(const wxString& file, bool nativeSize=false);
37+
void replaceImage(const wxString& file);
38+
void loadAndFit(const wxString& file, uint width, uint height);
39+
void reSize(uint width, uint height);
40+
void fitToWidth(uint newWidth);
41+
void fitToHeight(uint newHeight);
42+
43+
private:
44+
wxString m_file;
45+
wxBitmap* m_bitmap;
46+
uint m_width;
47+
uint m_height;
48+
49+
void fitToSize(uint rWidth, uint rHeight);
50+
bool reloadImage();
51+
void paintNow();
52+
53+
void render(wxDC& dc);
54+
void paintEvent(wxPaintEvent& evt);
55+
56+
void OnDoubleClick(wxMouseEvent& event);
57+
58+
DECLARE_EVENT_TABLE()
59+
};
60+
61+
//----------------------------------------------------------------------
62+
63+
inline void LightImagePanel::fitToWidth(uint newWidth)
64+
{
65+
reSize(newWidth, 0);
66+
}
67+
68+
//----------------------------------------------------------------------
69+
70+
inline void LightImagePanel::fitToHeight(uint newHeight)
71+
{
72+
reSize(0, newHeight);
73+
}
74+
75+
//--------------------------------------------------------------------
76+
77+
inline void LightImagePanel::OnDoubleClick(wxMouseEvent& event)
78+
{
79+
std::string str("xdg-open ");
80+
str.append(m_file.mb_str());
81+
system(str.c_str());
82+
}
83+
84+
//----------------------------------------------------------------------
85+
86+
#endif

0 commit comments

Comments
 (0)