Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加mousepressed函数 #76

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions man/api/input/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<tr><td><a href="mousepos.htm">mousepos</a></td><td>获取当前鼠标位置</td></tr>
<tr><td><a href="showmouse.htm">showmouse</a></td><td>设置鼠标显示状态</td></tr>
<tr><td><a href="flushmouse.htm">flushmouse</a></td><td>清空鼠标消息缓存区</td></tr>
<tr><td><a href="mousepressed.htm">mousepressed</a></td><td>检测是否有鼠标点击发生</td></tr>
<tr><td>clearmousepressed</td><td>(不建议普通用户使用)清除鼠标点击事件</td></tr>
<tr><td><a href="flushmousemsgbuffer.htm">FlushMouseMsgBuffer</a></td><td>(过时函数)清空鼠标消息缓冲区</td></tr>
<tr><td><a href="GetMouseMsg.htm">GetMouseMsg</a></td><td>(过时函数)获取一个鼠标消息。如果当前鼠标消息队列中没有,就一直等待</td></tr>
</table>
Expand Down
48 changes: 48 additions & 0 deletions man/api/input/mousepressed.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>mousepressed</title>
</head>
<body>

<pre><font size="4"><a href="../../index.htm">主页</a>-><a href="../index.htm">库函数目录</a>-><a href="index.htm">键盘鼠标输入函数</a>->mousepressed</font>
<font size="4">
<font size="5" color="#0000FF"><strong>功能:</strong></font>
这个函数用于检测是否有鼠标点击事件发生并立即返回。
当执行该函数并且检测到鼠标点击事件后,执行delay_fps/delay_ms/delay_jfps函数会清除鼠标点击状态。

<font size="5" color="#0000FF"><strong>声明:</strong></font>
<pre><font color=#0000FF>int </font><font color=#008080>mousepressed</font>();</pre>
<font size="5" color="#0000FF"><strong>参数:</strong></font>
(无)

<font size="5" color="#0000FF"><strong>返回值:</strong></font>
如果有鼠标点击发生,返回 1;否则返回 0。

<font size="5" color="#0000FF"><strong>示例:</strong></font>
#include <graphics.h>

int main() {
initgraph(800,600);
setrendermode(RENDER_MANUAL);


int count = 0;
for(;is_run();delay_fps(60)) {
if (mousepressed()) {
//检测到鼠标点击事件
count += 1;
//清除屏幕原有内容,然后输出点击提示
cleardevice();
xyprintf(50,50,"clicked %d times",count);
}
}
closegraph();
return 0;
}

</font>
</pre>

</body>


6 changes: 5 additions & 1 deletion src/ege.h
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,8 @@ double EGEAPI randomf();
int EGEAPI inputbox_getline(LPCSTR title, LPCSTR text, LPSTR buf, int len); //�����Ի������û����룬��ǰ����������ͣ�����ط�0��ʾ������Ч��0Ϊ��Ч
int EGEAPI inputbox_getline(LPCWSTR title, LPCWSTR text, LPWSTR buf, int len); //�����Ի������û����룬��ǰ����������ͣ�����ط�0��ʾ������Ч��0Ϊ��Ч

//�������ͨ�ú���
int EGEAPI keystate(int key); // ��ü���Ϊkey�ļ�����key_code_e���Ƿ��£����keyʹ����갴���ļ��룬���õ�������״̬

//���̴�������
int EGEAPI kbmsg();
Expand All @@ -1116,7 +1118,6 @@ EGE_DEPRECATE(getchEx)
int EGEAPI getchEx(int flag);
EGE_DEPRECATE(kbhitEx)
int EGEAPI kbhitEx(int flag);
int EGEAPI keystate(int key); // ��ü���Ϊkey�ļ�����key_code_e���Ƿ��£����keyʹ����갴���ļ��룬���õ�������״̬
void EGEAPI flushkey(); // ��ռ�����Ϣ������

#if !defined(_INC_CONIO) && !defined(_CONIO_H_)
Expand All @@ -1138,6 +1139,9 @@ EGE_DEPRECATE(GetMouseMsg)
void EGEAPI flushmouse(); // ��������Ϣ������
int EGEAPI showmouse(int bShow); // �����Ƿ���ʾ���
int EGEAPI mousepos(int *x, int *y); // ��ȡ��ǰ���λ��
int EGEAPI mousepressed(); // ����Ƿ��������
void EGEAPI clearmousepressed(); //���������¼�


/*
callback function define as:
Expand Down
7 changes: 7 additions & 0 deletions src/ege_head.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ class IMAGE
friend void getimage_from_png_struct(PIMAGE, void*, void*);
};

#define LBUTTON_PRESSED 0x01
#define MBUTTON_PRESSED 0x02
#define RBUTTON_PRESSED 0x04


// ����egeȫ��״̬����
struct _graph_setting {
bool has_init;
Expand Down Expand Up @@ -489,6 +494,8 @@ struct _graph_setting {
int mouse_lastclick_x, mouse_lastclick_y;
int mouse_lastup_x, mouse_lastup_y;
int mouse_show;
int mouse_pressed;
int mouse_pressed_tested;

LPMSG_KEY_PROC callback_key;
void* callback_key_param;
Expand Down
12 changes: 11 additions & 1 deletion src/egegapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ api_sleep(long dwMilliseconds) {

void
ege_sleep(long ms) {
if (ms <= 0) return;
if (ms <= 0) return;
if (0) { // ����ģʽ��ռCPU����
::Sleep(ms);
} else if (0) { //��ȷģʽ��ռCPU�Ը�
Expand Down Expand Up @@ -353,6 +353,10 @@ void
delay_ms(long ms) {
struct _graph_setting * pg = &graph_setting;
egeControlBase* &root = pg->egectrl_root;

//����������Ϣ
if (pg->mouse_pressed_tested)
clearmousepressed();
pg->skip_timer_mark = true;
if (ms == 0) {
if (pg->update_mark_count < UPDATE_MAX_CALL) {
Expand Down Expand Up @@ -430,6 +434,9 @@ delay_fps(double fps) {
double dw = get_highfeq_time_ls(pg) * 1000.0;
int nloop = 0;

//����������Ϣ
if (pg->mouse_pressed_tested)
clearmousepressed();
if (pg->delay_fps_dwLast == 0) {
pg->delay_fps_dwLast = get_highfeq_time_ls(pg) * 1000.0;
}
Expand Down Expand Up @@ -476,6 +483,9 @@ delay_jfps(double fps) {
double dw = get_highfeq_time_ls(pg) * 1000.0;
int nloop = 0;

//����������Ϣ
if (pg->mouse_pressed_tested)
clearmousepressed();
if (pg->delay_fps_dwLast == 0) {
pg->delay_fps_dwLast = get_highfeq_time_ls(pg) * 1000.0;
}
Expand Down
29 changes: 29 additions & 0 deletions src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,30 @@ flushmouse() {
return ;
}

int
mousepressed() {
int result;
struct _graph_setting * pg = &graph_setting;
if (pg->exit_window)
return 0;
result = (pg->mouse_pressed != 0);
if (result) {
pg->mouse_pressed_tested = 1;
} else {
pg->mouse_pressed_tested = 0;
}
return result;
}

void
clearmousepressed() {
struct _graph_setting * pg = &graph_setting;
if (pg->exit_window)
return;
pg->mouse_pressed_tested = 0;
pg->mouse_pressed = 0;
}

int
mousemsg() {
struct _graph_setting * pg = &graph_setting;
Expand Down Expand Up @@ -966,6 +990,7 @@ wndproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
}
break;
case WM_LBUTTONDOWN:
pg->mouse_pressed |= LBUTTON_PRESSED;
case WM_LBUTTONDBLCLK:
pg->mouse_lastclick_x = (short int)((UINT)lParam & 0xFFFF);
pg->mouse_lastclick_y = (short int)((UINT)lParam >> 16);
Expand All @@ -975,6 +1000,7 @@ wndproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
if (hWnd == pg->hwnd) push_mouse_msg(pg, message, wParam, lParam);
break;
case WM_MBUTTONDOWN:
pg->mouse_pressed |= MBUTTON_PRESSED;
case WM_MBUTTONDBLCLK:
pg->mouse_lastclick_x = (short int)((UINT)lParam & 0xFFFF);
pg->mouse_lastclick_y = (short int)((UINT)lParam >> 16);
Expand All @@ -984,6 +1010,7 @@ wndproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
if (hWnd == pg->hwnd) push_mouse_msg(pg, message, wParam, lParam);
break;
case WM_RBUTTONDOWN:
pg->mouse_pressed |= RBUTTON_PRESSED;
case WM_RBUTTONDBLCLK:
pg->mouse_lastclick_x = (short int)((UINT)lParam & 0xFFFF);
pg->mouse_lastclick_y = (short int)((UINT)lParam >> 16);
Expand Down Expand Up @@ -1342,6 +1369,8 @@ messageloopthread(LPVOID lpParameter) {
graph_init(pg);

{
pg->mouse_pressed = 0;
pg->mouse_pressed_tested = 0;
pg->mouse_show = 0;
pg->exit_flag = 0;
pg->use_force_exit = (g_initoption & INIT_NOFORCEEXIT ? false : true);
Expand Down