You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

213 lines
6.2 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
18 years ago
18 years ago
13 years ago
18 years ago
13 years ago
13 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2007-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2014 KiCad Developers, see AUTHORS.TXT for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef COLORS_H_
  25. #define COLORS_H_
  26. #include <wx/wx.h>
  27. /** The color enumeration. Also contains a flag and the alpha value in
  28. * the upper bits
  29. */
  30. enum EDA_COLOR_T
  31. {
  32. UNSPECIFIED_COLOR = -1,
  33. BLACK = 0,
  34. DARKDARKGRAY,
  35. DARKGRAY,
  36. LIGHTGRAY,
  37. WHITE,
  38. LIGHTYELLOW,
  39. DARKBLUE,
  40. DARKGREEN,
  41. DARKCYAN,
  42. DARKRED,
  43. DARKMAGENTA,
  44. DARKBROWN,
  45. BLUE,
  46. GREEN,
  47. CYAN,
  48. RED,
  49. MAGENTA,
  50. BROWN,
  51. LIGHTBLUE,
  52. LIGHTGREEN,
  53. LIGHTCYAN,
  54. LIGHTRED,
  55. LIGHTMAGENTA,
  56. YELLOW,
  57. PUREBLUE,
  58. PUREGREEN,
  59. PURECYAN,
  60. PURERED,
  61. PUREMAGENTA,
  62. PUREYELLOW,
  63. NBCOLORS, ///< Number of colors
  64. HIGHLIGHT_FLAG = ( 1<<19 ),
  65. MASKCOLOR = 31 ///< mask for color index into g_ColorRefs[]
  66. };
  67. /// Checked cast. Use only when necessary (usually I/O)
  68. inline EDA_COLOR_T ColorFromInt( int aColor )
  69. {
  70. wxASSERT( aColor >= UNSPECIFIED_COLOR && aColor < NBCOLORS );
  71. return static_cast<EDA_COLOR_T>( aColor );
  72. }
  73. inline EDA_COLOR_T NextColor( EDA_COLOR_T& aColor )
  74. {
  75. // We have to accept NBCOLORS for loop termination conditions
  76. wxASSERT( aColor >= UNSPECIFIED_COLOR && aColor <= NBCOLORS );
  77. aColor = static_cast<EDA_COLOR_T>( int( aColor ) + 1 );
  78. return aColor;
  79. }
  80. /// Return only the plain color part
  81. inline EDA_COLOR_T ColorGetBase( EDA_COLOR_T aColor)
  82. {
  83. EDA_COLOR_T base = static_cast<EDA_COLOR_T>( aColor & MASKCOLOR );
  84. return base;
  85. }
  86. /// Mix two colors in some way (hopefully like a logical OR)
  87. EDA_COLOR_T ColorMix( EDA_COLOR_T aColor1, EDA_COLOR_T aColor2 );
  88. /// Force the color part of a color to darkdarkgray
  89. inline void ColorTurnToDarkDarkGray( EDA_COLOR_T *aColor )
  90. {
  91. *aColor = static_cast<EDA_COLOR_T>( (int(*aColor) & ~MASKCOLOR) | DARKDARKGRAY );
  92. }
  93. inline void ColorChangeHighlightFlag( EDA_COLOR_T *aColor, bool flag )
  94. {
  95. if( flag )
  96. *aColor = static_cast<EDA_COLOR_T>( (int(*aColor) | HIGHLIGHT_FLAG ) );
  97. else
  98. *aColor = static_cast<EDA_COLOR_T>( (int(*aColor) & ~HIGHLIGHT_FLAG ) );
  99. }
  100. /**
  101. * Function SetAlpha
  102. * ORs in the alpha blend parameter in to a color index.
  103. */
  104. inline void SetAlpha( EDA_COLOR_T* aColor, unsigned char aBlend )
  105. {
  106. const unsigned char MASKALPHA = 0xFF;
  107. *aColor = static_cast<EDA_COLOR_T>((*aColor & ~(MASKALPHA << 24))
  108. | ((aBlend & MASKALPHA) << 24));
  109. }
  110. /**
  111. * Function GetAlpha
  112. * returns the alpha blend parameter from a color index.
  113. */
  114. inline unsigned char GetAlpha( EDA_COLOR_T aColor )
  115. {
  116. const unsigned char MASKALPHA = 0xFF;
  117. return (aColor >> 24) & MASKALPHA;
  118. }
  119. struct StructColors
  120. {
  121. unsigned char m_Blue;
  122. unsigned char m_Green;
  123. unsigned char m_Red;
  124. EDA_COLOR_T m_Numcolor;
  125. const wxChar* m_ColorName;
  126. EDA_COLOR_T m_LightColor;
  127. };
  128. /// list of existing Colors
  129. extern const StructColors g_ColorRefs[NBCOLORS];
  130. /// Step a color to the highlighted version if the highlight flag is set
  131. inline void ColorApplyHighlightFlag( EDA_COLOR_T *aColor )
  132. {
  133. EDA_COLOR_T base = ColorGetBase( *aColor );
  134. wxASSERT( base > UNSPECIFIED_COLOR && base < NBCOLORS );
  135. if( *aColor & HIGHLIGHT_FLAG )
  136. *aColor = g_ColorRefs[base].m_LightColor;
  137. }
  138. /// Find a color by name
  139. EDA_COLOR_T ColorByName( const wxString& aName );
  140. /// Find the nearest color match
  141. EDA_COLOR_T ColorFindNearest( const wxColour &aColor );
  142. /**
  143. * Find the nearest color match
  144. * @param aR is the red component of the color to be matched (in range 0-255)
  145. * @param aG is the green component of the color to be matched (in range 0-255)
  146. * @param aB is the blue component of the color to be matched (in range 0-255)
  147. */
  148. EDA_COLOR_T ColorFindNearest( int aR, int aG, int aB );
  149. /**
  150. * Check if a color is light i.e. if black would be more readable than
  151. * white on it
  152. */
  153. bool ColorIsLight( EDA_COLOR_T aColor );
  154. inline const wxChar *ColorGetName( EDA_COLOR_T aColor )
  155. {
  156. EDA_COLOR_T base = ColorGetBase( aColor );
  157. wxASSERT( base > UNSPECIFIED_COLOR && base < NBCOLORS );
  158. return g_ColorRefs[base].m_ColorName;
  159. }
  160. inline void ColorSetBrush( wxBrush *aBrush, EDA_COLOR_T aColor )
  161. {
  162. EDA_COLOR_T base = ColorGetBase( aColor );
  163. wxASSERT( base > UNSPECIFIED_COLOR && base < NBCOLORS );
  164. const StructColors &col = g_ColorRefs[base];
  165. aBrush->SetColour( col.m_Red, col.m_Green, col.m_Blue );
  166. }
  167. /**
  168. * Function MakeColour
  169. * returns a wxWidgets wxColor from a KiCad color index with alpha value.
  170. * Note that alpha support is not available on every wxWidgets platform. On
  171. * such platform the behavior is the same as for wxALPHA_OPAQUE and that
  172. * means the alpha value has no effect and will be ignored.
  173. * @return wxColour - given a KiCad color index with alpha value
  174. */
  175. inline wxColour MakeColour( EDA_COLOR_T aColor )
  176. {
  177. int alpha = GetAlpha( aColor );
  178. alpha = alpha ? alpha : wxALPHA_OPAQUE;
  179. EDA_COLOR_T ndx = ColorGetBase( aColor );
  180. wxASSERT( ndx > UNSPECIFIED_COLOR && ndx < NBCOLORS );
  181. return wxColour( g_ColorRefs[ndx].m_Red,
  182. g_ColorRefs[ndx].m_Green,
  183. g_ColorRefs[ndx].m_Blue
  184. ,(unsigned char) alpha
  185. );
  186. }
  187. #endif // COLORS_H_