Add touch button finding util

This commit is contained in:
Reed Nightingale 2020-02-09 16:16:57 -08:00
parent 49c5607dd3
commit e42b21fdf3
2 changed files with 25 additions and 0 deletions

View File

@ -1,5 +1,7 @@
#include "menu.h"
#include <avr/pgmspace.h>
#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;
}

View File

@ -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);