CnC_Remastered_Collection

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

TEXTBTN.CPP (20681B)


      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/TEXTBTN.CPP 1     3/03/97 10:25a 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 : TEXTBTN.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  *   TextButtonClass::Draw_Background -- Draws the background to the text button.              *
     34  *   TextButtonClass::Draw_Me -- Draws the text buttons as indicated.                          *
     35  *   TextButtonClass::Draw_Text -- This draws the text for the text button.                    *
     36  *   TextButtonClass::Set_Text -- Assigns a new text string to this button.                    *
     37  *   TextButtonClass::Set_Text -- Sets the text for this text button.                          *
     38  *   TextButtonClass::TextButtonClass -- Normal constructor for a text button.                 *
     39  *   TextButtonClass::TextButtonClass -- Normal constructor for a text button.                 *
     40  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     41 
     42 #include	"function.h"
     43 #include "textbtn.h"
     44 
     45 
     46 /***********************************************************************************************
     47  * TextButtonClass::TextButtonClass -- Normal constructor for a text button.                   *
     48  *                                                                                             *
     49  *    This is the constructor for text buttons if the text is provided as a string pointer.    *
     50  *                                                                                             *
     51  * INPUT:   id    -- The ID number to assign to this button.                                   *
     52  *                                                                                             *
     53  *          text  -- Pointer to the text string to display on top of the button.               *
     54  *                                                                                             *
     55  *          x,y   -- Pixel coordinate of button's upper left corner.                           *
     56  *                                                                                             *
     57  *          w,h   -- Dimensions of the button. If these are not filled in (or with -1), then   *
     58  *                   the dimensions are adapted to fit the text assigned to the button.        *
     59  *                                                                                             *
     60  *          style -- The print style for the text in the button. These are the TPF_ flags      *
     61  *                   used by Fancy_Text_Print().                                               *
     62  *                                                                                             *
     63  *          border-- If the button is to be surrounded by a black border, then this flag       *
     64  *                   should be set to true.                                                    *
     65  *                                                                                             *
     66  * OUTPUT:   none                                                                              *
     67  *                                                                                             *
     68  * WARNINGS: Call Set_Text & Set_Style, & init X,Y,Width,Height,ID before using this button.	  *
     69  *                                                                                             *
     70  * HISTORY:  01/15/1995 JLB : Created.                                                         *
     71  *=============================================================================================*/
     72 TextButtonClass::TextButtonClass(unsigned id, char const * text, TextPrintType style, int x, int y, int w, int h, int blackborder) :
     73 	ToggleClass(id, x, y, w, h),
     74 	String(text)
     75 {
     76 	PrintFlags = style;
     77 	IsBlackBorder = blackborder;
     78 
     79 	if (w == -1 || h == -1) {
     80 		//PG_TO_FIX
     81 		//Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, PrintFlags);
     82 		if (w == -1) {
     83 			Width = String_Pixel_Width(String)+8;
     84 		}
     85 		if (h == -1) {
     86 			Height = FontHeight + FontYSpacing + 2;
     87 		}
     88 	}
     89 }
     90 
     91 
     92 /***********************************************************************************************
     93  * TextButtonClass::TextButtonClass -- Default constructor for a text button.                  *
     94  *                                                                                             *
     95  * INPUT:   none                                                                               *
     96  *                                                                                             *
     97  * OUTPUT:   none                                                                              *
     98  *                                                                                             *
     99  * WARNINGS: none                                                                              *
    100  *                                                                                             *
    101  * HISTORY:  01/15/1995 JLB : Created.                                                         *
    102  *=============================================================================================*/
    103 TextButtonClass::TextButtonClass(void) :
    104 	ToggleClass(0, 0, 0, 0, 0)
    105 {
    106 	IsBlackBorder = false;
    107 	String = NULL;
    108 	PrintFlags = TPF_8POINT;
    109 }
    110 
    111 
    112 /***********************************************************************************************
    113  * TextButtonClass::TextButtonClass -- Normal constructor for a text button.                   *
    114  *                                                                                             *
    115  *    This is the constructor for text buttons if the text is provided as a string pointer.    *
    116  *                                                                                             *
    117  * INPUT:   id    -- The ID number to assign to this button.                                   *
    118  *                                                                                             *
    119  *          text  -- The text number to use for displaying on top of the button.               *
    120  *                                                                                             *
    121  *          x,y   -- Pixel coordinate of button's upper left corner.                           *
    122  *                                                                                             *
    123  *          w,h   -- Dimensions of the button. If these are not filled in (or with -1), then   *
    124  *                   the dimensions are adapted to fit the text assigned to the button.        *
    125  *                                                                                             *
    126  *                                                                                             *
    127  *          style -- The print style for the text in the button. These are the TPF_ flags      *
    128  *                   used by Fancy_Text_Print().                                               *
    129  *                                                                                             *
    130  *          border-- If the button is to be surrounded by a black border, then this flag       *
    131  *                   should be set to true.                                                    *
    132  *                                                                                             *
    133  * OUTPUT:  none                                                                               *
    134  *                                                                                             *
    135  * WARNINGS:   none                                                                            *
    136  *                                                                                             *
    137  * HISTORY:                                                                                    *
    138  *   01/15/1995 JLB : Created.                                                                 *
    139  *=============================================================================================*/
    140 TextButtonClass::TextButtonClass (unsigned id, int text, TextPrintType style, int x, int y, int w, int h, int blackborder) :
    141 	ToggleClass (id, x, y, w, h),
    142 	String(0)
    143 {
    144 	PrintFlags = style;
    145 	IsBlackBorder = blackborder;
    146 	Set_Text(text);
    147 
    148 	if (w == -1 || h == -1) {
    149 		//PG_TO_FIX
    150 		//Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, PrintFlags);
    151 		if (w == -1) {
    152 			Width = String_Pixel_Width(String)+8;
    153 		}
    154 		if (h == -1) {
    155 			Height = FontHeight + FontYSpacing + 2;
    156 		}
    157 	}
    158 }
    159 
    160 
    161 /***********************************************************************************************
    162  * TextButtonClass::Draw_Me -- Draws the text buttons as indicated.                            *
    163  *                                                                                             *
    164  *    This routine will draw the text button.                                                  *
    165  *                                                                                             *
    166  * INPUT:   forced   -- If the button is to be redrawn regardless of the state of the redraw   *
    167  *                      flag, then this parameter will be true.                                *
    168  *                                                                                             *
    169  * OUTPUT:  bool; Was the button redrawn?                                                      *
    170  *                                                                                             *
    171  * WARNINGS:   none                                                                            *
    172  *                                                                                             *
    173  * HISTORY:                                                                                    *
    174  *   01/03/1995 MML : Created.                                                                 *
    175  *   01/16/1995 JLB : Modified                                                                 *
    176  *=============================================================================================*/
    177 int TextButtonClass::Draw_Me(int forced)
    178 {
    179 	if (ControlClass::Draw_Me(forced)) {
    180 		/*
    181 		**	Hide the mouse.
    182 		*/
    183 		if (LogicPage == &SeenBuff) {
    184 			Conditional_Hide_Mouse(X, Y, X+Width-1, Y+Height-1);
    185 		}
    186 
    187 		/*
    188 		**	Draw the background and overlaying text. These are virtual function
    189 		**	calls so that they may be overridden.
    190 		*/
    191 		Draw_Background();
    192 		Draw_Text(String);
    193 
    194 		/*
    195 		**	Display the mouse.
    196 		*/
    197 		if (LogicPage == &SeenBuff) {
    198 			Conditional_Show_Mouse();
    199 		}
    200 		return(true);
    201 	}
    202 	return(false);
    203 }
    204 
    205 
    206 /***********************************************************************************************
    207  * TextButtonClass::Set_Text -- Assigns a new text string to this button.                      *
    208  *                                                                                             *
    209  *    Use this routine to assign a new text string to this button. By using this function it   *
    210  *    is possible to dynamically change the button's text. An example of this would be an      *
    211  *    on/off button that every time it is clicked, the text toggles between "on" and "off".    *
    212  *                                                                                             *
    213  * INPUT:   text  -- Pointer to the text string to assign to this button.                      *
    214  *                                                                                             *
    215  * OUTPUT:  none                                                                               *
    216  *                                                                                             *
    217  * WARNINGS:   The text is NOT copied to this button. You must make sure that the text         *
    218  *             remains valid throughout the lifetime of this text button.                      *
    219  *                                                                                             *
    220  * HISTORY:                                                                                    *
    221  *   01/16/1995 JLB : Created.                                                                 *
    222  *=============================================================================================*/
    223 void TextButtonClass::Set_Text(char const * text, bool resize)
    224 {
    225 	String = text;
    226 	Flag_To_Redraw();
    227 	if (resize && String) {
    228 		//PG_TO_FIX
    229 		//Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, PrintFlags);
    230 		Width = String_Pixel_Width(String)+8;
    231 		Height = FontHeight + FontYSpacing + 2;
    232 	}
    233 }
    234 
    235 
    236 /***********************************************************************************************
    237  * TextButtonClass::Set_Text -- Sets the text for this text button.                            *
    238  *                                                                                             *
    239  *    This will set the text for this button. The text is provided as a text number. This      *
    240  *    number is automatically converted to the appropriate text string before being stored     *
    241  *    in the button's structure.                                                               *
    242  *                                                                                             *
    243  * INPUT:   text  -- The text number to assign to this button.                                 *
    244  *                                                                                             *
    245  * OUTPUT:  none                                                                               *
    246  *                                                                                             *
    247  * WARNINGS:   The text number information is lost when it is assigned to the button. Once     *
    248  *             the assignment takes place, the text number is NOT remembered by the button.    *
    249  *             Only the associated text string is.                                             *
    250  *                                                                                             *
    251  * HISTORY:                                                                                    *
    252  *   01/16/1995 JLB : Created.                                                                 *
    253  *=============================================================================================*/
    254 void TextButtonClass::Set_Text(int text, bool resize)
    255 {
    256 	if (text != TXT_NONE) {
    257 		Set_Text(Text_String(text), resize);
    258 	}
    259 }
    260 
    261 
    262 /***********************************************************************************************
    263  * TextButtonClass::Draw_Background -- Draws the background to the text button.                *
    264  *                                                                                             *
    265  *    This localizes the drawing of the background for the text button. By overriding this     *
    266  *    function you can give a different background to the button. The text is drawn using      *
    267  *    a different routine. The mouse is hidden, if necessary, before this routine is called.   *
    268  *                                                                                             *
    269  * INPUT:   none                                                                               *
    270  *                                                                                             *
    271  * OUTPUT:  none                                                                               *
    272  *                                                                                             *
    273  * WARNINGS:   none                                                                            *
    274  *                                                                                             *
    275  * HISTORY:                                                                                    *
    276  *   01/19/1995 JLB : Created.                                                                 *
    277  *=============================================================================================*/
    278 void TextButtonClass::Draw_Background(void)
    279 {
    280 	/*
    281 	**	Draw a border if selected style.
    282 	*/
    283 	if (IsBlackBorder) {
    284 		LogicPage->Draw_Rect (X-1, Y-1, X+Width+2, Y+Height+2, BLACK);
    285 	}
    286 
    287 	/*
    288 	**	Draw the body & set text color.
    289 	*/
    290 	BoxStyleEnum style;
    291 
    292 	if (IsDisabled) {
    293 #ifdef WOLAPI_INTEGRATION
    294 		style = BOXSTYLE_BOX;
    295 #else
    296 		style = BOXSTYLE_DIS_RAISED;
    297 #endif
    298 	} else {
    299 		if (IsPressed) {
    300 			style = BOXSTYLE_DOWN;
    301 		} else {
    302 			style = BOXSTYLE_RAISED;
    303 		}
    304 	}
    305 
    306 	Draw_Box(X, Y, Width, Height, style, true);
    307 }
    308 
    309 
    310 /***********************************************************************************************
    311  * TextButtonClass::Draw_Text -- This draws the text for the text button.                      *
    312  *                                                                                             *
    313  *    This routine draws the text for the text button. You can override this routine if you    *
    314  *    wish different text rendering styles or colors. The background has already been drawn    *
    315  *    by the time this function is called. The mouse is hidden, if necessary, as well.         *
    316  *                                                                                             *
    317  * INPUT:   text  -- Pointer to the text string to print over the button.                      *
    318  *                                                                                             *
    319  * OUTPUT:  none                                                                               *
    320  *                                                                                             *
    321  * WARNINGS:   none                                                                            *
    322  *                                                                                             *
    323  * HISTORY:                                                                                    *
    324  *   01/19/1995 JLB : Created.                                                                 *
    325  *=============================================================================================*/
    326 void TextButtonClass::Draw_Text(char const * text)
    327 {
    328 	RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
    329 
    330 	/*
    331 	**	Display the text.
    332 	*/
    333 	if (String) {
    334 		TextPrintType flags;
    335 
    336 		if (IsDisabled) {
    337 			flags = (TextPrintType)0;
    338 		} else {
    339 			if (IsPressed || IsOn) {
    340 				flags = TPF_USE_GRAD_PAL|TPF_BRIGHT_COLOR;
    341 			} else {
    342 				flags = TPF_USE_GRAD_PAL|TPF_MEDIUM_COLOR;
    343 			}
    344 		}
    345 
    346 		Fancy_Text_Print(text, X+(Width>>1)-1, Y+1, scheme, TBLACK, PrintFlags|flags|TPF_CENTER);
    347 	}
    348 }