mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
get custom color selector working
This commit is contained in:
parent
a09fb17708
commit
e089a1e359
1 changed files with 79 additions and 42 deletions
|
@ -63,10 +63,10 @@ initEditAndSlider( HWND hDlg, XP_U16 sliderID, XP_U8 val )
|
||||||
static void
|
static void
|
||||||
initChooseColor( ClrEditDlgState* eState, HWND hDlg )
|
initChooseColor( ClrEditDlgState* eState, HWND hDlg )
|
||||||
{
|
{
|
||||||
eState->clrRect.left = 10;
|
eState->clrRect.left = 165;
|
||||||
eState->clrRect.top = 10;
|
eState->clrRect.top = 5;
|
||||||
eState->clrRect.right = 40;
|
eState->clrRect.right = 195;
|
||||||
eState->clrRect.bottom = 40;
|
eState->clrRect.bottom = 90;
|
||||||
|
|
||||||
InvalidateRect( hDlg, &eState->clrRect, FALSE );
|
InvalidateRect( hDlg, &eState->clrRect, FALSE );
|
||||||
|
|
||||||
|
@ -75,24 +75,69 @@ initChooseColor( ClrEditDlgState* eState, HWND hDlg )
|
||||||
initEditAndSlider( hDlg, CLREDT_SLIDER3, eState->b );
|
initEditAndSlider( hDlg, CLREDT_SLIDER3, eState->b );
|
||||||
} /* initChooseColor */
|
} /* initChooseColor */
|
||||||
|
|
||||||
static void
|
static XP_U8*
|
||||||
dragEnded( HWND hDlg, ClrEditDlgState* eState, XP_UCHAR sliderId, XP_U8* val )
|
colorForSlider( ClrEditDlgState* eState, XP_U16 sliderID )
|
||||||
{
|
{
|
||||||
XP_U16 newVal = SendDlgItemMessage( hDlg, sliderId, TBM_GETPOS, 0, 0L );
|
switch( sliderID ) {
|
||||||
XP_LOGF( "newVal=%d", newVal );
|
case CLREDT_SLIDER1:
|
||||||
XP_ASSERT( newVal >= 0 && newVal <= 255 );
|
return &eState->r;
|
||||||
*val = newVal;
|
case CLREDT_SLIDER2:
|
||||||
|
return &eState->g;
|
||||||
|
case CLREDT_SLIDER3:
|
||||||
|
return &eState->b;
|
||||||
|
default:
|
||||||
|
XP_LOGF( "huh???" );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
} /* colorForSlider */
|
||||||
|
|
||||||
ceSetDlgItemNum( hDlg, sliderId+1, newVal );
|
static void
|
||||||
|
updateForSlider( HWND hDlg, ClrEditDlgState* eState, XP_U16 sliderID )
|
||||||
|
{
|
||||||
|
XP_U8 newColor = SendDlgItemMessage( hDlg, sliderID, TBM_GETPOS, 0, 0L );
|
||||||
|
XP_U8* colorPtr = colorForSlider( eState, sliderID );
|
||||||
|
if ( newColor != *colorPtr ) {
|
||||||
|
*colorPtr = newColor;
|
||||||
|
|
||||||
InvalidateRect( hDlg, &eState->clrRect, FALSE );
|
ceSetDlgItemNum( hDlg, sliderID+1, (XP_S32)newColor );
|
||||||
} /* dragEnded */
|
|
||||||
|
InvalidateRect( hDlg, &eState->clrRect, FALSE );
|
||||||
|
}
|
||||||
|
} /* updateForSlider */
|
||||||
|
|
||||||
|
static void
|
||||||
|
updateForField( HWND hDlg, ClrEditDlgState* eState, XP_U16 fieldID )
|
||||||
|
{
|
||||||
|
XP_S32 newColor = ceGetDlgItemNum( hDlg, fieldID );
|
||||||
|
XP_U8* colorPtr = colorForSlider( eState, fieldID - 1 );
|
||||||
|
XP_Bool modified = XP_FALSE;;
|
||||||
|
|
||||||
|
if ( newColor > 255 ) {
|
||||||
|
newColor = 255;
|
||||||
|
modified = XP_TRUE;
|
||||||
|
} else if ( newColor < 0 ) {
|
||||||
|
newColor = 0;
|
||||||
|
modified = XP_TRUE;
|
||||||
|
}
|
||||||
|
if ( modified ) {
|
||||||
|
ceSetDlgItemNum( hDlg, fieldID, newColor );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( newColor != *colorPtr ) {
|
||||||
|
*colorPtr = newColor;
|
||||||
|
|
||||||
|
SendDlgItemMessage( hDlg, fieldID-1, TBM_SETPOS, TRUE,
|
||||||
|
(long)newColor );
|
||||||
|
InvalidateRect( hDlg, &eState->clrRect, FALSE );
|
||||||
|
}
|
||||||
|
} /* updateForField */
|
||||||
|
|
||||||
static LRESULT CALLBACK
|
static LRESULT CALLBACK
|
||||||
EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
|
EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
|
||||||
{
|
{
|
||||||
ClrEditDlgState* eState;
|
ClrEditDlgState* eState;
|
||||||
XP_U16 wid;
|
XP_U16 wid;
|
||||||
|
XP_U16 notifyCode;
|
||||||
NMTOOLBAR* nmToolP;
|
NMTOOLBAR* nmToolP;
|
||||||
XP_U16 idCtrl;
|
XP_U16 idCtrl;
|
||||||
|
|
||||||
|
@ -125,43 +170,35 @@ EditColorsDlg( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WM_NOTIFY:
|
case WM_NOTIFY:
|
||||||
XP_LOGF( "WM_NOTIFY" );
|
nmToolP = (NMTOOLBAR*)lParam;
|
||||||
nmToolP = (NMTOOLBAR*)lParam;
|
wid = nmToolP->hdr.idFrom;
|
||||||
if ( nmToolP->hdr.code == TBN_ENDDRAG ) {
|
switch ( wid ) {
|
||||||
XP_LOGF( "TBN_ENDDRAG" );
|
case CLREDT_SLIDER1:
|
||||||
switch( nmToolP->hdr.idFrom ) {
|
case CLREDT_SLIDER2:
|
||||||
case CLREDT_SLIDER1:
|
case CLREDT_SLIDER3:
|
||||||
dragEnded( hDlg, eState, CLREDT_SLIDER1, &eState->r );
|
updateForSlider( hDlg, eState, wid );
|
||||||
break;
|
break;
|
||||||
case CLREDT_SLIDER2:
|
}
|
||||||
dragEnded( hDlg, eState, CLREDT_SLIDER2, &eState->g );
|
break;
|
||||||
break;
|
|
||||||
case CLREDT_SLIDER3:
|
|
||||||
dragEnded( hDlg, eState, CLREDT_SLIDER3, &eState->b );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
XP_LOGF( "some other value: %d", nmToolP->hdr.idFrom );
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
} else if ( nmToolP->hdr.code == TBN_BEGINDRAG ) {
|
|
||||||
XP_LOGF( "TBN_BEGINDRAG" );
|
|
||||||
} else if ( nmToolP->hdr.code == TBN_DROPDOWN ) {
|
|
||||||
XP_LOGF( "TBN_DROPDOWN" );
|
|
||||||
} else {
|
|
||||||
XP_LOGF( "something else: 0x%x", nmToolP->hdr.code );
|
|
||||||
XP_LOGF( "ctl id is %d", nmToolP->hdr.idFrom );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
wid = LOWORD(wParam);
|
wid = LOWORD(wParam);
|
||||||
switch( wid ) {
|
switch( wid ) {
|
||||||
|
case RED_EDIT:
|
||||||
|
case GREEN_EDIT:
|
||||||
|
case BLUE_EDIT:
|
||||||
|
notifyCode = HIWORD(wParam);
|
||||||
|
if ( notifyCode == EN_CHANGE ) {
|
||||||
|
updateForField( hDlg, eState, wid );
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case IDOK:
|
case IDOK:
|
||||||
eState->cancelled = XP_FALSE;
|
eState->cancelled = XP_FALSE;
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
|
|
||||||
case IDCANCEL:
|
case IDCANCEL:
|
||||||
EndDialog(hDlg, wid);
|
EndDialog(hDlg, wid);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
Loading…
Reference in a new issue