comparison win/dw.c @ 1725:2e0f87ec24fe

Create a separate disabled image list with washed out and grayscale bitmaps on Windows. This allows bitmap buttons to change looks when visibly disabled... this also helps on XP because the default way icons are made to look disabled is terrible.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 14 May 2012 22:26:26 +0000
parents 48983a2f839f
children a02ce34692f0
comparison
equal deleted inserted replaced
1724:48983a2f839f 1725:2e0f87ec24fe
755 #ifdef TOOLBAR 755 #ifdef TOOLBAR
756 /* Bitmap Buttons */ 756 /* Bitmap Buttons */
757 else if(_tcsnicmp(tmpbuf, TOOLBARCLASSNAME, _tcslen(TOOLBARCLASSNAME)+1) == 0) 757 else if(_tcsnicmp(tmpbuf, TOOLBARCLASSNAME, _tcslen(TOOLBARCLASSNAME)+1) == 0)
758 { 758 {
759 HIMAGELIST imlist = (HIMAGELIST)SendMessage(handle, TB_GETIMAGELIST, 0, 0); 759 HIMAGELIST imlist = (HIMAGELIST)SendMessage(handle, TB_GETIMAGELIST, 0, 0);
760 HIMAGELIST dimlist = (HIMAGELIST)SendMessage(handle, TB_GETDISABLEDIMAGELIST, 0, 0);
760 761
761 SendMessage(handle, TB_SETIMAGELIST, 0, 0); 762 SendMessage(handle, TB_SETIMAGELIST, 0, 0);
763 SendMessage(handle, TB_SETDISABLEDIMAGELIST, 0, 0);
762 764
763 if(imlist) 765 if(imlist)
764 ImageList_Destroy(imlist); 766 ImageList_Destroy(imlist);
767 if(dimlist)
768 ImageList_Destroy(dimlist);
765 } 769 }
766 #endif 770 #endif
767 else if(_tcsnicmp(tmpbuf, FRAMECLASSNAME, _tcslen(FRAMECLASSNAME)+1)==0) 771 else if(_tcsnicmp(tmpbuf, FRAMECLASSNAME, _tcslen(FRAMECLASSNAME)+1)==0)
768 { 772 {
769 Box *box = (Box *)thiscinfo; 773 Box *box = (Box *)thiscinfo;
6164 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); 6168 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
6165 dw_window_set_font(tmp, DefaultFont); 6169 dw_window_set_font(tmp, DefaultFont);
6166 return tmp; 6170 return tmp;
6167 } 6171 }
6168 6172
6173 /* Internal function to create a grayscale bitmap from a color one */
6174 void _to_grayscale(HBITMAP hbm, int width, int height)
6175 {
6176 HDC hdc = CreateCompatibleDC(NULL);
6177 if (hdc)
6178 {
6179 HBITMAP hbmPrev = SelectBitmap(hdc, hbm);
6180 int x, y;
6181
6182 for(y=0;y<height;y++)
6183 {
6184 for(x=0;x<width;x++)
6185 {
6186 COLORREF c = GetPixel(hdc, x, y);
6187 /* Use half-values then add 127 to make it look washed out */
6188 int luma = (int)(GetRValue(c)*0.15 + GetGValue(c)*0.3+ GetBValue(c)*0.06) + 127;
6189
6190 SetPixel(hdc, x, y, RGB(luma,luma,luma));
6191 }
6192 }
6193 SelectBitmap(hdc, hbmPrev);
6194 DeleteDC(hdc);
6195 }
6196 }
6197
6169 /* Internal function to create a toolbar based button */ 6198 /* Internal function to create a toolbar based button */
6170 HWND _create_toolbar(char *text, ULONG id, HICON icon, HBITMAP hbitmap) 6199 HWND _create_toolbar(char *text, ULONG id, HICON icon, HBITMAP hbitmap)
6171 { 6200 {
6172 HWND tmp; 6201 HWND tmp;
6173 HIMAGELIST imlist; 6202 HIMAGELIST imlist, dimlist;
6174 BITMAP bmi = { 0 }; 6203 BITMAP bmi = { 0 };
6175 TBBUTTON tbButtons[] = { 6204 TBBUTTON tbButtons[] = {
6176 { MAKELONG(0, 0), id, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0} 6205 { MAKELONG(0, 0), id, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0}
6177 }; 6206 };
6178 6207
6180 if(hbitmap) 6209 if(hbitmap)
6181 { 6210 {
6182 GetObject(hbitmap, sizeof(BITMAP), &bmi); 6211 GetObject(hbitmap, sizeof(BITMAP), &bmi);
6183 imlist = ImageList_Create(bmi.bmWidth, bmi.bmHeight, ILC_COLOR32, 1, 0); 6212 imlist = ImageList_Create(bmi.bmWidth, bmi.bmHeight, ILC_COLOR32, 1, 0);
6184 ImageList_Add(imlist, hbitmap, NULL); 6213 ImageList_Add(imlist, hbitmap, NULL);
6214 dimlist = ImageList_Create(bmi.bmWidth, bmi.bmHeight, ILC_COLOR32, 1, 0);
6215 _to_grayscale(hbitmap, bmi.bmWidth, bmi.bmHeight);
6216 ImageList_Add(dimlist, hbitmap, NULL);
6185 } 6217 }
6186 else if(icon) 6218 else if(icon)
6187 { 6219 {
6188 ICONINFO iconinfo; 6220 ICONINFO iconinfo;
6189 6221
6190 GetIconInfo(icon, &iconinfo); 6222 GetIconInfo(icon, &iconinfo);
6191 GetObject(iconinfo.hbmColor, sizeof(BITMAP), &bmi); 6223 GetObject(iconinfo.hbmColor, sizeof(BITMAP), &bmi);
6192 imlist = ImageList_Create(bmi.bmWidth, bmi.bmHeight, ILC_COLOR32 | ILC_MASK, 1, 0); 6224 imlist = ImageList_Create(bmi.bmWidth, bmi.bmHeight, ILC_COLOR32 | ILC_MASK, 1, 0);
6193 ImageList_AddIcon(imlist, icon); 6225 ImageList_AddIcon(imlist, icon);
6226 dimlist = ImageList_Create(bmi.bmWidth, bmi.bmHeight, ILC_COLOR32 | ILC_MASK, 1, 0);
6227 _to_grayscale(iconinfo.hbmColor, bmi.bmWidth, bmi.bmHeight);
6228 ImageList_Add(dimlist, iconinfo.hbmColor, iconinfo.hbmMask);
6194 } 6229 }
6195 else 6230 else
6196 return 0; 6231 return 0;
6197 6232
6198 /* Create the toolbar */ 6233 /* Create the toolbar */
6202 /* Insert the single bitmap and button into the toolbar */ 6237 /* Insert the single bitmap and button into the toolbar */
6203 SendMessage(tmp, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); 6238 SendMessage(tmp, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
6204 SendMessage(tmp, TB_SETBUTTONSIZE, 0, MAKELPARAM(bmi.bmWidth, bmi.bmHeight)); 6239 SendMessage(tmp, TB_SETBUTTONSIZE, 0, MAKELPARAM(bmi.bmWidth, bmi.bmHeight));
6205 SendMessage(tmp, TB_SETPADDING, 0, 0); 6240 SendMessage(tmp, TB_SETPADDING, 0, 0);
6206 SendMessage(tmp, TB_SETIMAGELIST, 0, (LPARAM)imlist); 6241 SendMessage(tmp, TB_SETIMAGELIST, 0, (LPARAM)imlist);
6207 SendMessage(tmp, TB_SETDISABLEDIMAGELIST, 0, (LPARAM)imlist); 6242 SendMessage(tmp, TB_SETDISABLEDIMAGELIST, 0, (LPARAM)dimlist);
6208 SendMessage(tmp, TB_ADDBUTTONS, 1, (LONG) &tbButtons); 6243 SendMessage(tmp, TB_ADDBUTTONS, 1, (LONG) &tbButtons);
6209 6244
6210 _create_tooltip(tmp, text); 6245 _create_tooltip(tmp, text);
6211 return tmp; 6246 return tmp;
6212 } 6247 }