CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

CONTROL.CPP (14134B)


      1 //
      2 // Copyright 2020 Electronic Arts Inc.
      3 //
      4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 
      5 // software: you can redistribute it and/or modify it under the terms of 
      6 // the GNU General Public License as published by the Free Software Foundation, 
      7 // either version 3 of the License, or (at your option) any later version.
      8 
      9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 
     10 // in the hope that it will be useful, but with permitted additional restrictions 
     11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 
     12 // distributed with this program. You should have received a copy of the 
     13 // GNU General Public License along with permitted additional restrictions 
     14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
     15 
     16 /* $Header:   F:\projects\c&c\vcs\code\control.cpv   2.18   16 Oct 1995 16:51:38   JOE_BOSTIC  $ */
     17 /***********************************************************************************************
     18  ***             C O N F I D E N T I A L  ---  W E S T W O O D   S T U D I O S               ***
     19  ***********************************************************************************************
     20  *                                                                                             *
     21  *                 Project Name : Command & Conquer                                            *
     22  *                                                                                             *
     23  *                    File Name : CONTROL.CPP                                                  *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : 01/15/95                                                     *
     28  *                                                                                             *
     29  *                  Last Update : January 19, 1995 [JLB]                                       *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  *   ControlClass::Action -- Normal action for control gaget objects.                          *
     34  *   ControlClass::ControlClass -- Constructor for control class objects.                      *
     35  *   ControlClass::Draw_Me -- Draw logic for the control class object.                         *
     36  *   ControlClass::Get_ID -- Gets the ID number for this gadget.                               *
     37  *   ControlClass::Make_Peer -- Assigns a peer gadget to this gadget.                          *
     38  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     39 
     40 #include	"function.h"
     41 
     42 
     43 /***********************************************************************************************
     44  * ControlClass::ControlClass -- Constructor for control class objects.                        *
     45  *                                                                                             *
     46  *    This is the normal constructor for control class objects. At this level, it only needs   *
     47  *    to record the ID number assigned to this button.                                         *
     48  *                                                                                             *
     49  * INPUT:   id    -- The ID number for this gadget. If the ID number specified is 0, then      *
     50  *                   this tells the system that no special ID code should be returned.         *
     51  *                                                                                             *
     52  *          x,y   -- Pixel coordinate of upper left corner of gadget's region.                 *
     53  *                                                                                             *
     54  *          w,h   -- Pixel dimensions of the gadget's region.                                  *
     55  *                                                                                             *
     56  *          flags -- The input event flags that this gadget recognizes.                        *
     57  *                                                                                             *
     58  *          sticky-- This this a "sticky" gadget? A sticky gadget is one that takes over the   *
     59  *                   gadget list while the mouse button is held down, if the mouse button was  *
     60  *                   initially clicked over its region. This is the behavior of "normal"       *
     61  *                   buttons in Windows.                                                       *
     62  *                                                                                             *
     63  * OUTPUT:  none                                                                               *
     64  *                                                                                             *
     65  * WARNINGS:   none                                                                            *
     66  *                                                                                             *
     67  * HISTORY:                                                                                    *
     68  *   01/15/1995 JLB : Created.                                                                 *
     69  *=============================================================================================*/
     70 ControlClass::ControlClass(unsigned id, int x, int y, int w, int h, unsigned flags, int sticky)
     71 	: GadgetClass(x, y, w, h, flags, sticky)
     72 {
     73 	ID = id;
     74 	Peer = 0;
     75 }
     76 
     77 
     78 /***********************************************************************************************
     79  * ControlClass::Action -- Normal action for control gaget objects.                            *
     80  *                                                                                             *
     81  *    This function gets called when the input event that this control gadget is looking for   *
     82  *    occurs. In such a case, the return key code value is changed to the gaget's ID number    *
     83  *    with the special button bit flag attached.                                               *
     84  *                                                                                             *
     85  * INPUT:   flags -- The event that triggered this function call. If this value is NULL, then  *
     86  *                   this is a forced (probably due to the sticky flag) call and the key code  *
     87  *                   is not altered.                                                           *
     88  *                                                                                             *
     89  *          key   -- Reference to the key code that will be returned by the controlling        *
     90  *                   Input() function.                                                         *
     91  *                                                                                             *
     92  * OUTPUT:  bool; Should futher list processing be aborted?                                    *
     93  *                                                                                             *
     94  * WARNINGS:   none                                                                            *
     95  *                                                                                             *
     96  * HISTORY:                                                                                    *
     97  *   01/15/1995 JLB : Created.                                                                 *
     98  *=============================================================================================*/
     99 int ControlClass::Action(unsigned flags, KeyNumType & key)
    100 {
    101 	/*
    102 	**	If there is a peer link established, inform that gadget of this
    103 	**	action call.
    104 	*/
    105 	if (Peer) {
    106 		Peer->Peer_To_Peer(flags, key, *this);
    107 	}
    108 
    109 	/*
    110 	**	Only if the flags indicate that a recognized action has occured, do the
    111 	**	normal processing of this gadget and set return value to the gadget ID.
    112 	*/
    113 	if (flags) {
    114 		if (ID) {
    115 			key = (KeyNumType)(ID | KN_BUTTON);
    116 		} else {
    117 			key = KN_NONE;
    118 		}
    119 	}
    120 
    121 	return(GadgetClass::Action(flags, key));
    122 }
    123 
    124 
    125 /***********************************************************************************************
    126  * ControlClass::Make_Peer -- Assigns a peer gadget to this gadget.                            *
    127  *                                                                                             *
    128  *    This function will assign another gadget to this one. That other gadget will receive     *
    129  *    notification of any Action() call to this gadget. Presumably, this is how one gadget     *
    130  *    can automatically adapt to changes in another. Say for example, a slider bar can affect  *
    131  *    the list box it is attached to.                                                          *
    132  *                                                                                             *
    133  * INPUT:   gadget   -- The gadget to inform when any Action() function is called.             *
    134  *                                                                                             *
    135  * OUTPUT:  none                                                                               *
    136  *                                                                                             *
    137  * WARNINGS:   none                                                                            *
    138  *                                                                                             *
    139  * HISTORY:                                                                                    *
    140  *   01/16/1995 JLB : Created.                                                                 *
    141  *=============================================================================================*/
    142 void ControlClass::Make_Peer(GadgetClass & gadget)
    143 {
    144 	Peer = &gadget;
    145 }
    146 
    147 
    148 /***********************************************************************************************
    149  * ControlClass::Get_ID -- Gets the ID number for this gadget.                                 *
    150  *                                                                                             *
    151  *    This function will query and return with the ID number for this gadget. It is primarily  *
    152  *    used by the Extract_Gadget() function.                                                   *
    153  *                                                                                             *
    154  * INPUT:   none                                                                               *
    155  *                                                                                             *
    156  * OUTPUT:  Returns with the ID number for this gadget. If zero is returned, this means that   *
    157  *          no ID was assigned to this gadget. This is a special case since a zero value will  *
    158  *          never be returned as a pseudo-key as is done with non-zero values.                 *
    159  *                                                                                             *
    160  * WARNINGS:   none                                                                            *
    161  *                                                                                             *
    162  * HISTORY:                                                                                    *
    163  *   01/16/1995 JLB : Created.                                                                 *
    164  *=============================================================================================*/
    165 unsigned ControlClass::Get_ID(void) const
    166 {
    167 	return(ID);
    168 }
    169 
    170 
    171 /***********************************************************************************************
    172  * ControlClass::Draw_Me -- Draw logic for the control class object.                           *
    173  *                                                                                             *
    174  *    This is called when the control object might need to be redrawn or when redrawing is     *
    175  *    necessary. Since at this level of the class heirarchy, no actual drawing occurs, this    *
    176  *    routine doesn't perform any rendering. It does, however, inform any peer attached        *
    177  *    object that a Draw_Me function has been called. Presumably, the attached peer gadget     *
    178  *    might very well need to be redrawn as a result of some action by this gadget. Since this *
    179  *    gadget might, more than likely, be of the "sticky" variety, a normal call to Draw_Me     *
    180  *    for the other gadget will not occur. It must rely on the call by this routine in order   *
    181  *    to update correctly. A typical example of this would be a slider that is attached to     *
    182  *    a list box. As the slider is being drug around, the attached list box must be redrawn.   *
    183  *                                                                                             *
    184  * INPUT:   forced   -- Should the redraw be forced regardless of the redraw flag?             *
    185  *                                                                                             *
    186  * OUTPUT:  bool; Was the gadget redrawn?                                                      *
    187  *                                                                                             *
    188  * WARNINGS:   none                                                                            *
    189  *                                                                                             *
    190  * HISTORY:                                                                                    *
    191  *   01/16/1995 JLB : Created.                                                                 *
    192  *=============================================================================================*/
    193 int ControlClass::Draw_Me(int forced)
    194 {
    195 	if (Peer) {
    196 		Peer->Draw_Me();
    197 	}
    198 	return(GadgetClass::Draw_Me(forced));
    199 }