ColorPicker.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. /////////////////////////////////////////////////////////////////////////////
  26. //
  27. // Constants
  28. //
  29. //
  30. // Window styles
  31. //
  32. #define CPS_SUNKEN 0x00000001
  33. #define CPS_RAISED 0x00000002
  34. //
  35. // Window messages and notifications
  36. //
  37. #define CPN_COLORCHANGE 0x0001
  38. #define CPM_GETCOLOR (WM_USER+101)
  39. #define CPM_SETCOLOR (WM_USER+102)
  40. /////////////////////////////////////////////////////////////////////////////
  41. //
  42. // Structures
  43. //
  44. // Structure used to send notifications via WM_NOTIFY
  45. typedef struct
  46. {
  47. NMHDR hdr;
  48. float red;
  49. float green;
  50. float blue;
  51. float hue;
  52. } CP_NMHDR;
  53. /////////////////////////////////////////////////////////////////////////////
  54. //
  55. // ColorPickerClass window
  56. //
  57. class ColorPickerClass : public CWnd
  58. {
  59. // Construction
  60. public:
  61. ColorPickerClass();
  62. // Attributes
  63. public:
  64. // Operations
  65. public:
  66. // Overrides
  67. // ClassWizard generated virtual function overrides
  68. //{{AFX_VIRTUAL(ColorPickerClass)
  69. public:
  70. virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
  71. //}}AFX_VIRTUAL
  72. // Implementation
  73. public:
  74. virtual ~ColorPickerClass();
  75. // Generated message map functions
  76. protected:
  77. //{{AFX_MSG(ColorPickerClass)
  78. afx_msg void OnPaint();
  79. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  80. afx_msg void OnSize(UINT nType, int cx, int cy);
  81. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  82. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  83. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  84. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  85. //}}AFX_MSG
  86. DECLARE_MESSAGE_MAP()
  87. friend LRESULT WINAPI fnColorPickerProc (HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
  88. public:
  89. //////////////////////////////////////////////////////////////////////////
  90. // Public members
  91. //////////////////////////////////////////////////////////////////////////
  92. void Select_Color (int red, int green, int blue);
  93. void Get_Current_Color (int *red, int *green, int *blue);
  94. //////////////////////////////////////////////////////////////////////////
  95. // Static members
  96. //////////////////////////////////////////////////////////////////////////
  97. static ColorPickerClass *Get_Color_Picker (HWND window_handle) { return (ColorPickerClass *)::GetProp (window_handle, "CLASSPOINTER"); }
  98. protected:
  99. /////////////////////////////////////////////////////////////////////////
  100. //
  101. // Private member data
  102. //
  103. void Paint_DIB (int width, int height, UCHAR *pbits);
  104. void Create_Bitmap (void);
  105. void Free_Bitmap (void);
  106. void Fill_Rect (UCHAR *pbits, const RECT &rect, COLORREF color, int scanline_size);
  107. void Frame_Rect (UCHAR *pbits, const RECT &rect, COLORREF color, int scanline_size);
  108. void Draw_Horz_Line (UCHAR *pbits, int x, int y, int len, COLORREF color, int scanline_size);
  109. void Draw_Vert_Line (UCHAR *pbits, int x, int y, int len, COLORREF color, int scanline_size);
  110. COLORREF Color_From_Point (int x, int y);
  111. CPoint Point_From_Color (COLORREF color);
  112. void Paint_Marker (void);
  113. void Erase_Marker (void);
  114. void Calc_Display_Rect (RECT &rect);
  115. private:
  116. /////////////////////////////////////////////////////////////////////////
  117. //
  118. // Private member data
  119. //
  120. HBITMAP m_hBitmap;
  121. HDC m_hMemDC;
  122. UCHAR * m_pBits;
  123. int m_iWidth;
  124. int m_iHeight;
  125. CPoint m_CurrentPoint;
  126. COLORREF m_CurrentColor;
  127. bool m_bSelecting;
  128. float m_CurrentHue;
  129. };
  130. /////////////////////////////////////////////////////////////////////////////
  131. //{{AFX_INSERT_LOCATION}}
  132. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  133. #endif // !defined(AFX_COLORPICKER_H__C943A7EC_CAA3_11D2_8DDF_00104B6FD9E3__INCLUDED_)