Skip to content

Commit

Permalink
适配了鼠标拖动
Browse files Browse the repository at this point in the history
  • Loading branch information
Augtons committed Nov 27, 2023
1 parent a7ab9b5 commit 7c27355
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
5 changes: 5 additions & 0 deletions examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ int app_main(lv_disp_t *disp) {
lvglsim_init();

lv_example_keyboard_1();

auto slider = lv_slider_create(lv_disp_get_scr_act(disp));
lv_obj_set_align(slider, LV_ALIGN_TOP_MID);
lv_obj_set_pos(slider, 0, 100);

return 0;
}
26 changes: 18 additions & 8 deletions src/DisplayDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,24 @@ void DisplayDriver::mainLoop() {

while (true) {
while (SDL_PollEvent(&event) != 0) {
if (event.type == SDL_QUIT) {
return;
} else if (event.type == SDL_MOUSEBUTTONDOWN) {
int x, y;
SDL_GetMouseState(&x, &y);
mousePress(x, y);
} else if (event.type == SDL_MOUSEBUTTONUP) {
mouseRelease();
switch (event.type) {
case SDL_QUIT: {
return;
}
case SDL_MOUSEBUTTONUP: {
mouseRelease();
break;
}
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEMOTION: {
int x, y;
if (SDL_GetMouseState(&x, &y) & 0x01) {
mousePress(x, y);
} else {
mouseRelease();
}
break;
}
}
}
}
Expand Down

0 comments on commit 7c27355

Please sign in to comment.