From e42b21fdf3364c48f18ee45481fad1b005332ad0 Mon Sep 17 00:00:00 2001 From: Reed Nightingale Date: Sun, 9 Feb 2020 16:16:57 -0800 Subject: [PATCH] Add touch button finding util --- menu_utils.cpp | 19 +++++++++++++++++++ menu_utils.h | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/menu_utils.cpp b/menu_utils.cpp index 174892e..7254b81 100644 --- a/menu_utils.cpp +++ b/menu_utils.cpp @@ -1,5 +1,7 @@ #include "menu.h" +#include + #include "button.h" #include "color_theme.h" #include "nano_gui.h" @@ -44,3 +46,20 @@ void movePuck(const Button *const b_old, } } +bool findPressedButton(const Button *const buttons, + const uint8_t num_buttons, + Button *const button_out, + const Point touch_point) +{ + for(uint16_t i = 0; i < num_buttons; ++i){ + if((buttons[i].x <= touch_point.x) + &&(touch_point.x <= buttons[i].x + buttons[i].w) + &&(buttons[i].y <= touch_point.y) + &&(touch_point.y <= buttons[i].y + buttons[i].h)){ + memcpy_P(button_out,&buttons[i],sizeof(button_out)); + return true; + } + } + + return false; +} diff --git a/menu_utils.h b/menu_utils.h index 1441afb..a748b21 100644 --- a/menu_utils.h +++ b/menu_utils.h @@ -12,3 +12,9 @@ bool runSubmenu(Menu_t* current_menu, void movePuck(const Button *const b_old, const Button *const b_new); + +//Returns true if button was found, false otherwise +bool findPressedButton(const Button *const buttons, + const uint8_t num_buttons, + Button *const button_out, + const Point touch_point); \ No newline at end of file