EgtExecutor :
- piccole modifiche a scelta colore per dialogo lua.
This commit is contained in:
+56
-118
@@ -1220,23 +1220,18 @@ static string s_sCaption ;
|
||||
static string s_sText[MAX_CTRLS] ;
|
||||
static string s_sEdit[MAX_CTRLS] ;
|
||||
static int s_nType[MAX_CTRLS] ;
|
||||
|
||||
// preview statica per la selezione del colore
|
||||
#ifndef IDC_STATIC_PREVIEW
|
||||
#define IDC_STATIC_PREVIEW 41000
|
||||
#endif
|
||||
static COLORREF s_CustomColors[16] = {0} ; // 16 colori BLACK
|
||||
static COLORREF s_CustomColors[16] = {12632256} ; // 16 colori GRAY
|
||||
static bool s_bCustomColorsInit = false ; // flag di inizializzazione colori
|
||||
static const string s_CustomColorIniSection = "Scene" ; // [Scene]
|
||||
static const string s_CustomColorIniKey = "CustomColors" ; // [Scene]->CustomCulors=...
|
||||
const char* SEC_SCENE = "Scene" ;
|
||||
const char* KEY_CUSTOMCOLORS = "CustomColors" ;
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
BOOL
|
||||
CALLBACK DialogBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
// variabili static locali per mantenere lo stato tra chiamate static per selezione colori
|
||||
static HBRUSH g_hColorBrush[MAX_CTRLS] = {0} ; // BLACK
|
||||
static COLORREF g_selectedColor[MAX_CTRLS] = {0} ; // BLACK
|
||||
// variabili static locali per mantenere lo stato tra chiamate per selezione colori
|
||||
static COLORREF selectedColor[MAX_CTRLS] = {0} ; // BLACK
|
||||
static HBRUSH hColorBrush[MAX_CTRLS] = {NULL} ; // non definito
|
||||
|
||||
switch ( message) {
|
||||
case WM_INITDIALOG :
|
||||
@@ -1245,12 +1240,10 @@ CALLBACK DialogBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam
|
||||
COLORREF defaultColor = RGB( 255, 0, 0) ;
|
||||
// inizializzazione colori e brush
|
||||
for ( int i = 0 ; i < MAX_CTRLS ; ++ i) {
|
||||
if ( g_hColorBrush[i]) {
|
||||
DeleteObject( g_hColorBrush[i]) ;
|
||||
g_hColorBrush[i] = NULL ;
|
||||
}
|
||||
g_selectedColor[i] = defaultColor ;
|
||||
g_hColorBrush[i] = CreateSolidBrush( g_selectedColor[i]) ;
|
||||
selectedColor[i] = defaultColor ;
|
||||
if ( hColorBrush[i] != NULL)
|
||||
DeleteObject( hColorBrush[i]) ;
|
||||
hColorBrush[i] = CreateSolidBrush( selectedColor[i]) ;
|
||||
}
|
||||
// dati del dialogo
|
||||
HWND hwndOwner = GetParent( hwndDlg) ;
|
||||
@@ -1336,55 +1329,36 @@ 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) ;
|
||||
// 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 (...) {}
|
||||
|
||||
selectedColor[i] = RGB( CColor.GetIntRed(), CColor.GetIntGreen(), CColor.GetIntBlue()) ;
|
||||
if ( hColorBrush[i] != NULL)
|
||||
DeleteObject( hColorBrush[i]) ;
|
||||
hColorBrush[i] = CreateSolidBrush( selectedColor[i]) ;
|
||||
// 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()) ;
|
||||
string sCustomVals = GetPrivateProfileStringUtf8( SEC_SCENE, KEY_CUSTOMCOLORS, "", sIniFile.c_str()) ;
|
||||
STRVECTOR vsWinColors ; Tokenize( sCustomVals, ",", vsWinColors) ;
|
||||
for ( int i = 0 ; i < min( 16, int( vsWinColors.size())) ; ++ i) {
|
||||
try {
|
||||
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) ;
|
||||
for ( int j = 0 ; j < ssize( vsWinColors) && j < 16 ; ++ j) {
|
||||
unsigned int unVal ;
|
||||
if ( FromString( vsWinColors[j], unVal)) {
|
||||
unsigned int unR = unVal & 0xFF ;
|
||||
unsigned int unG = ( unVal >> 8) & 0xFF ;
|
||||
unsigned int unB = ( unVal >> 16) & 0xFF ;
|
||||
s_CustomColors[j] = RGB( unR, unG, unB) ;
|
||||
}
|
||||
catch (...) {}
|
||||
}
|
||||
}
|
||||
s_bCustomColorsInit = true ;
|
||||
}
|
||||
|
||||
// nascondo qualsiasi tipo di componente ( per sicurezza)
|
||||
HWND hwndEdit = GetDlgItem( hwndDlg, IDC_EDIT1 + i) ;
|
||||
if ( hwndEdit)
|
||||
ShowWindow( hwndEdit, SW_HIDE) ;
|
||||
HWND hwndCombo = GetDlgItem( hwndDlg, IDC_COMBO1 + i) ;
|
||||
if ( hwndCombo)
|
||||
ShowWindow( hwndCombo, SW_HIDE) ;
|
||||
HWND hwndChk = GetDlgItem( hwndDlg, IDC_CHECK1 + i) ;
|
||||
if ( hwndChk)
|
||||
ShowWindow( hwndChk, SW_HIDE) ;
|
||||
ShowWindow( GetDlgItem( hwndDlg, IDC_EDIT1 + i), SW_HIDE) ;
|
||||
ShowWindow( GetDlgItem( hwndDlg, IDC_COMBO1 + i), SW_HIDE) ;
|
||||
ShowWindow( GetDlgItem( hwndDlg, IDC_CHECK1 + i), SW_HIDE) ;
|
||||
|
||||
// margini per dimensione del rettangolo preview pickColor
|
||||
const int MARGIN_RIGHT = 8 ; // spazio tra preview e bordo destro dialog
|
||||
@@ -1392,7 +1366,7 @@ CALLBACK DialogBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam
|
||||
const int PREVIEW_MIN_WIDTH = 40 ; // larghezza minima
|
||||
|
||||
// ottieni o crea la static preview (allargata fino al bordo destro del dialog)
|
||||
HWND hwndPreview = GetDlgItem( hwndDlg, IDC_STATIC_PREVIEW + i) ;
|
||||
HWND hwndPreview = NULL ;
|
||||
RECT rcLabel ;
|
||||
HWND hwndLabel = GetDlgItem( hwndDlg, IDC_TEXT1 + i) ;
|
||||
RECT rcClient ; GetClientRect( hwndDlg, &rcClient) ; // coordinate client del dialog
|
||||
@@ -1405,43 +1379,15 @@ CALLBACK DialogBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam
|
||||
int width = rcClient.right - x - MARGIN_RIGHT ;
|
||||
if ( width < PREVIEW_MIN_WIDTH)
|
||||
width = PREVIEW_MIN_WIDTH ;
|
||||
if ( ! hwndPreview) {
|
||||
hwndPreview = CreateWindowEx(
|
||||
0, L"STATIC", NULL,
|
||||
WS_CHILD | WS_VISIBLE | SS_NOTIFY | SS_CENTERIMAGE | WS_BORDER,
|
||||
x, y, width, PREVIEW_HEIGHT,
|
||||
hwndDlg, ( HMENU)( IDC_STATIC_PREVIEW + i),
|
||||
GetModuleHandle( NULL), NULL) ;
|
||||
}
|
||||
else {
|
||||
// aggiornamento posizione e dimensione se già esiste
|
||||
LONG_PTR style = GetWindowLongPtr( hwndPreview, GWL_STYLE) ;
|
||||
style |= SS_NOTIFY | SS_CENTERIMAGE | WS_BORDER ;
|
||||
style &= ~SS_OWNERDRAW ;
|
||||
SetWindowLongPtr( hwndPreview, GWL_STYLE, style) ;
|
||||
SetWindowPos( hwndPreview, HWND_TOP, x, y, width, PREVIEW_HEIGHT, SWP_SHOWWINDOW | SWP_FRAMECHANGED) ;
|
||||
}
|
||||
// pulizia e aggiornamento brush colori
|
||||
SetWindowText( hwndPreview, L"") ;
|
||||
if ( g_hColorBrush[i]) {
|
||||
DeleteObject( g_hColorBrush[i]) ;
|
||||
g_hColorBrush[i] = NULL ;
|
||||
}
|
||||
g_hColorBrush[i] = CreateSolidBrush( g_selectedColor[i]) ;
|
||||
// ridisegno
|
||||
InvalidateRect( hwndPreview, NULL, TRUE) ;
|
||||
UpdateWindow( hwndPreview) ;
|
||||
hwndPreview = CreateWindowEx( 0, L"STATIC", NULL,
|
||||
WS_CHILD | WS_VISIBLE | SS_NOTIFY | SS_CENTERIMAGE | WS_BORDER,
|
||||
x, y, width, PREVIEW_HEIGHT,
|
||||
hwndDlg, ( HMENU)( IDC_COLOR1 + i),
|
||||
GetModuleHandle( NULL), NULL) ;
|
||||
}
|
||||
// pulizia elementi testuali
|
||||
if ( hwndPreview)
|
||||
SetWindowText( hwndPreview, L"") ;
|
||||
if ( g_hColorBrush[i]) {
|
||||
DeleteObject( g_hColorBrush[i]) ;
|
||||
g_hColorBrush[i] = NULL ;
|
||||
}
|
||||
// creazione brush di colori
|
||||
g_hColorBrush[i] = CreateSolidBrush( g_selectedColor[i]) ;
|
||||
if ( hwndPreview) {
|
||||
SetWindowText( hwndPreview, L"") ;
|
||||
SetWindowPos( hwndPreview, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE) ;
|
||||
InvalidateRect( hwndPreview, NULL, TRUE) ;
|
||||
UpdateWindow( hwndPreview) ;
|
||||
@@ -1460,7 +1406,6 @@ CALLBACK DialogBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam
|
||||
ShowWindow( GetDlgItem( hwndDlg, IDC_EDIT1 + i), SW_HIDE) ;
|
||||
ShowWindow( GetDlgItem( hwndDlg, IDC_COMBO1 + i), SW_HIDE) ;
|
||||
ShowWindow( GetDlgItem( hwndDlg, IDC_CHECK1 + i), SW_HIDE) ;
|
||||
ShowWindow( GetDlgItem( hwndDlg, IDC_STATIC_PREVIEW + i), SW_HIDE) ;
|
||||
s_nType[i] = CTRL_NONE ;
|
||||
}
|
||||
}
|
||||
@@ -1470,22 +1415,23 @@ CALLBACK DialogBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam
|
||||
HDC hdcStatic = ( HDC)wParam ;
|
||||
HWND hwndCtrl = ( HWND)lParam ;
|
||||
int ctrlId = GetDlgCtrlID( hwndCtrl) ;
|
||||
if ( ctrlId >= IDC_STATIC_PREVIEW && ctrlId < IDC_STATIC_PREVIEW + MAX_CTRLS) {
|
||||
int idx = ctrlId - IDC_STATIC_PREVIEW ;
|
||||
if ( g_hColorBrush[idx] == NULL)
|
||||
g_hColorBrush[idx] = CreateSolidBrush( g_selectedColor[idx]) ;
|
||||
if ( ctrlId >= IDC_COLOR1 && ctrlId <= IDC_COLOR8) {
|
||||
int idx = ctrlId - IDC_COLOR1 ;
|
||||
if ( hColorBrush[idx] == NULL)
|
||||
hColorBrush[idx] = CreateSolidBrush( selectedColor[idx]) ;
|
||||
SetBkMode( hdcStatic, OPAQUE) ;
|
||||
SetBkColor( hdcStatic, g_selectedColor[idx]) ;
|
||||
return ( INT_PTR)g_hColorBrush[idx] ;
|
||||
SetBkColor( hdcStatic, selectedColor[idx]) ;
|
||||
return ( INT_PTR)hColorBrush[idx] ;
|
||||
}
|
||||
}
|
||||
break ;
|
||||
case WM_COMMAND : {
|
||||
int id = LOWORD( wParam) ;
|
||||
int code = HIWORD( wParam) ;
|
||||
// comando di Preview per brush di colori mediante click del mouse
|
||||
if ( code == STN_CLICKED && id >= IDC_STATIC_PREVIEW && id < IDC_STATIC_PREVIEW + MAX_CTRLS) {
|
||||
int idx = id - IDC_STATIC_PREVIEW ;
|
||||
HWND hwndPreview = GetDlgItem( hwndDlg, IDC_STATIC_PREVIEW + idx) ;
|
||||
if ( code == STN_CLICKED && id >= IDC_COLOR1 && id <= IDC_COLOR8) {
|
||||
int idx = id - IDC_COLOR1 ;
|
||||
HWND hwndPreview = GetDlgItem( hwndDlg, IDC_COLOR1 + idx) ;
|
||||
if ( ! hwndPreview)
|
||||
return TRUE ;
|
||||
// apertura ChooseColor (usa hwndDlg come owner)
|
||||
@@ -1493,30 +1439,22 @@ CALLBACK DialogBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam
|
||||
cc.lStructSize = sizeof( cc) ;
|
||||
cc.hwndOwner = hwndDlg ;
|
||||
cc.lpCustColors = s_CustomColors ;
|
||||
cc.rgbResult = g_selectedColor[idx] ;
|
||||
cc.rgbResult = selectedColor[idx] ;
|
||||
cc.Flags = CC_FULLOPEN | CC_RGBINIT ;
|
||||
if ( ChooseColor( &cc)) {
|
||||
g_selectedColor[idx] = cc.rgbResult ;
|
||||
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()) ;
|
||||
string sOut = "" ;
|
||||
for ( int j = 0 ; j < ssize( s_CustomColors) && j < 16 ; ++ j)
|
||||
sOut += ToString( ( unsigned int)s_CustomColors[j]) + "," ;
|
||||
sOut.pop_back() ;
|
||||
WritePrivateProfileStringUtf8( SEC_SCENE, KEY_CUSTOMCOLORS, sOut.c_str(), sIniFile.c_str()) ;
|
||||
}
|
||||
if ( g_hColorBrush[idx]) {
|
||||
DeleteObject( g_hColorBrush[idx]) ;
|
||||
g_hColorBrush[idx] = NULL ;
|
||||
}
|
||||
g_hColorBrush[idx] = CreateSolidBrush( g_selectedColor[idx]) ;
|
||||
if ( hColorBrush[idx] != NULL)
|
||||
DeleteObject( hColorBrush[idx]) ;
|
||||
hColorBrush[idx] = CreateSolidBrush( selectedColor[idx]) ;
|
||||
InvalidateRect(hwndPreview, NULL, TRUE) ;
|
||||
UpdateWindow( hwndPreview) ;
|
||||
}
|
||||
@@ -1542,7 +1480,7 @@ CALLBACK DialogBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam
|
||||
break ;
|
||||
case CTRL_COLOR :
|
||||
{
|
||||
COLORREF col = g_selectedColor[i] ;
|
||||
COLORREF col = selectedColor[i] ;
|
||||
BYTE r = GetRValue( col), g = GetGValue( col), b = GetBValue( col) ;
|
||||
char buf[16] ;
|
||||
sprintf_s( buf, sizeof( buf), "%u,%u,%u", r, g, b) ;
|
||||
@@ -1555,9 +1493,9 @@ CALLBACK DialogBoxProc( HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam
|
||||
case IDCANCEL : {
|
||||
// pulizia brush colori
|
||||
for ( int i = 0 ; i < MAX_CTRLS ; ++ i) {
|
||||
if ( g_hColorBrush[i]) {
|
||||
DeleteObject( g_hColorBrush[i]) ;
|
||||
g_hColorBrush[i] = NULL ;
|
||||
if ( hColorBrush[i] != NULL) {
|
||||
DeleteObject( hColorBrush[i]) ;
|
||||
hColorBrush[i] = NULL ;
|
||||
}
|
||||
}
|
||||
EndDialog( hwndDlg, wParam) ;
|
||||
|
||||
+9
-1
@@ -37,7 +37,15 @@
|
||||
#define IDC_CHECK6 1036
|
||||
#define IDC_CHECK7 1037
|
||||
#define IDC_CHECK8 1038
|
||||
#define IDC_PICTURE1 1041
|
||||
#define IDC_COLOR1 1041
|
||||
#define IDC_COLOR2 1042
|
||||
#define IDC_COLOR3 1043
|
||||
#define IDC_COLOR4 1044
|
||||
#define IDC_COLOR5 1045
|
||||
#define IDC_COLOR6 1046
|
||||
#define IDC_COLOR7 1047
|
||||
#define IDC_COLOR8 1048
|
||||
#define IDC_PICTURE1 1101
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user