CnC_Remastered_Collection

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

DIAL8.CPP (13699B)


      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: /CounterStrike/DIAL8.CPP 1     3/03/97 10:24a 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 : DIAL8.CPP                                                    *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : 07/05/96                                                     *
     28  *                                                                                             *
     29  *                  Last Update : July 5, 1996 [JLB]                                           *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  *   Dial8Class::Action -- action routine for Dial8Class                                       *
     34  *   Dial8Class::Dial8Class -- constructor for the facing dial                                 *
     35  *   Dial8Class::Draw_Me -- render routine for Dial8Class                                      *
     36  *   Dial8Class::Get_Direction -- retrieves direction (0-255) of dial                          *
     37  *   Dial8Class::Set_Direction -- sets current direction (0-255) of dial                       *
     38  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     39 
     40 #include "function.h"
     41 
     42 
     43 /***************************************************************************
     44  * Dial8Class::Dial8Class -- constructor for the facing dial               *
     45  *                                                                         *
     46  * INPUT:                                                                  *
     47  *      id            button ID                                            *
     48  *      x,y,w,h      dimensions in window-relative pixels                  *
     49  *      dir         numerical initial facing value (0-255); this is the    *
     50  *                  value returned by WWLIB Desired_Facing8()              *
     51  *                                                                         *
     52  * OUTPUT:                                                                 *
     53  *      none.                                                              *
     54  *                                                                         *
     55  * WARNINGS:                                                               *
     56  *      none.                                                              *
     57  *                                                                         *
     58  * HISTORY:                                                                *
     59  *   11/16/1994 BR : Created.                                              *
     60  *=========================================================================*/
     61 Dial8Class::Dial8Class(int id, int x, int y, int w, int h, DirType dir) :
     62 	ControlClass(id, x, y, w, h, LEFTPRESS | LEFTHELD | LEFTRELEASE, true)
     63 {
     64 	/*
     65 	**	Center coordinates.
     66 	*/
     67 	FaceX = X + (Width / 2);
     68 	FaceY = Y + (Height / 2);
     69 
     70 	/*
     71 	**	Init directions.
     72 	*/
     73 	Direction = dir;							// 0 - 255
     74 	Facing = Dir_Facing(Direction);		// 0 - 7
     75 	OldFacing = Facing;						// 0 - 7
     76 
     77 	/*
     78 	**	Compute the drawing dimensions:  a 45-degree angle intersects a unity-
     79 	**	radius circle at (.707,.707). Make the decorations 8/10 of the radius,
     80 	**	and the line extend to 6/10 of the radius. Use Width/2 for x-radius,
     81 	**	Height/2 for y-radius.
     82 	*/
     83 	FacePoint[0][0] = FaceX;
     84 	FacePoint[0][1] = FaceY - (h * 8 / 2) / 10;
     85 
     86 	FacePoint[1][0] = FaceX + (w * 7 * 8 / 2) / 100;
     87 	FacePoint[1][1] = FaceY - (h * 7 * 8 / 2) / 100;
     88 
     89 	FacePoint[2][0] = FaceX + (w * 8 / 2) / 10;
     90 	FacePoint[2][1] = FaceY;
     91 
     92 	FacePoint[3][0] = FaceX + (w * 7 * 8 / 2) / 100;
     93 	FacePoint[3][1] = FaceY + (h * 7 * 8 / 2) / 100;
     94 
     95 	FacePoint[4][0] = FaceX;
     96 	FacePoint[4][1] = FaceY + (h * 8 / 2) / 10;
     97 
     98 	FacePoint[5][0] = FaceX - (w * 7 * 8 / 2) / 100;
     99 	FacePoint[5][1] = FaceY + (h * 7 * 8 / 2) / 100;
    100 
    101 	FacePoint[6][0] = FaceX - (w * 8 / 2) / 10;
    102 	FacePoint[6][1] = FaceY;
    103 
    104 	FacePoint[7][0] = FaceX - (w * 7 * 8 / 2) / 100;
    105 	FacePoint[7][1] = FaceY - (h * 7 * 8 / 2) / 100;
    106 
    107 	FaceLine[0][0] = FaceX;
    108 	FaceLine[0][1] = FaceY - (h * 6 / 2) / 10;
    109 
    110 	FaceLine[1][0] = FaceX + (w * 7 * 6 / 2) / 100;
    111 	FaceLine[1][1] = FaceY - (h * 7 * 6 / 2) / 100;
    112 
    113 	FaceLine[2][0] = FaceX + (w * 6 / 2) / 10;
    114 	FaceLine[2][1] = FaceY;
    115 
    116 	FaceLine[3][0] = FaceX + (w * 7 * 6 / 2) / 100;
    117 	FaceLine[3][1] = FaceY + (h * 7 * 6 / 2) / 100;
    118 
    119 	FaceLine[4][0] = FaceX;
    120 	FaceLine[4][1] = FaceY + (h * 6 / 2) / 10;
    121 
    122 	FaceLine[5][0] = FaceX - (w * 7 * 6 / 2) / 100;
    123 	FaceLine[5][1] = FaceY + (h * 7 * 6 / 2) / 100;
    124 
    125 	FaceLine[6][0] = FaceX - (w * 6 / 2) / 10;
    126 	FaceLine[6][1] = FaceY;
    127 
    128 	FaceLine[7][0] = FaceX - (w * 7 * 6 / 2) / 100;
    129 	FaceLine[7][1] = FaceY - (h * 7 * 6 / 2) / 100;
    130 }
    131 
    132 
    133 /***************************************************************************
    134  * Dial8Class::Action -- activation function for Dial8Class                *
    135  *                                                                         *
    136  * INPUT:                                                                  *
    137  *      flags      the reason we're being called                           *
    138  *      key      the KN_number that was pressed                            *
    139  *                                                                         *
    140  * OUTPUT:                                                                 *
    141  *      true = event was processed, false = event not processed            *
    142  *                                                                         *
    143  * WARNINGS:                                                               *
    144  *      none.                                                              *
    145  *                                                                         *
    146  * HISTORY:                                                                *
    147  *   02/06/1995 BR : Created.                                              *
    148  *=========================================================================*/
    149 int Dial8Class::Action(unsigned flags, KeyNumType &key)
    150 {
    151 	static int is_sel = 0;
    152 
    153 	/*
    154 	**	We might end up clearing the event bits. Make sure that the sticky
    155 	**	process is properly updated anyway.
    156 	*/
    157 	Sticky_Process(flags);
    158 
    159 	if (flags & LEFTPRESS) {
    160 		is_sel = 1;
    161 	}
    162 
    163 	/*
    164 	**	If left mouse is clicked or held, and the dial has changed its direction,
    165 	**	invoke the parent Action routine:
    166 	**	GadgetClass::Action handles Sticky processing, & sets IsToRepaint if any
    167 	**	  flag bits are set.
    168 	**	ControlClass::Action handles Peer_To_Peer notification, and substitutes
    169 	**	  'key' with the button ID if any flags are set, or 0 if no flags are set
    170 	*/
    171 	if (flags & LEFTPRESS || ((flags & LEFTHELD) && is_sel)) {
    172 		/*
    173 		**	Get new dial position (0-255)
    174 		*/
    175 		Direction = (DirType)Desired_Facing8(FaceX, FaceY, Get_Mouse_X(), Get_Mouse_Y());
    176 
    177 		/*
    178 		**	Convert to Facing value (0-7).
    179 		*/
    180 		Facing = Dir_Facing(Direction);
    181 
    182 		/*
    183 		**	If it's moved, redraw.
    184 		*/
    185 		if (Facing!=OldFacing) {
    186 			OldFacing = Facing;
    187 			ControlClass::Action(flags, key);
    188 			return(true);
    189 
    190 		} else {
    191 
    192 			/*
    193 			**	Dial hasn't moved; kill the event & return
    194 			*/
    195 			key = KN_NONE;
    196 			ControlClass::Action(0, key);
    197 			return(true);
    198 		}
    199 
    200 	} else {
    201 
    202 		/*
    203 		**	Otherwise, no events have occurred; kill the event if it's a LEFTRELEASE,
    204 		**	and return
    205 		*/
    206 		if (flags & LEFTRELEASE) {
    207 			key = KN_NONE;
    208 			is_sel = 0;
    209 		}
    210 		return(ControlClass::Action(0, key));
    211 	}
    212 }
    213 
    214 
    215 /***************************************************************************
    216  * Dial8Class::Draw_Me -- custom render routine for Dial8Class             *
    217  *                                                                         *
    218  * INPUT:                                                                  *
    219  *      forced      true = draw regardless of the current redraw flag state*
    220  *                                                                         *
    221  * OUTPUT:                                                                 *
    222  *      true = gadget was redrawn, false = wasn't                          *
    223  *                                                                         *
    224  * WARNINGS:                                                               *
    225  *      none.                                                              *
    226  *                                                                         *
    227  * HISTORY:                                                                *
    228  *   02/06/1995 BR : Created.                                              *
    229  *=========================================================================*/
    230 int Dial8Class::Draw_Me(int forced)
    231 {
    232 	RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
    233 
    234 	/*
    235 	**	Redraw if parent indicates a redraw is needed
    236 	*/
    237 	if (ControlClass::Draw_Me(forced)) {
    238 		/*
    239 		**	Hide the mouse.
    240 		*/
    241 
    242 		if (LogicPage == &SeenBuff) {
    243 			Hide_Mouse();
    244 		}
    245 
    246 		/*
    247 		**	Draw background & decorations.
    248 		*/
    249 		Draw_Box(X, Y, Width, Height, BOXSTYLE_DOWN, true);
    250 		for (int i=0; i<8; i++) {
    251 			Draw_Box(FacePoint[i][0] - 1, FacePoint[i][1] -1, 3, 3, BOXSTYLE_RAISED, false);
    252 		}
    253 
    254 		/*
    255 		**	Draw the hand & its shadow.
    256 		*/
    257 		LogicPage->Draw_Line(FaceX+1, FaceY+1, FaceLine[Facing][0]+1, FaceLine[Facing][1]+1, scheme->Shadow);
    258 		LogicPage->Draw_Line(FaceX, FaceY, FaceLine[Facing][0], FaceLine[Facing][1], scheme->Highlight);
    259 
    260 		/*
    261 		**	Restore the mouse.
    262 		*/
    263 		if (LogicPage == &SeenBuff) {
    264 			Show_Mouse();
    265 		}
    266 
    267 		return(true);
    268 	}
    269 
    270 	return(false);
    271 }
    272 
    273 
    274 /***************************************************************************
    275  * Dial8Class::Get_Direction -- retrieves direction (0-255) of dial        *
    276  *                                                                         *
    277  * INPUT:                                                                  *
    278  *      none.                                                              *
    279  *                                                                         *
    280  * OUTPUT:                                                                 *
    281  *      DirType dial is pointing to                                        *
    282  *                                                                         *
    283  * WARNINGS:                                                               *
    284  *      none.                                                              *
    285  *                                                                         *
    286  * HISTORY:                                                                *
    287  *   11/17/1994 BR : Created.                                              *
    288  *=========================================================================*/
    289 DirType Dial8Class::Get_Direction(void) const
    290 {
    291 	return(Direction);
    292 }
    293 
    294 
    295 /***************************************************************************
    296  * Dial8Class::Set_Direction -- sets current direction (0-255) of dial     *
    297  *                                                                         *
    298  * INPUT:                                                                  *
    299  *      DirType to set dial to                                             *
    300  *                                                                         *
    301  * OUTPUT:                                                                 *
    302  *      none.                                                              *
    303  *                                                                         *
    304  * WARNINGS:                                                               *
    305  *      none.                                                              *
    306  *                                                                         *
    307  * HISTORY:                                                                *
    308  *   11/17/1994 BR : Created.                                              *
    309  *=========================================================================*/
    310 void Dial8Class::Set_Direction(DirType dir)
    311 {
    312 	Direction = dir;
    313 	Facing = Dir_Facing(Direction);
    314 	OldFacing = Facing;
    315 	Flag_To_Redraw();
    316 }