マウスオーバー効果
This commit is contained in:
24
control.c
24
control.c
@@ -54,7 +54,7 @@ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||||||
char curinput[64] = {0};
|
char curinput[64] = {0};
|
||||||
int input_pos = 0;
|
int input_pos = 0;
|
||||||
int initialized = 0;
|
int initialized = 0;
|
||||||
SuwaButton buttons[NUM_ROWS][NUM_COLS];
|
SuwaButton *lasthover = NULL;
|
||||||
|
|
||||||
static const char *btn_labels[][10] = {
|
static const char *btn_labels[][10] = {
|
||||||
{ NULL }, // 数字表示
|
{ NULL }, // 数字表示
|
||||||
@@ -195,7 +195,6 @@ void initialize_basic_buttons(SuwaWindow *window, XftDraw *backdraw, float scale
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
suwaui_draw_button(window, &btn, backdraw);
|
suwaui_draw_button(window, &btn, backdraw);
|
||||||
buttons[row][col] = btn;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -385,23 +384,14 @@ redraw:
|
|||||||
control_expose(window, labels, &(SuwaButton){0});
|
control_expose(window, labels, &(SuwaButton){0});
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_mouse_hover(SuwaWindow *window, CtrlLabels *labels) {
|
void handle_mouse_hover(SuwaWindow *window, CtrlLabels *labels, int mx, int my) {
|
||||||
int x = window->event.xmotion.x;
|
SuwaButton *btn = find_button_at(window, mx, my);
|
||||||
int y = window->event.xmotion.y;
|
|
||||||
SuwaButton *btn = find_button_at(window, x, y);
|
|
||||||
if (!btn) return;
|
if (!btn) return;
|
||||||
|
|
||||||
btn->hovered = 1;
|
if (lasthover && lasthover != btn) lasthover->hovered = 0;
|
||||||
XftDraw *backdraw = XftDrawCreate(window->display, window->backbuf,
|
if (btn) btn->hovered = 1;
|
||||||
DefaultVisual(window->display, DefaultScreen(window->display)),
|
lasthover = btn;
|
||||||
DefaultColormap(window->display, DefaultScreen(window->display)));
|
|
||||||
if (!backdraw) {
|
|
||||||
fprintf(stderr, "Pixmap向けXftDrawの作成に失敗。\n");
|
|
||||||
XFreePixmap(window->display, window->backbuf);
|
|
||||||
window->backbuf = None;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
window->event = (XEvent){.type = Expose};
|
window->event = (XEvent){.type = Expose};
|
||||||
control_expose(window, labels, btn);
|
control_expose(window, labels, btn ? btn : &(SuwaButton){0});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,4 +47,4 @@ void control_expose(SuwaWindow *window, CtrlLabels *labels, SuwaButton *button);
|
|||||||
void handle_button_press(SuwaWindow *window, CtrlLabels *labels, int mx, int my);
|
void handle_button_press(SuwaWindow *window, CtrlLabels *labels, int mx, int my);
|
||||||
void handle_button_release(SuwaWindow *window, CtrlLabels *labels, int mx, int my);
|
void handle_button_release(SuwaWindow *window, CtrlLabels *labels, int mx, int my);
|
||||||
void handle_key_press(SuwaWindow *window, CtrlLabels *labels);
|
void handle_key_press(SuwaWindow *window, CtrlLabels *labels);
|
||||||
void handle_mouse_hover(SuwaWindow *window, CtrlLabels *labels);
|
void handle_mouse_hover(SuwaWindow *window, CtrlLabels *labels, int mx, int my);
|
||||||
|
|||||||
@@ -332,8 +332,8 @@ __attribute__((unused)) static SuwaWindow suwaui_create_window(int x, int y, int
|
|||||||
| ButtonPressMask
|
| ButtonPressMask
|
||||||
| ButtonReleaseMask
|
| ButtonReleaseMask
|
||||||
| KeyPressMask
|
| KeyPressMask
|
||||||
// | PointerMotionMask
|
| PointerMotionMask
|
||||||
// | ButtonMotionMask
|
| Button1MotionMask
|
||||||
// | StructureNotifyMask
|
// | StructureNotifyMask
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
15
main.c
15
main.c
@@ -43,6 +43,8 @@ const char *sofname = "ucalc";
|
|||||||
const char *version = "0.0.0";
|
const char *version = "0.0.0";
|
||||||
const char *disname = "Unix Calc";
|
const char *disname = "Unix Calc";
|
||||||
|
|
||||||
|
static Time lasthovertime = 0;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
#if defined(__OpenBSD__)
|
#if defined(__OpenBSD__)
|
||||||
SuwaWindow window = suwaui_create_window(
|
SuwaWindow window = suwaui_create_window(
|
||||||
@@ -109,7 +111,18 @@ int main() {
|
|||||||
handle_key_press(&window, &lbl);
|
handle_key_press(&window, &lbl);
|
||||||
break;
|
break;
|
||||||
case MotionNotify:
|
case MotionNotify:
|
||||||
handle_mouse_hover(&window, &lbl);
|
Time now = window.event.xmotion.time;
|
||||||
|
if (now - lasthovertime < 40) break;
|
||||||
|
lasthovertime = now;
|
||||||
|
Window root, child;
|
||||||
|
int root_x, root_y,
|
||||||
|
win_x, win_y;
|
||||||
|
unsigned int mask;
|
||||||
|
|
||||||
|
XQueryPointer(window.display, window.xwindow, &root, &child,
|
||||||
|
&root_x, &root_y, &win_x, &win_y, &mask);
|
||||||
|
if (window.event.xmotion.state == 0) break;
|
||||||
|
handle_mouse_hover(&window, &lbl, win_x, win_y);
|
||||||
break;
|
break;
|
||||||
case ClientMessage:
|
case ClientMessage:
|
||||||
// WM_DELETE_WINDOW
|
// WM_DELETE_WINDOW
|
||||||
|
|||||||
Reference in New Issue
Block a user