Devc++还原ggcc.graphics.h
生活随笔
收集整理的這篇文章主要介紹了
Devc++还原ggcc.graphics.h
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Hi~ o(* ̄▽ ̄*)ブ,我是臟臟包!
今天,我為大家帶來了新.頭文件:ggcc.graphisc.h!
眾所周知,ggcc.graphisc.h Devc++無法使用,
所以
@匿名用戶_在devc++上還原了ggcc.graghics.h
再此五體投地
上代碼!
//ggcc圖形庫 //ggcc_graphics.h/*---------------------------------------------------------------------- 介紹:本圖形庫1)是基于控制臺的偽圖形庫,借鑒于easyx, 可以理解為ggcc.h的升級版2)采用24位真彩色渲染圖像,拋棄了舊版的4位色渲染,渲染效果更加3)刪除了繁瑣的、落后的、底層的舊版函數,是新一代的ggcc標準4)修正了曾經不規范的定義,讓使用者更加容易5)刪除了許多多余的代碼,渲染速度更快6)適用于Dev-cpp 信息:版本:v1.6作者:匿名用戶__開始時間:2021-7-9 17:00 -----------------------------------------------------------------------*//*----------------------------------------------------------------------- 工作日志:| 日期 | 工作量 | 總行數 | 描述 __________________________________________________________________ 2021-7-9 625行 625行 完成了各種底層函數 2021-7-10 443行 1068行 正式進入圖形渲染部分,完成了點、線條、矩形、圓、橢圓的各種渲染方法 2021-7-11 227行 1295行 完成了文字處理、批量繪圖部分 2021-7-12 76行 1371行 完成了多邊形的渲染 2021-7-19 276行 1647行 完成了控制欄的繪制,完善了程序,修復了一系列bug 2021-7-23 54行 1701行 完成了顏色的混合與反轉 2021-8-3 -11行 1690行 修復了一系列bug 2021-8-9 65行 1755行 完成了圓角矩形的繪制,修復了線條、多邊形、BFS洪水填充的bug 2021-9-25 32行 1787行 添加了一些奇怪的東西,發現了一堆bug,尚未修復...-----------------------------------------------------------------------*/#include <bits/stdc++.h> #include <stdio.h> #include <conio.h> #include <cstdlib> #include <windows.h> #include <fstream> #include <pthread.h> #include <direct.h>// 顏色 #define BLACK 0x000000 #define BLUE 0xAA0000 #define GREEN 0x00AA00 #define CYAN 0xAAAA00 #define RED 0x0000AA #define MAGENTA 0xAA00AA #define BROWN 0x0055AA #define LIGHTGRAY 0xAAAAAA #define DARKGRAY 0x555555 #define LIGHTBLUE 0xFF5555 #define LIGHTGREEN 0x55FF55 #define LIGHTCYAN 0xFFFF55 #define LIGHTRED 0x5555FF #define LIGHTMAGENTA 0xFF55FF #define YELLOW 0x55FFFF #define WHITE 0xFFFFFF//VT常量 #define ENABLE_PROCESSED_INPUT 0x0001 #define ENABLE_LINE_INPUT 0x0002 #define ENABLE_ECHO_INPUT 0x0004 #define ENABLE_WINDOW_INPUT 0x0008 #define ENABLE_MOUSE_INPUT 0x0010 #define ENABLE_INSERT_MODE 0x0020 #define ENABLE_QUICK_EDIT_MODE 0x0040 #define ENABLE_EXTENDED_FLAGS 0x0080 #define ENABLE_AUTO_POSITION 0x0100 #define ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200 #define ENABLE_PROCESSED_OUTPUT 0x0001 #define ENABLE_WRAP_AT_EOL_OUTPUT 0x0002 #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 #define DISABLE_NEWLINE_AUTO_RETURN 0x0008 #define ENABLE_LVB_GRID_WORLDWIDE 0x0010// 填充樣式 #define BDIAGONAL_FILL 0x0001 // /// 填充 #define CROSS_FILL 0x0002 // +++ 填充 #define DIAGCROSS_FILL 0x0004 // xxx 填充 #define DOT_FILL 0x0008 // xxx 填充 #define FDIAGONAL_FILL 0x0010 // \\\ 填充 #define HORIZONTAL_FILL 0x0020 // === 填充 #define VERTICAL_FILL 0x0040 // ||| 填充// 填充動作 #define FLOODFILLBORDER 0x0000 // 填充動作在顏色參數圍成的封閉區域內填充 #define FLOODFILLSURFACE 0x0001 // 填充動作在顏色參數指定的連續顏色表面填充// 背景填充模式 #define OPAQUE 0x0000 // 默認背景色 #define TRANSPARENT 0x0001 // 透明 // 未完成標識符 #define pass ;// 定義顏色轉換宏 #define BGR(color) ((((color)&0xFF)<<16)|((color)&0xFF00FF00)|(((color)&0xFF0000)>>16))// 鼠標點擊 #define click(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)// 窗口緩沖區 #define wbs 2000 // 緩沖區邊長 #define cshc 300 // 窗口不顯示緩沖區邊長 using namespace std;//----------矩形存儲---------- struct RectAngle {POINT p1,p2;bool inRectangle(POINT p) {return (p.x>=p1.x&&p.x<=p2.x&&p.y>=p1.y&&p.y<=p2.y);} };//----------多邊形存儲---------- struct Region {vector<POINT> p;bool inRegion(POINT pt) {int nCross=0;for(int i=0; i<p.size(); i++) {POINT p1;POINT p2;p1=p[i];p2=p[(i+1)%p.size()];if(p1.y==p2.y)continue;if(pt.y<min(p1.y,p2.y))continue;if(pt.y>=max(p1.y,p2.y))continue;double x=(double)(pt.y-p1.y)*(double)(p2.x-p1.x)/(double)(p2.y-p1.y)+p1.x;if(x>pt.x)nCross++;}bool flag=nCross%2;if(!flag)for(int i=0; i<p.size(); i++)if(p[i].x==pt.x&&p[i].y==pt.y) {flag=true;break;}return flag;}int pSum() {return p.size();} };//----------圓的存儲---------- struct Circle {POINT p;int r;bool inCircle(POINT pt) {int a=abs(pt.x-p.x);int b=abs(pt.y-p.y);return sqrt(a*a+b*b)<=r;} };//----------點的儲存---------- struct Pixel {POINT p;bool inPixel(POINT pt) {return (pt.x==p.x&&pt.y==p.x);} };//----------畫線樣式---------- struct LINESTYLE {int style; // 畫線樣式(無用,為兼容easyx)int thickness; // 線的寬度 };//----------填充樣式---------- struct FILLSTYLE {int style; // 填充樣式 };//----------圖像儲存--------- struct IMAGE {//這里還沒有東西呢pass; };//----------臨時結構體---------- struct PointXYZ {PointXYZ() = default;PointXYZ(float x_,float y_,float theta_):x(x_),y(y_),theta(theta) {}float x {0.0};float y {0.0};float theta {0.0}; };//----------字體儲存---------- // 設置當前字體樣式 // nHeight: 字符的平均高度; // nWidth: 字符的平均寬度(0 表示自適應); // lpszFace: 字體名稱; // nEscapement: 字符串的書寫角度(單位 0.1 度); // nOrientation: 每個字符的書寫角度(單位 0.1 度); // nWeight: 字符的筆畫粗細(0 表示默認粗細); // bItalic: 是否斜體; // bUnderline: 是否下劃線; // bStrikeOut: 是否刪除線; // fbCharSet: 指定字符集; // fbOutPrecision: 指定文字的輸出精度; // fbClipPrecision: 指定文字的剪輯精度; // fbQuality: 指定文字的輸出質量; // fbPitchAndFamily: 指定以常規方式描述字體的字體系列。//----------繪制變量---------- int linecolor=RGB(0,0,0); // 線條顏色 int fillcolor=RGB(0,0,0); // 填充色 int bkcolor=RGB(0,0,0); // 背景色 int textcolor=RGB(0,0,0); // 字體色int nowbcolor=RGB(0,0,0); // 當前字體背景色 int nowwcolor=RGB(0,0,0); // 當前字體前景色bool ctrl=true; // 是否顯示控制欄 int choose_ctrl_time[10]; // 控制欄焦點選擇時間//----------系統變量---------- HANDLE hIn; HANDLE hOut; DWORD dwInMode, dwOutMode; HWND hwnd = GetConsoleWindow(); RECT rc; CONSOLE_CURSOR_INFO cciCursor; const int WINx = GetSystemMetrics(SM_CXSCREEN); // 屏幕分辨率 const int WINy = GetSystemMetrics(SM_CYSCREEN); // 屏幕分辨率 int cx = GetSystemMetrics(SM_CXSCREEN); // 窗口寬 int cy = GetSystemMetrics(SM_CYSCREEN); // 窗口高 double textX = 8.0; // 字體寬 double textY = 16.0; // 字體高 int win_TOP = false; // 是否置頂 int StartGameTime=clock(); // 開始游戲時間 int LastFPSTime=0; // 上一次檢測FPS時間 int LastCtrlTime=0; // 上一次控制欄檢測時間 int FPS=0; // 當前FPS int FPSSum=0; // 所有FPS總數 int LastFPS=0; // 上一次檢測的FPS//----------繪圖設備變量---------- RectAngle Cliprgn= {{0,0},{0,0}}; // 繪圖裁剪區 LINESTYLE Linestyle; // 當前畫線樣式 FILLSTYLE Fillstyle; // 當前填充樣式 int EPOTWcolor[wbs+1][wbs+1]; // 窗口上每個像素點的顏色 int EPOTWwcolor[wbs+1][wbs+1]; // 窗口上每個像素點的字體顏色 string EPOTWtext[wbs+1][wbs+1]; // 窗口上每個像素點上寫的字 int lEPOTWcolor[wbs+1][wbs+1]; // 上次窗口上每個像素點的顏色 int lEPOTWwcolor[wbs+1][wbs+1]; // 上次窗口上每個像素點的字體顏色 string lEPOTWtext[wbs+1][wbs+1]; // 上次窗口上每個像素點上寫的字 int bkmode; // 背景填充模式 bool batchDraw; // 是否開啟批量繪圖 POINT mouse_deviation1= {0,0}; // 鼠標偏差(加減)單位:像素 POINT mouse_deviation2= {10000,10000}; // 鼠標偏差(乘倍) int orx=0; // 坐標原點x int ory=0; // 坐標原點y//----------聲明函數----------// 繪圖模式相關函數HWND initgraph(int w, int h,bool _ctrl); // 初始化圖形環境 void closegraph(); // 關閉圖形環境// 繪圖環境設置 void cleardevice(); // 清屏 void setcliprgn(RectAngle hrgn); // 設置當前繪圖設備的裁剪區 void clearcliprgn(); // 清除裁剪區的屏幕內容 void getlinestyle(LINESTYLE* pstyle); // 獲取當前畫線樣式 void setlinestyle(const LINESTYLE* pstyle); // 設置當前畫線樣式 void setlinestyle(int style, int thickness = 1); // 設置當前畫線樣式 void getfillstyle(FILLSTYLE* pstyle); // 獲取當前填充樣式 void setfillstyle(FILLSTYLE pstyle); // 設置當前填充樣式 int getrop2(); // 獲取前景的二元光柵操作模式 void setrop2(int mode); // 設置前景的二元光柵操作模式 int getpolyfillmode(); // 獲取多邊形填充模式 void setpolyfillmode(int mode); // 設置多邊形填充模式 void graphdefaults(); // 重置所有繪圖設置為默認值 int getlinecolor(); // 獲取當前線條顏色 void setlinecolor(int color); // 設置當前線條顏色 int gettextcolor(); // 獲取當前文字顏色 void settextcolor(int color); // 設置當前文字顏色 int getfillcolor(); // 獲取當前填充顏色 void setfillcolor(int color); // 設置當前填充顏色 int getbkcolor(); // 獲取當前繪圖背景色 void setbkcolor(int color); // 設置當前繪圖背景色 int getbkmode(); // 獲取背景混合模式 void setbkmode(int mode); // 設置背景混合模式// 顏色模型轉換函數 int RGBtoGRAY(int rgb); void RGBtoHSL(int rgb, float *H, float *S, float *L); void RGBtoHSV(int rgb, float *H, float *S, float *V); int HSLtoRGB(float H, float S, float L); int HSVtoRGB(float H, float S, float V);// 繪圖函數 int getpixel(int x, int y); // 獲取點的顏色 void putpixel(int x, int y, int color); // 畫點 void line(int x1, int y1, int x2, int y2); // 畫線 void rectangle (int left, int top, int right, int bottom); // 畫矩形 void system_rectangle(int left, int top, int right, int bottom);// 畫矩形 void fillrectangle (int left, int top, int right,int bottom); // 畫填充矩形(有邊框) void solidrectangle(int left, int top, int right,int bottom); // 畫填充矩形(無邊框) void system_solidrectangle(int left, int top, int right,int bottom); // 畫填充矩形(無邊框) void clearrectangle(int left, int top, int right, int bottom); // 清空矩形區域 void circle (int x, int y, int radius); // 畫圓 void fillcircle (int x, int y, int radius); // 畫填充圓(有邊框) void solidcircle(int x, int y, int radius); // 畫填充圓(無邊框) void clearcircle(int x, int y, int radius); // 清空圓形區域 void ellipse (int left, int top, int right, int bottom); // 畫橢圓 void fillellipse (int left, int top, int right,int bottom); // 畫填充橢圓(有邊框) void solidellipse(int left, int top, int right,int bottom); // 畫填充橢圓(無邊框) void clearellipse(int left, int top, int right, int bottom); // 清空橢圓形區域 void roundrect (int left, int top, int right, int bottom, int ellipsewidth,int ellipseheight); // 畫圓角矩形 void fillroundrect (int left, int top, int right, int bottom, int ellipsewidth,int ellipseheight); // 畫填充圓角矩形(有邊框) void solidroundrect(int left, int top, int right, int bottom, int ellipsewidth,int ellipseheight); // 畫填充圓角矩形(無邊框) void clearroundrect(int left, int top, int right, int bottom, int ellipsewidth,int ellipseheight); // 清空圓角矩形區域 void arc (int left, int top, int right, int bottom, double stangle,double endangle); // 畫橢圓弧(起始角度和終止角度為弧度制) void pie (int left, int top, int right, int bottom, double stangle,double endangle); // 畫橢圓扇形(起始角度和終止角度為弧度制) void fillpie (int left, int top, int right, int bottom, double stangle,double endangle); // 畫填充橢圓扇形(有邊框) void solidpie(int left, int top, int right, int bottom, double stangle,double endangle); // 畫填充橢圓扇形(無邊框) void clearpie(int left, int top, int right, int bottom, double stangle,double endangle); // 清空橢圓扇形區域 void polyline (const POINT *points, int num); // 畫多條連續的線 void polygon (const POINT *points, int num); // 畫多邊形 void fillpolygon (const POINT *points,int num); // 畫填充的多邊形(有邊框) void solidpolygon(const POINT *points,int num); // 畫填充的多邊形(無邊框) void clearpolygon(const POINT *points, int num); // 清空多邊形區域 void polybezier(const POINT *points, int num); // 畫貝塞爾曲線 void floodfill(int x, int y, int color,int filltype = FLOODFILLBORDER); // 填充區域// 文字相關函數 void outtextxy(int x, int y, string str); // 在指定位置輸出字符串 void system_outtextxy(int x, int y, string str); // 在指定位置輸出字符串 int textwidth(string str); // 獲取字符串占用的像素寬 int textheight(string str); // 獲取字符串占用的像素高 int drawtext(string str, RECT* pRect,UINT uFormat); // 在指定區域內以指定格式輸出字符串 void settextstyle(int nHeight, int nWidth, string lpszFace); void settextstyle(int nHeight, int nWidth, string lpszFace, int nEscapement,int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut); void settextstyle(int nHeight, int nWidth, string lpszFace, int nEscapement,int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut,BYTE fbCharSet, BYTE fbOutPrecision, BYTE fbClipPrecision, BYTE fbQuality,BYTE fbPitchAndFamily); void settextstyle(const LOGFONT *font); // 設置當前字體樣式 void gettextstyle(LOGFONT *font); // 獲取當前字體樣式// 圖像處理函數 void loadimage(IMAGE *pDstImg, string pImgFile, int nWidth = 0,int nHeight = 0, bool bResize =false); // 從圖片文件獲取圖像(bmp/gif/jpg/png/tif/emf/wmf/ico) void loadimage(IMAGE *pDstImg, string pResType, string pResName,int nWidth = 0, int nHeight = 0,bool bResize = false); // 從資源文件獲取圖像(bmp/gif/jpg/png/tif/emf/wmf/ico) void saveimage(string pImgFile,IMAGE* pImg = NULL); // 保存圖像(bmp/gif/jpg/png/tif) void getimage(IMAGE *pDstImg, int srcX, int srcY, int srcWidth,int srcHeight); // 從當前繪圖設備獲取圖像 void putimage(int dstX, int dstY, const IMAGE *pSrcImg,DWORD dwRop = SRCCOPY); // 繪制圖像到屏幕 void putimage(int dstX, int dstY, int dstWidth, int dstHeight,const IMAGE *pSrcImg, int srcX, int srcY,DWORD dwRop = SRCCOPY); // 繪制圖像到屏幕(指定寬高) void rotateimage(IMAGE *dstimg, IMAGE *srcimg, double radian,int bkcolor = BLACK, bool autosize = false, bool highquality = true);// 旋轉圖像 void Resize(IMAGE* pImg, int width, int height); // 調整繪圖設備的大小 DWORD* GetImageBuffer(IMAGE* pImg = NULL); // 獲取繪圖設備的顯存指針 IMAGE* GetWorkingImage(); // 獲取當前繪圖設備 void SetWorkingImage(IMAGE* pImg = NULL); // 設置當前繪圖設備 HDC GetImageHDC(IMAGE* pImg = NULL); // 獲取繪圖設備句柄(HDC)// 其它函數 int getwidth(); // 獲取繪圖區寬度 int getheight(); // 獲取繪圖區高度 void BeginBatchDraw(); // 開始批量繪制 void FlushBatchDraw(); // 執行未完成的繪制任務 void FlushBatchDraw(int left, int top, int right,int bottom); // 執行指定區域內未完成的繪制任務 void EndBatchDraw(); // 結束批量繪制,并執行未完成的繪制任務 void EndBatchDraw(int left, int top, int right,int bottom); // 結束批量繪制,并執行指定區域內未完成的繪制任務 HWND GetHWnd(); // 獲取繪圖窗口句柄(HWND) string GetGGCCVer(); // 獲取 GGCC 當前版本 void settextsize(double sizex,double sizey);// 設置字體大小 void settitle(string a); // 設置標題//----------函數----------- string change_its(int a) {/*這個函數用于轉換int到string*/int b=abs(a);string ans;if(b==0)return "0";while(b) {ans=char(b%10+'0')+ans;b/=10;}if(a<0)ans='-'+ans;return ans; }POINT GetMousePos() {/*這個函數用于獲取鼠標位置*/POINT pt1,pt2,pt;CONSOLE_FONT_INFO cfi;GetCursorPos(&pt1);ScreenToClient(hwnd,&pt1);GetCurrentConsoleFont(hOut, FALSE, &cfi);pt2= {cfi.dwFontSize.X*2+mouse_deviation1.x,cfi.dwFontSize.Y+mouse_deviation1.y};pt1.x=pt1.x*1.0*mouse_deviation2.x/10000;pt1.y=pt1.y*1.0*mouse_deviation2.y/10000;pt= {1.0*pt1.x/pt2.x,1.0*pt1.y/pt2.y};return pt; }void modeset(int a1,int a2) {/*這個函數用于調整窗口大小 */string a=change_its(a1),b=change_its(a2);system(("mode "+a+","+b).c_str()); }bool inSight(int x,int y) {/*這個函數用于判斷坐標(x,y)是否在窗口可顯示的范圍內 */return (x>=0&&y>=0&&x<cx&&y<cy); }bool checkPoint(int x,int y) {/*這個函數用于判斷坐標(x,y)是否可顯示*/return inSight(x,y)&&!batchDraw; }HWND initgraph(int w, int h, bool _ctrl=false) {/*這個函數用于初始化繪圖窗口。width繪圖窗口的寬度。height繪圖窗口的高度。*/cout<<"初始化控制臺圖形化界面中......"<<endl<<endl;cout<<"圖形化引擎版本信息:"<<endl;cout<<GetGGCCVer()<<endl<<endl;cx=w,cy=h;hIn = GetStdHandle(STD_INPUT_HANDLE);hOut = GetStdHandle(STD_OUTPUT_HANDLE);cout<<"[Finished]初始化窗口輸入輸出句柄"<<endl;GetConsoleMode(hIn, &dwInMode);GetConsoleMode(hOut, &dwOutMode);dwInMode |= ENABLE_VIRTUAL_TERMINAL_INPUT;dwOutMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;SetConsoleMode(hIn, dwInMode);SetConsoleMode(hOut, dwOutMode);cout<<"[Finished]初始化ANSI控制碼"<<endl;GetWindowRect(hwnd, &rc);SetWindowLongPtr(hwnd,GWL_STYLE, GetWindowLong(hwnd,GWL_STYLE) & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX);SetWindowPos(hwnd,NULL,rc.left,rc.top,rc.right - rc.left, rc.bottom - rc.top,NULL);ctrl=_ctrl;settextsize(textX,textY);if(ctrl)modeset(w*2,h+1);else modeset(w*2,h);cout<<"初始化控制臺圖形化界面中......"<<endl<<endl;cout<<"圖形化引擎版本信息:"<<endl;cout<<GetGGCCVer()<<endl<<endl;cout<<"[Finished]初始化窗口輸入輸出句柄"<<endl;cout<<"[Finished]初始化ANSI控制碼"<<endl;cout<<"[Finished]重置窗口大小" <<endl;if(GetConsoleCursorInfo(hOut, &cciCursor)) {cciCursor.bVisible = FALSE;SetConsoleCursorInfo(hOut, &cciCursor);}dwInMode &= ~ENABLE_QUICK_EDIT_MODE;dwInMode &= ~ENABLE_MOUSE_INPUT;SetConsoleMode(hIn, dwInMode);for(int i=0; i<=wbs; i++)for(int j=0; j<=wbs; j++) {EPOTWcolor[i][j]=bkcolor;EPOTWwcolor[i][j]=bkcolor;EPOTWtext[i][j]=" ";}cout<<"[Finished]初始化圖形渲染界面"<<endl;system("cls");return hwnd; }void setorigin(int x,int y) {orx=x;ory=y; }void draw_ctrl(int Ctrl=0) {/*這個函數用于繪制控制欄*/if(ctrl) {int fc=fillcolor;int bkm=bkmode;int bkc=bkcolor;int tc=textcolor;POINT mp=GetMousePos();bkmode=0;fillcolor=RGB(197,186,180);bkcolor=RGB(96,169,230);textcolor=RGB(50,50,50);system_solidrectangle(0,cy,cx-1,cy);system_outtextxy(0,cy," ·GGCC· ");bkmode=1;fillcolor=fc;bkmode=bkm;bkcolor=bkc;textcolor=tc;} }void update_ctrl(int Ctrl=0) {/*這個函數用于更新控制欄*/FPS++;FPSSum++;if(clock()-LastFPSTime>=1000) {LastFPS=FPS;FPS=0;LastFPSTime=clock();}if(ctrl) {if(clock()-LastCtrlTime<100)return;LastCtrlTime=clock();int fc=fillcolor;int bkm=bkmode;int bkc=bkcolor;int tc=textcolor;int GameTime=(clock()-StartGameTime)/1000;POINT mp=GetMousePos(); // bkmode=0; // for(int i=0; i<=9; i++) // if(choose_ctrl_time[i]>1) // choose_ctrl_time[i]-=2; // if(mp.x>=cx-4&&mp.x<=cx&&mp.y==cy&&hwnd==GetConsoleWindow()) { // if(choose_ctrl_time[mp.x-(cx-4)]<23) // choose_ctrl_time[mp.x-(cx-4)]+=4; // if(mp.x-(cx-4)==0) { // if(click(VK_LBUTTON)) { // if(textX)textX++,textY+=2; // settextsize(textX,textY); // } // } else if(mp.x-(cx-4)==1) { // if(click(VK_LBUTTON)) { // if(textX)textX--,textY-=2; // settextsize(textX,textY); // } // } else if(mp.x-(cx-4)==2) { // if(click(VK_LBUTTON)) { // win_TOP=!win_TOP; // if(win_TOP) // SetWindowPos(hwnd,HWND_TOPMOST, 0, 0, 0, 0, // SWP_NOMOVE | SWP_DRAWFRAME | SWP_NOSIZE); // else // SetWindowPos(hwnd,HWND_NOTOPMOST, 0, 0, 0, 0, // SWP_NOMOVE | SWP_DRAWFRAME | SWP_NOSIZE); // } // } else if(mp.x-(cx-4)==3) { // if(click(VK_LBUTTON))ShowWindow(hwnd,SW_MINIMIZE); // } // } // fillcolor=RGB(197,186,180); // bkcolor=RGB(255,100,100); // textcolor=RGB(50,50,50); // string Button[4]= {"﹢","﹣","↑","↓"}; // bkmode=0; // for(int i=0; i<=3; i++) { // int cct=choose_ctrl_time[i]; // bkcolor=RGB(197-cct*3,186-cct*3,180-cct*3); // system_outtextxy(cx-4+i,cy,Button[i]); // } // bkmode=1;bkcolor=RGB(255,100,100);textcolor=RGB(50,50,50);if(cx>10)system_outtextxy(6,cy,"Pos:("+change_its(mp.x)+","+change_its(mp.y)+") ");if(cx>30)system_outtextxy(14,cy,"FPS:"+change_its(LastFPS)+"/"+change_its(FPSSum/GameTime)+" ");if(cx>50)if(GameTime<60)system_outtextxy(21,cy,"GameTime:"+change_its(GameTime)+" sec ");else if(GameTime<3600)system_outtextxy(21,cy,"GameTime:"+change_its(GameTime/60)+" min ");else if(GameTime<86400)system_outtextxy(21,cy,"GameTime:"+change_its(GameTime/3600)+" hour ");else system_outtextxy(21,cy,"GameTime:"+change_its(GameTime/86400)+" day ");time_t t = time(NULL);struct tm* stime=localtime(&t);if(cx>20) {string Time="Time:"+(change_its(1900+stime->tm_year)+'-'+change_its(1+stime->tm_mon)+'-'+change_its(stime->tm_mday)+' '+change_its(stime->tm_hour)+':'+change_its(stime->tm_min)+':'+change_its(stime->tm_sec))+" ";system_outtextxy(cx-15,cy,Time);}fillcolor=fc;bkmode=bkm;bkcolor=bkc;textcolor=tc;} }void mousetext(string text) {/*這個函數用于在鼠標旁顯示提示字幕*/POINT mp=GetMousePos();SetConsoleCursorPosition(hOut, {mp.x<<1,mp.y}); }void closegraph() {/*這個函數用于關閉繪圖窗口。*/exit(0); }void cleardevice() {/*這個函數用于清空繪圖設備。具體的,是用當前背景色清空繪圖設備并將當前點移至 (0, 0)。*/if(nowbcolor^bkcolor&&!batchDraw) {printf("\033[48;2;%d;%d;%dm",bkcolor%256,(bkcolor>>8)%256,bkcolor>>16);nowbcolor=bkcolor;}if(!batchDraw)system("cls");for(int i=0; i<=wbs; i++)for(int j=0; j<=wbs; j++) {EPOTWcolor[i][j]=bkcolor;EPOTWwcolor[i][j]=bkcolor;EPOTWtext[i][j]=" ";} }void setcliprgn(RectAngle hrgn) {/*這個函數用于設置當前繪圖設備的裁剪區。*/if(hrgn.p1.x>hrgn.p2.x)hrgn.p1.x^=hrgn.p2.x,hrgn.p2.x^=hrgn.p1.x,hrgn.p1.x^=hrgn.p2.x;if(hrgn.p1.y>hrgn.p2.y)hrgn.p1.y^=hrgn.p2.y,hrgn.p2.y^=hrgn.p1.y,hrgn.p1.y^=hrgn.p2.y;Cliprgn=hrgn; }void clearcliprgn() {/*這個函數用于清空裁剪區*/COORD pos;if(nowbcolor^bkcolor&&!batchDraw) {printf("\033[48;2;%d;%d;%dm",bkcolor%256,(bkcolor>>8)%256,bkcolor>>16);nowbcolor=bkcolor;}for(int i=Cliprgn.p1.y; i<=Cliprgn.p2.y; i++) {SetConsoleCursorPosition(hOut, {Cliprgn.p1.x<<1,i});for(int j=Cliprgn.p1.x; j<=Cliprgn.p2.x; j++) {if(checkPoint(j,i))printf(" ");EPOTWcolor[j+cshc][i+cshc]=bkcolor;EPOTWwcolor[j+cshc][i+cshc]=bkcolor;EPOTWtext[j+cshc][i+cshc]=" ";}} }void getlinestyle(LINESTYLE &pstyle) {/*這個函數用于獲取當前設備畫線樣式。*/pstyle=Linestyle; }void setlinestyle(LINESTYLE pstyle) {/*這個函數用于設置當前設備畫線樣式。*/Linestyle=pstyle; }void setlinestyle(int style, int thickness) {/*[重載]這個函數用于設置當前設備畫線樣式。*/Linestyle.style=style;Linestyle.thickness=thickness; }void getfillstyle(FILLSTYLE &pstyle) {/*這個函數用于獲取當前設備填充樣式。*/pstyle=Fillstyle; }void setfillstyle(FILLSTYLE pstyle) {/*這個函數用于設置當前設備填充樣式。*/Fillstyle=pstyle; }int getrop2() {/*這個函數用于獲取當前設備二元光柵操作模式。*/pass; } void setrop2(int mode) {/*這個函數用于設置當前設備二元光柵操作模式。*/pass; }int getpolyfillmode() {/*這個函數用于獲取當前設備多邊形填充模式。*/pass; }void setpolyfillmode(int mode) {/*這個函數用于設置當前設備多邊形填充模式。*/pass; }void graphdefaults() {/*這個函數用于重置視圖、當前點、繪圖色、背景色、線形、填充樣式、字體為默認值。*/int linecolor=RGB(0,0,0); //線條顏色int fillcolor=RGB(0,0,0); //填充色int bkcolor=RGB(0,0,0); //背景色int textcolor=RGB(0,0,0); //字體色const int WINx = GetSystemMetrics(SM_CXSCREEN); //屏幕分辨率const int WINy = GetSystemMetrics(SM_CYSCREEN); //屏幕分辨率RectAngle Cliprgn= {{0,0},{0,0}}; //繪圖裁剪區LINESTYLE Linestyle= {0,0}; //當前畫線樣式FILLSTYLE Fillstyle= {0}; //當前填充樣式 }int getlinecolor() {/*這個函數用于獲取當前設備畫線顏色。*/return linecolor; }void setlinecolor(int color) {/*這個函數用于設置當前設備畫線顏色。*/linecolor=color; }int gettextcolor() {/*這個函數用于獲取當前文字顏色。*/return textcolor; }void settextcolor(int color) {/*這個函數用于設置當前文字顏色。*/textcolor=color; }int getfillcolor() {/*這個函數用于獲取當前設備填充顏色。*/return fillcolor; }void setfillcolor(int color) {/*這個函數用于設置當前設備填充顏色。*/fillcolor=color; }int getbkcolor() {/*這個函數用于獲取當前設備背景色。*/return bkcolor; }void setbkcolor(int color) {/*這個函數用于設置當前設備繪圖背景色。*/bkcolor=color; }int getbkmode() {/*這個函數用于獲取當前設備圖案填充和文字輸出時的背景模式。*/return bkmode; }void setbkmode(int mode) {/*這個函數用于設置當前設備圖案填充和文字輸出時的背景模式。*/bkmode=mode; }void setcolor(int color) {/*這個函數用于設置當前繪圖前景色。*/linecolor=color;textcolor=color; }int RGBtoGRAY(int rgb) {/*該函數用于返回與指定顏色對應的灰度值顏色。*/int B=rgb>>16,G=(rgb>>8)/256,R=rgb%256;double y=0.212671*R+0.715160*G+(double)0.072169*B;if(y>0.008856)return 116.0*pow(y,1.0/3)-16.0;else return 903.3*y; }void RGBtoHSL(int rgb, float &H, float &S, float &L) {/*該函數用于轉換 RGB 顏色為 HSL 顏色。*/float B=rgb>>16,G=(rgb>>8)/256,R=rgb%256;float minn, maxn, delta,tmp;tmp=min(R,G);minn=min(tmp,B);tmp=max(R,G);maxn=max(tmp,B);L=maxn;delta=maxn-minn;if(maxn!=0)S=delta/maxn;else {S=0,H=0;return;}if(R==maxn)H=(G-B)/delta;else if(G==maxn)H=2+(B-R)/delta;else H=4+(R-G)/delta;H*=60;if(H<0)H+=360; }void RGBtoHSV(int rgb, float &H, float &S, float &V) {/*該函數用于轉換 RGB 顏色為 HSV 顏色。*/float B=rgb>>16,G=(rgb>>8)/256,R=rgb%256;float minn, maxn, delta,tmp;tmp=min(R,G);minn=min(tmp,B);tmp=max(R,G);maxn=max(tmp,B);V=maxn;delta=maxn-minn;if(maxn!=0)S=delta/maxn;else {S=0,H=0;return;}if(R==maxn)H=(G-B)/delta;else if(G==maxn)H=2+(B-R)/delta;else H=4+(R-G)/delta;H*=60;if(H<0)H+=360; }int HSLtoRGB(float H, float S, float L) {/*該函數用于轉換 HSL 顏色為 RGB 顏色。*/pass; }int HSVtoRGB(float H, float S, float V) {/*該函數用于轉換 RGB 顏色為 HSV 顏色。*/pass; }int getpixel(int x, int y) {/*這個函數用于獲取點的顏色。*/return EPOTWcolor[x+cshc][y+cshc]; }void putpixel(int x, int y, int color) {/*這個函數用于畫點。*/if(EPOTWcolor[x+cshc][y+cshc]==color)return;EPOTWcolor[x+cshc][y+cshc]=color;EPOTWtext[x+cshc][y+cshc]=" ";SetConsoleCursorPosition(hOut, {x<<1,y});if(nowbcolor^color&&!batchDraw) {int B=color>>16,G=(color>>8)%256,R=color%256;if(checkPoint(x,y))printf("\033[48;2;%d;%d;%dm ",R,G,B);nowbcolor=color;} else if(checkPoint(x,y))printf(" "); }void line(int x1, int y1, int x2, int y2) {/*這個函數用于畫直線。*/SetConsoleCursorPosition(hOut, {x1<<1,y1});if(nowbcolor^linecolor&&!batchDraw) {int B=linecolor>>16,G=(linecolor>>8)%256,R=linecolor%256;if(checkPoint(x1,y1))printf("\033[48;2;%d;%d;%dm ",R,G,B);nowbcolor=linecolor;EPOTWcolor[x1+cshc][y1+cshc]=linecolor;EPOTWtext[x1+cshc][y1+cshc]=" ";} else if(checkPoint(x1,y1)) {if(EPOTWcolor[x1+cshc][y1+cshc]!=linecolor) {printf(" ");EPOTWcolor[x1+cshc][y1+cshc]=linecolor;EPOTWtext[x1+cshc][y1+cshc]=" ";}}x1*=100,y1*=100,x2*=100,y2*=100;while(x1/100!=x2/100||y1/100!=y2/100) {int n=round(max(1.0*abs(x2-x1),1.0*abs(y2-y1))/100);x1+=round(1.0*(x2-x1)/n);y1+=round(1.0*(y2-y1)/n);if(checkPoint(int(x1/100.0),int(y1/100.0))&&EPOTWcolor[int(x1/100.0)+cshc][int(y1/100.0)+cshc]!=linecolor) {SetConsoleCursorPosition(hOut, {int(x1/100.0)<<1,y1/100.0});printf(" ");}EPOTWcolor[int(x1/100.0)+cshc][int(y1/100.0)+cshc]=linecolor;EPOTWtext[int(x1/100.0)+cshc][int(y1/100.0)+cshc]=" ";} }void rectangle(int left, int top, int right, int bottom) {/*這個函數用于畫無填充的矩形。*/if(left>right)left^=right,right^=left,left^=right;if(top>bottom)top^=bottom,bottom^=top,top^=bottom;if(nowbcolor^linecolor&&!batchDraw) {int B=linecolor>>16,G=(linecolor>>8)%256,R=linecolor%256;printf("\033[48;2;%d;%d;%dm",R,G,B);nowbcolor=linecolor;}SetConsoleCursorPosition(hOut, {left<<1,top});for(int i=left; i<=right; i++) {if(checkPoint(i,top))printf(" ");EPOTWcolor[i+cshc][top+cshc]=linecolor;EPOTWtext[i+cshc][top+cshc]=" ";}SetConsoleCursorPosition(hOut, {left<<1,bottom});for(int i=left; i<=right; i++) {if(checkPoint(i,bottom))printf(" ");EPOTWcolor[i+cshc][bottom+cshc]=linecolor;EPOTWtext[i+cshc][bottom+cshc]=" ";}for(int i=top; i<=bottom; i++) {SetConsoleCursorPosition(hOut, {left<<1,i});if(checkPoint(left,i))printf(" ");EPOTWcolor[left+cshc][i+cshc]=linecolor;EPOTWtext[left+cshc][i+cshc]=" ";}for(int i=top; i<=bottom; i++) {SetConsoleCursorPosition(hOut, {right<<1,i});if(checkPoint(right,i))printf(" ");EPOTWcolor[right+cshc][i+cshc]=linecolor;EPOTWtext[right+cshc][i+cshc]=" ";} }void system_rectangle(int left, int top, int right, int bottom) {/*這個函數用于畫無填充的矩形。(不受邊界限制)*/if(left>right)left^=right,right^=left,left^=right;if(top>bottom)top^=bottom,bottom^=top,top^=bottom;if(nowbcolor^linecolor&&!batchDraw) {int B=linecolor>>16,G=(linecolor>>8)%256,R=linecolor%256;printf("\033[48;2;%d;%d;%dm",R,G,B);nowbcolor=linecolor;}SetConsoleCursorPosition(hOut, {left<<1,top});for(int i=left; i<=right; i++) {printf(" ");EPOTWcolor[i+cshc][top+cshc]=linecolor;EPOTWtext[i+cshc][top+cshc]=" ";}SetConsoleCursorPosition(hOut, {left<<1,bottom});for(int i=left; i<=right; i++) {printf(" ");EPOTWcolor[i+cshc][bottom+cshc]=linecolor;EPOTWtext[i+cshc][bottom+cshc]=" ";}for(int i=top; i<=bottom; i++) {SetConsoleCursorPosition(hOut, {left<<1,i});printf(" ");EPOTWcolor[left+cshc][i+cshc]=linecolor;EPOTWtext[left+cshc][i+cshc]=" ";}for(int i=top; i<=bottom; i++) {SetConsoleCursorPosition(hOut, {right<<1,i});printf(" ");EPOTWcolor[right+cshc][i+cshc]=linecolor;EPOTWtext[right+cshc][i+cshc]=" ";} }void fillrectangle (int left, int top, int right,int bottom) {/*這個函數用于畫有邊框的填充矩形。*/if(fillcolor==linecolor) {solidrectangle(left,top,right,bottom);return;}if(left>right)left^=right,right^=left,left^=right;if(top>bottom)top^=bottom,bottom^=top,top^=bottom;rectangle(left,top,right,bottom);if(nowbcolor^fillcolor&&!batchDraw) {int B=fillcolor>>16,G=(fillcolor>>8)%256,R=fillcolor%256;printf("\033[48;2;%d;%d;%dm",R,G,B);nowbcolor=fillcolor;}for(int i=top+1; i<bottom; i++) {SetConsoleCursorPosition(hOut, {(left<<1)+2,i});for(int j=left+1; j<right; j++) {if(checkPoint(j,i))printf(" ");EPOTWcolor[j+cshc][i+cshc]=fillcolor;EPOTWtext[j+cshc][i+cshc]=" ";}} }void solidrectangle(int left, int top, int right,int bottom) {/*這個函數用于畫無邊框的填充矩形。*/if(left>right)left^=right,right^=left,left^=right;if(top>bottom)top^=bottom,bottom^=top,top^=bottom;if(nowbcolor^fillcolor&&!batchDraw) {int B=fillcolor>>16,G=(fillcolor>>8)%256,R=fillcolor%256;printf("\033[48;2;%d;%d;%dm",R,G,B);nowbcolor=fillcolor;}for(int i=top; i<=bottom; i++) {SetConsoleCursorPosition(hOut, {left<<1,i});for(int j=left; j<=right; j++) {if(checkPoint(j,i))printf(" ");EPOTWcolor[j+cshc][i+cshc]=fillcolor;EPOTWtext[j+cshc][i+cshc]=" ";}} }void system_solidrectangle(int left, int top, int right,int bottom) {/*這個函數用于畫無邊框的填充矩形(不受邊界限制)。*/if(left>right)left^=right,right^=left,left^=right;if(top>bottom)top^=bottom,bottom^=top,top^=bottom;if(nowbcolor^fillcolor&&!batchDraw) {int B=fillcolor>>16,G=(fillcolor>>8)%256,R=fillcolor%256;printf("\033[48;2;%d;%d;%dm",R,G,B);nowbcolor=fillcolor;}for(int i=top; i<=bottom; i++) {SetConsoleCursorPosition(hOut, {left<<1,i});for(int j=left; j<=right; j++) {printf(" ");EPOTWcolor[j+cshc][i+cshc]=fillcolor;EPOTWtext[j+cshc][i+cshc]=" ";}} }void clearrectangle(int left, int top, int right, int bottom) {/*這個函數用于清空矩形區域。*/if(left>right)left^=right,right^=left,left^=right;if(top>bottom)top^=bottom,bottom^=top,top^=bottom;if(nowbcolor^bkcolor&&!batchDraw) {int B=bkcolor>>16,G=(bkcolor>>8)%256,R=bkcolor%256;printf("\033[48;2;%d;%d;%dm",R,G,B);nowbcolor=bkcolor;}for(int i=top; i<=bottom; i++) {SetConsoleCursorPosition(hOut, {left<<1,i});for(int j=left; j<=right; j++) {if(checkPoint(j,i))printf(" ");EPOTWcolor[j+cshc][i+cshc]=bkcolor;EPOTWtext[j+cshc][i+cshc]=" ";}} }void circle (int x, int y, int radius) {/*這個函數用于畫無填充的圓。 */if(nowbcolor^linecolor&&!batchDraw) {int B=linecolor>>16,G=(linecolor>>8)%256,R=linecolor%256;printf("\033[48;2;%d;%d;%dm",R,G,B);nowbcolor=linecolor;}int sx=x-radius;int sy=y-radius;for(int i=1; i<=(radius<<1)+1; i++)for(int j=1; j<=(radius<<1)+1; j++) {int a=abs(i-(radius+1));int b=abs(j-(radius+1));double c=sqrt(a*a+b*b);if(round(c)==radius) {int px=i+x-radius-1,py=j+y-radius-1;SetConsoleCursorPosition(hOut, {px<<1,py});if(checkPoint(px,py))printf(" ");EPOTWcolor[px+cshc][py+cshc]=linecolor;EPOTWtext[px+cshc][px+cshc]=" ";}} }void fillcircle (int x, int y, int radius) {/*這個函數用于畫有邊框的填充圓。*/circle(x,y,radius);radius--;if(nowbcolor^fillcolor&&!batchDraw) {int B=fillcolor>>16,G=(fillcolor>>8)%256,R=fillcolor%256;printf("\033[48;2;%d;%d;%dm",R,G,B);nowbcolor=fillcolor;}int sx=x-radius;int sy=y-radius;for(int i=1; i<=(radius<<1)+1; i++)for(int j=1; j<=(radius<<1)+1; j++) {int a=abs(i-(radius+1));int b=abs(j-(radius+1));double c=sqrt(a*a+b*b);if(round(c)<=radius) {int px=i+x-radius-1,py=j+y-radius-1;SetConsoleCursorPosition(hOut, {px<<1,py});if(checkPoint(px,py))printf(" ");EPOTWcolor[px+cshc][py+cshc]=fillcolor;EPOTWtext[px+cshc][px+cshc]=" ";}} }void solidcircle(int x, int y, int radius) {/*這個函數用于畫無邊框的填充圓*/if(nowbcolor^fillcolor&&!batchDraw) {int B=fillcolor>>16,G=(fillcolor>>8)%256,R=fillcolor%256;printf("\033[48;2;%d;%d;%dm",R,G,B);nowbcolor=fillcolor;}int sx=x-radius;int sy=y-radius;for(int i=1; i<=(radius<<1)+1; i++)for(int j=1; j<=(radius<<1)+1; j++) {int a=abs(i-(radius+1));int b=abs(j-(radius+1));double c=sqrt(a*a+b*b);if(round(c)<=radius) {int px=i+x-radius-1,py=j+y-radius-1;SetConsoleCursorPosition(hOut, {px<<1,py});if(checkPoint(px,py))printf(" ");EPOTWcolor[px+cshc][py+cshc]=fillcolor;EPOTWtext[px+cshc][px+cshc]=" ";}} }void clearcircle(int x, int y, int radius) {/*這個函數用于清空圓形區域。*/if(nowbcolor^bkcolor&&!batchDraw) {int B=bkcolor>>16,G=(bkcolor>>8)%256,R=bkcolor%256;printf("\033[48;2;%d;%d;%dm",R,G,B);nowbcolor=bkcolor;}int sx=x-radius;int sy=y-radius;for(int i=1; i<=(radius<<1)+1; i++)for(int j=1; j<=(radius<<1)+1; j++) {int a=abs(i-(radius+1));int b=abs(j-(radius+1));double c=sqrt(a*a+b*b);if(round(c)<=radius) {int px=i+x-radius-1,py=j+y-radius-1;SetConsoleCursorPosition(hOut, {px<<1,py});if(checkPoint(px,py))printf(" ");EPOTWcolor[px+cshc][py+cshc]=bkcolor;EPOTWtext[px+cshc][px+cshc]=" ";}} }void ellipse (int left, int top, int right, int bottom) {/*這個函數用于畫無填充的橢圓。*/if(left>right)left^=right,right^=left,left^=right;if(top>bottom)top^=bottom,bottom^=top,top^=bottom;int x0=(left+right)>>1,y0=(top+bottom)>>1;int a=(right-left)>>1,b=(bottom-top)>>1;int x=0,y=b;putpixel(x0+x,y0+y,linecolor);putpixel(x0-x,y0+y,linecolor);putpixel(x0+x,y0-y,linecolor);putpixel(x0-x,y0-y,linecolor);//上部分double d1=b*b+a*a*(-b+0.25);while(b*b*x<a*a*y) {if(d1<0) {d1+=b*b*(2*x+3);x++;} else {d1+=(b*b*(2*x+3)+a*a*(-2*y+2));x++,y--;}putpixel(x0+x,y0+y,linecolor);putpixel(x0-x,y0+y,linecolor);putpixel(x0+x,y0-y,linecolor);putpixel(x0-x,y0-y,linecolor);}//下部分double d2=sqrt((double)b*(x+0.5))+sqrt((double)a*(y-1))-sqrt((double)a*b);while(y>0) {if(d2<0) {d2+=b*b*(2*x+2)+a*a*(-2*y+3);x++,y--;} else {d2+=a*a*(-2*y+3);y--;}putpixel(x0+x,y0+y,linecolor);putpixel(x0-x,y0+y,linecolor);putpixel(x0+x,y0-y,linecolor);putpixel(x0-x,y0-y,linecolor);} }void fillellipse (int left, int top, int right, int bottom) {/*這個函數用于畫有邊框的填充橢圓。*/ellipse(left,top,right,bottom);int x=(left+right)>>1,y=(top+bottom)>>1;floodfill(x,y,linecolor,FLOODFILLBORDER); }void solidellipse(int left, int top, int right, int bottom) {/*這個函數用于畫無邊框的填充橢圓。*/int lc=linecolor;linecolor=fillcolor;ellipse(left,top,right,bottom);int x=(left+right)>>1,y=(top+bottom)>>1;floodfill(x,y,linecolor,FLOODFILLBORDER);linecolor=lc; }void clearellipse(int left, int top, int right, int bottom) {/*這個函數用于清空橢圓區域。*/int lc=linecolor,fc=fillcolor;linecolor=bkcolor;fillcolor=bkcolor;ellipse(left,top,right,bottom);int x=(left+right)>>1,y=(top+bottom)>>1;floodfill(x,y,linecolor,FLOODFILLBORDER);linecolor=lc;fillcolor=fc; }void roundrect (int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight) {/*這個函數用于畫圓角矩形。*/int chang=(ellipsewidth+ellipseheight)/2;if(left>right)left^=right,right^=left,left^=right;if(top>bottom)top^=bottom,bottom^=top,top^=bottom;rectangle(left+chang,top,right-chang,top);rectangle(left+chang,bottom,right-chang,bottom);rectangle(left,top+chang,left,bottom-chang);rectangle(right,top+chang,right,bottom-chang);for(int i=1; i<=chang; i++) {for(int j=1; j<=chang; j++) {double c1;c1=sqrt(i*i+j*j);if(round(c1)==chang) {putpixel(right-chang+i,bottom-chang+j,linecolor);putpixel(left+chang-i,bottom-chang+j,linecolor);putpixel(right-chang+i,top+chang-j,linecolor);putpixel(left+chang-i,top+chang-j,linecolor);}}} }void fillroundrect (int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight) {/*這個函數用于畫有邊框的填充圓角矩形。*/int chang=(ellipsewidth+ellipseheight)/2;if(left>right)left^=right,right^=left,left^=right;if(top>bottom)top^=bottom,bottom^=top,top^=bottom;fillrectangle(left+chang,top,right-chang,bottom);fillrectangle(left,top+chang,left+chang,bottom-chang);fillrectangle(right-chang,top+chang,right,bottom-chang);for(int i=1; i<=chang; i++) {for(int j=1; j<=chang; j++) {double c1;c1=sqrt(i*i+j*j);if(round(c1)<=chang) {putpixel(right-chang+i,bottom-chang+j,linecolor);putpixel(left+chang-i,bottom-chang+j,linecolor);putpixel(right-chang+i,top+chang-j,linecolor);putpixel(left+chang-i,top+chang-j,linecolor);}}} }void solidroundrect(int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight) {/*這個函數用于畫無邊框的填充圓角矩形。*/int lc=linecolor;linecolor=fillcolor;fillroundrect(left,top,right,bottom,ellipsewidth,ellipseheight);linecolor=lc; }void clearroundrect(int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight) {/*這個函數用于清空圓角矩形區域。*/int lc=linecolor,fc=fillcolor;linecolor=bkcolor;fillcolor=bkcolor;fillroundrect(left,top,right,bottom,ellipsewidth,ellipseheight);linecolor=lc;fillcolor=fc; }void arc (int left, int top, int right, int bottom, double stangle, double endangle) {/*這個函數用于畫橢圓弧。*/pass; }void pie (int left, int top, int right, int bottom, double stangle, double endangle) {/*這個函數用于畫無填充的扇形。*/ // float R=20;//轉彎半徑為20米 // std::vector<PointXYZ> trajectory; // PointXYZ start(5,6,0); // PointXYZ next_point; // for(float len = 0; len < R*M_PI*2; len+=0.5) { // float t=len/R;//歸一化 將半徑看成單位1 // float d_x=sin(start.theta+t)-sin(start.theta); // float d_y=-cos(start.theta + t)+cos(start.theta); // float d_head; // double a=std::fmod(d_head+M_PI,2.0*M_PI); // if (a<0.0)a+=(2.0*M_PI); // d_head=a-M_PI; // //將半徑反乘回來,變成真實值 // next_point.x=d_x*R+start.x; // next_point.y=d_y*R+start.y; // next_point.theta = d_head; // trajectory.push_back(next_point); // putpixel(round(next_point.x),round(next_point.y),WHITE); // } }void fillpie (int left, int top, int right, int bottom, double stangle, double endangle) {/*這個函數用于畫有邊框的填充扇形。*/pass; }void solidpie(int left, int top, int right, int bottom, double stangle, double endangle) {/*這個函數用于畫無邊框的填充扇形。*/pass; }void clearpie(int left, int top, int right, int bottom, double stangle, double endangle) {/*這個函數用于清空扇形區域。*/pass; }void polyline (const POINT *points, int num) {/*這個函數用于畫連續的多條線段。*/for(int i=1; i<num; i++)line(points[i].x,points[i].y,points[i-1].x,points[i-1].y); }void polygon (const POINT *points, int num) {/*這個函數用于畫無填充的多邊形。*/for(int i=1; i<num; i++)line(points[i].x,points[i].y,points[i-1].x,points[i-1].y);line(points[num-1].x,points[num-1].y,points[0].x,points[0].y); }void fillpolygon (const POINT *points, int num) {/*這個函數用于畫有邊框的填充多邊形。*/for(int i=1; i<num; i++)line(points[i].x,points[i].y,points[i-1].x,points[i-1].y);line(points[num-1].x,points[num-1].y,points[0].x,points[0].y);bool flag=false;POINT pt;do {pt= {rand()%cx,rand()%cy};int nCross=0;for(int i=0; i<num; i++) {POINT p1;POINT p2;p1=points[i];p2=points[(i+1)%num];if(p1.y==p2.y)continue;if(pt.y<min(p1.y,p2.y))continue;if(pt.y>=max(p1.y,p2.y))continue;double x=(double)(pt.y-p1.y)*(double)(p2.x-p1.x)/(double)(p2.y-p1.y)+p1.x;if(x>pt.x)nCross++;}flag=nCross%2;} while(!flag);floodfill(pt.x,pt.y,linecolor,0); }void solidpolygon(const POINT *points, int num) {/*這個函數用于畫無邊框的填充多邊形。*/int lc=linecolor;linecolor=fillcolor;for(int i=1; i<num; i++)line(points[i].x,points[i].y,points[i-1].x,points[i-1].y);line(points[num-1].x,points[num-1].y,points[0].x,points[0].y);linecolor=lc;bool flag=false;POINT pt;do {pt= {rand()%cx,rand()%cy};int nCross=0;for(int i=0; i<num; i++) {POINT p1;POINT p2;p1=points[i];p2=points[(i+1)%num];if(p1.y==p2.y)continue;if(pt.y<min(p1.y,p2.y))continue;if(pt.y>=max(p1.y,p2.y))continue;double x=(double)(pt.y-p1.y)*(double)(p2.x-p1.x)/(double)(p2.y-p1.y)+p1.x;if(x>pt.x)nCross++;}flag=nCross%2;} while(!flag);floodfill(pt.x,pt.y,fillcolor,0); }void clearpolygon(const POINT *points, int num) {/*這個函數用于清空多邊形區域。*/int lc=linecolor,fc=fillcolor;linecolor=bkcolor;fillcolor=bkcolor;for(int i=1; i<num; i++)line(points[i].x,points[i].y,points[i-1].x,points[i-1].y);line(points[num-1].x,points[num-1].y,points[0].x,points[0].y);linecolor=lc;bool flag=false;POINT pt;do {pt= {rand()%cx,rand()%cy};int nCross=0;for(int i=0; i<num; i++) {POINT p1;POINT p2;p1=points[i];p2=points[(i+1)%num];if(p1.y==p2.y)continue;if(pt.y<min(p1.y,p2.y))continue;if(pt.y>=max(p1.y,p2.y))continue;double x=(double)(pt.y-p1.y)*(double)(p2.x-p1.x)/(double)(p2.y-p1.y)+p1.x;if(x>pt.x)nCross++;}flag=nCross%2;} while(!flag);floodfill(pt.x,pt.y,bkcolor,0);fillcolor=fc; }void polybezier(const POINT *points, int num) {/*這個函數用于畫三次方貝塞爾曲線。*/pass; }void floodfill(int x, int y, int color, int filltype) {/*這個函數用于填充區域。*/queue <POINT> q;int dx[4]= {0,1,0,-1},dy[4]= {1,0,-1,0};q.push({x,y});if(!filltype) {if(EPOTWcolor[x+cshc][y+cshc]==color)return;putpixel(x,y,fillcolor);while(!q.empty()) {POINT p=q.front();q.pop();for(int i=0; i<4; i++) {int nx=p.x+dx[i],ny=p.y+dy[i];if(nx<0||ny<0||nx>cx||ny>cy)continue;if(EPOTWcolor[nx+cshc][ny+cshc]!=color&&EPOTWcolor[nx+cshc][ny+cshc]!=fillcolor) {putpixel(nx,ny,fillcolor);q.push({nx,ny});}}}} else {if(EPOTWcolor[x+cshc][y+cshc]!=color)return;putpixel(x,y,fillcolor);while(!q.empty()) {POINT p=q.front();for(int i=0; i<4; i++) {int nx=p.x+dx[i],ny=p.y+dy[i];if(nx<0||ny<0||nx>cx||ny>cy)continue;if(EPOTWcolor[nx+cshc][ny+cshc]!=color) {putpixel(nx,ny,fillcolor);q.push({nx,ny});}}}} }void outtextxy(int x, int y, string str) {/*這個函數用于在指定位置輸出字符串。*/if(str.size()&1)str+=" ";if(nowwcolor^textcolor&&!batchDraw) {int B=textcolor>>16,G=(textcolor>>8)%256,R=textcolor%256;printf("\033[38;2;%d;%d;%dm",R,G,B);nowwcolor=textcolor;}if(bkmode) {SetConsoleCursorPosition(hOut, {x<<1,y});for(int i=0; i<str.size(); i+=2) {int color=EPOTWcolor[x+(i>>1)+cshc][y+cshc];int B=color>>16,G=(color>>8)%256,R=color%256;if(checkPoint(x+(i>>1),y))printf("\033[48;2;%d;%d;%dm%s",R,G,B,str.substr(i,2).c_str());nowbcolor=RGB(R,G,B);EPOTWtext[x+(i>>1)+cshc][y+cshc]=str.substr(i,2);EPOTWwcolor[x+(i>>1)+cshc][y+cshc]=textcolor;}} else {SetConsoleCursorPosition(hOut, {x<<1,y});if(nowbcolor^bkcolor) {int B=bkcolor>>16,G=(bkcolor>>8)%256,R=bkcolor%256;printf("\033[48;2;%d;%d;%dm",R,G,B);nowbcolor=bkcolor;}for(int i=0; i<str.size(); i+=2) {if(checkPoint(x+(i>>1),y))printf("%s",str.substr(i,2).c_str());EPOTWtext[x+(i>>1)+cshc][y+cshc]=str.substr(i,2);EPOTWwcolor[x+(i>>1)+cshc][y+cshc]=textcolor;EPOTWcolor[x+(i>>1)+cshc][y+cshc]=bkcolor;}} }void system_outtextxy(int x, int y, string str) {/*這個函數用于在指定位置輸出字符串(不受邊界限制)。*/if(nowwcolor^textcolor&&!batchDraw) {int B=textcolor>>16,G=(textcolor>>8)%256,R=textcolor%256;printf("\033[38;2;%d;%d;%dm",R,G,B);nowwcolor=textcolor;}if(bkmode) {SetConsoleCursorPosition(hOut, {x<<1,y});for(int i=0; i<str.size(); i+=2) {int color=EPOTWcolor[x+(i>>1)+cshc][y+cshc];int B=color>>16,G=(color>>8)%256,R=color%256;printf("\033[48;2;%d;%d;%dm%s",R,G,B,str.substr(i,2).c_str());EPOTWtext[x+(i>>1)+cshc][y+cshc]=str.substr(i,2);EPOTWwcolor[x+(i>>1)+cshc][y+cshc]=textcolor;nowbcolor=RGB(R,G,B);}} else {SetConsoleCursorPosition(hOut, {x<<1,y});if(nowbcolor^bkcolor) {int B=bkcolor>>16,G=(bkcolor>>8)%256,R=bkcolor%256;printf("\033[48;2;%d;%d;%dm",R,G,B);nowbcolor=bkcolor;}for(int i=0; i<str.size(); i+=2) {printf("%s",str.substr(i,2).c_str());EPOTWtext[x+(i>>1)+cshc][y+cshc]=str.substr(i,2);EPOTWwcolor[x+(i>>1)+cshc][y+cshc]=textcolor;EPOTWcolor[x+(i>>1)+cshc][y+cshc]=bkcolor;}} }int textwidth(string str) {/*這個函數用于獲取字符串實際占用的像素寬度。*/return 1; }int textheight(string str) {/*這個函數用于獲取字符串實際占用的像素高度。*/return str.size()>>1; }int drawtext(string str, RECT* pRect, UINT uFormat) {/*這個函數用于在指定區域內以指定格式輸出字符串。*/pass; }void settextstyle(int nHeight, int nWidth, string lpszFace) {/*這個函數用于設置當前字體樣式。*/pass; }void settextstyle(int nHeight, int nWidth, string lpszFace, int nEscapement,int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut) {/*這個函數用于設置當前字體樣式。*/pass; }void settextstyle(int nHeight, int nWidth, string lpszFace, int nEscapement,int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut,BYTE fbCharSet, BYTE fbOutPrecision, BYTE fbClipPrecision, BYTE fbQuality,BYTE fbPitchAndFamily) {/*這個函數用于設置當前字體樣式。*/pass; }void settextstyle(const LOGFONT *font) {/*這個函數用于設置當前字體樣式。*/pass; }void gettextstyle(LOGFONT *font) {/*這個函數用于獲取當前字體樣式。*/pass; }int getwidth() {/*該函數用于獲取繪圖區寬度*/return cx; }int getheight() {/*該函數用于獲取繪圖區高度*/return cy; }void BeginBatchDraw() {/*這個函數用于開始批量繪圖。執行后,任何繪圖操作都將暫時不輸出到繪圖窗口上,直到執行 FlushBatchDraw 或 EndBatchDraw 才將之前的繪圖輸出。*/batchDraw=true; }void FlushBatchDraw() {/*這個函數用于執行未完成的繪制任務。*/if(!batchDraw)return;int wR,wG,wB,bR,bG,bB;SetConsoleCursorPosition(hOut, {0,0}); // for(int j=0; j<cy; j++) { // for(int i=0; i<cx; i++) { // if(lEPOTWcolor[i+cshc][j+cshc]^EPOTWcolor[i+cshc][j+cshc]|| // lEPOTWwcolor[i+cshc][j+cshc]^EPOTWwcolor[i+cshc][j+cshc]|| // lEPOTWtext[i+cshc][j+cshc]!=EPOTWtext[i+cshc][j+cshc]) { // if(nowwcolor^EPOTWwcolor[i+cshc][j+cshc]) { // nowwcolor=EPOTWwcolor[i+cshc][j+cshc]; // wR=EPOTWwcolor[i+cshc][j+cshc]%256; // wG=(EPOTWwcolor[i+cshc][j+cshc]>>8)%256; // wB=EPOTWwcolor[i+cshc][j+cshc]>>16; // printf("\033[38;2;%d;%d;%dm",wR,wG,wB); // } // if(nowbcolor^EPOTWcolor[i+cshc][j+cshc]) { // nowbcolor=EPOTWcolor[i+cshc][j+cshc]; // bR=EPOTWcolor[i+cshc][j+cshc]%256; // bG=(EPOTWcolor[i+cshc][j+cshc]>>8)%256; // bB=EPOTWcolor[i+cshc][j+cshc]>>16; // printf("\033[48;2;%d;%d;%dm",bR,bG,bB); // } // printf("%s",EPOTWtext[i+cshc][j+cshc].c_str()); // } else SetConsoleCursorPosition(hOut, {(i<<1)+2,j}); // lEPOTWcolor[i+cshc][j+cshc]=EPOTWcolor[i+cshc][j+cshc]; // lEPOTWwcolor[i+cshc][j+cshc]=EPOTWwcolor[i+cshc][j+cshc]; // lEPOTWtext[i+cshc][j+cshc]=EPOTWtext[i+cshc][j+cshc]; // } // if(j^(cy-1))printf("\n"); // }int c=clock();DWORD count;string ans;for(int i=0; i<cx; i++)for(int j=0; j<cy; j++) {bR=EPOTWcolor[i+cshc][j+cshc]%256;bG=(EPOTWcolor[i+cshc][j+cshc]>>8)%256;bB=EPOTWcolor[i+cshc][j+cshc]>>16;string s1,s2,s3;ans+="\033[48;2;"+change_its(bR)+";"+change_its(bG)+";"+change_its(bB)+"m ";}WriteConsole(hOut, ans.c_str(), ans.size(), &count, NULL);settitle(change_its(clock()-c)); }void FlushBatchDraw(int left, int top, int right, int bottom) {/*[重載]執行指定區域內未完成的繪制任務*/if(!batchDraw)return;int wR,wG,wB,bR,bG,bB;SetConsoleCursorPosition(hOut, {0,0});for(int j=top; j<=bottom; j++) {SetConsoleCursorPosition(hOut, {left<<1,j});for(int i=left; i<=right; i++) {if(lEPOTWcolor[i+cshc][j+cshc]^EPOTWcolor[i+cshc][j+cshc]||lEPOTWwcolor[i+cshc][j+cshc]^EPOTWwcolor[i+cshc][j+cshc]||lEPOTWtext[i+cshc][j+cshc]!=EPOTWtext[i+cshc][j+cshc]) {if(nowwcolor^EPOTWwcolor[i+cshc][j+cshc]) {nowwcolor=EPOTWwcolor[i+cshc][j+cshc];wR=EPOTWwcolor[i+cshc][j+cshc]%256;wG=(EPOTWwcolor[i+cshc][j+cshc]>>8)%256;wB=EPOTWwcolor[i+cshc][j+cshc]>>16;printf("\033[38;2;%d;%d;%dm",wR,wG,wB);}if(nowbcolor^EPOTWcolor[i+cshc][j+cshc]) {nowbcolor=EPOTWcolor[i+cshc][j+cshc];bR=EPOTWcolor[i+cshc][j+cshc]%256;bG=(EPOTWcolor[i+cshc][j+cshc]>>8)%256;bB=EPOTWcolor[i+cshc][j+cshc]>>16;printf("\033[48;2;%d;%d;%dm",bR,bG,bB);}printf("%s",EPOTWtext[i+cshc][j+cshc].c_str());} else SetConsoleCursorPosition(hOut, {(i<<1)+2,j});lEPOTWcolor[i+cshc][j+cshc]=EPOTWcolor[i+cshc][j+cshc];lEPOTWwcolor[i+cshc][j+cshc]=EPOTWwcolor[i+cshc][j+cshc];lEPOTWtext[i+cshc][j+cshc]=EPOTWtext[i+cshc][j+cshc];}} }void EndBatchDraw() {/*這個函數用于結束批量繪制,并執行未完成的繪制任務。結束批量繪制,并執行未完成的繪制任務*/FlushBatchDraw();batchDraw=false; }void EndBatchDraw(int left, int top, int right, int bottom) {/*[重載]這個函數用于結束批量繪制,并執行未完成的繪制任務。結束批量繪制,并執行指定區域內未完成的繪制任務*/FlushBatchDraw(left,top,right,bottom);batchDraw=false; }HWND GetHWnd() {/*這個函數用于獲取繪圖窗口句柄。*/return hwnd; }string GetGGCCVer() {/*這個函數用于獲取當前 GGCC 的版本信息。*/return "GGCC[2018-2021][v5.2.1] ggcc_graphics[v1.6] 持續更新~"; }void settextsize(double sizex,double sizey) {/*這個函數用于設置字體寬高*/if(sizex<=0||sizey<=0)return;textX=sizex;textY=sizey;CONSOLE_FONT_INFOEX cfi;cfi.cbSize = sizeof cfi;cfi.nFont = 0;cfi.dwFontSize.X = sizex;cfi.dwFontSize.Y = sizey;cfi.FontFamily = FF_DONTCARE;cfi.FontWeight = FW_NORMAL;wcscpy(cfi.FaceName, L"Kaiti");SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi); }void setwindowsize(int sizex,int sizey) {/*這個函數用于設置窗口寬高*/settextsize(sizex/cx,sizey/cx); }void settitle(string a) {/*這個函數用于設置控制臺標題*/SetConsoleTitle(a.c_str()); }bool WinInFront() {/*這個函數用于判斷窗口是否在最頂層*/return hwnd==GetConsoleWindow(); }bool GetGameTime() {/*這個函數用于獲取游戲時間,單位:毫秒*/return clock()-StartGameTime; }int MixColor(int color1,int color2,int percent1,int percent2) {/*這個函數用于混合顏色*/int R1,G1,B1,R2,G2,B2,mcolor;R1=color1%256,R2=color2%256;G1=(color1>>8)%256,G2=(color2>>8)%256;B1=color1>>16,B2=color2>>16;mcolor=(R1*percent1/100+R2*percent2/100)+((G1*percent1/100+G2*percent2/100)<<8)+((B1*percent1/100+B2*percent2/100)<<16);return mcolor; }int ContraryColor(int color) {/*這個函數用于獲取該顏色的相反色*/int R,G,B;R=255-color%256,G=255-(color>>8)%256,B=255-(color>>16);return R+(G<<8)+(B<<16); }void popup(int x1,int y1,int x2,int y2,string message,string title,int boxcolor=WHITE) {/*這個函數用于繪制彈窗*/ }bool NewFolder(string path) {/*這個函數用于新建文件夾,失敗返回false*/bool flag; if(0!=access(path.c_str(),0))flag=mkdir(path.c_str())+1;return flag; }ヾ( ̄▽ ̄)886!
總結
以上是生活随笔為你收集整理的Devc++还原ggcc.graphics.h的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Excel技能培训之十六自动高亮重复值,
- 下一篇: Android-关于启动不了Androi