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:
Saleem Edah-Tally
2025-07-01 22:38:07 +02:00
parent c2c792dd3d
commit a2045aa1f6
38 changed files with 3376 additions and 71 deletions

View 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
}

View 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_

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
#include "wx/msw/wx.rc"

View 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
}

View 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_