From cb75b729781709f40387ea0bd9ee7fe1ba20615f Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 19 Jul 2017 11:26:06 +0200 Subject: [PATCH] Refinements if new color 4D selector --- common/widgets/color4Dpickerdlg.cpp | 44 +++++++++--------------- common/widgets/color4Dpickerdlg.h | 9 +++++ common/widgets/color4Dpickerdlg_base.cpp | 31 ++++++++--------- common/widgets/color4Dpickerdlg_base.fbp | 12 +++---- 4 files changed, 46 insertions(+), 50 deletions(-) diff --git a/common/widgets/color4Dpickerdlg.cpp b/common/widgets/color4Dpickerdlg.cpp index a5aa1aa1e1..d3dd0d51ff 100644 --- a/common/widgets/color4Dpickerdlg.cpp +++ b/common/widgets/color4Dpickerdlg.cpp @@ -580,49 +580,37 @@ void COLOR4D_PICKER_DLG::onRGBMouseDrag( wxMouseEvent& event ) void COLOR4D_PICKER_DLG::onHSVMouseClick( wxMouseEvent& event ) { - wxPoint mousePos = event.GetPosition(); - - // The cursor position is relative to the m_bitmapHSV wxBitmap center - wxSize bmsize = m_bitmapHSV->GetSize(); - int half_size = std::min( bmsize.x, bmsize.y )/2; - mousePos.x -= half_size; - mousePos.y -= half_size; - mousePos.y = -mousePos.y; // Use the bottom to top vertical axis - - wxPoint dist = m_cursorBitmapHSV - mousePos; - - if( std::abs( dist.x ) <= m_cursorsSize/2 && std::abs( dist.y ) <= m_cursorsSize/2 ) - m_selectedCursor = &m_cursorBitmapHSV; - else - m_selectedCursor = nullptr; + if( setHSvaluesFromCursor( event.GetPosition() ) ) + drawAll(); } void COLOR4D_PICKER_DLG::onHSVMouseDrag( wxMouseEvent& event ) { if( !event.Dragging() ) - { - m_selectedCursor = nullptr; - return; - } - - if( m_selectedCursor != &m_cursorBitmapHSV ) return; - // Adjust the HSV cursor position to follow the mouse cursor - // The cursor position is relative to the m_bitmapHSV wxBitmap center - wxPoint mousePos = event.GetPosition(); + if( setHSvaluesFromCursor( event.GetPosition() ) ) + drawAll(); +} + + +bool COLOR4D_PICKER_DLG::setHSvaluesFromCursor( wxPoint aMouseCursor ) +{ + wxPoint mousePos = aMouseCursor; wxSize bmsize = m_bitmapHSV->GetSize(); int half_size = std::min( bmsize.x, bmsize.y )/2; + // Make the cursor position relative to the m_bitmapHSV wxBitmap center mousePos.x -= half_size; mousePos.y -= half_size; - mousePos.y = -mousePos.y; // Use the bottom to top vertical axis + mousePos.y = -mousePos.y; // Use the bottom to top vertical axis - // The HSV cursor position is restricted to a circle of radius half_size + // The HS cursor position is restricted to a circle of radius half_size double dist_from_centre = hypot( (double)mousePos.x, (double)mousePos.y ); if( dist_from_centre > half_size ) - return; + // Saturation cannot be calculated: + return false; m_cursorBitmapHSV = mousePos; @@ -641,7 +629,7 @@ void COLOR4D_PICKER_DLG::onHSVMouseDrag( wxMouseEvent& event ) m_newColor4D.FromHSV( m_hue, m_sat, m_val ); SetEditVals( ALL_CHANGED ); - drawAll(); + return true; } diff --git a/common/widgets/color4Dpickerdlg.h b/common/widgets/color4Dpickerdlg.h index f55cdfa64d..9ac68a2ec1 100644 --- a/common/widgets/color4Dpickerdlg.h +++ b/common/widgets/color4Dpickerdlg.h @@ -81,6 +81,15 @@ private: void onHSVMouseClick( wxMouseEvent& event ) override; void onHSVMouseDrag( wxMouseEvent& event ) override; + /** manage the Hue and Saturation settings when the mouse cursor + * is at aMouseCursor. + * @param aMouseCursor is the mouse cursor position on the HSV bitmap + * @return true if the Hue and Saturation can be set from aMouseCursor, + * if Saturation value computed from aMouseCursor is <= 1.0, + * and false if aMouseCursor is outside this area. + */ + bool setHSvaluesFromCursor( wxPoint aMouseCursor ); + ///> Event handler for defined color buttons void buttColorClick( wxCommandEvent& event ); diff --git a/common/widgets/color4Dpickerdlg_base.cpp b/common/widgets/color4Dpickerdlg_base.cpp index e1f30e958a..3768de62d9 100644 --- a/common/widgets/color4Dpickerdlg_base.cpp +++ b/common/widgets/color4Dpickerdlg_base.cpp @@ -45,7 +45,7 @@ COLOR4D_PICKER_DLG_BASE::COLOR4D_PICKER_DLG_BASE( wxWindow* parent, wxWindowID i bSizerPanels->Add( sbSizerViewRGB, 1, wxEXPAND|wxBOTTOM|wxRIGHT, 5 ); wxStaticBoxSizer* sbSizerViewHSV; - sbSizerViewHSV = new wxStaticBoxSizer( new wxStaticBox( m_panelFreeColors, wxID_ANY, wxT("HSV") ), wxVERTICAL ); + sbSizerViewHSV = new wxStaticBoxSizer( new wxStaticBox( m_panelFreeColors, wxID_ANY, wxT("Hue and Saturation") ), wxVERTICAL ); sbSizerViewHSV->Add( 0, 0, 1, wxEXPAND|wxALIGN_CENTER_HORIZONTAL, 5 ); @@ -125,36 +125,35 @@ COLOR4D_PICKER_DLG_BASE::COLOR4D_PICKER_DLG_BASE( wxWindow* parent, wxWindowID i bSizerLowerFreeColors->Add( sbSizerSetRGB, 1, wxEXPAND, 5 ); wxStaticBoxSizer* sbSizerSetHSV; - sbSizerSetHSV = new wxStaticBoxSizer( new wxStaticBox( m_panelFreeColors, wxID_ANY, wxT("RGB Values") ), wxHORIZONTAL ); + sbSizerSetHSV = new wxStaticBoxSizer( new wxStaticBox( m_panelFreeColors, wxID_ANY, wxT("HS Values") ), wxHORIZONTAL ); - wxFlexGridSizer* fgSizerHSB; - fgSizerHSB = new wxFlexGridSizer( 0, 2, 0, 0 ); - fgSizerHSB->AddGrowableCol( 0 ); - fgSizerHSB->AddGrowableCol( 1 ); - fgSizerHSB->AddGrowableCol( 2 ); - fgSizerHSB->SetFlexibleDirection( wxBOTH ); - fgSizerHSB->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); + wxFlexGridSizer* fgSizerHSV; + fgSizerHSV = new wxFlexGridSizer( 0, 2, 0, 0 ); + fgSizerHSV->AddGrowableCol( 0 ); + fgSizerHSV->AddGrowableCol( 1 ); + fgSizerHSV->SetFlexibleDirection( wxBOTH ); + fgSizerHSV->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); m_staticTextHue = new wxStaticText( sbSizerSetHSV->GetStaticBox(), wxID_ANY, wxT("Hue"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextHue->Wrap( -1 ); - fgSizerHSB->Add( m_staticTextHue, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + fgSizerHSV->Add( m_staticTextHue, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); m_staticTextSat = new wxStaticText( sbSizerSetHSV->GetStaticBox(), wxID_ANY, wxT("Saturation"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextSat->Wrap( -1 ); - fgSizerHSB->Add( m_staticTextSat, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); + fgSizerHSV->Add( m_staticTextSat, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); m_spinCtrlHue = new wxSpinCtrl( sbSizerSetHSV->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS|wxSP_WRAP, 0, 359, 0 ); m_spinCtrlHue->SetMinSize( wxSize( 80,-1 ) ); - fgSizerHSB->Add( m_spinCtrlHue, 0, wxALL|wxEXPAND, 5 ); + fgSizerHSV->Add( m_spinCtrlHue, 0, wxALL|wxEXPAND, 5 ); m_spinCtrlSaturation = new wxSpinCtrl( sbSizerSetHSV->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 255, 128 ); m_spinCtrlSaturation->SetMinSize( wxSize( 80,-1 ) ); - fgSizerHSB->Add( m_spinCtrlSaturation, 0, wxALL|wxEXPAND, 5 ); + fgSizerHSV->Add( m_spinCtrlSaturation, 0, wxALL|wxEXPAND, 5 ); - sbSizerSetHSV->Add( fgSizerHSB, 1, wxEXPAND, 5 ); + sbSizerSetHSV->Add( fgSizerHSV, 1, wxEXPAND, 5 ); bSizerLowerFreeColors->Add( sbSizerSetHSV, 1, wxEXPAND, 5 ); @@ -166,7 +165,7 @@ COLOR4D_PICKER_DLG_BASE::COLOR4D_PICKER_DLG_BASE( wxWindow* parent, wxWindowID i m_panelFreeColors->SetSizer( bSizerUpperFreeColors ); m_panelFreeColors->Layout(); bSizerUpperFreeColors->Fit( m_panelFreeColors ); - m_notebook->AddPage( m_panelFreeColors, wxT("Color Picker"), false ); + m_notebook->AddPage( m_panelFreeColors, wxT("Color Picker"), true ); m_panelDefinedColors = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); m_SizerDefinedColors = new wxBoxSizer( wxVERTICAL ); @@ -192,7 +191,7 @@ COLOR4D_PICKER_DLG_BASE::COLOR4D_PICKER_DLG_BASE( wxWindow* parent, wxWindowID i m_panelDefinedColors->SetSizer( m_SizerDefinedColors ); m_panelDefinedColors->Layout(); m_SizerDefinedColors->Fit( m_panelDefinedColors ); - m_notebook->AddPage( m_panelDefinedColors, wxT("Defined Colors"), true ); + m_notebook->AddPage( m_panelDefinedColors, wxT("Defined Colors"), false ); bSizerUpperMain->Add( m_notebook, 1, wxEXPAND | wxALL, 5 ); diff --git a/common/widgets/color4Dpickerdlg_base.fbp b/common/widgets/color4Dpickerdlg_base.fbp index e7fe5e2195..703a68fd70 100644 --- a/common/widgets/color4Dpickerdlg_base.fbp +++ b/common/widgets/color4Dpickerdlg_base.fbp @@ -187,7 +187,7 @@ Color Picker - 0 + 1 1 1 @@ -398,7 +398,7 @@ 1 wxID_ANY - HSV + Hue and Saturation sbSizerViewHSV wxVERTICAL @@ -1273,7 +1273,7 @@ 1 wxID_ANY - RGB Values + HS Values sbSizerSetHSV wxHORIZONTAL @@ -1287,11 +1287,11 @@ 2 wxBOTH - 0,1,2 + 0,1 0 - fgSizerHSB + fgSizerHSV wxFLEX_GROWMODE_SPECIFIED none 0 @@ -1650,7 +1650,7 @@ Defined Colors - 1 + 0 1 1