CnC_Remastered_Collection

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

TEXTBTN.CPP (20876B)


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