Home |
HMI (Human-Machine Interface) Classes Class PegColorLight |
Class PegColorLightPegColorLight is a state driven object that allows for graphically displaying data states by shape and color. The two basic shapes supported are a rectangle and a circle. Style FlagsPegColorLight supports the standard PegThingstyles for borders: FF_NONE, FF_THIN, FF_RECESSED and FF_RAISED. PegColorLight also supports two additional styles: LS_RECTANGLE and LS_CIRCLE. These additional styles define the drawing style of the PegColorLight. SignalsPegColorLight does not send any signals. class PegColorLight : public PegLight { public: PegColorLight(const PegRect& Rect, PEGUINT wNumStates, PEGUINT wStyle = FF_RAISED|LS_RECTANGLE); PegColorLight(PEGINT iLeft, PEGINT iTop, PEGUINT wNumStates, PEGUINT wStyle = FF_RAISED|LS_RECTANGLE); virtual void Draw(); virtual PEGUINT SetNumStates(PEGUINT wNumStates); BOOL SetStateColor(PEGUINT wState, COLORVAL tColor); protected: COLORVAL * mpStateColor; }; ConstructorsThe first constructor takes a reference to a PegRect to determine its size, a PEGUINT value for the number of states it supports, and a style PEGUINT. It is important to remember that the light states are 0 based. Therefore, the first state is 0 and the last state is wNumStates - 1. This constructor takes PEGINT values for the left and top position of the light. By default, it will make the light 100 pixels wide and 100 pixels high. It also takes WORDs for the number of states and the style. Method DrawPegColorLight overrides the Draw() function to draw the correct color and shape for the current state of the light. Method SetNumStatesThis method allows resetting the number of states supported by the object at runtime. It will copy over the COLORVAL's that were already assigned to it, if there are any. If the new number of states is less than the previous number of states, it will only copy over as many as are newly assigned. If the new number of states is greater, then it will copy all of the previous COLORVAL's, and NULL out the remainder. It will also set the current state to a valid state if the current state is beyond the range of the number of states. Method SetStateColorThis method allows a color to be associated with a state. It returns a boolean for success or failure. It will fail if wState is less than 0 or greater than maximum states - 1. ExamplesThe following is an example of two PegColorLight objects on a PegDecoratedWindow. The first light, on the left, has the LS_RECTANGLE style flag set and is being drawn with a raised border. The second has the LS_CIRCLE style flag set. The above PegColorLight objects were created by the following code snippet: PegColorLight * mpLight1, * mpLight2; . . PegRect LightRect = mClient; LightRect.wTop += 20; LightRect.wLeft += 20; LightRect.wRight = LightRect.wLeft + 100; LightRect.wBottom = LightRect.wTop + 100; mpLight1 = new PegColorLight(LightRect, 3, FF_RAISED | LS_RECTANGLE); mpLight1->SetStateColor(0, RED); mpLight1->SetStateColor(1, BLUE); mpLight1->SetStateColor(2, GREEN); mpLight1->SetState(1, FALSE); Add(mpLight1); LightRect.Shift(120, 0); mpLight2 = new PegColorLight(LightRect, 4, LS_CIRCLE | FF_RECESSED | AF_TRANSPARENT); mpLight2->SetStateColor(0, CYAN); mpLight2->SetStateColor(1, BLUE); mpLight2->SetStateColor(2, GREEN); mpLight2->SetStateColor(3, LIGHTGREEN); mpLight2->SetState(3, FALSE); Add(mpLight2);
|