DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

DeviceContext.h (6184B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code.  If not, please request a copy in writing from id Software at the address below.
     23 
     24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
     25 
     26 ===========================================================================
     27 */
     28 
     29 #ifndef __DEVICECONTEXT_H__
     30 #define __DEVICECONTEXT_H__
     31 
     32 // device context support for gui stuff
     33 //
     34 
     35 #include "Rectangle.h"
     36 #include "../renderer/Font.h"
     37 
     38 const int VIRTUAL_WIDTH = 640;
     39 const int VIRTUAL_HEIGHT = 480;
     40 const int BLINK_DIVISOR = 200;
     41 
     42 class idDeviceContext {
     43 public:
     44 	idDeviceContext();
     45 	~idDeviceContext() { }
     46 	
     47 	void				Init();
     48 	void				Shutdown();
     49 	bool				Initialized() { return initialized; }
     50 	void				EnableLocalization();
     51 
     52 	void				GetTransformInfo(idVec3& origin, idMat3& mat );
     53 
     54 	void				SetTransformInfo(const idVec3 &origin, const idMat3 &mat);
     55 	void				DrawMaterial(float x, float y, float w, float h, const idMaterial *mat, const idVec4 &color, float scalex = 1.0, float scaley = 1.0);
     56 	void				DrawRect(float x, float y, float width, float height, float size, const idVec4 &color);
     57 	void				DrawFilledRect(float x, float y, float width, float height, const idVec4 &color);
     58 	int					DrawText(const char *text, float textScale, int textAlign, idVec4 color, idRectangle rectDraw, bool wrap, int cursor = -1, bool calcOnly = false, idList<int> *breaks = NULL, int limit = 0 );
     59 	void				DrawMaterialRect( float x, float y, float w, float h, float size, const idMaterial *mat, const idVec4 &color);
     60 	void				DrawStretchPic(float x, float y, float w, float h, float s0, float t0, float s1, float t1, const idMaterial *mat);
     61 	void				DrawMaterialRotated(float x, float y, float w, float h, const idMaterial *mat, const idVec4 &color, float scalex = 1.0, float scaley = 1.0, float angle = 0.0f);
     62 	void				DrawStretchPicRotated(float x, float y, float w, float h, float s0, float t0, float s1, float t1, const idMaterial *mat, float angle = 0.0f);
     63 	void				DrawWinding( idWinding & w, const idMaterial * mat );
     64 
     65 	int					CharWidth( const char c, float scale );
     66 	int					TextWidth(const char *text, float scale, int limit);
     67 	int					TextHeight(const char *text, float scale, int limit);
     68 	int					MaxCharHeight(float scale);
     69 	int					MaxCharWidth(float scale);
     70 
     71 	idRegion *			GetTextRegion(const char *text, float textScale, idRectangle rectDraw, float xStart, float yStart);
     72 
     73 	void				SetSize( float width, float height );
     74 	void				SetOffset( float x, float y );
     75 
     76 	const idMaterial *	GetScrollBarImage(int index);
     77 
     78 	void				DrawCursor(float *x, float *y, float size);
     79 	void				SetCursor(int n);
     80 
     81 	// clipping rects
     82 	virtual bool		ClippedCoords(float *x, float *y, float *w, float *h, float *s1, float *t1, float *s2, float *t2);
     83 	virtual void		PushClipRect(idRectangle r);
     84 	virtual void		PopClipRect();
     85 	virtual void		EnableClipping(bool b);
     86 
     87 	void				SetFont( idFont * font ) { activeFont = font; }
     88 
     89 	void				SetOverStrike(bool b) { overStrikeMode = b; }
     90 
     91 	bool				GetOverStrike() { return overStrikeMode; }
     92 
     93 	void				DrawEditCursor(float x, float y, float scale);
     94 
     95 	enum {
     96 		CURSOR_ARROW,
     97 		CURSOR_HAND,
     98 		CURSOR_HAND_JOY1,
     99 		CURSOR_HAND_JOY2,
    100 		CURSOR_HAND_JOY3,
    101 		CURSOR_HAND_JOY4,
    102 		CURSOR_COUNT
    103 	};
    104 
    105 	enum {
    106 		ALIGN_LEFT,
    107 		ALIGN_CENTER,
    108 		ALIGN_RIGHT
    109 	};
    110 
    111 	enum {
    112 		SCROLLBAR_HBACK,
    113 		SCROLLBAR_VBACK,
    114 		SCROLLBAR_THUMB,
    115 		SCROLLBAR_RIGHT,
    116 		SCROLLBAR_LEFT,
    117 		SCROLLBAR_UP,
    118 		SCROLLBAR_DOWN,
    119 		SCROLLBAR_COUNT
    120 	};
    121 
    122 	static idVec4 colorPurple;
    123 	static idVec4 colorOrange;
    124 	static idVec4 colorYellow;
    125 	static idVec4 colorGreen;
    126 	static idVec4 colorBlue;
    127 	static idVec4 colorRed;
    128 	static idVec4 colorWhite;
    129 	static idVec4 colorBlack;
    130 	static idVec4 colorNone;
    131 
    132 protected:
    133 	virtual int			DrawText( float x, float y, float scale, idVec4 color, const char *text, float adjust, int limit, int style, int cursor = -1);
    134 	void				PaintChar( float x, float y, const scaledGlyphInfo_t & glyphInfo );
    135 	void				Clear();
    136 
    137 	const idMaterial *	cursorImages[CURSOR_COUNT];
    138 	const idMaterial *	scrollBarImages[SCROLLBAR_COUNT];
    139 	const idMaterial *	whiteImage;
    140 	idFont *			activeFont;
    141 
    142 	float				xScale;
    143 	float				yScale;
    144 	float				xOffset;
    145 	float				yOffset;
    146 
    147 	int					cursor;
    148 
    149 	idList<idRectangle>	clipRects;
    150 
    151 	bool				enableClipping;
    152 
    153 	bool				overStrikeMode;
    154 
    155 	idMat3				mat;
    156 	bool				matIsIdentity;
    157 	idVec3				origin;
    158 	bool				initialized;
    159 };
    160 
    161 class idDeviceContextOptimized : public idDeviceContext {
    162 
    163 	virtual bool		ClippedCoords(float *x, float *y, float *w, float *h, float *s1, float *t1, float *s2, float *t2);
    164 	virtual void		PushClipRect(idRectangle r);
    165 	virtual void		PopClipRect();
    166 	virtual void		EnableClipping(bool b);
    167 
    168 	virtual int			DrawText( float x, float y, float scale, idVec4 color, const char *text, float adjust, int limit, int style, int cursor = -1);
    169 
    170 	float				clipX1;
    171 	float				clipX2;
    172 	float				clipY1;
    173 	float				clipY2;
    174 };
    175 
    176 #endif /* !__DEVICECONTEXT_H__ */