Changeset 1321

Show
Ignore:
Timestamp:
12/26/07 01:21:48 (10 months ago)
Author:
calvin
Message:

added a simple color picker property item

Location:
trunk/src/buzelib
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/buzelib/MachineView.cpp

    r1320 r1321  
    11851185***/ 
    11861186 
    1187  
    1188 #define RGB_GETRED(rgb)         (((rgb) >> 16) & 0xff) 
    1189 #define RGB_GETGREEN(rgb)       (((rgb) >> 8) & 0xff) 
    1190 #define RGB_GETBLUE(rgb)        ((rgb) & 0xff) 
    1191  
    1192  
    11931187void CMachineView::drawVolumeSlider(CDC& dc, RECT vsr, int value) { 
    11941188 
  • trunk/src/buzelib/PropertyList/PropertyItemImpl.h

    r1300 r1321  
    249249      if( di.state & ODS_DISABLED ) clrText = di.clrDisabled;  
    250250      dc.SetTextColor(clrText); 
     251 
    251252      // Draw icon if available 
    252253      if( m_hIcon ) { 
     
    579580 
    580581///////////////////////////////////////////////////////////////////////////// 
     582// Color property 
     583 
     584class CPropertyColorItem : public CPropertyReadOnlyItem 
     585{ 
     586   COLORREF m_color; 
     587public: 
     588   CPropertyColorItem(LPCTSTR pstrName, LPARAM lParam) : CPropertyReadOnlyItem(pstrName, lParam) 
     589   { 
     590   } 
     591 
     592   void DrawValue(PROPERTYDRAWINFO& di) 
     593   { 
     594      CPropertyReadOnlyItem::DrawValue(di); 
     595      if (di.state & ODS_SELECTED) { 
     596         CDCHandle dc(di.hDC); 
     597         RECT rc = di.rcItem; 
     598         rc.left = rc.right - 16; 
     599         // Paint as ellipsis button 
     600         dc.DrawFrameControl(&rc, DFC_BUTTON, DFCS_BUTTONPUSH); 
     601         //dc.DrawFrameControl(&rc, DFC_BUTTON, (di.state & ODS_SELECTED) ? DFCS_BUTTONPUSH | DFCS_PUSHED : DFCS_BUTTONPUSH); 
     602         dc.SetBkMode(TRANSPARENT); 
     603         LPCTSTR pstrEllipsis = _T("..."); 
     604         dc.DrawText(pstrEllipsis, ::lstrlen(pstrEllipsis), &rc, DT_CENTER | DT_EDITCONTROL | DT_SINGLELINE | DT_VCENTER); 
     605      } 
     606   } 
     607 
     608   BOOL SetValue(const VARIANT& value) 
     609   { 
     610      ATLASSERT(V_VT(&value)==VT_UI4); 
     611      m_val = value; 
     612      m_color = m_val.uintVal; 
     613 
     614          // create an icon with the new color 
     615      CDC dc; 
     616      dc.CreateCompatibleDC(0); 
     617      CBitmap iconBitmap; 
     618      SIZE sz = { ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON) }; 
     619 
     620      iconBitmap.CreateBitmap(sz.cx, sz.cy, 1, 32, 0); 
     621      RECT rcFull; 
     622      RECT rc; 
     623      SetRect(&rcFull, 0, 0, sz.cx, sz.cy ); 
     624      SetRect(&rc, 0, 0, sz.cx, sz.cy-5 ); 
     625      CBrush brush; 
     626      CBrush whiteBrush; 
     627      brush.CreateSolidBrush(m_color); 
     628      whiteBrush.CreateSolidBrush(RGB(0xFF, 0xFF, 0xFF)); 
     629      dc.SelectBitmap(iconBitmap); 
     630      dc.FillRect(&rcFull, whiteBrush); 
     631      dc.FillRect(&rc, brush); 
     632 
     633      CBitmap iconMaskBitmap; 
     634      iconMaskBitmap.CreateBitmap(sz.cx, sz.cy, 1, 32, 0); 
     635      brush.DeleteObject(); 
     636      brush.CreateSolidBrush(0); 
     637      dc.SelectBitmap(iconMaskBitmap); 
     638      dc.FillRect(&rcFull, whiteBrush); 
     639      dc.FillRect(&rc, brush); 
     640 
     641      ICONINFO ii; 
     642      ii.fIcon = TRUE; 
     643      ii.hbmColor = iconBitmap; 
     644      ii.hbmMask = iconMaskBitmap; 
     645      ii.xHotspot = 0; 
     646      ii.yHotspot = 0; 
     647      HICON hIcon = CreateIconIndirect(&ii); 
     648      HICON hOldIcon = SetIcon(hIcon); 
     649      if (hOldIcon != 0) 
     650         DestroyIcon(hOldIcon); 
     651      return TRUE; 
     652   } 
     653   BOOL SetValue(HWND /*hWnd*/)  
     654   { 
     655      // Do nothing... A value should be set on reacting to the button notification. 
     656      // In other words: Use SetItemValue() in response to the PLN_BROWSE notification! 
     657      return TRUE; 
     658   } 
     659   BOOL Activate(UINT action, LPARAM lParam) 
     660   { 
     661      RECT rc; 
     662      GetClientRect(m_hWndOwner, &rc); 
     663      WTL::CColorDialog clg(m_color, CC_FULLOPEN); 
     664      switch( action ) { 
     665         case PACT_CLICK: 
     666            if (m_fEnabled) { 
     667               int x = GET_X_LPARAM(lParam); 
     668               if (x > rc.right - 20) { 
     669                  return Activate(PACT_BROWSE, 0); 
     670               } 
     671            } 
     672            break; 
     673         case PACT_BROWSE: 
     674            if (IDOK == clg.DoModal(m_hWndOwner)) { 
     675               CComVariant vCol = CComVariant(clg.m_cc.rgbResult); 
     676               ::SendMessage(m_hWndOwner, WM_USER_PROP_CHANGEDPROPERTY, (WPARAM) (VARIANT*) &vCol, (LPARAM) this); 
     677            } 
     678            break; 
     679         case PACT_DBLCLICK: 
     680            // Let control owner know 
     681            NMPROPERTYITEM nmh = { m_hWndOwner, ::GetDlgCtrlID(m_hWndOwner), PIN_BROWSE, this }; 
     682            ::SendMessage(::GetParent(m_hWndOwner), WM_NOTIFY, nmh.hdr.idFrom, (LPARAM) &nmh); 
     683      } 
     684      return TRUE; 
     685   } 
     686   BOOL GetDisplayValue(LPTSTR pstr, UINT cchMax) const 
     687   { 
     688#define RGBA_GETRED(rgb)        (((rgb) >> 16) & 0xff) 
     689#define RGBA_GETGREEN(rgb)      (((rgb) >> 8) & 0xff) 
     690#define RGBA_GETBLUE(rgb)       ((rgb) & 0xff) 
     691      ATLASSERT(V_VT(&m_val)==VT_UI4); 
     692      lstrcpy(pstr, "#"); 
     693      TCHAR szValue[64] = { 0 }; 
     694      _itot(RGBA_GETRED(m_val.uintVal), szValue, 16); 
     695      if (szValue[1] == '\0') lstrcat(pstr, "0"); 
     696      lstrcat(pstr, szValue); 
     697 
     698      _itot(RGBA_GETGREEN(m_val.uintVal), szValue, 16); 
     699      if (szValue[1] == '\0') lstrcat(pstr, "0"); 
     700      lstrcat(pstr, szValue); 
     701 
     702      _itot(RGBA_GETBLUE(m_val.uintVal), szValue, 16); 
     703      if (szValue[1] == '\0') lstrcat(pstr, "0"); 
     704      lstrcat(pstr, szValue); 
     705      return TRUE; 
     706   } 
     707   UINT GetDisplayValueLength() const 
     708   { 
     709      TCHAR szPath[MAX_PATH] = { 0 }; 
     710      if( !GetDisplayValue(szPath, (sizeof(szPath) / sizeof(TCHAR)) - 1) ) return 0; 
     711      return ::lstrlen(szPath); 
     712   } 
     713}; 
     714 
     715 
     716///////////////////////////////////////////////////////////////////////////// 
    581717// DropDown List property 
    582718 
     
    9121048} 
    9131049 
     1050inline HPROPERTY PropCreateColor(LPCTSTR pstrName, COLORREF color, LPARAM lParam = 0) 
     1051{ 
     1052   CPropertyColorItem* prop = NULL; 
     1053   ATLTRY( prop = new CPropertyColorItem(pstrName, lParam) ); 
     1054   ATLASSERT(prop); 
     1055   if( prop == NULL ) return NULL; 
     1056   CComVariant vValue = color; 
     1057   prop->SetValue(vValue); 
     1058   return prop; 
     1059} 
     1060 
     1061 
    9141062 
    9151063#endif // __PROPERTYITEMIMPL__H 
  • trunk/src/buzelib/Utils/utils.h

    r1280 r1321  
    1010#define MT_GENERATOR                    1 
    1111#define MT_EFFECT                               2 
     12 
     13#define RGB_GETRED(rgb)         (((rgb) >> 16) & 0xff) 
     14#define RGB_GETGREEN(rgb)       (((rgb) >> 8) & 0xff) 
     15#define RGB_GETBLUE(rgb)        ((rgb) & 0xff) 
    1216 
    1317// system tools