| 4365 | } |
| 4366 | |
| 4367 | static void paint_update() |
| 4368 | { |
| 4369 | if (G->files.Count <= 0 || !G->graphics.paint_canvas_uav) |
| 4370 | return; |
| 4371 | |
| 4372 | if (keydn(Key_B)) { |
| 4373 | G->paint_mode_toggled = !G->paint_mode_toggled; |
| 4374 | } |
| 4375 | G->paint_mode = (keypress(Key_Shift) && !G->ui_want_capture_mouse) || (G->paint_mode_toggled); |
| 4376 | if (G->paint_mode) { |
| 4377 | G->crop_mode = false; |
| 4378 | SetCursor(G->hcursor[Cursor_Type_pen]); |
| 4379 | } else { |
| 4380 | G->paint_mode = false; |
| 4381 | G->paint_last_mouse = { -1.0f, -1.0f }; |
| 4382 | SetCursor(G->hcursor[Cursor_Type_arrow]); |
| 4383 | } |
| 4384 | |
| 4385 | // Always clear preview canvas. |
| 4386 | const float c[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; |
| 4387 | G->graphics.device_ctx->ClearUnorderedAccessViewFloat(G->graphics.paint_canvas_preview_uav, c); |
| 4388 | |
| 4389 | if (G->paint_mode && !G->ui_want_capture_mouse) { |
| 4390 | v2 p0, p1; // Start and end pixel-center position of our stroke. |
| 4391 | iv2 s; // Rotated canvas/image size. |
| 4392 | bool down = keydn(MouseL) || keydn(MouseR); |
| 4393 | bool pressed = keypress(MouseL) || keypress(MouseR); |
| 4394 | bool moved = (G->keys.Mouse_rel.x || G->keys.Mouse_rel.y); |
| 4395 | |
| 4396 | bool paint_on_click = down; |
| 4397 | bool paint_on_move = pressed && moved && (G->paint_last_mouse.x != -1.0f && G->paint_last_mouse.y != -1.0f); |
| 4398 | |
| 4399 | // Change brush size with mouse wheel. |
| 4400 | G->paint_brush_size += G->keys.scroll_y_diff; |
| 4401 | G->paint_brush_size = clamp(G->paint_brush_size, 1, 100); |
| 4402 | |
| 4403 | v2 mouse_current = get_rotated_pixel_mouse(&s); |
| 4404 | if (paint_on_click) { |
| 4405 | p0 = mouse_current; |
| 4406 | p1 = mouse_current; |
| 4407 | G->paint_last_mouse = mouse_current; |
| 4408 | } else if (paint_on_move) { |
| 4409 | p0 = G->paint_last_mouse; |
| 4410 | p1 = mouse_current; |
| 4411 | G->paint_last_mouse = p1; |
| 4412 | } |
| 4413 | |
| 4414 | { |
| 4415 | Shader_Constants_Paint constants; |
| 4416 | constants.point_a = p0; |
| 4417 | constants.point_b = p1; |
| 4418 | constants.color = G->paint_brush_color; |
| 4419 | constants.canvas_size = s; |
| 4420 | constants.radius = G->paint_brush_size * 0.5f; |
| 4421 | constants.smoothness = G->paint_brush_aa ? 2.0f : 0.0f; |
| 4422 | constants.erase = keypress(MouseR); |
| 4423 | |
| 4424 | // Render brush stroke. |
no test coverage detected