-
Notifications
You must be signed in to change notification settings - Fork 0
/
textDX.h
91 lines (72 loc) · 2.67 KB
/
textDX.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
Group #: 3
Members: Chris Prosser, Jacob Gearhart, Kory Kappel, Andrew Miller
Course: COMP 322, Advanced Programming
Date: 28 October 2013
Description: This file is inherited from the skeleton
provided by Charles Kelly.
*/
// Programming 2D Games
// Copyright (c) 2011 by:
// Charles Kelly
// textDX.h v1.0
// DirectX font
#ifndef _TEXTDX_H // Prevent multiple definitions if this
#define _TEXTDX_H // file is included in more than one place
#define WIN32_LEAN_AND_MEAN
#include <string>
#include "constants.h"
#include "graphics.h"
class TextDX
{
private:
Graphics *graphics;
COLOR_ARGB color; // font color (a,r,g,b)
LP_DXFONT dxFont;
RECT fontRect; // text rectangle
// matrix to rotate the text
D3DXMATRIX matrix;
float angle; // rotation angle of text in radians
public:
// Constructor (sprite text)
TextDX();
// Destructor
virtual ~TextDX();
// Initialize font
// Pre: *g points to Graphics object
// height = height in pixels
// bold = true/false
// italic = true/false
// &fontName = name of font to use
virtual bool initialize(Graphics *g, int height, bool bold, bool italic, const std::string &fontName);
// Print at x,y. Call between spriteBegin()/spriteEnd()
// Return 0 on fail, height of text on success
// Pre: &str contains text to display
// x, y = screen location
virtual int print(const std::string &str, int x, int y);
// Print inside rect using format. Call between spriteBegin()/spriteEnd()
// Return 0 on fail, height of text on success
// Pre: &str = text to display
// &rect = rectangular region
// format = format specifier
virtual int print(const std::string &str, RECT &rect, UINT format);
// Return rotation angle in degrees.
virtual float getDegrees() {return angle*(180.0f/(float)PI);}
// Return rotation angle in radians.
virtual float getRadians() {return angle;}
// Returns font color
virtual COLOR_ARGB getFontColor() {return color;}
// Set rotation angle in degrees.
// 0 degrees is up. Angles progress clockwise.
virtual void setDegrees(float deg) {angle = deg*((float)PI/180.0f);}
// Set rotation angle in radians.
// 0 radians is up. Angles progress clockwise.
virtual void setRadians(float rad) {angle = rad;}
// Set the font color. Use SETCOLOR_ARGB macro or colors from graphicsNS::
virtual void setFontColor(COLOR_ARGB c) {color = c;}
// Release resources
virtual void onLostDevice();
// Restore resources
virtual void onResetDevice();
};
#endif