-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmygraphics.cpp
More file actions
115 lines (93 loc) · 3.33 KB
/
mygraphics.cpp
File metadata and controls
115 lines (93 loc) · 3.33 KB
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
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void myLine(int x1, int y1, int x2, int y2,COLORREF lineColor)
{
HWND console_handle = GetConsoleWindow();
HDC device_context = GetDC(console_handle);
//change the color by changing the values in RGB (from 0-255)
HPEN pen =CreatePen(PS_SOLID,2,lineColor); //2 is the width of the pen
SelectObject(device_context,pen);
MoveToEx(device_context,x1,y1,NULL);
LineTo(device_context,x2, y2);
DeleteObject(pen);
ReleaseDC(console_handle, device_context);
}
void myRect(int x1, int y1, int x2, int y2,COLORREF lineColor,COLORREF fillColor)
{
HWND console_handle = GetConsoleWindow();
HDC device_context = GetDC(console_handle);
//change the color by changing the values in RGB (from 0-255)
HPEN pen =CreatePen(PS_SOLID,2,lineColor);
SelectObject(device_context,pen);
HBRUSH brush = ::CreateSolidBrush(fillColor);
SelectObject(device_context,brush);
Rectangle(device_context,x1,y1,x2,y2);
DeleteObject(pen);
DeleteObject(brush);
ReleaseDC(console_handle, device_context);
}
void myEllipse(int x1, int y1, int x2, int y2,COLORREF lineColor,COLORREF fillColor)
{
HWND console_handle = GetConsoleWindow();
HDC device_context = GetDC(console_handle);
//change the color by changing the values in RGB (from 0-255)
HPEN pen =CreatePen(PS_SOLID,2,lineColor);
SelectObject(device_context,pen);
HBRUSH brush = ::CreateSolidBrush(fillColor);
SelectObject(device_context,brush);
Ellipse(device_context,x1,y1,x2,y2);
DeleteObject(pen);
DeleteObject(brush);
ReleaseDC(console_handle, device_context);
}
void myDrawText(int x,int y,int ht,char str[],COLORREF lineColor,COLORREF fillColor)
{
WCHAR wstr[20]={};
for (int i=0;i<20&&str[i];++i)
wstr[i] = str[i];
RECT rects;
rects.left = x;
rects.top = y;
rects.right = x+ht;
rects.bottom = y+ht;//(x,y,x+ht,y+ht);
HWND console_handle = GetConsoleWindow();
HDC device_context = GetDC(console_handle);
SetTextColor(device_context,lineColor);
SetBkColor(device_context,fillColor);
DrawText(device_context,str,-1,&rects,DT_TOP|DT_NOCLIP);
ReleaseDC(console_handle, device_context);
}
void myDrawTextWithFont(int x,int y,int ht,char str[],COLORREF lineColor,COLORREF fillColor)
{
WCHAR wstr[20]={};
for (int i=0;i<20&&str[i];++i)
wstr[i] = str[i];
RECT rects;
HFONT hFont;
rects.left = x;
rects.top = y;
rects.right = x+ht;
rects.bottom = y+ht;//(x,y,x+ht,y+ht);
HWND console_handle = GetConsoleWindow();
HDC device_context = GetDC(console_handle);
hFont = CreateFont(ht,0,0,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS,1, VARIABLE_PITCH,TEXT("Impact"));
SelectObject(device_context, hFont);
SetTextColor(device_context,lineColor);
SetBkColor(device_context,fillColor);
DrawText(device_context,str,-1,&rects,DT_TOP|DT_NOCLIP);
DeleteObject(hFont);
ReleaseDC(console_handle, device_context);
}
void mySetPixel(float x,float y,COLORREF colorVal)
{
HWND console_handle = GetConsoleWindow();
HDC device_context = GetDC(console_handle);
SetPixel(device_context,x,y,colorVal);
ReleaseDC(console_handle,device_context);
}