This repository has been archived by the owner on Apr 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
201 lines (180 loc) · 5.72 KB
/
main.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include <Windows.h>
#include "Painter.h"
#pragma comment(lib, "Msimg32.lib")
namespace paint{
/*
Draws a single Bitmap into hDC, 1:1 stretch.
hDC: Drawing DC,
fX: x-Pos,
fY: y-Pos,
fWidth: x-Dimensions,
fWidth: y-Dimensions,
hbm: Handle of Bitmap,
bm: Loaded Bitmap,
clrAlphaChannel: Which color should be transparent;
*/
void drawTile(HDC hDC, float fX, float fY, float fWidth, float fHeight, HBITMAP hbm, BITMAP bm, COLORREF clrAlphaChannel){
HDC hdcMem = CreateCompatibleDC(hDC);
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hbm);
GetObject(hbm, sizeof(bm), &bm);
TransparentBlt(hDC, (int)fX, (int)fY, (int)fWidth, (int)fHeight, hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, clrAlphaChannel);
//BitBlt(hDC, _x, _y, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
}
/*
Draws a single Bitmap into hDC, includes scaling.
hDC: Drawing DC,
fX: x-Pos,
fY: y-Pos,
fWidth: x-Dimensions,
fWidth: y-Dimensions,
hbm: Handle of Bitmap,
bm: Loaded Bitmap,
fInBitmap... = part of Bitmap rectangle.
clrAlphaChannel: Which color should be transparent;
*/
void drawTileEx(HDC hDC, float fX, float fY, float fWidth, float fHeight, float fInbitmapX, float fInBitmapY, float fInBitmapWidth, float fInBitmapHeight, HBITMAP hbm, BITMAP bm, COLORREF clrAlphaChannel){
HDC hdcMem = CreateCompatibleDC(hDC);
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hbm);
GetObject(hbm, sizeof(bm), &bm);
TransparentBlt(hDC, (int)fX, (int)fY, (int)fWidth, (int)fHeight, hdcMem, fInbitmapX, fInBitmapY, fInBitmapWidth, fInBitmapHeight, clrAlphaChannel);
//BitBlt(hDC, _x, _y, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
}
/* DOESN'T WORK YET !!!!
hDC: Drawing DC,
HWND: Your Window-Handle. (in console: GetConsoleWindow())
YourPaintMethod: your personal paint-method:
f. ex.:
#include <Windows.h>
void paint(){
HWND hWnd = GetConsoleWindow();
HDC hDC = GetDC(hWnd);
//Do sth here like DrawFancyShit(hDC, x, y);
ReleaseDC(hWnd, hDC);
}
-> use DoubleBuffer(GetConsoleWindow(), paint); instead of your pure paint();
=> paint() fills a paint buffer and split surface.
*/
void doubleBuffer(HWND hWnd, void(*YourPaintMethod)()){
HDC hDC = GetDC(hWnd);
RECT recWindow;
GetWindowRect(hWnd, &recWindow);
HBITMAP hBitmapBuffer = CreateCompatibleBitmap(hDC, recWindow.right, recWindow.bottom);
HDC hDCMem = CreateCompatibleDC(hDC);
SelectObject(hDCMem, hBitmapBuffer);//Init Buffer als Bitmap
//Hier beginnst du das malen! Du musst aber in das BufferDC schreiben!! -> hDCMem
{
//PAINT
YourPaintMethod();
//WICHTIG!! Falls du einen Kreis malst und verschiedene Brushes initialisierst, musst du die am ende wieder löschen!!
//Sonst hast du das Problem dass wenn du was malst die GDI-Objekte-Heaps voll sind und du somit nur noch weiße RECTS bzw Ellipsen, etc malen kannst...
}
//Ende vom malen!
BitBlt(hDC, 0, 0, recWindow.right, recWindow.bottom, hDCMem, 0, 0, SRCCOPY);//Ganzer Buffer hDCMem ausgeben
DeleteDC(hDCMem);
DeleteObject(hBitmapBuffer);
}
/*
MessageBox:
TYPE: MB_...
Declared in "Windows.h"
MB_DEFBUTTON1 LAYOUT !!!
*/
int msgBox(char * CAPTION, char * TEXT, int TYPE){
return MessageBoxA(NULL, TEXT, CAPTION, TYPE | MB_DEFBUTTON1);
}
}
////////////////////////////////////////////////////////////////////////CONSOLEEXTRA
namespace console{
namespace chars{
namespace uml{
const char cauml = '„';
const char cAuml = 'Ž';
const char cuuml = '';
const char cUuml = 'š';
const char couml = '”';
const char cOuml = '™';
const char csharps = 'á';
}
namespace border_single{
const char cLeftUpperCorner = 'Ú';
const char cLeftMiddleCorner = 'Ã';
const char cLeftLowerCorner = 'Ù';
const char cVerticalLine = '³';
const char cHorizontalLine = 'Ä';
const char cRightUpperCorner = 'Ú';
const char cRightMiddleCorner = '´';
const char cRightLowerCorner = 'Ù';
const char cUpperMiddleCorner = 'Â';
const char cLowerMiddleCorner = 'Á';
const char cCenterCross = 'Å';
}
namespace border_double{
const char cLeftUpperCorner = 'É';
const char cLeftMiddleCorner = 'Ì';
const char cLeftLowerCorner = 'È';
const char cVerticalLine = 'º';
const char cHorizontalLine = 'Í';
const char cRightUpperCorner = '»';
const char cRightMiddleCorner = '¹';
const char cRightLowerCorner = '¼';
const char cUpperMiddleCorner = 'Ë';
const char cLowerMiddleCorner = 'Ê';
const char cCenterCross = 'Î';
}
namespace block{
const char cBlockDensity0 = ' ';
const char cBlockDensity1 = '°';
const char cBlockDensity2 = '±';
const char cBlockDensity3 = '²';
const char cBlockDensity4 = 'Û';
const char cUpperHalfBlock = 'Ü';
const char cLowerHalfBlock = 'ß';
}
}
/*
COLORRANGE: HEX: 0x00 to 0xFF
First digit: Backgroundcolor
Last digit: Foregroundcolor
f.ex: 0x0A == black-green (typical matrix style)
*/
void color(int iColor){
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hCon, iColor);
}
/*
Hide Caret (visible(true)/invisible(false))
*/
void caretVisibility(bool bVisible){
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cocuInfo;
cocuInfo.dwSize = 10;
if (bVisible)
cocuInfo.bVisible = 1;
else
cocuInfo.bVisible = 0;
SetConsoleCursorInfo(hCon, &cocuInfo);
}
/*
Move Cursor to (x|y)
*/
void gotoxy(int x, int y){
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
COORD co = { x, y };
SetConsoleCursorPosition(hCon, co);
}
/*
Set Title of Console.
*/
void title(char * TITLE){
SetConsoleTitleA(TITLE);
}
}
//////////////////////////////////////////////////////////////////////////////////TESTAREA
int main(){
char x = Painter::console::chars::uml::cauml;
return 0;
}