Skip to content

Commit

Permalink
implement fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tylernh10 committed Jan 6, 2023
1 parent e8322c6 commit 105e5f2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
9 changes: 8 additions & 1 deletion Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ void Menu::initFont(ALLEGRO_FONT* f) {
font = f;
}

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

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

Expand Down
13 changes: 10 additions & 3 deletions header-files/Menu.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#ifndef MENU_H
#define MENU_H

class Menu;
class EditModeMouseFunction;
class InsertModeMouseFunction;

#include "ECGraphicViewImp.h"
#include "MouseFunction.h"

#include <allegro5/allegro_image.h>
#include <allegro5/allegro_primitives.h>
Expand All @@ -11,8 +16,8 @@ using namespace std;

class Menu {
public:
Menu() {}
~Menu() {} // TODO: destory all bitmaps
Menu(EditModeMouseFunction& e, InsertModeMouseFunction& i): editModeMouseFunction(e), insertModeMouseFunction(i) {}
~Menu() {} // TODO: destroy all bitmaps
void initDivider(ALLEGRO_BITMAP* div);
void initBackground(ALLEGRO_BITMAP* bg);

Expand All @@ -21,7 +26,7 @@ class Menu {
void initColorButtons(vector<ALLEGRO_BITMAP*> bts);
void initColorHoverButtons(vector<ALLEGRO_BITMAP*> bts);
void initFont(ALLEGRO_FONT* f);
void draw(); // draws all menu buttons
void timer(int mode); // draws all menu buttons and take care of trace shapes
void detectMouse(int px, int py);
private:
ALLEGRO_BITMAP* divider;
Expand Down Expand Up @@ -53,6 +58,8 @@ class Menu {
"Save",
"Help"
};
EditModeMouseFunction& editModeMouseFunction;
InsertModeMouseFunction& insertModeMouseFunction;
};

#endif
6 changes: 3 additions & 3 deletions source-files/ECRealObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void ECDrawObserver :: Update() {
x->Draw(view);
view.SetRedraw(true);
}
menu->draw(); // draw menu buttons
menu->timer(ctrl.getMode()); // draw menu buttons
int x, y;
view.GetCursorPosition(x, y);
//cout << "(" << x << "," << y << ")" << endl;
Expand All @@ -42,9 +42,9 @@ void ECMouseObserver::Update() {
if (view.GetCurrEvent() == ECGV_EV_MOUSE_BUTTON_DOWN) {
mouseFunction.mouseDown();
}
if (view.GetCurrEvent() == ECGV_EV_TIMER) {
/*if (view.GetCurrEvent() == ECGV_EV_TIMER) {
mouseFunction.timer();
}
}*/
}
}

Expand Down
12 changes: 8 additions & 4 deletions source-files/test-gv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,20 @@ CompositeShape* parseComposite(int numMembers, ifstream& f, ShapesModel* model)
// Test graphical view code
int real_main(int argc, char** argv)
{
// Initialize view
const int widthWin = 1000, heightWin = 1000;
ECGraphicViewImp view(widthWin, heightWin);

// Initialize Model and Controller
ShapesModel* model = new ShapesModel;
// TODO: adjust window title
Controller ctrl(model);
Menu* menu = new Menu;

// Mouse Functions --> these will be accessed in the menu and in the mouse observers
InsertModeMouseFunction insertMouseFunctionality(view, ctrl);
EditModeMouseFunction editMouseFunctionality(view, ctrl);

// menu init
Menu* menu = new Menu(editMouseFunctionality, insertMouseFunctionality);
menu->initFont(al_load_ttf_font("IBMPlexSans-Regular.ttf", 18, 0));

menu->initDivider(al_load_bitmap("res/divider.jpg"));
Expand Down Expand Up @@ -140,8 +146,6 @@ int real_main(int argc, char** argv)
ECRightArrowObserver* RightKeyObserver = new ECRightArrowObserver(view, ctrl);

// Mouse Observers Init
InsertModeMouseFunction insertMouseFunctionality(view, ctrl);
EditModeMouseFunction editMouseFunctionality(view, ctrl);
ECMouseObserver* EditModeMouseObserver = new ECMouseObserver(view, ctrl, 0, editMouseFunctionality);
ECMouseObserver* InsertModeMouseObserver = new ECMouseObserver(view, ctrl, 1, insertMouseFunctionality);

Expand Down

0 comments on commit 105e5f2

Please sign in to comment.