Vital
Loading...
Searching...
No Matches
border_bounds_constrainer.cpp
Go to the documentation of this file.
2#include "full_interface.h"
3#include "load_save.h"
5
6void BorderBoundsConstrainer::checkBounds(Rectangle<int>& bounds, const Rectangle<int>& previous,
7 const Rectangle<int>& limits,
8 bool stretching_top, bool stretching_left,
9 bool stretching_bottom, bool stretching_right) {
10 // Apply the defined border before checking the standard constraints.
11 border_.subtractFrom(bounds);
12 double aspect_ratio = getFixedAspectRatio();
13
14 // Let the base class handle initial constraint checks.
15 ComponentBoundsConstrainer::checkBounds(bounds, previous, limits,
16 stretching_top, stretching_left,
17 stretching_bottom, stretching_right);
18
19 // Get the total display area and adjust for window frame size if a GUI is available.
20 Rectangle<int> display_area = Desktop::getInstance().getDisplays().getTotalBounds(true);
21 if (gui_) {
22 ComponentPeer* peer = gui_->getPeer();
23 if (peer)
24 peer->getFrameSize().subtractFrom(display_area);
25 }
26
27 // Ensure the window doesn't exceed the display area width.
28 if (display_area.getWidth() < bounds.getWidth()) {
29 int new_width = display_area.getWidth();
30 int new_height = std::round(new_width / aspect_ratio);
31 bounds.setWidth(new_width);
32 bounds.setHeight(new_height);
33 }
34
35 // Ensure the window doesn't exceed the display area height.
36 if (display_area.getHeight() < bounds.getHeight()) {
37 int new_height = display_area.getHeight();
38 int new_width = std::round(new_height * aspect_ratio);
39 bounds.setWidth(new_width);
40 bounds.setHeight(new_height);
41 }
42
43 // Reapply the border to the adjusted bounds.
44 border_.addTo(bounds);
45}
46
48 // Temporarily disable background redraw for smoother resizing if GUI is present.
49 if (gui_)
51}
52
54 // Once resizing is complete, save the new window size and re-enable redraw if GUI is present.
55 if (gui_) {
58 }
59}
virtual void resizeEnd() override
Called after a resize operation finishes.
Definition border_bounds_constrainer.cpp:53
FullInterface * gui_
A pointer to the associated GUI interface, which may be nullptr if none is set.
Definition border_bounds_constrainer.h:79
virtual void resizeStart() override
Called before a resize operation begins.
Definition border_bounds_constrainer.cpp:47
virtual void checkBounds(Rectangle< int > &bounds, const Rectangle< int > &previous, const Rectangle< int > &limits, bool stretching_top, bool stretching_left, bool stretching_bottom, bool stretching_right) override
Adjusts the given bounds to enforce border constraints, maintain aspect ratio, and limit the window s...
Definition border_bounds_constrainer.cpp:6
BorderSize< int > border_
The border to be applied to the component bounds.
Definition border_bounds_constrainer.h:84
void enableRedoBackground(bool enable)
Enables or disables redrawing of the background when resized.
Definition full_interface.h:482
static void saveWindowSize(float window_size)
Saves the window size scaling factor.
Definition load_save.cpp:1324
constexpr int kDefaultWindowWidth
Default width of the Vital window (in pixels).
Definition synth_constants.h:61