Skip to content

Commit

Permalink
优化拖动操作
Browse files Browse the repository at this point in the history
  • Loading branch information
cgoxopx committed Jul 6, 2023
1 parent c498265 commit 6d27a1a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/view/editWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,10 @@ void editWindow::scrollBuilder_onGetAllNotePos(mgnr::note* n) {
rect.h = 1;
if (n->tone > nmin && n->tone < nmax) {
rect.y = 30 - ((n->tone - nmin) * 30) / hlen;
rect.w = (n->duration * 1024) / noteTimeMax;
rect.w = round((n->duration * 1024.) / noteTimeMax);
if (rect.w <= 0)
rect.w = 1;
rect.x = (n->begin * 1024) / noteTimeMax;
rect.x = round((n->begin * 1024.) / noteTimeMax);

SDL_SetRenderDrawColor(parent->renderer, 128, 128, 128, SDL_ALPHA_OPAQUE);
SDL_RenderFillRect(parent->renderer, &rect);
Expand Down
8 changes: 6 additions & 2 deletions src/view/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,14 @@ void renderContext::processEvents_mouse() {
drawing->previewNote_on(p.Y, drawing->defaultVolume);
}
} else if (dragMode) {
double deltaX = (mouse_x - moveNoteX) / drawing->noteLength;
int deltaX_screen = mouse_x - moveNoteX;
double deltaY = (mouse_y - moveNoteY) / drawing->noteHeight;
drawing->lookAtX = drawing->moveWindowStartX - deltaX;
drawing->lookAtY = drawing->moveWindowStartY + deltaY;
if ((!drawing->playingStatus) || abs(deltaX_screen) > 30 || moveScreenWithPlaying) {
double deltaX = (deltaX_screen) / drawing->noteLength;
drawing->lookAtX = drawing->moveWindowStartX - deltaX;
moveScreenWithPlaying = true;
}
} else {
if (selectNoteFail) {
if (drawing->show_edit_window) {
Expand Down
1 change: 1 addition & 0 deletions src/view/renderContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ void renderContext::loop() {
resizeNoteMode = false;
resizeNoteReady = false;
dragMode = false;
moveScreenWithPlaying = false;
if (drawing) {
drawing->showDisplayBuffer = false;
drawing->previewNote_off();
Expand Down
1 change: 1 addition & 0 deletions src/view/renderContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ struct renderContext : public mgnr::clipboard_t {
bool resizeNoteReady = false;
bool selectNoteFail = false;
bool dragMode = false;
bool moveScreenWithPlaying = false;
//////////////////////////////////////////////////////////////////
///ui相关

Expand Down

0 comments on commit 6d27a1a

Please sign in to comment.