mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 12:05:14 -04:00
Fix mouse movement in servers menu
This commit is contained in:
parent
4fbe2f20c3
commit
54c3fb28b9
@ -134,15 +134,14 @@ static void LScreen_MouseUp(struct LScreen* s, MouseButton btn) {
|
||||
static void LScreen_MouseMove(struct LScreen* s, int deltaX, int deltaY) {
|
||||
struct LWidget* over = LScreen_WidgetAt(s, Mouse_X, Mouse_Y);
|
||||
struct LWidget* prev = s->HoveredWidget;
|
||||
if (over == prev) return; /* TODO: ... */
|
||||
bool overSame = prev == over;
|
||||
|
||||
if (prev) {
|
||||
if (prev && !overSame) {
|
||||
prev->Hovered = false;
|
||||
s->HoveredWidget = NULL;
|
||||
s->UnhoverWidget(s, prev);
|
||||
|
||||
if (!prev->VTABLE->MouseLeft) return;
|
||||
prev->VTABLE->MouseLeft(prev);
|
||||
if (prev->VTABLE->MouseLeft) prev->VTABLE->MouseLeft(prev);
|
||||
}
|
||||
|
||||
if (over) {
|
||||
@ -151,7 +150,7 @@ static void LScreen_MouseMove(struct LScreen* s, int deltaX, int deltaY) {
|
||||
s->HoverWidget(s, over);
|
||||
|
||||
if (!over->VTABLE->MouseMove) return;
|
||||
over->VTABLE->MouseMove(over, deltaX, deltaY);
|
||||
over->VTABLE->MouseMove(over, deltaX, deltaY, overSame);
|
||||
}
|
||||
}
|
||||
static void LScreen_MouseWheel(struct LScreen* s, float delta) { }
|
||||
@ -1258,6 +1257,12 @@ static void ServersScreen_KeyDown(struct LScreen* s_, Key key, bool was) {
|
||||
}
|
||||
}
|
||||
|
||||
static void ServersScreen_MouseUp(struct LScreen* s_, MouseButton btn) {
|
||||
struct ServersScreen* s = (struct ServersScreen*)s_;
|
||||
s->Table.VTABLE->OnUnselect(&s->Table);
|
||||
LScreen_MouseUp(s_, btn);
|
||||
}
|
||||
|
||||
struct LScreen* ServersScreen_MakeInstance(void) {
|
||||
struct ServersScreen* s = &ServersScreen_Instance;
|
||||
LScreen_Reset((struct LScreen*)s);
|
||||
@ -1269,6 +1274,7 @@ struct LScreen* ServersScreen_MakeInstance(void) {
|
||||
s->Reposition = ServersScreen_Reposition;
|
||||
s->MouseWheel = ServersScreen_MouseWheel;
|
||||
s->KeyDown = ServersScreen_KeyDown;
|
||||
s->MouseUp = ServersScreen_MouseUp;
|
||||
s->OnEnterWidget = (struct LWidget*)&s->BtnConnect;
|
||||
return (struct LScreen*)s;
|
||||
}
|
||||
|
@ -129,7 +129,11 @@ static void LButton_Draw(void* widget) {
|
||||
if (!w->Hovered) Drawer2D_Cols['f'] = Drawer2D_Cols['F'];
|
||||
Launcher_MarkDirty(w->X, w->Y, w->Width, w->Height);
|
||||
}
|
||||
static void LButton_Hover(void* w, int x, int y) { LButton_Draw(w); }
|
||||
|
||||
static void LButton_Hover(void* w, int x, int y, bool wasOver) {
|
||||
/* only need to redraw when changing from unhovered to hovered */
|
||||
if (!wasOver) LButton_Draw(w);
|
||||
}
|
||||
|
||||
static struct LWidgetVTABLE lbutton_VTABLE = {
|
||||
LButton_Draw, NULL,
|
||||
@ -893,18 +897,21 @@ static void LTable_KeyDown(void* widget, Key key, bool was) {
|
||||
LTable_SetSelectedTo(w, index);
|
||||
}
|
||||
|
||||
static void LTable_MouseMove(void* widget, int deltaX, int deltaY) {
|
||||
static void LTable_MouseMove(void* widget, int deltaX, int deltaY, bool wasOver) {
|
||||
struct LTable* w = widget;
|
||||
int x = Mouse_X - w->X, y = Mouse_Y - w->Y, col;
|
||||
|
||||
if (w->DraggingScrollbar) {
|
||||
float scale = w->Height / (float)w->RowsCount;
|
||||
w->TopRow = (int)((y - w->MouseOffset) / scale);
|
||||
int row = (int)((y - w->MouseOffset) / scale);
|
||||
/* avoid expensive redraw when possible */
|
||||
if (w->TopRow == row) return;
|
||||
|
||||
w->TopRow = row;
|
||||
LTable_ClampTopRow(w);
|
||||
LWidget_Redraw(w);
|
||||
} else if (w->DraggingColumn >= 0) {
|
||||
if (x >= w->X + w->Width - 20) return;
|
||||
if (!deltaX || x >= w->X + w->Width - 20) return;
|
||||
col = w->DraggingColumn;
|
||||
|
||||
w->Columns[col].Width += deltaX;
|
||||
@ -919,7 +926,7 @@ static void LTable_RowsClick(struct LTable* w) {
|
||||
TimeMS now;
|
||||
|
||||
LTable_SetSelectedTo(w, row);
|
||||
now = DateTime_CurrentUTC_MS();
|
||||
now = DateTime_CurrentUTC_MS();
|
||||
|
||||
/* double click on row to join */
|
||||
if (w->_lastClick + 1000 >= now && row == w->_lastRow) {
|
||||
@ -932,12 +939,12 @@ static void LTable_RowsClick(struct LTable* w) {
|
||||
|
||||
/* Handles clicking on column headers (either resizes a column or sort rows) */
|
||||
static void LTable_HeadersClick(struct LTable* w) {
|
||||
int x, i, mouseX = Mouse_X - w->X;
|
||||
int x, i, mouseX = Mouse_X;
|
||||
|
||||
for (i = 0, x = w->X; i < w->NumColumns; i++) {
|
||||
/* clicked on gridline, begin dragging */
|
||||
if (mouseX >= (x - 8) && mouseX < (x + 8) && w->Columns[i].Interactable) {
|
||||
w->DraggingColumn = i;
|
||||
w->DraggingColumn = i - 1;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ struct LWidgetVTABLE {
|
||||
/* Called when key is pressed and this widget is selected. */
|
||||
void (*KeyPress)(void* widget, char c);
|
||||
/* Called when mouse hovers/moves over this widget. */
|
||||
void (*MouseMove)(void* widget, int deltaX, int deltaY);
|
||||
void (*MouseMove)(void* widget, int deltaX, int deltaY, bool wasOver);
|
||||
/* Called when mouse moves away from this widget. */
|
||||
void (*MouseLeft)(void* widget);
|
||||
/* Called when mouse clicks on this widget. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user