Commits

Ivan Vučica committed edbfc73

Subclass of Button: ExitButton.

  • Participants
  • Parent commits 7be9954

Comments (0)

Files changed (5)

 #include "button.h"
 #include "texture.h"
 
+extern bool gRunning;
+
 Button::Button(const std::string& textureFile,
                const int argX,
                const int argY) : texture(new Texture(textureFile)), x(argX), y(argY)
     {
         if(mouseInside(event.button.x, event.button.y))
         {
-            printf("KLIK\n");
+            this->handleClick();
             state = STATE_OVER;
         }
         else
         state = STATE_UP;
     }
 }
+
+void Button::handleClick()
+{
+    printf("Click\n");
+}
+
+///////////////////////////////
+
+void ExitButton::handleClick()
+{
+    gRunning = 0;
+}
     Button(const std::string& textureFile,
            const int x,
            const int y);
-    ~Button();
+    virtual ~Button();
 
     enum State
     {
     void mouseDown(const SDL_Event &event);
     void mouseMove(const SDL_Event &event);
 
+    virtual void handleClick();
+
     private:
     Texture * texture;
     float x, y;
     State state;
 };
 
+class ExitButton : public Button
+{
+    public:
+    ExitButton(const std::string& textureFile,
+               const int x,
+               const int y) :
+               Button(textureFile, x, y)
+    {
+    }
+    void handleClick();
+};
+
 #endif

File exit.png

Added
New image

File gm_mainmenu.cpp

 
 GM_MainMenu::GM_MainMenu()
 {
-    Button *testButton(new Button("button.png", 400, 400));
-    Button *testButton2(new Button("button.png", 400, 200));
+    Button *exitButton(new ExitButton("exit.png", 400, 200));
 
-    this->buttons.push_back(testButton);
-    this->buttons.push_back(testButton2);
+    this->buttons.push_back(exitButton);
 
     for(int i = 0; i < 3; i++)
     {

File pucaljka.cpp

 
     }
 
+    delete gGame;
+
     SDL_Quit();
 
     return 0;