#include
using namespace std;
#include
ExMessage msg = { 0 };
void drawShape()
{
putpixel(50, 50, RED);
setlinecolor(BLUE);
setlinestyle(PS_SOLID, 3);
line(0, 0, getwidth(), getheight());
setfillcolor(YELLOW);
rectangle(100, 0, 100 + 50, 0 + 50);
fillrectangle(100, 50, 100 + 50, 50 + 50);
solidrectangle(100, 100, 100 + 50, 100 + 50);
roundrect(160, 0, 160 + 50, 0 + 50, 10, 10);
fillroundrect(160, 50, 160 + 50, 50 + 50, 10, 10);
solidroundrect(160, 100, 160 + 50, 100 + 50, 10, 10);
circle(50, 50, 50);
fillcircle(50, 150, 50);
solidcircle(50, 250, 50);
ellipse(200, 0, 200 + 50, 0 + 100);
fillellipse(200, 200, 200 + 50, 200 + 100);
solidellipse(200, 300, 200 + 50, 300 + 100);
POINT points[] = { {0,0}, {20,20},{50, 80},{10,60} };
polyline(points, 4);
}
void drawText()
{
printf("hello EasyX!");
settextstyle(48, 0, _T("微软雅黑"));
settextcolor(BROWN);
setbkmode(TRANSPARENT);
outtextxy(10, 10, "hello EasyX!");
settextstyle(30, 0, "微软雅黑");
int score = 66;
char str[50] = "";
sprintf(str, "Score:%d", score);
outtextxy(getwidth() - 100, 0, str);
}
void centerText()
{
int rx = 30;
int ry = 380;
int rw = 200;
int rh = 60;
setfillcolor(RGB(230, 231, 232));
fillrectangle(rx, ry, rx + rw, ry + rh);
settextcolor(RED);
char str[] = "Center Text";
int hSpace = (rw - textwidth(str)) / 2;
int vSpace = (rh - textheight(str)) / 2;
outtextxy(rx + hSpace, ry + vSpace, str);
}
bool inArea(int mx, int my, int x, int y, int w, int h)
{
if (mx > x && mx<x + w && my>y && my < y + h)
{
return true;
}
return false;
}
bool button(int x, int y, int w, int h, const char* text)
{
if (inArea(msg.x, msg.y, x, y, w, h))
{
setfillcolor(RGB(93, 107, 153));
}
else
{
setfillcolor(RGB(230, 231, 232));
}
fillroundrect(x, y, x + w, y + h, 5, 5);
int hSpace = (w -textwidth(text)) / 2;
int vSpace = (h - textheight(text)) / 2;
outtextxy(x + hSpace, y + vSpace, text);
if (msg.message == WM_LBUTTONDOWN && inArea(msg.x, msg.y, x, y, w, h))
{
return true;
}
else
{
return false;
}
}
int main()
{
initgraph(640, 480, EX_SHOWCONSOLE | EX_DBLCLKS);
setbkcolor(BLUE);
cleardevice();
while (true)
{
if (peekmessage(&msg, EX_MOUSE))
{
switch (msg.message)
{
case WM_LBUTTONDOWN:
printf("左键按下 pos (%d ,%d) \n", msg.x, msg.y);
break;
case WM_RBUTTONDOWN:
printf("右键按下");
break;
case WM_MBUTTONDOWN:
printf("中键按下");
break;
case WM_MOUSEWHEEL:
printf("滚轮滚动 dir (%d) \n", msg.wheel);
break;
case WM_LBUTTONDBLCLK:
printf("左键双击");
break;
}
}
}
while (true)
{
if (peekmessage(&msg, EX_MOUSE))
{
}
BeginBatchDraw();
cleardevice();
if (button(20, 20, 150, 35, "Start Game"))
{
printf("Start Game!\n");
}
EndBatchDraw();
msg.message = 0;
}
getchar();
int arr[10] = { 0 };
return 0;
}