Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Allow custom line endings during checkout, but enforce LF on checkin
*.cc text
*.c text
*.hh text
*.h text

*.py text
*.md text

*.txt text

*.bml binary

71 changes: 71 additions & 0 deletions src/opengl/AutoNavBar.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "opengl/AutoNavBar.hh"

using namespace std;

AutoNavBar::AutoNavBar(GLWin* w, float x, float y, float axisPadding,
float horizontalPadding, float verticalPadding,
bool isVertical, bool isReverseOrder)
: NavigationBar(w, x, y, 0, 0, axisPadding, isVertical),
horizontalPadding(horizontalPadding),
verticalPadding(verticalPadding),
isReverseOrder(isReverseOrder) {
w->autoNavBar = this;
}

void AutoNavBar::addButton(Member* m) {
int index = buttons.size();
ButtonWidget* bw = NavigationBar::addButton(m->getName(), "action");
bw->setAction(bind(&GLWin::switchTab, parentWin, index));

if (isReverseOrder) {
reverseButtonOrder();
c->getGuiText()->clear();
}

fitBarDimensions(horizontalPadding, verticalPadding);
drawBarBox();
}

void AutoNavBar::reverseButtonOrder() {
float currentX = xPos;
float currentY = yPos;
for (int i = buttons.size() - 1; i >= 0; i--) {
if (isVertical) {
buttons[i]->setY(currentY);
currentY += buttons[i]->getH() + axisPadding;
} else {
buttons[i]->setX(currentX);
currentX += buttons[i]->getW() + axisPadding;
}
}
}

void AutoNavBar::fitBarDimensions(float widthPadding, float heightPadding) {
if (isVertical) {
barWidth = buttonsWidth() + widthPadding;
barHeight = buttonsLength() + heightPadding;
} else {
barWidth = buttonsLength() + widthPadding;
barHeight = buttonsWidth() + heightPadding;
}
}

float AutoNavBar::buttonsLength() {
if (isVertical) {
if (isReverseOrder) {
return buttons.front()->getY() + buttons.front()->getH() -
buttons.back()->getY();
} else {
return buttons.back()->getY() + buttons.back()->getH() -
buttons.front()->getY();
}
} else {
if (isReverseOrder) {
return buttons.front()->getX() + buttons.front()->getW() -
buttons.back()->getX();
} else {
return buttons.back()->getX() + buttons.back()->getW() -
buttons.front()->getX();
}
}
}
69 changes: 69 additions & 0 deletions src/opengl/AutoNavBar.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#pragma once

#include "opengl/NavigationBar.hh"

/**
* @brief Version of NavigationBar in which new buttons are automatically added
* when a new member is added. The dimensions of the buttons and the navigation
* bar are also automatically determined and updated. An AutoNavBar should be
* added to a window BEFORE any other members.
*
*/
class AutoNavBar : public NavigationBar {
private:
bool isReverseOrder;
float horizontalPadding, verticalPadding;

public:
/**
* @brief Create a new automated navigation bar
*
* @param w The initial window to draw on
* @param x x-coordinate of top-left corner
* @param y y-coordinate of top-left corner
* @param axisPadding distance between the edges of two buttons
* @param horizontalPadding horizontal distance between buttons and bar edge
* @param verticalPadding vertical distance between buttons and bar edge
* @param isVertical allow vertical navigation bars (e.x. Ubuntu's task bar)
* @param isReverseOrder display buttons in the reverse order the members are
* added (leftmost/topmost button corresponds to first member displayed)
*/
AutoNavBar(GLWin* w, float x, float y, float axisPadding,
float horizontalPadding, float verticalPadding,
bool isVertical = false, bool isReverseOrder = false);

/**
* @brief Add a button to the nav bar for a new member
*
* @param m pointer to member
*/
void addButton(Member* m);

/**
* @brief Update the positions of all buttons in the nav bar such that their
* displayed left-to-right/top-to-bottom order is opposite that of their index
* order
*
*/
void reverseButtonOrder();

/**
* @brief Updates the dimensions of the nav bar to fit around the buttons.
* Option to add padding between the buttons and nav bar edges. Override of
* fitBarDimensions function from NavigationBar that accounts for
* isReverseOrder
*
* @param widthPadding horizontal distance between nav bar edge and closest
* button
* @param heightPadding vertical distance between nav bar edge and closest
* button
*/
void fitBarDimensions(float widthPadding = 0, float heightPadding = 0);

/**
* @brief Calculates and returns the lengthwise distance of the list of
* buttons in the nav bar. Override of buttonsLength function from
* NavigationBar that accounts for isReverseOrder
*/
float buttonsLength();
};
20 changes: 14 additions & 6 deletions src/opengl/ButtonWidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,25 @@ void ButtonWidget::click(float mouseX, float mouseY) {

void ButtonWidget::init() {}

ButtonWidget::ButtonWidget(MainCanvas* c, float x, float y, float w, float h,
ButtonWidget::ButtonWidget(MainCanvas* c, const Style* s, float x, float y,
float w, float h, const std::string& text,
const char action[])
: InteractiveWidget2D(c, s, x, y, w, h), text(text) {
redraw();
}

ButtonWidget::ButtonWidget(MainCanvas* c, const Style* s, float x, float y,
const std::string& text, const char action[])
: InteractiveWidget2D(c, x, y, w, h), text(text) {
: InteractiveWidget2D(c, s, x, y, s->f->getWidth(text), s->f->getHeight()),
text(text) {
redraw();
}

void ButtonWidget::redraw() {
int borderSize = 2;
float borderSize = s->lineWidth;

m->fillRectangle(x - borderSize, y - borderSize, w + (borderSize * 2),
h + (borderSize * 2), grail::black);
m->fillRectangle(x, y, w, h, grail::red);
t->addCentered(x, y, w, h, c->getStyle()->f, text);
h + (borderSize * 2), s->bg);
m->fillRectangle(x, y, w, h, s->fg);
t->addCentered(x, y, w, h, s->f, text);
}
18 changes: 15 additions & 3 deletions src/opengl/ButtonWidget.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ class ButtonWidget : public InteractiveWidget2D {
std::optional<std::function<void(void)>> func;

public:
ButtonWidget(MainCanvas* c, float x, float y, float w, float h,
const std::string& text, const char action[]);
ButtonWidget(StyledMultiShape2D* m, MultiText* t, float x, float y, float w,
ButtonWidget(MainCanvas* c, const Style* s, float x, float y, float w,
float h, const std::string& text, const char action[]);
ButtonWidget(StyledMultiShape2D* m, MultiText* t, const Style* s, float x,
float y, float w, float h, const std::string& text,
const char action[]);
ButtonWidget(MainCanvas* c, const Style* s, float x, float y,
const std::string& text, const char action[]);
void click(float mouseX, float mouseY) override;
void init() override;

Expand All @@ -25,4 +28,13 @@ class ButtonWidget : public InteractiveWidget2D {
void setAction(Func func) {
this->func = func;
}

void updateCanvas(MainCanvas* canvas) { c = canvas; };

float getX() { return x; };
void setX(float newX) { x = newX; };
float getY() { return y; };
void setY(float newY) { y = newY; };
float getW() { return w; };
float getH() { return h; };
};
2 changes: 2 additions & 0 deletions src/opengl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(grail-opengl
AutoNavBar.cc
AxisWidget.cc
BarChartWidget.cc
BoxChartWidget.cc
Expand All @@ -8,6 +9,7 @@ set(grail-opengl
Colors.cc
Document.cc
DocView.cc
DropDownMenu.cc
ErrNames.cc
ESRIPolygon.cc
ESRIShape.cc
Expand Down
12 changes: 10 additions & 2 deletions src/opengl/Canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ Canvas::Canvas(Tab* tab) : Canvas(tab->getParentWin(), tab) {}

Canvas::~Canvas() { cleanup(); }

void MainCanvas::copy(const MainCanvas& orig) {
gui = orig.gui;
guiText = orig.guiText;
menu = orig.menu;
menuText = orig.menuText;
}

void Canvas::cleanup() {
for (uint32_t i = 0; i < layers.size(); i++) delete layers[i];
layers.clear();
Expand Down Expand Up @@ -86,8 +93,9 @@ void MainCanvas::init() {
menuText->init();
tab->registerCallback(Tab::Inputs::MOUSE0_PRESS, "Widget Callback- Press",
Tab::Security::SAFE, bind(&MainCanvas::click, this));
tab->registerCallback(Tab::Inputs::MOUSE0_RELEASE, "Widget Callback- Release",
Tab::Security::SAFE, bind(&MainCanvas::click, this));
// tab->registerCallback(Tab::Inputs::MOUSE0_RELEASE, "Widget Callback-
// Release",
// Tab::Security::SAFE, bind(&MainCanvas::click, this));
}

void MainCanvas::render() {
Expand Down
3 changes: 2 additions & 1 deletion src/opengl/Canvas.hh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Canvas {
// z!=0
}
~Canvas();
Canvas(const Canvas& orig) = delete;
Canvas(const Canvas&) = delete;
Canvas& operator=(const Canvas& orig) = delete;
uint32_t getWidth() const { return vpW; }
uint32_t getHeight() const { return vpH; }
Expand Down Expand Up @@ -126,6 +126,7 @@ class MainCanvas : public Canvas {
~MainCanvas();
MainCanvas(const MainCanvas&) = delete;
MainCanvas& operator=(const MainCanvas&) = delete;
void copy(const MainCanvas&);
StyledMultiShape2D* getGui() { return gui; }
MultiText* getGuiText() { return guiText; }
StyledMultiShape2D* getMenu() { return menu; }
Expand Down
82 changes: 82 additions & 0 deletions src/opengl/DropDownMenu.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "opengl/DropDownMenu.hh"

#include <iostream>

DropDownMenu::DropDownMenu(GLWin* w, float x, float y, float menuWidth,
float menuHeight, const char label[],
float axisPadding, Style* buttonStyle,
bool isVertical)
: Member(w->getSharedMenuTab(), "DDMenu", 0),
w(w),
buttonStyle(buttonStyle),
isVertical(isVertical),
isOpen(false) {
menuButton = new ButtonWidget(tab->getMainCanvas(), buttonStyle, x, y, label,
"open menu");
menuButton->setAction([this]() { this->openClose(); });

if (isVertical) {
nav = new NavigationBar(w, x, y + menuButton->getH(), menuWidth, menuHeight,
axisPadding, isVertical);
} else {
nav = new NavigationBar(w, x + menuButton->getW(), y, menuWidth, menuHeight,
axisPadding, isVertical);
}
nav->setButtonStyle(buttonStyle->f, buttonStyle->bg, buttonStyle->fg,
buttonStyle->lineWidth);
}

// TODO: fix menu breaking when isReverseOrder is true
DropDownMenu::DropDownMenu(GLWin* w, float x, float y, const char label[],
float axisPadding, float menuHorizontalPadding,
float menuVerticalPadding, Style* buttonStyle,
bool isVertical, bool isReverseOrder)
: Member(w->getSharedMenuTab(), "DDMenu", 0),
w(w),
buttonStyle(buttonStyle),
isVertical(isVertical),
isOpen(false) {
menuButton = new ButtonWidget(tab->getMainCanvas(), buttonStyle, x, y, label,
"open menu");
menuButton->setAction([this]() { this->openClose(); });

if (isVertical) {
nav = new AutoNavBar(w, x, y + menuButton->getH(), axisPadding,
menuHorizontalPadding, menuVerticalPadding, isVertical,
isReverseOrder);
} else {
nav = new AutoNavBar(w, x + menuButton->getW(), y, axisPadding,
menuHorizontalPadding, menuVerticalPadding, isVertical,
isReverseOrder);
}
nav->setButtonStyle(buttonStyle->f, buttonStyle->bg, buttonStyle->fg,
buttonStyle->lineWidth);
}

void DropDownMenu::openMenu() {
std::cout << "Opening menu!" << std::endl;
isOpen = true;
}
void DropDownMenu::closeMenu() {
std::cout << "Closing menu!" << std::endl;
isOpen = false;

MainCanvas* c = w->getSharedTab()->getMainCanvas();
c->getGui()->clear();
c->getGuiText()->clear();
}

/*
void DropDownMenu::setButtonStyle(const Font* f, glm::vec4 borderColor,
glm::vec4 buttonColor,
float borderThickness) {
buttonStyle->f = f;
buttonStyle->bg = borderColor;
buttonStyle->fg = buttonColor;
buttonStyle->lineWidth = borderThickness;

c->getGuiText()->clear();
menuButton->redraw();
nav->setButtonStyle(f, borderColor, buttonColor, borderThickness);
}
*/
Loading