forked from ClemensLode/Wars
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathText.cpp
118 lines (94 loc) · 3.08 KB
/
Text.cpp
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "engine.h"
#include <string.h>
#include <math.h>
int tR,bR;
int tG,bG;
int tB,bB;
BOOL Engine_Graphics::WriteS(IDirectDrawSurface *Oberflaeche,int x,int y,char *txt,BOOL Transparent)
{
if (FAILED(Oberflaeche->GetDC(&info.hdc)))
{
return Fail("Engine::WriteS = GetDC");
}
SetBkColor( info.hdc, RGB( bR, bG, bB ) );
SetTextColor( info.hdc, RGB( tR, tG, tB ) );
SetTextAlign( info.hdc, TA_CENTER );
if (Transparent)
{
SetBkMode(info.hdc,TRANSPARENT);
}
SelectObject(info.hdc,CreateFont(fntname,0,0,150,TRUE));
TextOut( info.hdc, x, y, txt, lstrlen( txt ) );
if (FAILED(Oberflaeche->ReleaseDC( info.hdc )))
{
return Fail("Engine::WriteS = ReleaseDC");
}
return TRUE;
}
void Engine_Graphics::WriteSquick(IDirectDrawSurface *Oberflaeche,int x,int y,char *txt)
{
Oberflaeche->GetDC(&info.hdc );
SetTextColor(info.hdc ,RGB(tR,tG,tB));
SetBkMode(info.hdc,TRANSPARENT);
TextOut( info.hdc , x, y, txt, lstrlen( txt ) );
Oberflaeche->ReleaseDC( info.hdc );
}
HFONT Engine_Graphics::CreateFont (char * szFaceName, int iDeciPtHeight,
int iDeciPtWidth, int iAttributes, BOOL fLogRes)
{
FLOAT cxDpi, cyDpi ;
HFONT hFont ;
LOGFONT lf ;
POINT pt ;
TEXTMETRIC tm ;
SaveDC (info.hdc) ;
SetGraphicsMode (info.hdc, GM_ADVANCED) ;
ModifyWorldTransform (info.hdc, NULL, MWT_IDENTITY) ;
SetViewportOrgEx (info.hdc, 0, 0, NULL) ;
SetWindowOrgEx (info.hdc, 0, 0, NULL) ;
if (fLogRes)
{
cxDpi = (FLOAT) GetDeviceCaps (info.hdc, LOGPIXELSX) ;
cyDpi = (FLOAT) GetDeviceCaps (info.hdc, LOGPIXELSY) ;
}
else
{
cxDpi = (FLOAT) (25.4 * GetDeviceCaps (info.hdc , HORZRES) /
GetDeviceCaps (info.hdc , HORZSIZE)) ;
cyDpi = (FLOAT) (25.4 * GetDeviceCaps (info.hdc , VERTRES) /
GetDeviceCaps (info.hdc , VERTSIZE)) ;
}
pt.x = (int) (iDeciPtWidth * cxDpi / 72) ;
pt.y = (int) (iDeciPtHeight * cyDpi / 72) ;
DPtoLP (info.hdc, &pt, 1) ;
lf.lfHeight = - (int) (fabs (pt.y) / 10.0 + 0.5) ;
lf.lfWidth = 0 ;
lf.lfEscapement = 0 ;
lf.lfOrientation = 0 ;
lf.lfWeight = 0 ;
lf.lfItalic = 0 ;
lf.lfUnderline = 0 ;
lf.lfStrikeOut = 0 ;
lf.lfCharSet = 0 ;
lf.lfOutPrecision = 0 ;
lf.lfClipPrecision = 0 ;
lf.lfQuality = 0 ;
lf.lfPitchAndFamily = 0 ;
strcpy (lf.lfFaceName, szFaceName) ;
hFont = CreateFontIndirect (&lf) ;
if (iDeciPtWidth != 0)
{
hFont = (HFONT) SelectObject (info.hdc, hFont) ;
GetTextMetrics (info.hdc, &tm) ;
DeleteObject (SelectObject (info.hdc, hFont)) ;
lf.lfWidth = (int) (tm.tmAveCharWidth *
fabs (pt.x) / fabs (pt.y) + 0.5) ;
hFont = CreateFontIndirect (&lf) ;
}
RestoreDC (info.hdc, -1) ;
return hFont ;
}
void Engine_Graphics::SetFontName(char*Fontname)
{
fntname = Fontname;
}