MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / MouseDown

Method MouseDown

System/LemonWM/wm.cpp:282–360  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280}
281
282void WMInstance::MouseDown(){
283 if(Lemon::Graphics::PointInRect(contextMenuBounds, input.mouse.pos)){
284 return;
285 }
286
287 auto it = windows.end();
288 do {
289 WMWindow* win = *it;
290
291 if(PointInWindow(win, input.mouse.pos)){
292 if(win->minimized) continue;
293
294 SetActive(win);
295
296 if(PointInWindowProper(win, input.mouse.pos)){
297 Lemon::LemonEvent ev;
298 ev.event = Lemon::EventMousePressed;
299 ev.mousePos = input.mouse.pos - active->pos;
300
301 if(!(win->flags & WINDOW_FLAGS_NODECORATION)) ev.mousePos = ev.mousePos - (vector2i_t){1, 25};
302
303 PostEvent(ev, active);
304 } else if(input.mouse.pos.y - win->pos.y < WINDOW_TITLEBAR_HEIGHT + WINDOW_BORDER_THICKNESS && input.mouse.pos.y - win->pos.y > WINDOW_BORDER_THICKNESS) { // Check if user pressed titlebar
305 if(Lemon::Graphics::PointInRect(win->GetCloseRect(), input.mouse.pos)){
306 win->closeBState = ButtonStatePressed;
307 return;
308 } else if(Lemon::Graphics::PointInRect(win->GetMinimizeRect(), input.mouse.pos)) {
309 win->minimizeBState = ButtonStatePressed;
310 return;
311 }
312
313 drag = true;
314 dragOffset = {input.mouse.pos.x - win->pos.x, input.mouse.pos.y - win->pos.y};
315 } else { // Resize the window
316 resize = true;
317 if (Lemon::Graphics::PointInRect(win->GetBottomBorderRect(), input.mouse.pos)){
318 rect_t left = win->GetLeftBorderRect(); // Resize corner if within 10 pixels of border bounds
319 left.width += 10;
320
321 rect_t right = win->GetRightBorderRect();
322 right.width += 10;
323 right.x -= 10;
324
325 if (Lemon::Graphics::PointInRect(left, input.mouse.pos)){
326 resizePoint = ResizePoint::BottomLeft;
327 } else if (Lemon::Graphics::PointInRect(right, input.mouse.pos)){
328 resizePoint = ResizePoint::BottomRight;
329 } else {
330 resizePoint = ResizePoint::Bottom;
331 }
332 } else if (Lemon::Graphics::PointInRect(win->GetTopBorderRect(), input.mouse.pos)){
333 rect_t left = win->GetLeftBorderRect(); // Resize corner if within 10 pixels of border bounds
334 left.width += 10;
335
336 rect_t right = win->GetRightBorderRect();
337 right.width += 10;
338 right.x -= 10;
339

Callers 1

PollMethod · 0.80

Calls 11

PointInRectFunction · 0.85
PointInWindowFunction · 0.85
PointInWindowProperFunction · 0.85
GetCloseRectMethod · 0.80
GetMinimizeRectMethod · 0.80
GetBottomBorderRectMethod · 0.80
GetLeftBorderRectMethod · 0.80
GetRightBorderRectMethod · 0.80
GetTopBorderRectMethod · 0.80
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected