CnC_Remastered_Collection

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

SHAPEBTN.CPP (9093B)


      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\shapebtn.cpv   2.17   16 Oct 1995 16:52:00   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 : SHAPEBTN.CPP                                                 *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : 01/15/95                                                     *
     28  *                                                                                             *
     29  *                  Last Update : January 15, 1995 [JLB]                                       *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  *   ShapeButtonClass::ShapeButtonClass -- Constructor for a shape type button.                *
     34  *   ShapeButtonClass::Draw_Me -- Renders the shape button's imagery.                          *
     35  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     36 
     37 #include	"function.h"
     38 #include "shapebtn.h"
     39 
     40 
     41 /***********************************************************************************************
     42  * ShapeButtonClass::ShapeButtonClass -- Default Constructor for a shape type button.          *
     43  *                                                                                             *
     44  * INPUT:   none                                                                               *
     45  *                                                                                             *
     46  * OUTPUT:  none                                                                               *
     47  *                                                                                             *
     48  * WARNINGS:   You must call Set_Shape() before using a button constructed with this function, *
     49  *             and you must set X & Y, and ID.                                                 *
     50  *                                                                                             *
     51  * HISTORY:                                                                                    *
     52  *   01/15/1995 JLB : Created.                                                                 *
     53  *=============================================================================================*/
     54 ShapeButtonClass::ShapeButtonClass(void) :
     55 	ToggleClass(0, 0, 0, 0, 0)
     56 {
     57 	ReflectButtonState = false;
     58 }
     59 
     60 
     61 /***********************************************************************************************
     62  * ShapeButtonClass::ShapeButtonClass -- Constructor for a shape type button.                  *
     63  *                                                                                             *
     64  *    This is the normal constructor for a shape type button. Shape buttons are ones that      *
     65  *    have their imagery controlled by a shape file. The various states of the button are      *
     66  *    given a visual form as one of these shapes. Button dimensions are controlled by the      *
     67  *    first shape.                                                                             *
     68  *                                                                                             *
     69  * INPUT:   id    -- The button ID.                                                            *
     70  *                                                                                             *
     71  *          shape -- Pointer to the shape file that controls the button's display.             *
     72  *                                                                                             *
     73  *          x,y   -- The pixel coordinate of the upper left corner of the button.              *
     74  *                                                                                             *
     75  * OUTPUT:  none                                                                               *
     76  *                                                                                             *
     77  * WARNINGS:   The width and height of the shape is controlled by the first shape in the       *
     78  *             shape file provided. This means that all the shapes in the shape file must be   *
     79  *             the same size.                                                                  *
     80  *                                                                                             *
     81  * HISTORY:                                                                                    *
     82  *   01/15/1995 JLB : Created.                                                                 *
     83  *=============================================================================================*/
     84 ShapeButtonClass::ShapeButtonClass(unsigned id, void const * shape, int x, int y) :
     85 	ToggleClass(id, x, y, 0, 0)
     86 {
     87 	Width = 0;
     88 	Height = 0;
     89 	ReflectButtonState = false;
     90 	Set_Shape(shape);
     91 }
     92 
     93 
     94 void ShapeButtonClass::Set_Shape(void const * data)
     95 {
     96 	ShapeData = data;
     97 	if (ShapeData) {
     98 		Width = Get_Build_Frame_Width(ShapeData);
     99 		Height = Get_Build_Frame_Height(ShapeData);
    100 	}
    101 }
    102 
    103 
    104 /***********************************************************************************************
    105  * ShapeButtonClass::Draw_Me -- Renders the shape button's imagery.                            *
    106  *                                                                                             *
    107  *    This function is called when the button detects that it must be redrawn. The actual      *
    108  *    shape to use is controled by the button's state and the shape file provided when then    *
    109  *    button was constructed.                                                                  *
    110  *                                                                                             *
    111  * INPUT:   forced   -- Should the button be redrawn regardless of the redraw flag?            *
    112  *                                                                                             *
    113  * OUTPUT:  bool; Was the shape redrawn?                                                       *
    114  *                                                                                             *
    115  * WARNINGS:   none                                                                            *
    116  *                                                                                             *
    117  * HISTORY:                                                                                    *
    118  *   01/15/1995 JLB : Created.                                                                 *
    119  *=============================================================================================*/
    120 int ShapeButtonClass::Draw_Me(int forced)
    121 {
    122 	if (ControlClass::Draw_Me(forced) && ShapeData) {
    123 
    124 		/*
    125 		**	Hide the mouse.
    126 		*/
    127 		if (LogicPage == &SeenBuff) {
    128 			Conditional_Hide_Mouse(X, Y, X+Width-1, Y+Height-1);
    129 		}
    130 
    131 		/*
    132 		**	Draw the body & set text color.
    133 		*/
    134 		int shapenum = 0;
    135 		if (IsDisabled) {
    136 			shapenum = DISABLED_SHAPE;
    137 		} else {
    138 
    139 			if (!ReflectButtonState){
    140 				if (IsPressed) {
    141 					shapenum = DOWN_SHAPE;
    142 				} else {
    143 					shapenum = UP_SHAPE;
    144 				}
    145 			}else{
    146 				shapenum = IsOn;
    147 			}
    148 		}
    149 		CC_Draw_Shape(ShapeData, shapenum, X, Y, WINDOW_MAIN, SHAPE_NORMAL);
    150 
    151 		/*
    152 		**	Display the mouse.
    153 		*/
    154 		if (LogicPage == &SeenBuff) {
    155 			Conditional_Show_Mouse();
    156 		}
    157 		return(true);
    158 	}
    159 	return(false);
    160 }
    161 
    162 
    163