-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathButton.cpp
More file actions
33 lines (28 loc) · 882 Bytes
/
Button.cpp
File metadata and controls
33 lines (28 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//
// Button.cpp
// KSDL
//
// Created by Kyle Koser on 7/19/15.
// Copyright (c) 2015 Kyle Koser. All rights reserved.
//
#include "Button.h"
Button::Button(SDL_Rect aFrame, SDL_Renderer *aRenderer, std::string aTitle, ButtonResponder &aListener) : View(aFrame, aRenderer), listener(aListener) {
label = new TextView(aTitle, "/Library/Fonts/Arial.ttf", {255,0,0}, 40, {0,0,100,100}, aRenderer);
addSubview(label);
}
void Button::handleEvent(SDL_Event e) {
// Call super
View::handleEvent(e);
if (e.type != SDL_MOUSEBUTTONDOWN) {
return;
}
// Check if the click is inside the frame
int x, y;
SDL_GetMouseState( &x, &y );
SDL_Rect rect = getFrame();
if (rect.x < x && (rect.x + rect.w) > x && rect.y < y && (rect.y + rect.h) > y) {
listener.buttonClicked(*this);
}
}
ButtonResponder::~ButtonResponder() {
}