From 7082561a42c8d6d173d653ca76ef138939c59e2f Mon Sep 17 00:00:00 2001 From: David Maciejak Date: Sun, 7 Sep 2014 10:47:21 +0800 Subject: [PATCH] WPrefs: set default to 1st color in gradient texture This patch is updating the gradient texture user experience by auto selecting the first color in the list when possible and fixing the autoselection after a delete action. In fact what that is called gradient colors is just a list of colors with hue/saturation/brightness value. That patch is loading the first one from the list (color, hue, saturation, brightness) and setting the 3 sliders according to that value instead of using some default hardcoded values. The default color value on the top-right is never modified. Signed-off-by: Carlos R. Mafra --- WPrefs.app/TexturePanel.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/WPrefs.app/TexturePanel.c b/WPrefs.app/TexturePanel.c index 58e9eccc..f12f6e98 100644 --- a/WPrefs.app/TexturePanel.c +++ b/WPrefs.app/TexturePanel.c @@ -357,10 +357,9 @@ static void sliderChangeCallback(WMWidget * w, void *data) { TexturePanel *panel = (TexturePanel *) data; RHSVColor hsv; - int row, rows; + int i, row, rows; WMListItem *item; RColor **colors; - int i; RImage *image; WMScreen *scr = WMWidgetScreen(w); @@ -368,7 +367,20 @@ static void sliderChangeCallback(WMWidget * w, void *data) hsv.saturation = WMGetSliderValue(panel->gsatS); hsv.value = WMGetSliderValue(panel->gvalS); + rows = WMGetListNumberOfRows(panel->gcolL); row = WMGetListSelectedItemRow(panel->gcolL); + + if (row < 0 && rows > 0) { + row = 0; + WMSelectListItem(panel->gcolL, row); + item = WMGetListItem(panel->gcolL, row); + RRGBtoHSV((RColor *) item->clientData, &hsv); + + WMSetSliderValue(panel->ghueS, hsv.hue); + WMSetSliderValue(panel->gsatS, hsv.saturation); + WMSetSliderValue(panel->gvalS, hsv.value); + } + if (row >= 0) { RColor *rgb; @@ -382,6 +394,7 @@ static void sliderChangeCallback(WMWidget * w, void *data) } if (w == panel->ghueS) { + updateHueSlider(panel->ghueS, panel->listFont, &hsv); updateSVSlider(panel->gsatS, True, panel->listFont, &hsv); updateSVSlider(panel->gvalS, False, panel->listFont, &hsv); } else if (w == panel->gsatS) { @@ -392,7 +405,6 @@ static void sliderChangeCallback(WMWidget * w, void *data) updateSVSlider(panel->gsatS, True, panel->listFont, &hsv); } - rows = WMGetListNumberOfRows(panel->gcolL); if (rows == 0) return; @@ -503,7 +515,7 @@ static void gradDeleteCallback(WMWidget * w, void *data) { TexturePanel *panel = (TexturePanel *) data; WMListItem *item; - int row; + int row, rows; /* Parameter not used, but tell the compiler that it is ok */ (void) w; @@ -516,9 +528,14 @@ static void gradDeleteCallback(WMWidget * w, void *data) wfree(item->clientData); WMRemoveListItem(panel->gcolL, row); + if (row > 0) + WMSelectListItem(panel->gcolL, row - 1); + else { + rows = WMGetListNumberOfRows(panel->gcolL); + if (rows > 0) + WMSelectListItem(panel->gcolL, 0); - WMSelectListItem(panel->gcolL, row - 1); - + } updateGradButtons(panel); gradClickCallback(panel->gcolL, panel);