use keys to browse images
This commit is contained in:
parent
a9c8d053d6
commit
1a090d26d5
|
@ -36,11 +36,11 @@
|
|||
{
|
||||
"json-save": true,
|
||||
"json-save-directory": "local/scans",
|
||||
"barcode": "015700057605"
|
||||
"barcode": "645175525233"
|
||||
},
|
||||
"api":
|
||||
{
|
||||
"user-agent": "Pudding making game for http://shampoo.ooo",
|
||||
"user-agent": "Custom pudding creation game for http://shampoo.ooo",
|
||||
"nutronix-app-id": "ea0f2e7e",
|
||||
"nutronix-app-key": "39218dde526dd3349daa028deda518ae",
|
||||
"edamam-app-id": "c23b139f",
|
||||
|
|
10
src/Item.cpp
10
src/Item.cpp
|
@ -38,6 +38,11 @@ const std::vector<std::shared_ptr<SDL_Texture>>& Item::get_image_textures() cons
|
|||
return image_textures;
|
||||
}
|
||||
|
||||
const std::shared_ptr<SDL_Texture>& Item::get_active_image_texture() const
|
||||
{
|
||||
return get_image_textures()[current_image_index];
|
||||
}
|
||||
|
||||
void Item::set_brand_name(const std::string& name)
|
||||
{
|
||||
set_text_property(name, brand_name, "brand name");
|
||||
|
@ -79,6 +84,11 @@ std::string Item::get_full_name() const
|
|||
return name;
|
||||
}
|
||||
|
||||
void Item::increment_image_index(int increment)
|
||||
{
|
||||
current_image_index = sfw::mod(current_image_index + increment, static_cast<int>(get_image_textures().size()));
|
||||
}
|
||||
|
||||
Item::~Item()
|
||||
{
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "destroying item %p", this);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <string>
|
||||
#include <memory>
|
||||
#include <SDL.h>
|
||||
#include <extension.hpp>
|
||||
|
||||
class Item
|
||||
{
|
||||
|
@ -12,12 +13,14 @@ class Item
|
|||
private:
|
||||
std::vector<std::shared_ptr<SDL_Texture>> image_textures;
|
||||
std::string brand_name = "", product_name = "", upc = "";
|
||||
int current_image_index = 0;
|
||||
void set_text_property(const std::string&, std::string&, const std::string&);
|
||||
static void destroy_texture(SDL_Texture*);
|
||||
|
||||
public:
|
||||
void add_image_texture(SDL_Texture*);
|
||||
const std::vector<std::shared_ptr<SDL_Texture>>& get_image_textures() const;
|
||||
const std::shared_ptr<SDL_Texture>& get_active_image_texture() const;
|
||||
void set_brand_name(const std::string&);
|
||||
const std::string& get_brand_name() const;
|
||||
void set_product_name(const std::string&);
|
||||
|
@ -25,6 +28,7 @@ public:
|
|||
void set_upc(const std::string&);
|
||||
const std::string& get_upc() const;
|
||||
std::string get_full_name() const;
|
||||
void increment_image_index(int = 1);
|
||||
~Item();
|
||||
|
||||
};
|
||||
|
|
|
@ -25,9 +25,30 @@ int main()
|
|||
|
||||
Pudding::Pudding()
|
||||
{
|
||||
get_delegate().subscribe(&Pudding::respond, this);
|
||||
load_sdl_context();
|
||||
}
|
||||
|
||||
void Pudding::respond(SDL_Event& event)
|
||||
{
|
||||
if (get_delegate().compare(event, "up"))
|
||||
{
|
||||
increment_item_index();
|
||||
}
|
||||
else if (get_delegate().compare(event, "right"))
|
||||
{
|
||||
get_current_item().increment_image_index();
|
||||
}
|
||||
else if (get_delegate().compare(event, "down"))
|
||||
{
|
||||
increment_item_index(-1);
|
||||
}
|
||||
else if (get_delegate().compare(event, "left"))
|
||||
{
|
||||
get_current_item().increment_image_index(-1);
|
||||
}
|
||||
}
|
||||
|
||||
void Pudding::load_sdl_context()
|
||||
{
|
||||
super::load_sdl_context();
|
||||
|
@ -252,6 +273,16 @@ SDL_Texture* Pudding::texture_from_image_url(const std::string& url)
|
|||
}
|
||||
}
|
||||
|
||||
void Pudding::increment_item_index(int increment)
|
||||
{
|
||||
current_item_index = sfw::mod(current_item_index + increment, static_cast<int>(items.size()));
|
||||
}
|
||||
|
||||
Item& Pudding::get_current_item()
|
||||
{
|
||||
return items[current_item_index];
|
||||
}
|
||||
|
||||
void Pudding::update()
|
||||
{
|
||||
get_root()->configuration.load("config.json");
|
||||
|
@ -263,9 +294,6 @@ void Pudding::update()
|
|||
}
|
||||
if (items.size() > 0)
|
||||
{
|
||||
if (items.front().get_image_textures().size() > 0)
|
||||
{
|
||||
SDL_RenderCopyF(get_renderer(), items.front().get_image_textures().back().get(), nullptr, nullptr);
|
||||
}
|
||||
SDL_RenderCopyF(get_renderer(), get_current_item().get_active_image_texture().get(), nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,9 +32,11 @@ struct Pudding : Game
|
|||
typedef Game super;
|
||||
std::string current_barcode;
|
||||
std::vector<Item> items;
|
||||
int current_item_index;
|
||||
|
||||
Pudding();
|
||||
void load_sdl_context();
|
||||
void respond(SDL_Event&);
|
||||
void add_item(const std::string&);
|
||||
void incorporate_open_food_api(Item&);
|
||||
void incorporate_nutronix_api(Item&);
|
||||
|
@ -44,6 +46,8 @@ struct Pudding : Game
|
|||
void curl_get_bytes(const std::string& url, std::vector<std::uint8_t>&, const std::vector<std::string>& = {});
|
||||
static size_t curl_write_response(std::uint8_t*, size_t, size_t, std::vector<std::uint8_t>*);
|
||||
SDL_Texture* texture_from_image_url(const std::string&);
|
||||
void increment_item_index(int = 1);
|
||||
Item& get_current_item();
|
||||
void update();
|
||||
std::string get_class_name() { return "Pudding"; }
|
||||
|
||||
|
|
Loading…
Reference in New Issue