Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tylernh10 committed Jan 9, 2023
1 parent ad07833 commit c214d79
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 194 deletions.
Binary file removed IBMPlexSans-Regular.ttf
Binary file not shown.
143 changes: 0 additions & 143 deletions Menu.cpp

This file was deleted.

43 changes: 0 additions & 43 deletions Menu.h

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This is a Graphical Editor written in C++ using the game engine Allegro as the basis for the GUI.

### To Compile:
g++ source-files/ECGraphicViewImp.cpp source-files/test-gv.cpp source-files/Command.cpp source-files/ShapesModel.cpp source-files/Shape.cpp source-files/ECRealObserver.cpp source-files/MouseFunction.cpp source-file/Menu.cpp -lallegro -lallegro_font -lallegro_primitives -lallegro_main -lallegro_image -lallegro_main -lallegro_dialog -lallegro_ttf -o editor
g++ source-files/ECGraphicViewImp.cpp source-files/GraphicViewMain.cpp source-files/Command.cpp source-files/ShapesModel.cpp source-files/Shape.cpp source-files/ECRealObserver.cpp source-files/MouseFunction.cpp source-files/Menu.cpp -lallegro -lallegro_font -lallegro_primitives -lallegro_main -lallegro_image -lallegro_main -lallegro_dialog -lallegro_ttf -o editor

**Note:** Allegro must be installed. If you are on Mac or Linux, Allegro can be installed directly. If you are on Windows, you can run Allegro5 applications through visual studio. Please refer to [this video](https://www.youtube.com/watch?v=UgGKBW_kU20) for instructions.

Expand Down
Binary file modified editor
Binary file not shown.
2 changes: 2 additions & 0 deletions source-files/ECGraphicViewImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//
// Created by Yufeng Wu on 3/2/22.
//
// Modified by Tyler Hinrichs in 2022-2023.
//

#include "../header-files/ECGraphicViewImp.h"
#include "allegro5/allegro_primitives.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//
// Created by Yufeng Wu on 3/2/22.
//
#include "../header-files/ECGraphicViewImp.h"
#include "../header-files/ECRealObserver.h"
#include "../header-files/ShapesModel.h"
Expand Down Expand Up @@ -52,7 +49,7 @@ int real_main(int argc, char** argv)

// menu init
Menu menu(editMouseFunctionality, insertMouseFunctionality);
menu.initFont(al_load_ttf_font("IBMPlexSans-Regular.ttf", 18, 0));
menu.initFont(al_load_ttf_font("res/IBMPlexSans-Regular.ttf", 18, 0));
menu.initDivider(al_load_bitmap("res/divider.jpg"));
menu.initBackground(al_load_bitmap("res/background.jpg"));

Expand Down
140 changes: 137 additions & 3 deletions source-files/Menu.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,143 @@
#include "header-files/Menu.h"
#include "../header-files/Menu.h"

void Menu::initBackrgound(ALLEGRO_BITMAP* bg) {
Menu::Menu(EditModeMouseFunction& e, InsertModeMouseFunction& i) : editModeMouseFunction(e), insertModeMouseFunction(i) {
for (int i = 0; i < 20; i++) {
currentHover.push_back(false);
}
}

Menu::~Menu() {
al_destroy_bitmap(divider);
al_destroy_bitmap(background);
al_destroy_font(font);
for (auto i : buttons) {
al_destroy_bitmap(i);
}
for (auto i : hoverButtons) {
al_destroy_bitmap(i);
}
for (auto i : colorButtons) {
al_destroy_bitmap(i);
}
for (auto i : colorHoverButtons) {
al_destroy_bitmap(i);
}
}

void Menu::initDivider(ALLEGRO_BITMAP* div) {
divider = div;
}

void Menu::initBackground(ALLEGRO_BITMAP* bg) {
background = bg;
}

void Menu::draw() {
void Menu::initButtons(vector<ALLEGRO_BITMAP*> bts) {
buttons = bts;
}

void Menu::initHoverButtons(vector<ALLEGRO_BITMAP*> bts) {
hoverButtons = bts;
}

void Menu::initColorButtons(vector<ALLEGRO_BITMAP*> bts) {
colorButtons = bts;
}

void Menu::initColorHoverButtons(vector<ALLEGRO_BITMAP*> bts) {
colorHoverButtons = bts;
}

void Menu::initFont(ALLEGRO_FONT* f) {
font = f;
}

void Menu::timer(int mode) {
if (!mode) {
editModeMouseFunction.timer();
}
else if (mode == 1) {
insertModeMouseFunction.timer();
}

// draw background
al_draw_bitmap(background, 0, 0, 0);

// draw both dividers
al_draw_bitmap(divider, 0, 75, 0);
al_draw_bitmap(divider, 0, 103, 0);

// draw buttons before color buttons
// first 10 buttons follow this sizing scheme
for (unsigned int i = 0; i < 10; i++) {
al_draw_bitmap(buttons.at(i), i*75, 0, 0);
}

// draw color buttons
for (unsigned int i = 0; i < 4; i++) {
al_draw_bitmap(colorButtons.at(i), 10*75 + 37*i, 0, 0);
}
for (unsigned int i = 4; i < 8; i++) {
al_draw_bitmap(colorButtons.at(i), 10*75 + 37*(i-4), 38, 0);
}
// draw save button
al_draw_bitmap(buttons.at(10), 900, 14, 0);

// draw help button
al_draw_bitmap(buttons.at(11), 950, 14, 0);
}

void Menu::detectMouse(int px, int py) {
// first 10 buttons follow this sizing scheme
for (int i = 0; i < 10; i++) {
if (py < 75 && py > 0 && px >= i*75 && px < (i+1)*75) {
al_draw_bitmap(hoverButtons[i], i*75, 0, 0);
al_draw_text(font, al_map_rgb(0, 0, 0), 3, 80, ALLEGRO_ALIGN_LEFT, hoverStrings[i]);
currentHover.at(i) = true;
}
else {
currentHover.at(i) = false;
}
}
for (int i = 0; i < 4; i++) {
if (py < 37 && py > 0 && px >= 10 * 75 + 37 * i && px < 10 * 75 + 37 * (i + 1)) {
al_draw_bitmap(colorHoverButtons.at(i), 10 * 75 + 37 * i, 0, 0);
al_draw_text(font, al_map_rgb(0, 0, 0), 3, 80, ALLEGRO_ALIGN_LEFT, hoverStrings[i+10]);
currentHover.at(i + 10) = true;
}
else {
currentHover.at(i + 10) = false;
}
}
for (int i = 4; i < 8; i++) {
if (py < 75 && py > 37 && px >= 10 * 75 + 37 * (i - 4) && px < 10 * 75 + 37 * (i - 4 + 1)) {
al_draw_bitmap(colorHoverButtons.at(i), 10 * 75 + 37 * (i - 4), 38, 0);
al_draw_text(font, al_map_rgb(0, 0, 0), 3, 80, ALLEGRO_ALIGN_LEFT, hoverStrings[i-4+14]);
currentHover.at(i + 10) = true;
}
else {
currentHover.at(i + 10) = false;
}
}

if (py > 14 && py < 69 && px >= 900 && px < 950) {
al_draw_bitmap(hoverButtons.at(10), 900, 14, 0);
al_draw_text(font, al_map_rgb(0, 0, 0), 3, 80, ALLEGRO_ALIGN_LEFT, hoverStrings[18]);
currentHover.at(18) = true;
}
else {
currentHover.at(18) = false;
}
if (py > 14 && py < 69 && px >= 950 && px < 1000) {
al_draw_bitmap(hoverButtons.at(11), 950, 14, 0);
al_draw_text(font, al_map_rgb(0, 0, 0), 3, 80, ALLEGRO_ALIGN_LEFT, hoverStrings[19]);
currentHover.at(19) = true;
}
else {
currentHover.at(19) = false;
}
}

bool Menu::checkOverButton(int x) {
return currentHover.at(x);
}

0 comments on commit c214d79

Please sign in to comment.