KSM edits

Dependencies:   mbed RA8875

Committer:
kerrysmartin
Date:
Thu Jul 11 14:04:19 2019 +0000
Revision:
20:d25fb9c55781
Parent:
19:fee3f71fab2d
Initial check in

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lizard753 19:fee3f71fab2d 1
lizard753 19:fee3f71fab2d 2 #include "Button.h"
lizard753 19:fee3f71fab2d 3 /** Button Constructor
lizard753 19:fee3f71fab2d 4 * creates an object to emulate a button on the screen
lizard753 19:fee3f71fab2d 5 * arguments:
lizard753 19:fee3f71fab2d 6 *
lizard753 19:fee3f71fab2d 7 *
lizard753 19:fee3f71fab2d 8 */
kerrysmartin 20:d25fb9c55781 9 Button::Button(rect_t arg_rect, color_t arg_color, RA8875 *arg_display, const char * arg_name)
kerrysmartin 20:d25fb9c55781 10 : button_rect(arg_rect),
lizard753 19:fee3f71fab2d 11 button_color(arg_color),
lizard753 19:fee3f71fab2d 12 lcd(arg_display)
lizard753 19:fee3f71fab2d 13 {
lizard753 19:fee3f71fab2d 14 int len = strlen(arg_name) + 1;
lizard753 19:fee3f71fab2d 15 button_name = new char[len];
lizard753 19:fee3f71fab2d 16 snprintf(button_name, len, "%s", arg_name);
lizard753 19:fee3f71fab2d 17 }
lizard753 19:fee3f71fab2d 18
kerrysmartin 20:d25fb9c55781 19 Button::Button(loc_t arg_corner1_x, loc_t arg_corner1_y, loc_t arg_corner2_x, loc_t arg_corner2_y, color_t arg_color, RA8875 *arg_display, const char * arg_name)
kerrysmartin 20:d25fb9c55781 20 {
kerrysmartin 20:d25fb9c55781 21
kerrysmartin 20:d25fb9c55781 22
kerrysmartin 20:d25fb9c55781 23 //button_name(arg_name),
kerrysmartin 20:d25fb9c55781 24 button_color = arg_color;
kerrysmartin 20:d25fb9c55781 25 lcd = arg_display;
kerrysmartin 20:d25fb9c55781 26 button_rect.p1.x = arg_corner1_x;
kerrysmartin 20:d25fb9c55781 27 button_rect.p1.y = arg_corner1_y;
kerrysmartin 20:d25fb9c55781 28 button_rect.p2.x = arg_corner2_x;
kerrysmartin 20:d25fb9c55781 29 button_rect.p2.y = arg_corner2_y;
kerrysmartin 20:d25fb9c55781 30 int len = strlen(arg_name) + 1;
kerrysmartin 20:d25fb9c55781 31 button_name = new char[len];
kerrysmartin 20:d25fb9c55781 32 snprintf(button_name, len, "%s", arg_name);
kerrysmartin 20:d25fb9c55781 33
kerrysmartin 20:d25fb9c55781 34
kerrysmartin 20:d25fb9c55781 35 }
kerrysmartin 20:d25fb9c55781 36
kerrysmartin 20:d25fb9c55781 37
kerrysmartin 20:d25fb9c55781 38 /*
kerrysmartin 20:d25fb9c55781 39
kerrysmartin 20:d25fb9c55781 40 */
lizard753 19:fee3f71fab2d 41 //Button::Button()
lizard753 19:fee3f71fab2d 42 //: Button(0, 0, 0, 0, RGB(0,0,0), RA8875(), string("noname"))
lizard753 19:fee3f71fab2d 43 //{
lizard753 19:fee3f71fab2d 44 //}
lizard753 19:fee3f71fab2d 45 /** isPressed
lizard753 19:fee3f71fab2d 46 * given the current coordinates of the press, is it within the bounds of the button
lizard753 19:fee3f71fab2d 47 * returns true/false
lizard753 19:fee3f71fab2d 48 */
lizard753 19:fee3f71fab2d 49 bool Button::isPressed(loc_t cur_x, loc_t cur_y)
lizard753 19:fee3f71fab2d 50 {
kerrysmartin 20:d25fb9c55781 51 /*if(corner1_x < cur_x && corner2_x > cur_x && corner1_y < cur_y && corner2_y > cur_y)
lizard753 19:fee3f71fab2d 52 {
lizard753 19:fee3f71fab2d 53 return true;
kerrysmartin 20:d25fb9c55781 54 }*/
kerrysmartin 20:d25fb9c55781 55 point_t touch_pt;
kerrysmartin 20:d25fb9c55781 56 touch_pt.x = cur_x;
kerrysmartin 20:d25fb9c55781 57 touch_pt.y = cur_y;
kerrysmartin 20:d25fb9c55781 58 return lcd->Intersect(button_rect, touch_pt);
lizard753 19:fee3f71fab2d 59 }
lizard753 19:fee3f71fab2d 60
lizard753 19:fee3f71fab2d 61 /** draw
lizard753 19:fee3f71fab2d 62 * will use the screen given in the constructor to draw out a rectangle and text to symbolize the button
lizard753 19:fee3f71fab2d 63 * returns: void
lizard753 19:fee3f71fab2d 64 */
lizard753 19:fee3f71fab2d 65 void Button::draw()
lizard753 19:fee3f71fab2d 66 {
kerrysmartin 20:d25fb9c55781 67 lcd->rect(button_rect, button_color);
kerrysmartin 20:d25fb9c55781 68 lcd->puts(button_rect.p1.x, button_rect.p1.y, button_name);
lizard753 19:fee3f71fab2d 69 }
lizard753 19:fee3f71fab2d 70
lizard753 19:fee3f71fab2d 71 /** toString
lizard753 19:fee3f71fab2d 72 * returns a string with the values of the button
lizard753 19:fee3f71fab2d 73 * used mainly for debugging
lizard753 19:fee3f71fab2d 74 * returns: string with values of button
lizard753 19:fee3f71fab2d 75 */
lizard753 19:fee3f71fab2d 76 string Button::toString()
lizard753 19:fee3f71fab2d 77 {
lizard753 19:fee3f71fab2d 78 string return_string = "Liz is awesome";
lizard753 19:fee3f71fab2d 79 //sprintf(return_string, "Button Name: %s\nLocation: %d,%d:%d,%d\n", button_name, corner1_x, corner1_y, corner2_x, corner2_y);
lizard753 19:fee3f71fab2d 80 return return_string;
lizard753 19:fee3f71fab2d 81 }