ColorPicker.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #if !defined(AFX_COLORPICKER_H__C943A7EC_CAA3_11D2_8DDF_00104B6FD9E3__INCLUDED_)
  19. #define AFX_COLORPICKER_H__C943A7EC_CAA3_11D2_8DDF_00104B6FD9E3__INCLUDED_
  20. #if _MSC_VER >= 1000
  21. #pragma once
  22. #endif // _MSC_VER >= 1000
  23. // ColorPicker.h : header file
  24. //
  25. #ifdef WWCTRL_LIB
  26. #define LINKAGE_SPEC __declspec (dllexport)
  27. #else
  28. #define LINKAGE_SPEC
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. //
  32. // Constants
  33. //
  34. //
  35. // Window styles
  36. //
  37. #define CPS_SUNKEN 0x00000001
  38. #define CPS_RAISED 0x00000002
  39. //
  40. // Window messages and notifications
  41. //
  42. #define CPN_COLORCHANGE 0x0001
  43. #define CPM_GETCOLOR (WM_USER+101)
  44. #define CPM_SETCOLOR (WM_USER+102)
  45. /////////////////////////////////////////////////////////////////////////////
  46. //
  47. // Structures
  48. //
  49. // Structure used to send notifications via WM_NOTIFY
  50. typedef struct
  51. {
  52. NMHDR hdr;
  53. float red;
  54. float green;
  55. float blue;
  56. float hue;
  57. } CP_NMHDR;
  58. /////////////////////////////////////////////////////////////////////////////
  59. //
  60. // ColorPickerClass window
  61. //
  62. class LINKAGE_SPEC ColorPickerClass : public CWnd
  63. {
  64. // Construction
  65. public:
  66. ColorPickerClass();
  67. // Attributes
  68. public:
  69. // Operations
  70. public:
  71. // Overrides
  72. // ClassWizard generated virtual function overrides
  73. //{{AFX_VIRTUAL(ColorPickerClass)
  74. public:
  75. virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
  76. //}}AFX_VIRTUAL
  77. // Implementation
  78. public:
  79. virtual ~ColorPickerClass();
  80. // Generated message map functions
  81. protected:
  82. //{{AFX_MSG(ColorPickerClass)
  83. afx_msg void OnPaint();
  84. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  85. afx_msg void OnSize(UINT nType, int cx, int cy);
  86. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  87. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  88. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  89. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  90. //}}AFX_MSG
  91. DECLARE_MESSAGE_MAP()
  92. friend LRESULT WINAPI fnColorPickerProc (HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
  93. public:
  94. //////////////////////////////////////////////////////////////////////////
  95. // Public members
  96. //////////////////////////////////////////////////////////////////////////
  97. void Select_Color (int red, int green, int blue);
  98. void Get_Current_Color (int *red, int *green, int *blue);
  99. //////////////////////////////////////////////////////////////////////////
  100. // Static members
  101. //////////////////////////////////////////////////////////////////////////
  102. static ColorPickerClass *Get_Color_Picker (HWND window_handle) { return (ColorPickerClass *)::GetProp (window_handle, "CLASSPOINTER"); }
  103. protected:
  104. /////////////////////////////////////////////////////////////////////////
  105. //
  106. // Private member data
  107. //
  108. void Paint_DIB (int width, int height, UCHAR *pbits);
  109. void Create_Bitmap (void);
  110. void Free_Bitmap (void);
  111. void Fill_Rect (UCHAR *pbits, const RECT &rect, COLORREF color, int scanline_size);
  112. void Frame_Rect (UCHAR *pbits, const RECT &rect, COLORREF color, int scanline_size);
  113. void Draw_Horz_Line (UCHAR *pbits, int x, int y, int len, COLORREF color, int scanline_size);
  114. void Draw_Vert_Line (UCHAR *pbits, int x, int y, int len, COLORREF color, int scanline_size);
  115. COLORREF Color_From_Point (int x, int y);
  116. CPoint Point_From_Color (COLORREF color);
  117. void Paint_Marker (void);
  118. void Erase_Marker (void);
  119. void Calc_Display_Rect (RECT &rect);
  120. private:
  121. /////////////////////////////////////////////////////////////////////////
  122. //
  123. // Private member data
  124. //
  125. HBITMAP m_hBitmap;
  126. HDC m_hMemDC;
  127. UCHAR * m_pBits;
  128. int m_iWidth;
  129. int m_iHeight;
  130. CPoint m_CurrentPoint;
  131. COLORREF m_CurrentColor;
  132. bool m_bSelecting;
  133. float m_CurrentHue;
  134. };
  135. /////////////////////////////////////////////////////////////////////////////
  136. //{{AFX_INSERT_LOCATION}}
  137. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  138. #endif // !defined(AFX_COLORPICKER_H__C943A7EC_CAA3_11D2_8DDF_00104B6FD9E3__INCLUDED_)