TC graphics library Tips

TC drawing graphics library known as Turbo C programming library in the early version 2.0, TC graphics library 460 contains a plurality of library functions, wherein the plurality of graphics functions 70, these functions include graphics, image processing and picture elements, and the screen view zone control, color and line control, status queries, and error handling, which makes the TC has a strong graphics capabilities!

TC库的头文件 #include<graphics.h>

Because of this relatively simple and basic functions involved, so do not eleven out (full talk is not realistic)
Note: Please install the graphics library when using the TC vs
vs2019 installation tutorial (ultra-detailed)
installed after the installation EasyX vs library:
Click here to download the library
after downloading graphics library will check your own vs, then you can install, this is not about a simple

@@@@@@ 1. Drawing class functions (filled and unfilled)
! ! ! ! To this can be achieved only drawing in a graphical interface, console can not draw, specifically to see the second step

  1. Draw a function point:
putpixel(int x,int y,int pixelcolor)   3个参数,分别表示你想要画的点的
x,y坐标和该点的像素颜色

Here Insert Picture Description

2. Functions draw a straight line

line(int x0,int y0,int x1,int y1)   4个参数,在两点之间画一条直线
该两点的坐标分别是(x0,y0)和(x1,y1);

Here Insert Picture Description

3 . Draw a straight line function of the cursor

lineto(int x,int y)       2个参数画一条从光标到该点(x,y)的直线

Here Insert Picture Description
4. The function draws a circle

circle(int x,int y,int radius)   画一个以(x,y)为圆心,radius
为半径的圆 (只能填充边界颜色的圆)
fillcircle(int x,int y,int radius) (可以填充内部颜色的圆)

5. Draw a rectangular function

rectangle(int x0,int y0,int x1,int y1)  (x0,y0)是矩形左上角的
顶点坐标,(x1,y1)是矩形右下角的顶点坐标 (只能填充边界的矩形)
fillrectangle(int x0,int y0,int x1,int x2) (可以填充内部颜色的矩形)

6 . To set the color graphics border

setcolor(int color) 

Here Insert Picture Description
7. to fill the interior fill color pattern class

setfillcolor(int color) //颜色代码和上面一致

@@@@@ 2. Create a graphical interface
on a blog introduced the concept of window handle

在TC里面有一个创建一种非控制台输出类的图形界面
HWND app;//  创建一个窗口句柄 app
app = initgraph(int length,int width) 图形窗口的长和宽
例如  app = initgraph(640,480) 这是不显示控制台窗口的640*480图形窗口
例如  app = initgraph(640,480,SHOWCONSOLE) 这里SHOWCONSLOE是指
显示控制台窗口的意思

一般用完图形界面后要安全关闭
closegraph()  //关闭图形界面

Examples of a circle:
Here Insert Picture Description
Boundary addition Red: (setColor on Circle)
Here Insert Picture Description
filled with Red (setfillcolor of FillCircle,)
Here Insert Picture Description@@@@@ 3. text-based position, color, form, etc.

1. In the designated location of the output text (can be compared on a blog to comprehend it)

outtextxy(int x,int y,TCHAR c)  在图形界面x,y的坐标位置来输出内容c

Here Insert Picture Description
2. Set the output text font color

settextcolor(COLORRER color) //设置你将要输出字体的颜色

有人可能会问SetTextColor()      函数是不是一样的,这两者本质目的差不多,
但参数对象不一样,下面这个设计到HDC(设备场景句柄) 这个有点繁琐,
就不做过多介绍了

Here Insert Picture Description
3. Set the text function

settextstyle(int height,int width, LPCTSTR IpszFace)  分别表示你输出
文本的字体高度,长度和字体类型

Here Insert Picture Description4. Get the height of the string (font)

textheight(char *textstring)   //返回以像素为单位的字符串高度,一般
输入的字符串都是16

Here Insert Picture Description. @@@@@ 3 Create the message box
GUI message box is a window-based command button mouse click intersection box to achieve,
its function is:

函数原型
MessageBox(HWND hWnd,LPCTSTR lpText,LPCTSTR lpCaption,UINT uType)
该函数返回int 型整数

1.hwnd 此参数代表消息框拥有的窗口。如果为NULL,则消息框没有拥有窗口。
2.lpText 指该消息框你所要执行的所有的命令内容
3.lpCaption 消息框的标题,就像每个窗口都有一个标题一样
4.uType 指实现命令的按钮,视情况而定

Find a picture on a command button that can be achieved
Here Insert Picture Description, for example to achieve this:

#include<iostream>
#include<graphics.h>
using namespace std;

int main()
{
	HWND app;
	app = initgraph(640, 480);
	int sx = MessageBox(app, "是否退出游戏", "消息窗口", MB_YESNO);
	while (1)
	{
		if (sx == IDYES)
			exit(0);
		if (sx == IDNO)
			continue;
	}
	
	system("pause");
	return 0;
}

Here Insert Picture DescriptionThis produced a simple message window.

@@@@@ 4. The image is loaded, read, adjust

1. When novice computer language will first try to understand the type of variable name, such as integers are int, float is float, the real number is double, the character is char, string is the string, and so on, but the photo is what category it belongs, TC inside photo variable type name is IMAGE;

IMAGE img //定义一个有关于照片的类型变量,
//jpg和bmp的图片格式是支持的

2. What is the function loads an image asset?

IMAGE img //创建一个图片变量
loadimage(IMAGE *pDstlmg,LRCTSTR plmgFile,int width,int height,
          bool bResize=false)
1.pDstlmg,是取你创建的图片变量名的地址
2.plmgFile 你所要加载的图片的路径位置
3.width  你所要将你加载的图片变化为多宽
4.height 你所要将加载你的图片变化为多高
5.bResize  是否将图片改变为你设置的类型(感觉真没什么用)

// You can also you want to load images into the file explorer inside
Here Insert Picture DescriptionHere Insert Picture Description! Benefits like this picture can be loaded directly, without the need to write a long path

3. Draw a picture for you to load graphical interface

putimage(int x,int y,const IMAGE *pSrclmg,DWORD dwRop)
1. x  图贴位置的x坐标
2. y  图贴位置的y坐标
   (x,y是指你要贴的图片左上角顶点的坐标
3. pSrclmg  是指向你所加载图片的IMAGE位置指针
4. dwRop  三元光栅
//举例:
//图片自己准备,我这里的图片和你们的不一样,所以代码你们不能编译,参考一下
#include<iostream>
#include<graphics.h>
using namespace std;

int main()
{
	HWND app;
	app = initgraph(640, 480);
	IMAGE img;
	loadimage(&img,"5.jpg",300,300,true);
	putimage(1, 1, &img);
	while (1)
	{
		putimage(1, 1, &img);
	}
	system("pause");
	return 0;
}

Here Insert Picture DescriptionProduction of the game picture material can be resolved from the game, but of course also possible to achieve a transparent background textures, which involves the issue of the mask map and sprite, here temporarily introduced to Sokoban game assets can leave a message, although I picture a little black-linear, but severely distorted compared to the picture, or you can go off, this blog introduced here, have questions, please leave a message!

Released nine original articles · won praise 14 · views 2164

Guess you like

Origin blog.csdn.net/YSJ367635984/article/details/104807909