Kerry Martin / Mbed 2 deprecated Liz_Test_Code

Dependencies:   mbed RA8875

Button.cpp

Committer:
lizard753
Date:
2019-07-10
Revision:
19:fee3f71fab2d
Child:
20:d25fb9c55781

File content as of revision 19:fee3f71fab2d:


#include "Button.h"
/** Button Constructor
  * creates an object to emulate a button on the screen
  * arguments:
  *     
  *
  */
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)
: corner1_x(arg_corner1_x),
  corner1_y(arg_corner1_y),
  corner2_x(arg_corner2_x),
  corner2_y(arg_corner2_y),
  //button_name(arg_name),
  button_color(arg_color),
  lcd(arg_display)
{
    int len = strlen(arg_name) + 1;
    button_name = new char[len];
    snprintf(button_name, len, "%s", arg_name);
}

//Button::Button()
//: Button(0, 0, 0, 0, RGB(0,0,0), RA8875(), string("noname"))
//{
//}
/** isPressed
  * given the current coordinates of the press, is it within the bounds of the button 
  * returns true/false
  */
bool Button::isPressed(loc_t cur_x, loc_t cur_y)
{
    if(corner1_x < cur_x && corner2_x > cur_x && corner1_y < cur_y && corner2_y > cur_y)
    {
        return true;
    }
    return false;
}

/** draw
  * will use the screen given in the constructor to draw out a rectangle and text to symbolize the button
  * returns: void
  */
void Button::draw()
{
    lcd->rect(corner1_x, corner1_y, corner2_x, corner2_y, button_color);
    lcd->puts(corner1_x, corner2_y, button_name);
}

/** toString
  * returns a string with the values of the button 
  * used mainly for debugging
  * returns: string with values of button
  */
string Button::toString()
{
    string return_string = "Liz is awesome";
    //sprintf(return_string, "Button Name: %s\nLocation: %d,%d:%d,%d\n", button_name, corner1_x, corner1_y, corner2_x, corner2_y);
    return return_string;
}