summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2017-05-19 19:09:17 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2017-05-19 19:09:17 +0200
commitff83cfac10939ceba524c93d4e36f634f4bec805 (patch)
treed481913f2136bf04d2d1deb650e6bd084a531676 /plugingui
parenta3dc9bd19f976cbc84ba3d1a16c72257b42b28ba (diff)
Make sure we don't resize to negative values.
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/abouttab.cc6
-rw-r--r--plugingui/abouttab.h2
-rw-r--r--plugingui/diskstreamingframecontent.cc4
-rw-r--r--plugingui/diskstreamingframecontent.h4
-rw-r--r--plugingui/drumkitframecontent.cc4
-rw-r--r--plugingui/drumkitframecontent.h6
-rw-r--r--plugingui/filebrowser.cc9
-rw-r--r--plugingui/frame.cc4
-rw-r--r--plugingui/frame.h12
-rw-r--r--plugingui/layout.cc5
-rw-r--r--plugingui/lineedit.cc2
-rw-r--r--plugingui/mainwindow.cc2
-rw-r--r--plugingui/tabwidget.cc18
-rw-r--r--plugingui/textedit.cc2
-rw-r--r--plugingui/textedit.h6
-rw-r--r--plugingui/widget.cc1
16 files changed, 46 insertions, 41 deletions
diff --git a/plugingui/abouttab.cc b/plugingui/abouttab.cc
index 2e4eace..f731100 100644
--- a/plugingui/abouttab.cc
+++ b/plugingui/abouttab.cc
@@ -38,14 +38,16 @@ AboutTab::AboutTab(Widget* parent)
{
text_edit.setText(getAboutText());
text_edit.setReadOnly(true);
- text_edit.resize(width() - 2*margin, height() - 2*margin);
+ text_edit.resize(std::max((int)width() - 2*margin,0),
+ std::max((int)height() - 2*margin, 0));
text_edit.move(margin, margin);
}
void AboutTab::resize(std::size_t width, std::size_t height)
{
Widget::resize(width, height);
- text_edit.resize(width - 2*margin, height - 2*margin);
+ text_edit.resize(std::max((int)width - 2*margin, 0),
+ std::max((int)height - 2*margin, 0));
}
std::string AboutTab::getAboutText()
diff --git a/plugingui/abouttab.h b/plugingui/abouttab.h
index 556b5bb..ecec13a 100644
--- a/plugingui/abouttab.h
+++ b/plugingui/abouttab.h
@@ -48,7 +48,7 @@ private:
std::string getAboutText();
TextEdit text_edit{this};
- std::size_t margin{10};
+ int margin{10};
Resource about{":../ABOUT"};
Resource authors{":../AUTHORS"};
diff --git a/plugingui/diskstreamingframecontent.cc b/plugingui/diskstreamingframecontent.cc
index 33367de..4bd9cad 100644
--- a/plugingui/diskstreamingframecontent.cc
+++ b/plugingui/diskstreamingframecontent.cc
@@ -73,10 +73,10 @@ void DiskstreamingframeContent::resize(std::size_t width, std::size_t height)
{
Widget::resize(width, height);
- std::size_t slider_button_gap = 10;
+ int slider_button_gap = 10;
slider_width = 0.8 * width;
- button_width = width - slider_width - slider_button_gap;
+ button_width = std::max((int)width - slider_width - slider_button_gap, 0);
label_text.move(0, 0);
slider.move(0, 20);
diff --git a/plugingui/diskstreamingframecontent.h b/plugingui/diskstreamingframecontent.h
index 0f9a098..e404807 100644
--- a/plugingui/diskstreamingframecontent.h
+++ b/plugingui/diskstreamingframecontent.h
@@ -63,8 +63,8 @@ private:
Slider slider{this};
Button button{this};
- std::size_t slider_width;
- std::size_t button_width;
+ int slider_width;
+ int button_width;
Settings& settings;
SettingsNotifier& settings_notifier;
diff --git a/plugingui/drumkitframecontent.cc b/plugingui/drumkitframecontent.cc
index f90f346..d58f7b4 100644
--- a/plugingui/drumkitframecontent.cc
+++ b/plugingui/drumkitframecontent.cc
@@ -51,8 +51,8 @@ void BrowseFile::resize(std::size_t width, std::size_t height)
{
Widget::resize(width, height);
- lineedit_width = 0.77 * width - gap;
- button_width = width - lineedit_width - gap;
+ lineedit_width = std::max((int)(0.77 * (int)width - gap), 0);
+ button_width = std::max((int)width - lineedit_width - gap, 0);
lineedit.resize(lineedit_width, 29);
browse_button.resize(button_width, 30);
diff --git a/plugingui/drumkitframecontent.h b/plugingui/drumkitframecontent.h
index c6e0942..866b720 100644
--- a/plugingui/drumkitframecontent.h
+++ b/plugingui/drumkitframecontent.h
@@ -61,9 +61,9 @@ private:
LineEdit lineedit{this};
Button browse_button{this};
- std::size_t lineedit_width;
- std::size_t button_width;
- std::size_t gap{10};
+ int lineedit_width;
+ int button_width;
+ int gap{10};
};
class DrumkitframeContent
diff --git a/plugingui/filebrowser.cc b/plugingui/filebrowser.cc
index 8854f6e..75d717d 100644
--- a/plugingui/filebrowser.cc
+++ b/plugingui/filebrowser.cc
@@ -118,18 +118,19 @@ void FileBrowser::resize(std::size_t width, std::size_t height)
offset += btn_h;
lbl_path.resize(60, btn_h);
- lineedit.resize(width - 60 - brd, btn_h);
+ lineedit.resize(std::max((int)width - 60 - brd, 0), btn_h);
offset += brd;
listbox.move(brd, offset);
- listbox.resize(width - 1 - 2*brd, height - btn_h - 2*brd - offset);
+ listbox.resize(std::max((int)width - 1 - 2*brd, 0),
+ std::max((int)height - btn_h - 2*brd - offset, 0));
btn_esc.move(brd, height - btn_h - brd);
- btn_esc.resize((width - 1 - 2*brd) / 2 - brd / 2, btn_h);
+ btn_esc.resize(std::max(((int)width - 1 - 2*brd) / 2 - brd / 2, 0), btn_h);
btn_sel.move(brd + width / 2 - brd / 2, height - btn_h - brd);
- btn_sel.resize((width - 1 - 2*brd) / 2, btn_h);
+ btn_sel.resize(std::max((int)((int)width - 1 - 2*brd) / 2, 0), btn_h);
}
void FileBrowser::repaintEvent(RepaintEvent* repaintEvent)
diff --git a/plugingui/frame.cc b/plugingui/frame.cc
index efe0281..81cc3c2 100644
--- a/plugingui/frame.cc
+++ b/plugingui/frame.cc
@@ -110,8 +110,8 @@ void FrameWidget::sizeChanged(int width, int height)
{
content_start_x = content_margin;
content_start_y = bar_height + content_margin;
- content_width = width - 2 * content_margin;
- content_height = height - (bar_height + 2 * content_margin);
+ content_width = std::max((int)width - 2 * content_margin, 0);
+ content_height = std::max((int)height - (bar_height + 2 * content_margin), 0);
content->move(content_start_x, content_start_y);
content->resize(content_width, content_height);
diff --git a/plugingui/frame.h b/plugingui/frame.h
index 8475690..eb745f6 100644
--- a/plugingui/frame.h
+++ b/plugingui/frame.h
@@ -80,7 +80,7 @@ private:
void powerButtonStateChanged(bool clicked);
// grey box
- std::size_t bar_height;
+ int bar_height;
GUI::Colour grey_box_colour{0.7};
GUI::Colour background_colour{0.85, 0.8};
@@ -95,12 +95,12 @@ private:
// content box
Widget* content{nullptr};
- std::size_t content_margin{12};
+ int content_margin{12};
- std::size_t content_start_x;
- std::size_t content_start_y;
- std::size_t content_width;
- std::size_t content_height;
+ int content_start_x;
+ int content_start_y;
+ int content_width;
+ int content_height;
};
} // GUI::
diff --git a/plugingui/layout.cc b/plugingui/layout.cc
index ea025bd..1e18c40 100644
--- a/plugingui/layout.cc
+++ b/plugingui/layout.cc
@@ -106,7 +106,8 @@ void BoxLayout::setSpacing(size_t spacing)
//
VBoxLayout::VBoxLayout(LayoutItem* parent)
- : BoxLayout(parent), align(HAlignment::center)
+ : BoxLayout(parent)
+ , align(HAlignment::center)
{
}
@@ -315,7 +316,7 @@ auto GridLayout::calculateCellSize() const -> CellSize
}
void GridLayout::moveAndResize(
- LayoutItem& item, GridRange const& range, CellSize cell_size) const
+ LayoutItem& item, GridRange const& range, CellSize cell_size) const
{
std::size_t x = range.column_begin * (cell_size.width + spacing);
std::size_t y = range.row_begin * (cell_size.height + spacing);
diff --git a/plugingui/lineedit.cc b/plugingui/lineedit.cc
index 96bf56f..5dd8bc5 100644
--- a/plugingui/lineedit.cc
+++ b/plugingui/lineedit.cc
@@ -237,7 +237,7 @@ void LineEdit::repaintEvent(RepaintEvent *repaintEvent)
while(true)
{
int textWidth = font.textWidth(visibleText);
- if(textWidth <= (w - BORDER - 4 + 3))
+ if(textWidth <= std::max(w - BORDER - 4 + 3, 0))
{
break;
}
diff --git a/plugingui/mainwindow.cc b/plugingui/mainwindow.cc
index 578af28..d98d335 100644
--- a/plugingui/mainwindow.cc
+++ b/plugingui/mainwindow.cc
@@ -99,7 +99,7 @@ void MainWindow::repaintEvent(RepaintEvent* repaintEvent)
void MainWindow::sizeChanged(std::size_t width, std::size_t height)
{
- tabs.resize(width - 2 * 16, height);
+ tabs.resize(std::max((int)width - 2 * 16, 0), height);
}
void MainWindow::closeEventHandler()
diff --git a/plugingui/tabwidget.cc b/plugingui/tabwidget.cc
index dde2137..b18f62f 100644
--- a/plugingui/tabwidget.cc
+++ b/plugingui/tabwidget.cc
@@ -94,13 +94,13 @@ void TabWidget::sizeChanged(int width, int height)
{
std::size_t pos = 0;
- std::size_t button_width = 1;
- std::size_t bar_height = 25;
- std::size_t button_border_width = 10;
+ int button_width = 1;
+ int bar_height = 25;
+ int button_border_width = 10;
- std::size_t button_padding_left = 25;
- std::size_t button_padding_inner = 3;
- std::size_t logo_padding_right = button_padding_left / 2;
+ int button_padding_left = 25;
+ int button_padding_inner = 3;
+ int logo_padding_right = button_padding_left / 2;
Painter p(*this);
@@ -108,11 +108,11 @@ void TabWidget::sizeChanged(int width, int height)
{
for (auto& button : buttons)
{
- auto min_width = button.getMinimalWidth();
+ int min_width = button.getMinimalWidth();
button_width = std::max(button_width, min_width + button_border_width);
}
- button_width = std::min(button_width, width / buttons.size());
+ button_width = std::min(button_width, width / (int)buttons.size());
}
// draw the upper bar
@@ -132,7 +132,7 @@ void TabWidget::sizeChanged(int width, int height)
}
stack.move(0, bar_height);
- stack.resize(width, height - bar_height);
+ stack.resize(width, std::max((int)height - bar_height, 0));
}
} // GUI::
diff --git a/plugingui/textedit.cc b/plugingui/textedit.cc
index ebe8d32..fd2f891 100644
--- a/plugingui/textedit.cc
+++ b/plugingui/textedit.cc
@@ -50,7 +50,7 @@ void TextEdit::resize(std::size_t width, std::size_t height)
needs_preprocessing = true;
scroll.move(width - 2*x_border - 3, y_border - 1);
- scroll.resize(scroll.width(), height - 2*(y_border - 1));
+ scroll.resize(scroll.width(), std::max((int)height - 2*(y_border - 1), 0));
}
void TextEdit::setReadOnly(bool readonly)
diff --git a/plugingui/textedit.h b/plugingui/textedit.h
index 6ce59b6..17a04ff 100644
--- a/plugingui/textedit.h
+++ b/plugingui/textedit.h
@@ -74,9 +74,9 @@ private:
0, // atlas offset (x, y)
7, 1, 7, // dx1, dx2, dx3
7, 63, 7}; // dy1, dy2, dy3
-
- static constexpr std::size_t x_border{10};
- static constexpr std::size_t y_border{8};
+
+ static constexpr int x_border{10};
+ static constexpr int y_border{8};
ScrollBar scroll;
Font font;
diff --git a/plugingui/widget.cc b/plugingui/widget.cc
index 4a99524..c148219 100644
--- a/plugingui/widget.cc
+++ b/plugingui/widget.cc
@@ -122,6 +122,7 @@ void Widget::reparent(Widget* parent)
void Widget::resize(std::size_t width, std::size_t height)
{
+ assert(width < 32000 && height < 32000); // Catch negative values as size_t
if((width < 1) || (height < 1) ||
((width == _width) && (height == _height)))
{