Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef GRAPHICS_H
- #define GRAPHICS_H
- #include <iostream>
- #include <math.h>
- #include <windows.h>
- #include <Windows.h>
- using namespace std;
- HPEN getPen(int iPEN_STYLE, int iPEN_SIZE, int iCOLORREF);
- BOOL SetPoint(HDC hDC, HPEN hPen, COORD PNT);
- BOOL PlotLine(HDC hDC, HPEN hPen, COORD BGN, COORD END);
- BOOL PlotRect(HDC hDC, HPEN hPen, COORD BGN, COORD END);
- BOOL PlotCirc(HDC hDC, HPEN hPen, COORD BGN, COORD END);
- COORD setCordScale(COORD POS, RECT pRECT);
- HDC hDC;
- HPEN PEN;
- HANDLE StdOut;
- WORD COLOR;
- COORD BGN, POS;
- short mov;
- short movx;
- void initgraph(void)
- {
- system("cls");
- mov = 30;
- movx = 0;
- HWND hWnd = GetForegroundWindow();
- RECT pRECT = { 0 };
- COORD POS1 = { 0 };
- COORD BGN1 = setCordScale(POS1, pRECT);
- GetWindowRect(hWnd, &pRECT);
- hDC = GetWindowDC(hWnd);
- PEN = getPen(PS_SOLID, 2, RGB(255, 255, 255));
- StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- }
- void changey(int value) { if (value>-1000 & value <1000) mov = (short)value; }
- void changex(int value) { if (value>-1000 & value <1000) movx = (short)value; }
- int getmaxx(void) { return 640; }
- int getmaxy(void) { return 300; }
- void setcolorRGB(int r, int g, int b)
- {
- PEN = getPen(PS_SOLID, 2, RGB(r, g, b));
- }
- void setcolor(int color)
- {
- if (color < 0) color = -color;
- if (color > 15) color %= 16;
- switch (color)
- {
- case 0: PEN = getPen(PS_SOLID, 2, RGB(0, 0, 0)); break;
- case 1: PEN = getPen(PS_SOLID, 2, RGB(0, 0, 128)); break;
- case 2: PEN = getPen(PS_SOLID, 2, RGB(0, 128, 0)); break;
- case 3: PEN = getPen(PS_SOLID, 2, RGB(128, 0, 0)); break;
- case 4: PEN = getPen(PS_SOLID, 2, RGB(0, 128, 128)); break;
- case 5: PEN = getPen(PS_SOLID, 2, RGB(128, 0, 128)); break;
- case 6: PEN = getPen(PS_SOLID, 2, RGB(128, 128, 0)); break;
- case 7: PEN = getPen(PS_SOLID, 2, RGB(0, 0, 255)); break;
- case 8: PEN = getPen(PS_SOLID, 2, RGB(0, 255, 0)); break;
- case 9: PEN = getPen(PS_SOLID, 2, RGB(255, 0, 0)); break;
- case 10: PEN = getPen(PS_SOLID, 2, RGB(0, 255, 255)); break;
- case 11: PEN = getPen(PS_SOLID, 2, RGB(255, 0, 255)); break;
- case 12: PEN = getPen(PS_SOLID, 2, RGB(255, 255, 0)); break;
- case 13: PEN = getPen(PS_SOLID, 2, RGB(192, 192, 192)); break;
- case 14: PEN = getPen(PS_SOLID, 2, RGB(192, 192, 192)); break;
- case 15: PEN = getPen(PS_SOLID, 2, RGB(255, 255, 255)); break;
- }
- }
- void setfontcolor(int color)
- {
- if (color < 0) color = -color;
- if (color > 15) color %= 16;
- switch (color)
- {
- case 0: COLOR = (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); COLOR = COMMON_LVB_REVERSE_VIDEO; break;
- case 1: COLOR = (FOREGROUND_BLUE); break;
- case 2: COLOR = (FOREGROUND_GREEN); break;
- case 3: COLOR = (FOREGROUND_RED); break;
- case 4: COLOR = (FOREGROUND_BLUE | FOREGROUND_GREEN); break;
- case 5: COLOR = (FOREGROUND_BLUE | FOREGROUND_RED); break;
- case 6: COLOR = (FOREGROUND_GREEN | FOREGROUND_RED); break;
- case 7: COLOR = (FOREGROUND_BLUE | FOREGROUND_INTENSITY); break;
- case 8: COLOR = (FOREGROUND_GREEN | FOREGROUND_INTENSITY); break;
- case 9: COLOR = (FOREGROUND_RED | FOREGROUND_INTENSITY); break;
- case 10: COLOR = (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY); break;
- case 11: COLOR = (FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY); break;
- case 12: COLOR = (FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY); break;
- case 13: COLOR = (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); break;
- case 14: COLOR = (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | COMMON_LVB_REVERSE_VIDEO); break;
- case 15: COLOR = (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | COMMON_LVB_REVERSE_VIDEO | FOREGROUND_INTENSITY); break;
- }
- SetConsoleTextAttribute(StdOut, COLOR);
- }
- void line(int x1, int y1, int x2, int y2)
- {
- BGN.X = (short)x1 + movx;
- BGN.Y = (short)y1 + mov;
- POS.X = (short)x2 + movx;
- POS.Y = (short)y2 + mov;
- PlotLine(hDC, PEN, BGN, POS);
- }
- void putpixel(int x, int y)
- {
- line(x, y, x, y);
- }
- void circle(int x, int y, int radius)
- {
- BGN.X = (short)x + movx - radius / 2;
- BGN.Y = (short)y + mov - radius / 2;
- POS.X = (short)x + movx + radius / 2;
- POS.Y = (short)y + mov + radius / 2;
- PlotCirc(hDC, PEN, BGN, POS);
- }
- void rectangle(int x1, int y1, int x2, int y2)
- {
- BGN.X = (short)x1 + movx;
- BGN.Y = (short)y1 + mov;
- POS.X = (short)x2 + movx;
- POS.Y = (short)y2 + mov;
- PlotRect(hDC, PEN, BGN, POS);
- }
- void gotoxy(int x, int y)
- {
- BGN.X = (short)x;
- BGN.Y = (short)y;
- SetConsoleCursorPosition(StdOut, BGN);
- }
- void outtextxy(int x, int y, char * text)
- {
- gotoxy(x / 8, y / 12);
- std::cout << text;
- }
- void clrscr()
- {
- setcolor(0);
- for (int i = 5; i <= 645; i++)
- line(i - movx, 32 - mov, i - movx, 331 - mov);
- }
- void SetWindow(int Width, int Height)
- {
- _COORD coord;
- coord.X = Width;
- coord.Y = Height;
- _SMALL_RECT Rect;
- Rect.Top = 0;
- Rect.Left = 0;
- Rect.Bottom = Height - 1;
- Rect.Right = Width - 1;
- HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE); // Get Handle
- SetConsoleScreenBufferSize(Handle, coord); // Set Buffer Size
- SetConsoleWindowInfo(Handle, TRUE, &Rect); // Set Window Size
- WINDOWPLACEMENT wd;
- HWND hWnd = GetForegroundWindow();
- if (GetWindowPlacement(hWnd, &wd))
- {
- ShowWindow(hWnd, SW_MAXIMIZE);
- }
- }
- HPEN getPen(int iPEN_STYLE, int iPEN_SIZE, int iCOLORREF)
- {
- return CreatePen(iPEN_STYLE, iPEN_SIZE, iCOLORREF);
- }
- BOOL SetPoint(HDC hDC, HPEN hPen, COORD PNT)
- {
- EXTLOGPEN pINFO;
- GetObject(hPen, sizeof(EXTLOGPEN), &pINFO);
- SelectObject(hDC, hPen);
- return Ellipse
- (
- hDC,
- PNT.X - pINFO.elpWidth,
- PNT.Y + pINFO.elpWidth,
- PNT.X + pINFO.elpWidth,
- PNT.Y - pINFO.elpWidth
- );
- }
- BOOL PlotLine(HDC hDC, HPEN hPen, COORD BGN, COORD END)
- {
- SelectObject(hDC, hPen);
- MoveToEx(hDC, BGN.X, BGN.Y, NULL);
- return LineTo(hDC, END.X, END.Y);
- }
- BOOL PlotRect(HDC hDC, HPEN hPen, COORD BGN, COORD END)
- {
- SelectObject(hDC, hPen);
- return Rectangle(hDC, BGN.X, BGN.Y, END.X, END.Y);
- }
- BOOL PlotCirc(HDC hDC, HPEN hPen, COORD BGN, COORD END)
- {
- SelectObject(hDC, hPen);
- return Ellipse(hDC, BGN.X, BGN.Y, END.X, END.Y);
- }
- COORD setCordScale(COORD POS, RECT pRECT)
- {
- if (POS.X == 0)
- POS.X = 1;
- if (POS.Y == 0)
- POS.Y = 1;
- int nROWS = 25;
- int nCOLS = 80;
- double CX = (pRECT.right - pRECT.left) / nCOLS;
- double CY = (pRECT.bottom - pRECT.top) / nROWS;
- //Ïðè òåêñòîâîì ðåæèìå(text mode) ýêðàí äåëèòñÿ íà ÿ÷åéêè
- //(80 èëè 40 êîëîíîê â øèðèíó è 25 ñòðîê â âûñîòó)
- POS.X *= CX;
- POS.Y *= CY;
- int xBORDER = GetSystemMetrics(SM_CXBORDER);//Øèðèíà ãðàíèöû îêíà
- int yBORDER = GetSystemMetrics(SM_CYMENU); //Âûñîòà çàãîëîâêà îêíà ~= âûñîòå ñòðîê ìåíþ
- int xDRAG = GetSystemMetrics(SM_CXDRAG); //×èñëî ïèêñåëåé íà ãîðèç äðîæåíèå ìûøè
- int yDRAG = GetSystemMetrics(SM_CYDRAG); //×èñëî ïèêñåëåé íà âåðòèê äðîæåíèå ìûøè
- POS.X += xBORDER + xDRAG;//Øèðèíà ãðàíèöû îêíà + ÷èñëî ïèêñåëåé íà äðîæåíèå ìûøè
- POS.Y += yBORDER + yDRAG;
- return POS;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment