CnC_Remastered_Collection

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

DIAL8.CPP (13225B)


      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\dial8.cpv   2.18   16 Oct 1995 16:51:32   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 : Bill Randolph                            *
     26  *                                                                         *
     27  *                   Start Date : February 6, 1995                         *
     28  *                                                                         *
     29  *                  Last Update : February 6, 1995   [BR]                  *
     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 substitues
    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 	/*
    233 	**	Redraw if parent indicates a redraw is needed
    234 	*/
    235 	if (ControlClass::Draw_Me(forced)) {
    236 		/*
    237 		**	Hide the mouse.
    238 		*/
    239 
    240 		if (LogicPage == &SeenBuff) {
    241 			Hide_Mouse();
    242 		}
    243 
    244 		/*
    245 		**	Draw background & decorations.
    246 		*/
    247 		Draw_Box(X, Y, Width, Height, BOXSTYLE_GREEN_DOWN, true);
    248 		for (int i=0; i<8; i++) {
    249 			Draw_Box(FacePoint[i][0] - 1, FacePoint[i][1] -1, 3, 3, BOXSTYLE_GREEN_RAISED, false);
    250 		}
    251 
    252 		/*
    253 		**	Draw the hand & its shadow.
    254 		*/
    255 		LogicPage->Draw_Line(FaceX+1, FaceY+1, FaceLine[Facing][0]+1, FaceLine[Facing][1]+1,CC_GREEN_SHADOW);
    256 		LogicPage->Draw_Line(FaceX, FaceY, FaceLine[Facing][0], FaceLine[Facing][1],CC_LIGHT_GREEN);
    257 
    258 		/*
    259 		**	Restore the mouse.
    260 		*/
    261 		if (LogicPage == &SeenBuff) {
    262 			Show_Mouse();
    263 		}
    264 
    265 		return(true);
    266 	}
    267 
    268 	return(false);
    269 }
    270 
    271 
    272 /***************************************************************************
    273  * Dial8Class::Get_Direction -- retrieves direction (0-255) of dial        *
    274  *                                                                         *
    275  * INPUT:                                                                  *
    276  *      none.                                                              *
    277  *                                                                         *
    278  * OUTPUT:                                                                 *
    279  *      DirType dial is pointing to                                        *
    280  *                                                                         *
    281  * WARNINGS:                                                               *
    282  *      none.                                                              *
    283  *                                                                         *
    284  * HISTORY:                                                                *
    285  *   11/17/1994 BR : Created.                                              *
    286  *=========================================================================*/
    287 DirType Dial8Class::Get_Direction(void) const
    288 {
    289 	return(Direction);
    290 }
    291 
    292 
    293 /***************************************************************************
    294  * Dial8Class::Set_Direction -- sets current direction (0-255) of dial     *
    295  *                                                                         *
    296  * INPUT:                                                                  *
    297  *      DirType to set dial to                                             *
    298  *                                                                         *
    299  * OUTPUT:                                                                 *
    300  *      none.                                                              *
    301  *                                                                         *
    302  * WARNINGS:                                                               *
    303  *      none.                                                              *
    304  *                                                                         *
    305  * HISTORY:                                                                *
    306  *   11/17/1994 BR : Created.                                              *
    307  *=========================================================================*/
    308 void Dial8Class::Set_Direction(DirType dir)
    309 {
    310 	Direction = dir;
    311 	Facing = Dir_Facing(Direction);
    312 	OldFacing = Facing;
    313 	Flag_To_Redraw();
    314 }