EgtExecutor :

- in LUA_GENERAL migliorato e corretto il dialogo di tipo Brush/ColorPicker.
This commit is contained in:
Riccardo Elitropi
2026-02-23 15:53:39 +01:00
parent 7b48821c00
commit 71009205b5
+58 -26
View File
@@ -30,6 +30,7 @@
#include "/EgtDev/Include/EgtIniFile.h"
#include "/EgtDev/Include/EgtNumUtils.h"
#include "/EgtDev/Include/EgtStringConverter.h"
#include <sstream>
#include <Windowsx.h>
#include <shlobj.h>
@@ -1224,15 +1225,18 @@ static int s_nType[MAX_CTRLS] ;
#ifndef IDC_STATIC_PREVIEW
#define IDC_STATIC_PREVIEW 41000
#endif
static COLORREF s_CustomColors[16] = {0} ; // 16 colori BLACK
static bool s_bCustomColorsInit = false ; // flag di inizializzazione colori
static const string s_CustomColorIniSection = "Scene" ; // [Scene]
static const string s_CustomColorIniKey = "CustomColors" ; // [Scene]->CustomCulors=...
//-------------------------------------------------------------------------------
BOOL
CALLBACK DialogBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
// variabili static locali per mantenere lo stato tra chiamate static per selezione colori
COLORREF g_customColors[16] = {0} ;
static HBRUSH g_hColorBrush[MAX_CTRLS] = {0} ;
static COLORREF g_selectedColor[MAX_CTRLS] = {0} ;
static HBRUSH g_hColorBrush[MAX_CTRLS] = {0} ; // BLACK
static COLORREF g_selectedColor[MAX_CTRLS] = {0} ; // BLACK
switch ( message) {
case WM_INITDIALOG :
@@ -1332,30 +1336,43 @@ CALLBACK DialogBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam
}
else if ( s_sEdit[i].find( "CP:") == 0) {
string sVal = s_sEdit[i].substr( 3) ;
// recupero eventuale colore di default
if ( ! sVal.empty()) {
// rimuovo eventuale carattere di "#"
if ( sVal[0] == '#')
sVal.erase( 0, 1) ;
// il colore di base deve essere composto da esattamente 6 caratteri
if ( sVal.size() == 6) {
bool bOk = true ;
for ( char c : sVal) {
if ( ! isxdigit( static_cast<unsigned char>(c))) {
bOk = false;
break ;
}
}
if ( bOk) {
// aggiungo Alpha, in questo caso sempre 100
sVal += ",100" ;
Color CColor ;
if ( ! FromString( sVal, CColor))
CColor = INVISIBLE ;
try {
double dRed = double( CColor.GetRed()) ;
double dGreen = double( CColor.GetGreen()) ;
double dBlue = double( CColor.GetBlue()) ;
BYTE byteRed = static_cast<BYTE>( Clamp( dRed * 255. + .5, 0., 255.)) ;
BYTE byteGreen = static_cast<BYTE>( Clamp( dGreen * 255. + .5, 0., 255.)) ;
BYTE byteBlue = static_cast<BYTE>( Clamp( dBlue * 255. + .5, 0., 255.)) ;
g_selectedColor[i] = RGB( byteRed, byteGreen, byteBlue) ;
} catch (...) {}
// recupero i valori dei colori personalizzati dal file .ini
if ( ! s_bCustomColorsInit) {
// recupero il file Ini
string sIniFile = ExeGetIniFile() ;
if ( ! sIniFile.empty()) {
string sCustomVals = GetPrivateProfileStringUtf8(
string{s_CustomColorIniSection}.c_str(),
string{s_CustomColorIniKey}.c_str(),
string{""}.c_str(), sIniFile.c_str()) ;
STRVECTOR vsWinColors ; Tokenize( sCustomVals, ",", vsWinColors) ;
for ( int i = 0 ; i < min( 16, int( vsWinColors.size())) ; ++ i) {
try {
unsigned long hex = stoul( sVal, nullptr, 16) ;
BYTE r = ( hex >> 16) & 0xFF ;
BYTE g = ( hex >> 8) & 0xFF ;
BYTE b = hex & 0xFF ;
g_selectedColor[i] = RGB( r, g, b) ;
} catch (...) {}
uint32_t uWinCol = static_cast<uint32_t>( stoul( vsWinColors[i])) ;
unsigned int unR = uWinCol & 0xFF ;
unsigned int unG = ( uWinCol >> 8) & 0xFF ;
unsigned int unB = ( uWinCol >> 16) & 0xFF ;
s_CustomColors[i] = RGB( unR, unG, unB) ;
}
catch (...) {}
}
}
s_bCustomColorsInit = true ;
}
// nascondo qualsiasi tipo di componente ( per sicurezza)
@@ -1475,11 +1492,26 @@ CALLBACK DialogBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam
CHOOSECOLOR cc = {} ;
cc.lStructSize = sizeof( cc) ;
cc.hwndOwner = hwndDlg ;
cc.lpCustColors = g_customColors ;
cc.lpCustColors = s_CustomColors ;
cc.rgbResult = g_selectedColor[idx] ;
cc.Flags = CC_FULLOPEN | CC_RGBINIT ;
if ( ChooseColor( &cc)) {
g_selectedColor[idx] = cc.rgbResult ;
// salvo nel file Ini i nuovi colori personalizzati
string sIniFile = ExeGetIniFile() ;
if ( ! sIniFile.empty()) {
ostringstream ss ;
for ( int i = 0 ; i < 16 ; ++ i) {
if ( i > 0)
ss << "," ;
ss << static_cast<unsigned long>( s_CustomColors[i]) ;
}
string sVal = ss.str() ;
WritePrivateProfileStringUtf8(
s_CustomColorIniSection.c_str(),
s_CustomColorIniKey.c_str(),
sVal.c_str(), sIniFile.c_str()) ;
}
if ( g_hColorBrush[idx]) {
DeleteObject( g_hColorBrush[idx]) ;
g_hColorBrush[idx] = NULL ;
@@ -1513,7 +1545,7 @@ CALLBACK DialogBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam
COLORREF col = g_selectedColor[i] ;
BYTE r = GetRValue( col), g = GetGValue( col), b = GetBValue( col) ;
char buf[16] ;
sprintf_s( buf, sizeof( buf), "#%02X%02X%02X", r, g, b) ;
sprintf_s( buf, sizeof( buf), "%u,%u,%u", r, g, b) ;
s_sEdit[i] = buf ;
break ;
}