Add a 'Stamp' widget.
Place one or multiple stamps on scanned pages in defined locations. A stamp is understood here as - a transparent text in a transparent frame with no borders - an opaque text on an opaque background with no borders. Stamp parameters: - text - font - foreground colour - background colour - angle of rotation - transparency. Locations: - centre - cardinal directions - inter-cardinal directions.
This commit is contained in:
22
Resources/StampWidget/CMakeLists.txt
Normal file
22
Resources/StampWidget/CMakeLists.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(StampWidget)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
|
||||
|
||||
find_package(wxWidgets COMPONENTS base core CONFIG REQUIRED)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_CURRENT_LIST_DIR}/UI)
|
||||
|
||||
add_library(stampwidget STATIC
|
||||
|
||||
DefsStampWidget.h
|
||||
UI/StampWidget.cpp
|
||||
UI/StampWidgets.cpp
|
||||
XStampWidget.cpp
|
||||
XStampWidgets.cpp
|
||||
StampWorker.cpp)
|
||||
|
||||
target_link_libraries(stampwidget
|
||||
${wxWidgets_LIBRARIES})
|
||||
30
Resources/StampWidget/DefsStampWidget.h
Normal file
30
Resources/StampWidget/DefsStampWidget.h
Normal file
@@ -0,0 +1,30 @@
|
||||
// /*
|
||||
// * File: Common.h
|
||||
// * Author: Saleem Edah-Tally - nmset@yandex.com
|
||||
// * License : CeCILL-C
|
||||
// * Copyright Saleem Edah-Tally - © 2025
|
||||
// *
|
||||
// * Created on 27 06 2025, 20:34
|
||||
// */
|
||||
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#include <wx/wx.h>
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
enum {CENTRE = 0, NORTH, SOUTH, EAST, WEST,
|
||||
NORTH_EAST, NORTH_WEST, SOUTH_EAST, SOUTH_WEST};
|
||||
|
||||
struct StampDescriptor
|
||||
{
|
||||
wxImage image;
|
||||
wxString text;
|
||||
wxFont font = wxNullFont;
|
||||
wxColour foregroundColour = wxNullColour;
|
||||
wxColour backgroundColour = wxNullColour;
|
||||
int rotationAngle = 45;
|
||||
int location = 0;
|
||||
bool transparent = true;
|
||||
};
|
||||
#endif // COMMON_H
|
||||
121
Resources/StampWidget/StampWorker.cpp
Normal file
121
Resources/StampWidget/StampWorker.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
// /*
|
||||
// * File: StampWorker.cpp
|
||||
// * Author: Saleem Edah-Tally - nmset@yandex.com
|
||||
// * License : CeCILL-C
|
||||
// * Copyright Saleem Edah-Tally - © 2025
|
||||
// *
|
||||
// * Created on 02 07 2025, 21:23
|
||||
// */
|
||||
|
||||
#include "StampWorker.h"
|
||||
#include <math.h> // M_PI
|
||||
|
||||
wxImage StampWorker::CreateStamp(StampDescriptor * descriptor, int scanResolution)
|
||||
{
|
||||
/*
|
||||
* Rescale the font point size of the stamp according to the scan resolution.
|
||||
* Exclude rescaling on v4l that does not have a resolution parameter.
|
||||
*/
|
||||
wxFont dcFont(descriptor->font);
|
||||
double scale = (scanResolution > 0)
|
||||
? (double) scanResolution / 72.0
|
||||
:1.0;
|
||||
|
||||
wxCoord extentWidth, extentHeight, textLineHeight;
|
||||
{
|
||||
wxMemoryDC dc;
|
||||
if (scale != 1.0)
|
||||
dcFont.SetFractionalPointSize(descriptor->font.GetFractionalPointSize() * scale);
|
||||
dc.SetFont(dcFont); // Mandatory despite set below.
|
||||
dc.GetMultiLineTextExtent(descriptor->text, &extentWidth, &extentHeight, &textLineHeight, &dcFont);
|
||||
}
|
||||
wxBitmap bmp;
|
||||
// bmp.UseAlpha(true); // Not mandatory.
|
||||
bmp.Create(extentWidth, extentHeight); // Memo: See CreateWithDIPSize
|
||||
wxImage img0, img;
|
||||
|
||||
wxMemoryDC dc(bmp);
|
||||
dc.SetFont(dcFont);
|
||||
if (descriptor->transparent)
|
||||
{
|
||||
// +++, Use the red channel only: used by ConvertColourToAlpha().
|
||||
// The chosen value is inversely proportional to the transparency of the text itself.
|
||||
dc.SetTextForeground(wxColour(128, 0, 0)); // A good mean is reasonable.
|
||||
dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
|
||||
}
|
||||
else
|
||||
{
|
||||
dc.SetTextForeground(descriptor->foregroundColour);
|
||||
dc.SetTextBackground(descriptor->backgroundColour);
|
||||
dc.SetBackgroundMode(wxBRUSHSTYLE_SOLID);
|
||||
}
|
||||
|
||||
dc.DrawText(descriptor->text, wxPoint(0, 0));
|
||||
|
||||
img0 = bmp.ConvertToImage();
|
||||
if (!descriptor->transparent)
|
||||
img0.InitAlpha(); // So that there is no dark surrounding if it is rotated.
|
||||
|
||||
img = img0.Rotate((M_PI / 180.0) * descriptor->rotationAngle, wxPoint(0, 0));
|
||||
if (descriptor->transparent)
|
||||
{
|
||||
img.ConvertColourToAlpha(descriptor->foregroundColour.GetRed(),
|
||||
descriptor->foregroundColour.GetGreen(),
|
||||
descriptor->foregroundColour.GetBlue()); // The target colour is passed in.
|
||||
img.ChangeSaturation(-0.7); // Slightly better looking.
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
void StampWorker::StampBackground(wxImage& background,
|
||||
const wxImage& stamp, int location)
|
||||
{
|
||||
// Simply pasting the stamp on the background, i.e., the scanned page.
|
||||
wxPoint bgCentre(background.GetWidth() / 2, background.GetHeight() / 2);
|
||||
wxPoint stampCentre(stamp.GetWidth() / 2, stamp.GetHeight() / 2);
|
||||
int x = 0, y = 0;
|
||||
switch (location)
|
||||
{
|
||||
case NORTH:
|
||||
x = bgCentre.x - stampCentre.x;
|
||||
y = 0;
|
||||
break;
|
||||
case SOUTH:
|
||||
x = bgCentre.x - stampCentre.x;
|
||||
y = background.GetHeight() - stamp.GetHeight();
|
||||
break;
|
||||
case EAST:
|
||||
x = background.GetWidth() - stamp.GetWidth();
|
||||
y = bgCentre.y - stampCentre.y;
|
||||
break;
|
||||
case WEST:
|
||||
x = 0;
|
||||
y = bgCentre.y - stampCentre.y;
|
||||
break;
|
||||
case NORTH_EAST:
|
||||
x = background.GetWidth() - stamp.GetWidth();
|
||||
y = 0;
|
||||
break;
|
||||
case NORTH_WEST:
|
||||
x = 0;
|
||||
y = 0;
|
||||
break;
|
||||
case SOUTH_EAST:
|
||||
x = background.GetWidth() - stamp.GetWidth();
|
||||
y = background.GetHeight() - stamp.GetHeight();
|
||||
break;
|
||||
case SOUTH_WEST:
|
||||
x = 0;
|
||||
y = background.GetHeight() - stamp.GetHeight();
|
||||
break;
|
||||
default: // CENTRE
|
||||
x = bgCentre.x - stampCentre.x;
|
||||
y = bgCentre.y - stampCentre.y;
|
||||
break;
|
||||
}
|
||||
|
||||
wxPoint stampLocation(x, y);
|
||||
background.Paste(stamp, stampLocation.x, stampLocation.y, wxIMAGE_ALPHA_BLEND_COMPOSE);
|
||||
}
|
||||
|
||||
38
Resources/StampWidget/StampWorker.h
Normal file
38
Resources/StampWidget/StampWorker.h
Normal file
@@ -0,0 +1,38 @@
|
||||
// /*
|
||||
// * File: StampWorker.h
|
||||
// * Author: Saleem Edah-Tally - nmset@yandex.com
|
||||
// * License : CeCILL-C
|
||||
// * Copyright Saleem Edah-Tally - © 2025
|
||||
// *
|
||||
// * Created on 02 07 2025, 21:23
|
||||
// */
|
||||
|
||||
#ifndef STAMPWORKER_H
|
||||
#define STAMPWORKER_H
|
||||
|
||||
#include <wx/wx.h>
|
||||
#include "DefsStampWidget.h"
|
||||
|
||||
struct StampDescriptor;
|
||||
|
||||
/**
|
||||
* A stamp is understood here as\n
|
||||
* - a transparent text in a transparent frame with no borders\n
|
||||
* - an opaque text on an opaque background with no borders.\n
|
||||
*
|
||||
* The text may be rotated. Actually, an initial image with the text is rotated
|
||||
* and its new orthogonal bounds accepted (fortunately, we don't have to compute
|
||||
* that).\n
|
||||
* The font point size is rescaled to match the scan resolution. If the
|
||||
* scanResolution parameter is invalid (<=0), the font is not rescaled.
|
||||
*/
|
||||
class StampWorker
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS( StampWorker )
|
||||
public:
|
||||
static wxImage CreateStamp(StampDescriptor * descriptor, int scanResolution = -1);
|
||||
static void StampBackground(wxImage& background, const wxImage& stamp, int location = CENTRE);
|
||||
|
||||
};
|
||||
|
||||
#endif // STAMPWORKER_H
|
||||
239
Resources/StampWidget/UI/StampWidget.cpp
Normal file
239
Resources/StampWidget/UI/StampWidget.cpp
Normal file
@@ -0,0 +1,239 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: StampWidget.cpp
|
||||
// Purpose:
|
||||
// Author: Saleem EDAH-TALLY
|
||||
// Modified by:
|
||||
// Created: mar. 01 juil. 2025 19:14:05
|
||||
// RCS-ID:
|
||||
// Copyright: Copyright Saleem EDAH-TALLY. All rights reserved.
|
||||
// Licence:
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx/wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
|
||||
////@begin includes
|
||||
////@end includes
|
||||
|
||||
#include "StampWidget.h"
|
||||
|
||||
////@begin XPM images
|
||||
////@end XPM images
|
||||
|
||||
|
||||
/*
|
||||
* StampWidget type definition
|
||||
*/
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS( StampWidget, wxPanel )
|
||||
|
||||
|
||||
/*
|
||||
* StampWidget event table definition
|
||||
*/
|
||||
|
||||
BEGIN_EVENT_TABLE( StampWidget, wxPanel )
|
||||
|
||||
////@begin StampWidget event table entries
|
||||
////@end StampWidget event table entries
|
||||
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
/*
|
||||
* StampWidget constructors
|
||||
*/
|
||||
|
||||
StampWidget::StampWidget()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
StampWidget::StampWidget( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
|
||||
{
|
||||
Init();
|
||||
Create(parent, id, pos, size, style);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* StampWidget creator
|
||||
*/
|
||||
|
||||
bool StampWidget::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
|
||||
{
|
||||
////@begin StampWidget creation
|
||||
SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
|
||||
wxPanel::Create( parent, id, pos, size, style );
|
||||
|
||||
CreateControls();
|
||||
if (GetSizer())
|
||||
{
|
||||
GetSizer()->SetSizeHints(this);
|
||||
}
|
||||
Centre();
|
||||
////@end StampWidget creation
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* StampWidget destructor
|
||||
*/
|
||||
|
||||
StampWidget::~StampWidget()
|
||||
{
|
||||
////@begin StampWidget destruction
|
||||
////@end StampWidget destruction
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Member initialisation
|
||||
*/
|
||||
|
||||
void StampWidget::Init()
|
||||
{
|
||||
////@begin StampWidget member initialisation
|
||||
szStampWidgetMain = NULL;
|
||||
txtStamp = NULL;
|
||||
szStampWidgetH0 = NULL;
|
||||
szStampWidgetFlexGrid = NULL;
|
||||
lblForegroundColour = NULL;
|
||||
cpkForegroundStamp = NULL;
|
||||
lblBackgroundColour = NULL;
|
||||
cpkBackgroundStamp = NULL;
|
||||
lblLocation = NULL;
|
||||
cmbStampLocation = NULL;
|
||||
panBitmapPreview = NULL;
|
||||
szBitmapPreviewInPanel = NULL;
|
||||
szStampWidgetH1 = NULL;
|
||||
fpkStamp = NULL;
|
||||
tglTransparent = NULL;
|
||||
sldTextRotationAngle = NULL;
|
||||
////@end StampWidget member initialisation
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Control creation for StampWidget
|
||||
*/
|
||||
|
||||
void StampWidget::CreateControls()
|
||||
{
|
||||
////@begin StampWidget content construction
|
||||
StampWidget* itemPanel1 = this;
|
||||
|
||||
szStampWidgetMain = new wxBoxSizer(wxVERTICAL);
|
||||
itemPanel1->SetSizer(szStampWidgetMain);
|
||||
|
||||
txtStamp = new wxTextCtrl( itemPanel1, ID_TEXTCTRL, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
|
||||
if (StampWidget::ShowToolTips())
|
||||
txtStamp->SetToolTip(_("Create a stamp with this text, which can be multiline.\n\nCTRL + S: save the current text.\nCTRL + R: restore the saved text."));
|
||||
szStampWidgetMain->Add(txtStamp, 0, wxGROW|wxALL, 5);
|
||||
|
||||
szStampWidgetH0 = new wxBoxSizer(wxHORIZONTAL);
|
||||
szStampWidgetMain->Add(szStampWidgetH0, 0, wxALIGN_LEFT|wxALL, 5);
|
||||
|
||||
szStampWidgetFlexGrid = new wxFlexGridSizer(0, 2, 0, 0);
|
||||
szStampWidgetH0->Add(szStampWidgetFlexGrid, 1, wxGROW|wxALL, 5);
|
||||
|
||||
lblForegroundColour = new wxStaticText( itemPanel1, ID_STATIC_FOREGROUND_COLOUR, _("Foreground:"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
szStampWidgetFlexGrid->Add(lblForegroundColour, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
|
||||
cpkForegroundStamp = new wxColourPickerCtrl( itemPanel1, ID_COLOURCTRL_FOREGROUND, wxColour(), wxDefaultPosition, wxDefaultSize, wxCLRP_DEFAULT_STYLE );
|
||||
if (StampWidget::ShowToolTips())
|
||||
cpkForegroundStamp->SetToolTip(_("Foreground colour of the text."));
|
||||
szStampWidgetFlexGrid->Add(cpkForegroundStamp, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
|
||||
lblBackgroundColour = new wxStaticText( itemPanel1, ID_STATIC_BACKGROUND_COLOUR, _("Background:"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
szStampWidgetFlexGrid->Add(lblBackgroundColour, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
|
||||
cpkBackgroundStamp = new wxColourPickerCtrl( itemPanel1, ID_COLOURCTRL_BACKGROUND, wxColour(255, 255, 255), wxDefaultPosition, wxDefaultSize, wxCLRP_DEFAULT_STYLE );
|
||||
if (StampWidget::ShowToolTips())
|
||||
cpkBackgroundStamp->SetToolTip(_("Background colour of the text."));
|
||||
szStampWidgetFlexGrid->Add(cpkBackgroundStamp, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
|
||||
lblLocation = new wxStaticText( itemPanel1, ID_STATIC_LOCATION, _("Location:"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
szStampWidgetFlexGrid->Add(lblLocation, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
|
||||
wxArrayString cmbStampLocationStrings;
|
||||
cmbStampLocation = new wxComboBox( itemPanel1, ID_COMBOBOX, wxEmptyString, wxDefaultPosition, wxDefaultSize, cmbStampLocationStrings, wxCB_READONLY );
|
||||
if (StampWidget::ShowToolTips())
|
||||
cmbStampLocation->SetToolTip(_("Location of the stamp on the output."));
|
||||
szStampWidgetFlexGrid->Add(cmbStampLocation, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
|
||||
panBitmapPreview = new wxPanel( itemPanel1, ID_PANEL_BITMAP_PREVIEW, wxDefaultPosition, wxSize(200, 200), wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
|
||||
panBitmapPreview->SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
|
||||
if (StampWidget::ShowToolTips())
|
||||
panBitmapPreview->SetToolTip(_("Click to update the preview."));
|
||||
szStampWidgetH0->Add(panBitmapPreview, 0, wxALIGN_TOP|wxALL, 5);
|
||||
|
||||
szBitmapPreviewInPanel = new wxBoxSizer(wxVERTICAL);
|
||||
panBitmapPreview->SetSizer(szBitmapPreviewInPanel);
|
||||
|
||||
szStampWidgetH1 = new wxBoxSizer(wxHORIZONTAL);
|
||||
szStampWidgetMain->Add(szStampWidgetH1, 0, wxGROW|wxALL, 5);
|
||||
|
||||
fpkStamp = new wxFontPickerCtrl( itemPanel1, ID_FONTCTRL, wxFont(), wxDefaultPosition, wxDefaultSize, wxFNTP_FONTDESC_AS_LABEL );
|
||||
if (StampWidget::ShowToolTips())
|
||||
fpkStamp->SetToolTip(_("Select the font of the stamp text."));
|
||||
szStampWidgetH1->Add(fpkStamp, 1, wxGROW|wxALL, 5);
|
||||
|
||||
tglTransparent = new wxToggleButton( itemPanel1, ID_TOGGLE_TRANSPARENT, _("Transparent"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
tglTransparent->SetValue(true);
|
||||
if (StampWidget::ShowToolTips())
|
||||
tglTransparent->SetToolTip(_("Check for a completely transparent background and for a transparent text."));
|
||||
szStampWidgetH1->Add(tglTransparent, 0, wxGROW|wxALL, 5);
|
||||
|
||||
sldTextRotationAngle = new wxSlider( itemPanel1, ID_SLIDER, 45, -180, 180, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_AUTOTICKS|wxSL_LABELS );
|
||||
if (StampWidget::ShowToolTips())
|
||||
sldTextRotationAngle->SetToolTip(_("Select the rotation angle of the stamp text."));
|
||||
szStampWidgetMain->Add(sldTextRotationAngle, 0, wxGROW|wxALL, 5);
|
||||
|
||||
////@end StampWidget content construction
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Should we show tooltips?
|
||||
*/
|
||||
|
||||
bool StampWidget::ShowToolTips()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get bitmap resources
|
||||
*/
|
||||
|
||||
wxBitmap StampWidget::GetBitmapResource( const wxString& name )
|
||||
{
|
||||
// Bitmap retrieval
|
||||
////@begin StampWidget bitmap retrieval
|
||||
wxUnusedVar(name);
|
||||
return wxNullBitmap;
|
||||
////@end StampWidget bitmap retrieval
|
||||
}
|
||||
|
||||
/*
|
||||
* Get icon resources
|
||||
*/
|
||||
|
||||
wxIcon StampWidget::GetIconResource( const wxString& name )
|
||||
{
|
||||
// Icon retrieval
|
||||
////@begin StampWidget icon retrieval
|
||||
wxUnusedVar(name);
|
||||
return wxNullIcon;
|
||||
////@end StampWidget icon retrieval
|
||||
}
|
||||
129
Resources/StampWidget/UI/StampWidget.h
Normal file
129
Resources/StampWidget/UI/StampWidget.h
Normal file
@@ -0,0 +1,129 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: StampWidget.h
|
||||
// Purpose:
|
||||
// Author: Saleem EDAH-TALLY
|
||||
// Modified by:
|
||||
// Created: mar. 01 juil. 2025 19:14:05
|
||||
// RCS-ID:
|
||||
// Copyright: Copyright Saleem EDAH-TALLY. All rights reserved.
|
||||
// Licence:
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _STAMPWIDGET_H_
|
||||
#define _STAMPWIDGET_H_
|
||||
|
||||
|
||||
/*!
|
||||
* Includes
|
||||
*/
|
||||
|
||||
////@begin includes
|
||||
#include "wx/clrpicker.h"
|
||||
#include "wx/fontpicker.h"
|
||||
#include "wx/tglbtn.h"
|
||||
////@end includes
|
||||
#include "wx/combobox.h"
|
||||
#include "wx/stattext.h"
|
||||
/*!
|
||||
* Forward declarations
|
||||
*/
|
||||
|
||||
////@begin forward declarations
|
||||
class wxBoxSizer;
|
||||
class wxFlexGridSizer;
|
||||
class wxColourPickerCtrl;
|
||||
class wxFontPickerCtrl;
|
||||
class wxToggleButton;
|
||||
////@end forward declarations
|
||||
|
||||
/*!
|
||||
* Control identifiers
|
||||
*/
|
||||
|
||||
////@begin control identifiers
|
||||
#define ID_STAMPWIDGET 10000
|
||||
#define ID_TEXTCTRL 10001
|
||||
#define ID_STATIC_FOREGROUND_COLOUR 10008
|
||||
#define ID_COLOURCTRL_FOREGROUND 10003
|
||||
#define ID_STATIC_BACKGROUND_COLOUR 10009
|
||||
#define ID_COLOURCTRL_BACKGROUND 10006
|
||||
#define ID_STATIC_LOCATION 10010
|
||||
#define ID_COMBOBOX 10005
|
||||
#define ID_PANEL_BITMAP_PREVIEW 10011
|
||||
#define ID_FONTCTRL 10002
|
||||
#define ID_TOGGLE_TRANSPARENT 10007
|
||||
#define ID_SLIDER 10004
|
||||
#define SYMBOL_STAMPWIDGET_STYLE wxTAB_TRAVERSAL
|
||||
#define SYMBOL_STAMPWIDGET_TITLE _("StampWidget")
|
||||
#define SYMBOL_STAMPWIDGET_IDNAME ID_STAMPWIDGET
|
||||
#define SYMBOL_STAMPWIDGET_SIZE wxSize(400, 300)
|
||||
#define SYMBOL_STAMPWIDGET_POSITION wxDefaultPosition
|
||||
////@end control identifiers
|
||||
|
||||
#include <wx/panel.h>
|
||||
#include <wx/slider.h>
|
||||
|
||||
/*!
|
||||
* StampWidget class declaration
|
||||
*/
|
||||
|
||||
class StampWidget: public wxPanel
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS( StampWidget )
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
public:
|
||||
/// Constructors
|
||||
StampWidget();
|
||||
StampWidget( wxWindow* parent, wxWindowID id = SYMBOL_STAMPWIDGET_IDNAME, const wxPoint& pos = SYMBOL_STAMPWIDGET_POSITION, const wxSize& size = SYMBOL_STAMPWIDGET_SIZE, long style = SYMBOL_STAMPWIDGET_STYLE );
|
||||
|
||||
/// Creation
|
||||
bool Create( wxWindow* parent, wxWindowID id = SYMBOL_STAMPWIDGET_IDNAME, const wxPoint& pos = SYMBOL_STAMPWIDGET_POSITION, const wxSize& size = SYMBOL_STAMPWIDGET_SIZE, long style = SYMBOL_STAMPWIDGET_STYLE );
|
||||
|
||||
/// Destructor
|
||||
~StampWidget();
|
||||
|
||||
/// Initialises member variables
|
||||
void Init();
|
||||
|
||||
/// Creates the controls and sizers
|
||||
void CreateControls();
|
||||
|
||||
////@begin StampWidget event handler declarations
|
||||
|
||||
////@end StampWidget event handler declarations
|
||||
|
||||
////@begin StampWidget member function declarations
|
||||
|
||||
/// Retrieves bitmap resources
|
||||
wxBitmap GetBitmapResource( const wxString& name );
|
||||
|
||||
/// Retrieves icon resources
|
||||
wxIcon GetIconResource( const wxString& name );
|
||||
////@end StampWidget member function declarations
|
||||
|
||||
/// Should we show tooltips?
|
||||
static bool ShowToolTips();
|
||||
|
||||
////@begin StampWidget member variables
|
||||
wxBoxSizer* szStampWidgetMain;
|
||||
wxTextCtrl* txtStamp;
|
||||
wxBoxSizer* szStampWidgetH0;
|
||||
wxFlexGridSizer* szStampWidgetFlexGrid;
|
||||
wxStaticText* lblForegroundColour;
|
||||
wxColourPickerCtrl* cpkForegroundStamp;
|
||||
wxStaticText* lblBackgroundColour;
|
||||
wxColourPickerCtrl* cpkBackgroundStamp;
|
||||
wxStaticText* lblLocation;
|
||||
wxComboBox* cmbStampLocation;
|
||||
wxPanel* panBitmapPreview;
|
||||
wxBoxSizer* szBitmapPreviewInPanel;
|
||||
wxBoxSizer* szStampWidgetH1;
|
||||
wxFontPickerCtrl* fpkStamp;
|
||||
wxToggleButton* tglTransparent;
|
||||
wxSlider* sldTextRotationAngle;
|
||||
////@end StampWidget member variables
|
||||
};
|
||||
|
||||
#endif
|
||||
// _STAMPWIDGET_H_
|
||||
1612
Resources/StampWidget/UI/StampWidget.pjd
Normal file
1612
Resources/StampWidget/UI/StampWidget.pjd
Normal file
File diff suppressed because it is too large
Load Diff
1
Resources/StampWidget/UI/StampWidget.rc
Normal file
1
Resources/StampWidget/UI/StampWidget.rc
Normal file
@@ -0,0 +1 @@
|
||||
#include "wx/msw/wx.rc"
|
||||
178
Resources/StampWidget/UI/StampWidgets.cpp
Normal file
178
Resources/StampWidget/UI/StampWidgets.cpp
Normal file
@@ -0,0 +1,178 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: StampWidgets.cpp
|
||||
// Purpose:
|
||||
// Author: Saleem EDAH-TALLY
|
||||
// Modified by:
|
||||
// Created: dim. 06 juil. 2025 22:33:34
|
||||
// RCS-ID:
|
||||
// Copyright: Copyright Saleem EDAH-TALLY. All rights reserved.
|
||||
// Licence:
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx/wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
|
||||
////@begin includes
|
||||
#include "wx/imaglist.h"
|
||||
////@end includes
|
||||
|
||||
#include "StampWidgets.h"
|
||||
|
||||
////@begin XPM images
|
||||
////@end XPM images
|
||||
|
||||
|
||||
/*
|
||||
* StampWidgets type definition
|
||||
*/
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS( StampWidgets, wxPanel )
|
||||
|
||||
|
||||
/*
|
||||
* StampWidgets event table definition
|
||||
*/
|
||||
|
||||
BEGIN_EVENT_TABLE( StampWidgets, wxPanel )
|
||||
|
||||
////@begin StampWidgets event table entries
|
||||
////@end StampWidgets event table entries
|
||||
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
/*
|
||||
* StampWidgets constructors
|
||||
*/
|
||||
|
||||
StampWidgets::StampWidgets()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
StampWidgets::StampWidgets( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
|
||||
{
|
||||
Init();
|
||||
Create(parent, id, pos, size, style);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* StampWidgets creator
|
||||
*/
|
||||
|
||||
bool StampWidgets::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
|
||||
{
|
||||
////@begin StampWidgets creation
|
||||
SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
|
||||
wxPanel::Create( parent, id, pos, size, style );
|
||||
|
||||
CreateControls();
|
||||
Centre();
|
||||
////@end StampWidgets creation
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* StampWidgets destructor
|
||||
*/
|
||||
|
||||
StampWidgets::~StampWidgets()
|
||||
{
|
||||
////@begin StampWidgets destruction
|
||||
////@end StampWidgets destruction
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Member initialisation
|
||||
*/
|
||||
|
||||
void StampWidgets::Init()
|
||||
{
|
||||
////@begin StampWidgets member initialisation
|
||||
szNoteBookMain = NULL;
|
||||
szNoteBookButtons = NULL;
|
||||
btnAddStampWidget = NULL;
|
||||
btnDeleteStampWidget = NULL;
|
||||
nbStampWidgets = NULL;
|
||||
////@end StampWidgets member initialisation
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Control creation for StampWidgets
|
||||
*/
|
||||
|
||||
void StampWidgets::CreateControls()
|
||||
{
|
||||
////@begin StampWidgets content construction
|
||||
StampWidgets* itemPanel1 = this;
|
||||
|
||||
szNoteBookMain = new wxBoxSizer(wxHORIZONTAL);
|
||||
itemPanel1->SetSizer(szNoteBookMain);
|
||||
|
||||
szNoteBookButtons = new wxBoxSizer(wxHORIZONTAL);
|
||||
szNoteBookMain->Add(szNoteBookButtons, 0, wxALIGN_TOP, 5);
|
||||
|
||||
btnAddStampWidget = new wxButton( itemPanel1, ID_BUTTON_NB, _("+"), wxDefaultPosition, wxSize(30, -1), 0 );
|
||||
if (StampWidgets::ShowToolTips())
|
||||
btnAddStampWidget->SetToolTip(_("Add a stamp widget."));
|
||||
szNoteBookButtons->Add(btnAddStampWidget, 0, wxALIGN_CENTER_VERTICAL|wxFIXED_MINSIZE, 1);
|
||||
|
||||
btnDeleteStampWidget = new wxButton( itemPanel1, ID_BUTTON_NB1, _("-"), wxDefaultPosition, wxSize(30, -1), 0 );
|
||||
if (StampWidgets::ShowToolTips())
|
||||
btnDeleteStampWidget->SetToolTip(_("Remove the selected stamp widget."));
|
||||
szNoteBookButtons->Add(btnDeleteStampWidget, 0, wxALIGN_CENTER_VERTICAL, 1);
|
||||
|
||||
nbStampWidgets = new wxNotebook( itemPanel1, ID_NOTEBOOK_STAMPWIDGETS_, wxDefaultPosition, wxDefaultSize, wxBK_DEFAULT );
|
||||
|
||||
szNoteBookMain->Add(nbStampWidgets, 1, wxGROW|wxALL, 5);
|
||||
|
||||
////@end StampWidgets content construction
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Should we show tooltips?
|
||||
*/
|
||||
|
||||
bool StampWidgets::ShowToolTips()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get bitmap resources
|
||||
*/
|
||||
|
||||
wxBitmap StampWidgets::GetBitmapResource( const wxString& name )
|
||||
{
|
||||
// Bitmap retrieval
|
||||
////@begin StampWidgets bitmap retrieval
|
||||
wxUnusedVar(name);
|
||||
return wxNullBitmap;
|
||||
////@end StampWidgets bitmap retrieval
|
||||
}
|
||||
|
||||
/*
|
||||
* Get icon resources
|
||||
*/
|
||||
|
||||
wxIcon StampWidgets::GetIconResource( const wxString& name )
|
||||
{
|
||||
// Icon retrieval
|
||||
////@begin StampWidgets icon retrieval
|
||||
wxUnusedVar(name);
|
||||
return wxNullIcon;
|
||||
////@end StampWidgets icon retrieval
|
||||
}
|
||||
103
Resources/StampWidget/UI/StampWidgets.h
Normal file
103
Resources/StampWidget/UI/StampWidgets.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: StampWidgets.h
|
||||
// Purpose:
|
||||
// Author: Saleem EDAH-TALLY
|
||||
// Modified by:
|
||||
// Created: dim. 06 juil. 2025 22:33:34
|
||||
// RCS-ID:
|
||||
// Copyright: Copyright Saleem EDAH-TALLY. All rights reserved.
|
||||
// Licence:
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _STAMPWIDGETS_H_
|
||||
#define _STAMPWIDGETS_H_
|
||||
|
||||
|
||||
/*!
|
||||
* Includes
|
||||
*/
|
||||
|
||||
////@begin includes
|
||||
#include "wx/notebook.h"
|
||||
////@end includes
|
||||
|
||||
/*!
|
||||
* Forward declarations
|
||||
*/
|
||||
|
||||
////@begin forward declarations
|
||||
class wxBoxSizer;
|
||||
class wxNotebook;
|
||||
////@end forward declarations
|
||||
#include <wx/panel.h>
|
||||
#include <wx/button.h>
|
||||
/*!
|
||||
* Control identifiers
|
||||
*/
|
||||
|
||||
////@begin control identifiers
|
||||
#define ID_STAMPWIDGETS 10000
|
||||
#define ID_BUTTON_NB 10002
|
||||
#define ID_BUTTON_NB1 10003
|
||||
#define ID_NOTEBOOK_STAMPWIDGETS_ 10001
|
||||
#define SYMBOL_STAMPWIDGETS_STYLE wxTAB_TRAVERSAL
|
||||
#define SYMBOL_STAMPWIDGETS_TITLE _("StampWidgets")
|
||||
#define SYMBOL_STAMPWIDGETS_IDNAME ID_STAMPWIDGETS
|
||||
#define SYMBOL_STAMPWIDGETS_SIZE wxSize(400, 300)
|
||||
#define SYMBOL_STAMPWIDGETS_POSITION wxDefaultPosition
|
||||
////@end control identifiers
|
||||
|
||||
|
||||
/*!
|
||||
* StampWidgets class declaration
|
||||
*/
|
||||
|
||||
class StampWidgets: public wxPanel
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS( StampWidgets )
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
public:
|
||||
/// Constructors
|
||||
StampWidgets();
|
||||
StampWidgets( wxWindow* parent, wxWindowID id = SYMBOL_STAMPWIDGETS_IDNAME, const wxPoint& pos = SYMBOL_STAMPWIDGETS_POSITION, const wxSize& size = SYMBOL_STAMPWIDGETS_SIZE, long style = SYMBOL_STAMPWIDGETS_STYLE );
|
||||
|
||||
/// Creation
|
||||
bool Create( wxWindow* parent, wxWindowID id = SYMBOL_STAMPWIDGETS_IDNAME, const wxPoint& pos = SYMBOL_STAMPWIDGETS_POSITION, const wxSize& size = SYMBOL_STAMPWIDGETS_SIZE, long style = SYMBOL_STAMPWIDGETS_STYLE );
|
||||
|
||||
/// Destructor
|
||||
~StampWidgets();
|
||||
|
||||
/// Initialises member variables
|
||||
void Init();
|
||||
|
||||
/// Creates the controls and sizers
|
||||
void CreateControls();
|
||||
|
||||
////@begin StampWidgets event handler declarations
|
||||
|
||||
////@end StampWidgets event handler declarations
|
||||
|
||||
////@begin StampWidgets member function declarations
|
||||
|
||||
/// Retrieves bitmap resources
|
||||
wxBitmap GetBitmapResource( const wxString& name );
|
||||
|
||||
/// Retrieves icon resources
|
||||
wxIcon GetIconResource( const wxString& name );
|
||||
////@end StampWidgets member function declarations
|
||||
|
||||
/// Should we show tooltips?
|
||||
static bool ShowToolTips();
|
||||
|
||||
////@begin StampWidgets member variables
|
||||
wxBoxSizer* szNoteBookMain;
|
||||
wxBoxSizer* szNoteBookButtons;
|
||||
wxButton* btnAddStampWidget;
|
||||
wxButton* btnDeleteStampWidget;
|
||||
wxNotebook* nbStampWidgets;
|
||||
////@end StampWidgets member variables
|
||||
};
|
||||
|
||||
#endif
|
||||
// _STAMPWIDGETS_H_
|
||||
230
Resources/StampWidget/XStampWidget.cpp
Normal file
230
Resources/StampWidget/XStampWidget.cpp
Normal file
@@ -0,0 +1,230 @@
|
||||
// /*
|
||||
// * File: XStampWidget.cpp
|
||||
// * Author: Saleem Edah-Tally - nmset@yandex.com
|
||||
// * License : CeCILL-C
|
||||
// * Copyright Saleem Edah-Tally - © 2025
|
||||
// *
|
||||
// * Created on 01 07 2025, 20:35
|
||||
// */
|
||||
|
||||
#include "XStampWidget.h"
|
||||
#include "DefsStampWidget.h"
|
||||
#include "StampWorker.h"
|
||||
#include <wx/bmpbndl.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
IMPLEMENT_CLASS( XStampWidget, StampWidget )
|
||||
|
||||
XStampWidget::XStampWidget(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
|
||||
: StampWidget(parent, id, pos, size, style)
|
||||
{}
|
||||
|
||||
bool XStampWidget::Setup(wxConfig * config)
|
||||
{
|
||||
m_config = config;
|
||||
if (!m_config)
|
||||
return false;
|
||||
|
||||
const wxString fontDesc = m_config->Read("/Stamp/FontDesc", "");
|
||||
if (!fontDesc.IsEmpty())
|
||||
{
|
||||
wxFont font = wxNullFont;
|
||||
font.SetNativeFontInfo(fontDesc);
|
||||
if (font.IsOk())
|
||||
{
|
||||
fpkStamp->SetSelectedFont(font);
|
||||
fpkStamp->Update();
|
||||
}
|
||||
}
|
||||
long rgb = m_config->Read("/Stamp/ForegroundRGB", wxNOT_FOUND);
|
||||
if (rgb > wxNOT_FOUND)
|
||||
{
|
||||
wxColour foregroundColour = wxNullColour;
|
||||
foregroundColour.SetRGB((wxUint32) rgb);
|
||||
if (foregroundColour.IsOk())
|
||||
{
|
||||
cpkForegroundStamp->SetColour(foregroundColour);
|
||||
}
|
||||
}
|
||||
rgb = m_config->Read("/Stamp/BackgroundRGB", wxNOT_FOUND);
|
||||
if (rgb > wxNOT_FOUND)
|
||||
{
|
||||
wxColour backgroundColour = wxNullColour;
|
||||
backgroundColour.SetRGB((wxUint32) rgb);
|
||||
if (backgroundColour.IsOk())
|
||||
{
|
||||
cpkBackgroundStamp->SetColour(backgroundColour);
|
||||
}
|
||||
}
|
||||
int textRotationAngle = m_config->Read("/Stamp/RotationAngle", 45);
|
||||
sldTextRotationAngle->SetValue(textRotationAngle);
|
||||
bool transparency = m_config->ReadBool("/Stamp/Transparency", true);
|
||||
tglTransparent->SetValue(transparency);
|
||||
wxCommandEvent evt;
|
||||
evt.SetInt(transparency);
|
||||
OnTransparencyToggled(evt);
|
||||
|
||||
fpkStamp->Bind(wxEVT_FONTPICKER_CHANGED, &XStampWidget::OnFontChanged, this);
|
||||
cpkForegroundStamp->Bind(wxEVT_COLOURPICKER_CHANGED, &XStampWidget::OnForegroundColourChanged, this);
|
||||
cpkBackgroundStamp->Bind(wxEVT_COLOURPICKER_CHANGED, &XStampWidget::OnBackgroundColourChanged, this);
|
||||
// *End* of any mouse and any keyboard interaction.
|
||||
sldTextRotationAngle->Bind(wxEVT_SCROLL_CHANGED, &XStampWidget::OnAngleSliderChanged, this);
|
||||
txtStamp->Bind(wxEVT_KEY_UP, &XStampWidget::OnTxtKeyPressed, this);
|
||||
tglTransparent->Bind(wxEVT_TOGGLEBUTTON, &XStampWidget::OnTransparencyToggled, this);
|
||||
|
||||
wxArrayString stampLocations ({_("Centre"),
|
||||
_("North"), _("South"), _("East"), _("West"),
|
||||
_("North-east"), _("North-west"),
|
||||
_("South-east"), _("South-west")});
|
||||
cmbStampLocation->Append(stampLocations);
|
||||
int location = m_config->Read("/Stamp/Location", wxNOT_FOUND);
|
||||
cmbStampLocation->Select((location >= cmbStampLocation->GetCount() || location < 0) ? 0 : location);
|
||||
cmbStampLocation->Bind(wxEVT_COMMAND_COMBOBOX_SELECTED, &XStampWidget::OnLocationChanged, this);
|
||||
|
||||
// A panel container is used to have its borders.
|
||||
m_sbmpPreview = new wxGenericStaticBitmap(panBitmapPreview, wxID_ANY, wxBitmapBundle(wxNullBitmap), wxDefaultPosition, panBitmapPreview->GetSize());
|
||||
szBitmapPreviewInPanel->Add(m_sbmpPreview, 0, wxGROW | wxALL, 5);
|
||||
m_sbmpPreview->SetScaleMode(wxStaticBitmapBase::Scale_AspectFit);
|
||||
|
||||
m_sbmpPreview->Bind(wxEVT_LEFT_UP, &XStampWidget::OnBitmapPreview, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
void XStampWidget::OnFontChanged(wxFontPickerEvent& evt)
|
||||
{
|
||||
if (!m_config)
|
||||
{
|
||||
evt.Skip();
|
||||
return;
|
||||
}
|
||||
const wxString desc = evt.GetFont().GetNativeFontInfoDesc();
|
||||
m_config->Write("/Stamp/FontDesc", desc);
|
||||
m_config->Flush();
|
||||
|
||||
evt.Skip();
|
||||
}
|
||||
|
||||
void XStampWidget::OnForegroundColourChanged(wxColourPickerEvent& evt)
|
||||
{
|
||||
if (!m_config)
|
||||
{
|
||||
evt.Skip();
|
||||
return;
|
||||
}
|
||||
const wxUint32 rgb = evt.GetColour().GetRGB();
|
||||
m_config->Write("/Stamp/ForegroundRGB", (long) rgb);
|
||||
m_config->Flush();
|
||||
|
||||
evt.Skip();
|
||||
}
|
||||
|
||||
void XStampWidget::OnBackgroundColourChanged(wxColourPickerEvent& evt)
|
||||
{
|
||||
if (!m_config)
|
||||
{
|
||||
evt.Skip();
|
||||
return;
|
||||
}
|
||||
const wxUint32 rgb = evt.GetColour().GetRGB();
|
||||
m_config->Write("/Stamp/BackgroundRGB", (long) rgb);
|
||||
m_config->Flush();
|
||||
|
||||
evt.Skip();
|
||||
}
|
||||
|
||||
void XStampWidget::OnAngleSliderChanged(wxScrollEvent& evt)
|
||||
{
|
||||
if (!m_config)
|
||||
{
|
||||
evt.Skip();
|
||||
return;
|
||||
}
|
||||
m_config->Write("/Stamp/RotationAngle", evt.GetInt());
|
||||
m_config->Flush();
|
||||
evt.Skip();
|
||||
}
|
||||
|
||||
void XStampWidget::OnTxtKeyPressed(wxKeyEvent& evt)
|
||||
{
|
||||
if (!m_config || !evt.ControlDown())
|
||||
{
|
||||
evt.Skip();
|
||||
return;
|
||||
}
|
||||
if (evt.GetKeyCode() == 'S')
|
||||
{
|
||||
if (txtStamp->IsEmpty())
|
||||
{
|
||||
evt.Skip();
|
||||
return;
|
||||
}
|
||||
m_config->Write("/Stamp/Text", txtStamp->GetValue());
|
||||
m_config->Flush();
|
||||
}
|
||||
else if (evt.GetKeyCode() == 'R')
|
||||
{
|
||||
wxString last;
|
||||
if (m_config->Read("/Stamp/Text", &last))
|
||||
{
|
||||
txtStamp->SetValue(last);
|
||||
txtStamp->SetSelection(last.Len(), last.Len());
|
||||
}
|
||||
}
|
||||
|
||||
evt.Skip();
|
||||
}
|
||||
|
||||
void XStampWidget::OnLocationChanged(wxCommandEvent& evt)
|
||||
{
|
||||
if (!m_config)
|
||||
{
|
||||
evt.Skip();
|
||||
return;
|
||||
}
|
||||
m_config->Write("/Stamp/Location", evt.GetSelection());
|
||||
m_config->Flush();
|
||||
evt.Skip();
|
||||
}
|
||||
|
||||
void XStampWidget::OnTransparencyToggled(wxCommandEvent& evt)
|
||||
{
|
||||
lblBackgroundColour->Show(evt.GetInt() == 0);
|
||||
cpkBackgroundStamp->Show(evt.GetInt() == 0);
|
||||
if (GetSizer())
|
||||
GetSizer()->Layout();
|
||||
|
||||
if (!m_config)
|
||||
{
|
||||
evt.Skip();
|
||||
return;
|
||||
}
|
||||
m_config->Write("/Stamp/Transparency", evt.GetInt());
|
||||
m_config->Flush();
|
||||
evt.Skip();
|
||||
}
|
||||
|
||||
|
||||
StampDescriptor * XStampWidget::GetStampDescriptor()
|
||||
{
|
||||
m_descriptor.reset(nullptr);
|
||||
m_descriptor = std::make_unique<StampDescriptor> ();
|
||||
m_descriptor->text = txtStamp->GetValue();
|
||||
m_descriptor->font = fpkStamp->GetSelectedFont();
|
||||
m_descriptor->foregroundColour = cpkForegroundStamp->GetColour();
|
||||
m_descriptor->backgroundColour = cpkBackgroundStamp->GetColour();
|
||||
m_descriptor->rotationAngle = sldTextRotationAngle->GetValue();
|
||||
m_descriptor->location = cmbStampLocation->GetSelection();
|
||||
m_descriptor->transparent = tglTransparent->GetValue();
|
||||
// Not setting image, it is to be created.
|
||||
return m_descriptor.get();
|
||||
}
|
||||
|
||||
void XStampWidget::OnBitmapPreview(wxMouseEvent& evt)
|
||||
{
|
||||
StampDescriptor * descriptor = GetStampDescriptor();
|
||||
wxImage preview = StampWorker::CreateStamp(descriptor, 72);
|
||||
m_sbmpPreview->SetBitmap(wxBitmapBundle(preview));
|
||||
GetSizer()->Layout();
|
||||
evt.Skip();
|
||||
}
|
||||
52
Resources/StampWidget/XStampWidget.h
Normal file
52
Resources/StampWidget/XStampWidget.h
Normal file
@@ -0,0 +1,52 @@
|
||||
// /*
|
||||
// * File: XStampWidget.h
|
||||
// * Author: Saleem Edah-Tally - nmset@yandex.com
|
||||
// * License : CeCILL-C
|
||||
// * Copyright Saleem Edah-Tally - © 2025
|
||||
// *
|
||||
// * Created on 01 07 2025, 20:35
|
||||
// */
|
||||
|
||||
#ifndef XSTAMPWIDGET_H
|
||||
#define XSTAMPWIDGET_H
|
||||
|
||||
#include "StampWidget.h"
|
||||
#include <wx/wx.h>
|
||||
#include <wx/config.h>
|
||||
#include <wx/generic/statbmpg.h>
|
||||
|
||||
struct StampDescriptor;
|
||||
|
||||
/**
|
||||
* This widget collects inputs for the creation of a stamp on scan pages.\n
|
||||
* - text
|
||||
* - font
|
||||
* - foreground colour
|
||||
* - background colour
|
||||
* - angle of rotation
|
||||
* - transparency.
|
||||
*/
|
||||
class XStampWidget : public StampWidget
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS( XStampWidget )
|
||||
public:
|
||||
XStampWidget( wxWindow* parent, wxWindowID id = SYMBOL_STAMPWIDGET_IDNAME, const wxPoint& pos = SYMBOL_STAMPWIDGET_POSITION, const wxSize& size = SYMBOL_STAMPWIDGET_SIZE, long style = SYMBOL_STAMPWIDGET_STYLE );
|
||||
|
||||
bool Setup(wxConfig * config);
|
||||
StampDescriptor * GetStampDescriptor();
|
||||
private:
|
||||
wxConfig * m_config;
|
||||
std::unique_ptr<StampDescriptor> m_descriptor;
|
||||
wxGenericStaticBitmap * m_sbmpPreview;
|
||||
|
||||
void OnFontChanged(wxFontPickerEvent& evt);
|
||||
void OnForegroundColourChanged(wxColourPickerEvent& evt);
|
||||
void OnBackgroundColourChanged(wxColourPickerEvent& evt);
|
||||
void OnAngleSliderChanged(wxScrollEvent& evt);
|
||||
void OnTxtKeyPressed ( wxKeyEvent& evt );
|
||||
void OnLocationChanged(wxCommandEvent& evt);
|
||||
void OnTransparencyToggled(wxCommandEvent& evt);
|
||||
void OnBitmapPreview(wxMouseEvent& evt);
|
||||
};
|
||||
|
||||
#endif // XSTAMPWIDGET_H
|
||||
88
Resources/StampWidget/XStampWidgets.cpp
Normal file
88
Resources/StampWidget/XStampWidgets.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
// /*
|
||||
// * File: XStampWidgets.cpp
|
||||
// * Author: Saleem Edah-Tally - nmset@yandex.com
|
||||
// * License : CeCILL-C
|
||||
// * Copyright Saleem Edah-Tally - © 2025
|
||||
// *
|
||||
// * Created on 06 07 2025, 22:41
|
||||
// */
|
||||
|
||||
#include "XStampWidgets.h"
|
||||
#include <XStampWidget.h>
|
||||
#include <DefsStampWidget.h>
|
||||
|
||||
IMPLEMENT_CLASS( XStampWidgets, StampWidgets )
|
||||
|
||||
XStampWidgets::XStampWidgets(wxWindow* parent, wxWindowID id, const wxPoint& pos,
|
||||
const wxSize& size, long style)
|
||||
: StampWidgets(parent, id, pos, size, style)
|
||||
{}
|
||||
|
||||
bool XStampWidgets::Setup(wxFileConfig* config)
|
||||
{
|
||||
m_config = config;
|
||||
if (!m_config)
|
||||
return false;
|
||||
|
||||
wxMouseEvent evt;
|
||||
AddStampWidget(evt);
|
||||
btnAddStampWidget->Bind(wxEVT_LEFT_UP, &XStampWidgets::AddStampWidget, this);
|
||||
btnDeleteStampWidget->Bind(wxEVT_LEFT_UP, &XStampWidgets::DeleteStampWidget, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
void XStampWidgets::AddStampWidget(wxMouseEvent& evt)
|
||||
{
|
||||
XStampWidget * stampWidget = new XStampWidget(nbStampWidgets);
|
||||
stampWidget->Setup(m_config);
|
||||
stampWidget->Bind(wxEVT_COMMAND_COMBOBOX_SELECTED, &XStampWidgets::OnStampLocationChanged, this);
|
||||
nbStampWidgets->AddPage(stampWidget, stampWidget->cmbStampLocation->GetStringSelection(), true);
|
||||
if (GetParent()->GetSizer())
|
||||
GetParent()->GetSizer()->Layout();
|
||||
|
||||
evt.Skip();
|
||||
}
|
||||
|
||||
void XStampWidgets::DeleteStampWidget(wxMouseEvent& evt)
|
||||
{
|
||||
int selectedPage = nbStampWidgets->GetSelection();
|
||||
if (selectedPage == wxNOT_FOUND)
|
||||
{
|
||||
evt.Skip();
|
||||
return;
|
||||
}
|
||||
nbStampWidgets->DeletePage(selectedPage);
|
||||
evt.Skip();
|
||||
}
|
||||
|
||||
std::vector<StampDescriptor*> * XStampWidgets::GetStampDescriptors()
|
||||
{
|
||||
m_stampDescriptors.clear(); // Stored as unique_ptr in XStampWidget.
|
||||
for (uint i = 0; i < nbStampWidgets->GetPageCount(); i++)
|
||||
{
|
||||
XStampWidget * stampWidget = static_cast<XStampWidget*> (nbStampWidgets->GetPage(i));
|
||||
if (stampWidget)
|
||||
{
|
||||
m_stampDescriptors.push_back(stampWidget->GetStampDescriptor());
|
||||
}
|
||||
}
|
||||
return &m_stampDescriptors;
|
||||
}
|
||||
|
||||
void XStampWidgets::OnStampLocationChanged(wxCommandEvent& evt)
|
||||
{
|
||||
int selectedPage = nbStampWidgets->GetSelection();
|
||||
if (selectedPage == wxNOT_FOUND)
|
||||
{
|
||||
evt.Skip();
|
||||
return;
|
||||
}
|
||||
XStampWidget * stampWidget = static_cast<XStampWidget*> (nbStampWidgets->GetPage(selectedPage));
|
||||
if (!stampWidget)
|
||||
{
|
||||
evt.Skip();
|
||||
return;
|
||||
}
|
||||
nbStampWidgets->SetPageText(selectedPage, stampWidget->cmbStampLocation->GetStringSelection());
|
||||
evt.Skip();
|
||||
}
|
||||
41
Resources/StampWidget/XStampWidgets.h
Normal file
41
Resources/StampWidget/XStampWidgets.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// /*
|
||||
// * File: XStampWidgets.h
|
||||
// * Author: Saleem Edah-Tally - nmset@yandex.com
|
||||
// * License : CeCILL-C
|
||||
// * Copyright Saleem Edah-Tally - © 2025
|
||||
// *
|
||||
// * Created on 06 07 2025, 22:41
|
||||
// */
|
||||
|
||||
#ifndef XSTAMPWIDGETS_H
|
||||
#define XSTAMPWIDGETS_H
|
||||
|
||||
#include "StampWidgets.h"
|
||||
#include <wx/wx.h>
|
||||
#include <wx/config.h>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
struct StampDescriptor;
|
||||
|
||||
class XStampWidgets : public StampWidgets
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS( XStampWidgets )
|
||||
public:
|
||||
XStampWidgets(wxWindow* parent, wxWindowID id = SYMBOL_STAMPWIDGETS_IDNAME,
|
||||
const wxPoint& pos = SYMBOL_STAMPWIDGETS_POSITION,
|
||||
const wxSize& size = SYMBOL_STAMPWIDGETS_SIZE,
|
||||
long style = SYMBOL_STAMPWIDGETS_STYLE);
|
||||
bool Setup(wxConfig * config);
|
||||
std::vector<StampDescriptor*> * GetStampDescriptors();
|
||||
|
||||
private:
|
||||
wxConfig * m_config;
|
||||
std::vector<StampDescriptor*> m_stampDescriptors;
|
||||
|
||||
void AddStampWidget(wxMouseEvent& evt);
|
||||
void DeleteStampWidget(wxMouseEvent& evt);
|
||||
void OnStampLocationChanged(wxCommandEvent& evt);
|
||||
};
|
||||
|
||||
#endif // XSTAMPWIDGETS_H
|
||||
Reference in New Issue
Block a user