|
|
(4 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
| A class for handling and specifying colors. | | {{DISPLAYTITLE:vCmdWindow}} |
| | A class to show a window with various command panes. |
|
| |
|
| ==Synopsis== | | ==Synopsis== |
| | | ;Header: <tt><v/vcmdwin.h></tt> |
| ; '''Header:''' | | ;Class name: vCmdWindow |
| : <tt>[vquickr.htm#vColor <v/vcolor.h>]</tt> | | ;Hierarchy: vBaseWindow ->[[vWindow]] ->vCmdWindow |
| ; '''Class name:''' | | ;Contains: [[vDialog]], [[vPane]] |
| : vColor | |
|
| |
|
| ==Description== | | ==Description== |
| | | The <tt>vCmdWindow</tt> class is derived from the <tt>vWindow</tt> class. This class is intended as a class that serves as a main control window containing various <tt>vPane</tt> objects such as menu bars, canvases, and command bars. The main difference between the <tt>vCmdWindow</tt> class and the <tt>vWindow</tt> class is how they are treated by the host windowing system. You will normally derive your windows from the <tt>vCmdWindow</tt> class. |
| The '''''V''''' color model allows you to specify colors as an RGB value. The intensity of each primary color, red, green, and blue are specified as a value between 0 and 255. This allows you to specify up to 2<sup>24</sup> colors. Just how many of all these colors you can see and how they will look on your display will depend on that display. Even so, you can probably count on (255,0,0) being something close to red on most displays. Given this 24 bit model, the <tt>vColor</tt> class allows you to define colors easily. | |
| | |
| In order to make using colors somewhat easier, '''''V''''' has defined a standard array of 16 basic colors that you can access by including <tt>v/vcolor.h></tt>. This array is called <tt>vStdColors</tt>. You index the array using the symbols <tt>vC_Black</tt>, <tt>vC_Red</tt>, <tt>vC_DimRed</tt>, <tt>vC_Green</tt>, <tt>vC_DimGreen</tt>, <tt>vC_Blue</tt>, <tt>vC_DimBlue</tt>, <tt>vC_Yellow</tt>, <tt>vC_DimYellow</tt>, <tt>vC_Magenta</tt>, <tt>vC_DimMagenta</tt>, <tt>vC_Cyan</tt>, <tt>vC_DimCyan</tt>, <tt>vC_DarkGray</tt>, <tt>vC_MedGray</tt>, and <tt>vC_White</tt>. For example, use the standard color <tt>vStdColors[vC_Green]</tt> to represent green. You can also get a <tt>char</tt> for the color by using the symbol to index the <tt>char* vColorName[16]</tt> array.
| |
| | |
| The file <tt><v/vcb2x4.h></tt> contains definitions for 8 color buttons in a 2 high by 4 wide frame. The file <tt><v/vcb2x8.h></tt> has a 2 by 8 frame of all 16 standard colors. You can specify the size of each button in the frame by defining <tt>vC_Size</tt>. The default is 8. You can also specify the location in a dialog of the color button frame by defining the symbols <tt>vC_Frame, vC_RightOf,</tt> and <tt>vC_Below</tt>. The ids of each button in the frame correspond to the color indexes, but with a <tt>M</tt> prefix (e.g., <tt>M_Red</tt> for <tt>vC_Red</tt>). See the example in <tt>v/examp</tt> for and example of using the standard color button frames.
| |
| | |
| Also note that unlike most other '''''V''''' objects, it makes perfect sense to assign and copy <tt>vColor</tt> values. Thus, assignment, copy constructor, and equality comparison operators are provided.
| |
|
| |
|
| ==Constructor== | | ==Constructor== |
| | ;vCmdWindow(char* title) |
| | ;vCmdWindow(char* title, int h, int w):These construct a <tt>vCmdWindow</tt> with a title and a size specified in pixels. You can use <tt>theApp->DefaultHeight()</tt> and <tt>theApp->DefaultWidth()</tt> in the call to the constructor to create a ''standard'' size window. Note that the height and width are of the canvas area, and not the entire window. |
|
| |
|
| ====vColor(unsigned int rd 0, unsigned int gr = 0, unsigned int bl = 0)==== | | ==Inherited Methods== |
| | | See the section <tt>[[vWindow]]</tt> for details of the following methods. |
| The class has been defined so you can easily initialize a color either by using its constructor directly, or indirectly via an array declaration. Each color has a red, green, and blue value in the range of 0 to 255.
| | :virtual void KeyIn(vKey key, unsigned int shift) |
| | | :virtual void MenuCommand(ItemVal itemId) |
| <font size="-2"> </font> | | :virtual void WindowCommand(ItemVal Id, ItemVal Val, CmdType Type) |
| | | :virtual void AddPane(vPane* pane) |
|
| | :virtual void GetPosition(int& left, int& top, int& width, int& height) |
| // Declare Red via constructor
| | :virtual int GetValue(ItemVal itemId) |
| vColor btncolor(255, 0 , 0); // Red
| | :virtual void RaiseWindow(void) |
|
| | :virtual void ShowPane(vPane* wpane, int OnOrOff) |
| // Declare array with green and blue
| | :virtual void SetValue(ItemVal itemId, int Val, ItemSetType what) |
| vColor GreenAndBlue[2] =
| | :virtual void SetString(ItemVal itemId, char* title) |
| {
| | :virtual void SetTitle(char* title) |
| (0, 255, 0), // Green
| | :virtual void UpdateView(vWindow* sender, int hint, void* pHint) |
| (0, 0, 255) // Blue
| | :virtual void CloseWin() |
| };
| |
| | |
| ==Utility Methods==
| |
| | |
| ====BitsOfColor()====
| |
| | |
| This method returns the number of bits used by the machine to display to represent color. A value of 8, for example, means the computer is using 8 bits to show the color.
| |
| | |
| ====ResetColor(unsigned int rd = 0, unsigned int gr = 0, unsigned int bl = 0)====
| |
| | |
| ====ResetColor(vColor& c)====
| |
| | |
| Like the <tt>Set</tt> method, this method will set all three values of the color at once. However, '''''V''''' tries to preserve entries in the system color palette or color map with <tt>ResetColor</tt>. You can also pass a <tt>vColor</tt> object.
| |
| | |
| Consider the following code excerpt:
| |
| | |
| <font size="-2"> </font>
| |
| | |
|
| |
| vColor aColor; // A V Color
| |
| vBrush aBrush;
| |
| int iy;
| |
|
| |
| ...
| |
|
| |
| for (iy = 0 ; iy < 128 ; ++iy)
| |
| {
| |
| aColor.Set(iy,iy,iy); // Set to shade of gray
| |
| aBrush.SetColor(aColor); // Set brush
| |
| canvas.DrawLine(10,iy+100,200,iy+100); // Draw line
| |
| }
| |
| ...
| |
|
| |
| | |
| This example will use up 128 color map entries on some systems (X, for example). Once a system has run out of entries, '''''V''''' will draw in black or white. When these systems run out of new color map entries, the color drawn for new colors will be black or white.
| |
| | |
| <font size="-2"> </font>
| |
| | |
|
| |
| vColor aColor; // A V Color
| |
| vBrush aBrush;
| |
| int iy;
| |
| | |
| ...
| |
|
| |
| for (iy = 0 ; iy < 128 ; ++iy)
| |
| {
| |
| aColor.ResetColor(iy,iy,iy); // Set to shade of gray
| |
| aBrush.SetColor(aColor); // Set brush
| |
| canvas.DrawLine(10,iy+100,200,iy+100); // Draw line
| |
| }
| |
| ...
| |
|
| |
| | |
| This example accomplishes the same as the first, but does not use up color map entries. Instead, the entry used for <tt>aColor</tt> is reused to get better use of the color map. If your application will be working with a large number of colors that will vary, using <tt>ResetColor</tt> will minimize the number of color map accesses.
| |
| | |
| On some systems, and systems with a full 24 bits of color, <tt>ResetColor</tt> and <tt>Set</tt> work identically.
| |
| | |
| ''WARNING''<nowiki>: If you intend to use </nowiki><tt>ResetColor</tt> on a <tt>vColor</tt> object, then <tt>ResetColor</tt> is the only way you should change the color of that object. You should not use the color assignment operator, or <tt>Set</tt>. <tt>ResetColor</tt> needs to do some unconventional things internally to preserve color palette entries, and these can be incompatible with regular assignment or <tt>Set</tt>. You can, however, safely use such a <tt>vColor</tt> object with any other <tt>vColor</tt> object. For example:
| |
| | |
| <font size="-2"> </font>
| |
| | |
|
| |
| vColor c1, c2;
| |
|
| |
| c1.ResetColor(100,100,100); // You can use c1 with others.
| |
| c2 = c1; // OK, but this = now makes c2
| |
| // incompatible with ResetColor.
| |
| c2.ResetColor(200,200,200); // DON'T DO THIS
| |
| | |
| ====Set(unsigned int rd = 0, unsigned int gr = 0, unsigned int bl = 0)====
| |
| | |
| Set all three values of the color at once.
| |
| | |
| ====void SetR(unsigned int rd = 0)====
| |
| | |
| Set the Red value.
| |
| | |
| ====void SetG(unsigned int gr = 0)====
| |
| | |
| Set the Green value.
| |
| | |
| ====void SetB(unsigned int bl = 0)====
| |
| | |
| Set the Blue value.
| |
| | |
| ====unsigned int r()====
| |
| | |
| Get the Red value.
| |
| | |
| ====unsigned int g()====
| |
| | |
| Get the Green value.
| |
| | |
| ====unsigned int b()====
| |
| | |
| Get the Blue value.
| |
| | |
| ====int operator ======
| |
| | |
| Compare two color objects for equality.
| |
| | |
| ====int operator !=====
| |
| | |
| Compare two color objects for inequality.
| |
| | |
| ==Notes about color==
| |
| | |
| The color model used by '''''V''''' attempts to hide most of the details for using color. However, for some applications you may end up confronting some of the sticky issues of color.
| |
| | |
| Most machines in use in 1996 will not support all 2<sup>24</sup> colors that can be represented by the RGB color specification. Typically, they devote 8 or 16 bits to each pixel. This means that the 24-bit RGB colors must be mapped to the smaller 8-bit or 16-bit range. This mapping is usually accomplished by using a palette or colormap.
| |
| | |
| '''''V''''' tries to use the default system color palette provided by the machine it is running on. On some systems, such as X, it is possible to run out of entries in the color map. Others, like Windows, map colors not in the color palette to dithered colors. '''''V''''' provides two methods to help with this problem. First, <tt>vColor::BitsOfColor()</tt> tells you how many bits are used by the running system to represent color. The method <tt>vColor::ResetColor(r,g,b)</tt> can be used to change the value of a color without using up another entry in the system color map. For now, these methods should allow you to work with color with pretty good flexibility. Eventually, '''''V''''' may include more direct support for color palettes.
| |
| | |
| ==See Also==
| |
| | |
| [commands.htm#C_ColorButton C_ColorButton], [vcanvas.htm vCanvas]
| |
|
| |
|
| [[Category:Tools Articles]] | | [[Category:V C++ GUI Framework]] |
A class to show a window with various command panes.
Synopsis
- Header
- <v/vcmdwin.h>
- Class name
- vCmdWindow
- Hierarchy
- vBaseWindow ->vWindow ->vCmdWindow
- Contains
- vDialog, vPane
Description
The vCmdWindow class is derived from the vWindow class. This class is intended as a class that serves as a main control window containing various vPane objects such as menu bars, canvases, and command bars. The main difference between the vCmdWindow class and the vWindow class is how they are treated by the host windowing system. You will normally derive your windows from the vCmdWindow class.
Constructor
- vCmdWindow(char* title)
- vCmdWindow(char* title, int h, int w)
- These construct a vCmdWindow with a title and a size specified in pixels. You can use theApp->DefaultHeight() and theApp->DefaultWidth() in the call to the constructor to create a standard size window. Note that the height and width are of the canvas area, and not the entire window.
Inherited Methods
See the section vWindow for details of the following methods.
- virtual void KeyIn(vKey key, unsigned int shift)
- virtual void MenuCommand(ItemVal itemId)
- virtual void WindowCommand(ItemVal Id, ItemVal Val, CmdType Type)
- virtual void AddPane(vPane* pane)
- virtual void GetPosition(int& left, int& top, int& width, int& height)
- virtual int GetValue(ItemVal itemId)
- virtual void RaiseWindow(void)
- virtual void ShowPane(vPane* wpane, int OnOrOff)
- virtual void SetValue(ItemVal itemId, int Val, ItemSetType what)
- virtual void SetString(ItemVal itemId, char* title)
- virtual void SetTitle(char* title)
- virtual void UpdateView(vWindow* sender, int hint, void* pHint)
- virtual void CloseWin()