ppsspp/Common/UI/UI.h

68 lines
2.1 KiB
C
Raw Normal View History

2012-04-10 10:36:38 +00:00
// Simple immediate mode UI implementation.
//
// Heavily inspired by Sol's tutorial at http://sol.gfxile.net/imgui/.
//
// A common pattern is Adapter classes for changing how things are drawn
// in lists, for example.
//
2012-07-26 11:47:15 +00:00
// Immediate UI works great for overlay UI for games, for example, but is actually
// not really a good idea for full app UIs. Also, animations are difficult because
// there's not really any good place to store state.
//
2012-04-10 10:36:38 +00:00
// hrydgard@gmail.com
#pragma once
// Simple ID generators. Absolutely no guarantee of collision avoidance if you implement
// multiple parts of a single screen of UI over multiple files unless you use IMGUI_SRC_ID.
#ifdef IMGUI_SRC_ID
2013-03-30 18:23:02 +00:00
#define GEN_ID (int)((IMGUI_SRC_ID) + (__LINE__))
#define GEN_ID_LOOP(i) (int)((IMGUI_SRC_ID) + (__LINE__) + (i) * 13612)
2012-04-10 10:36:38 +00:00
#else
#define GEN_ID (__LINE__)
#define GEN_ID_LOOP(i) ((__LINE__) + ((int)i) * 13612)
2012-04-10 10:36:38 +00:00
#endif
2012-04-12 10:52:55 +00:00
#include <string>
2012-04-10 10:36:38 +00:00
#include <vector>
#include "Common/Render/DrawBuffer.h"
#include "Common/Input/InputState.h"
2013-03-30 18:23:02 +00:00
class UIContext;
2012-04-12 17:45:21 +00:00
2012-04-10 10:36:38 +00:00
struct Atlas;
// This is the drawbuffer used for UI. Remember to flush it at the end of the frame.
// TODO: One should probably pass it in through UIInit.
extern DrawBuffer ui_draw2d;
2012-10-29 13:49:09 +00:00
extern DrawBuffer ui_draw2d_front; // for things that need to be on top of the rest
2012-04-10 10:36:38 +00:00
// TODO: These don't really belong here.
// Implement this interface to style your lists
class UIListAdapter {
public:
virtual ~UIListAdapter() {}
2012-10-29 13:49:09 +00:00
virtual size_t getCount() const = 0;
virtual void drawItem(int item, int x, int y, int w, int h, bool active) const = 0;
virtual float itemHeight(int itemIndex) const { return 64; }
virtual bool itemEnabled(int itemIndex) const { return true; }
2012-04-10 10:36:38 +00:00
};
class StringVectorListAdapter : public UIListAdapter {
public:
2012-10-29 13:49:09 +00:00
StringVectorListAdapter(const std::vector<std::string> *items) : items_(items) {}
size_t getCount() const override { return items_->size(); }
void drawItem(int item, int x, int y, int w, int h, bool active) const override;
2012-04-10 10:36:38 +00:00
private:
2012-10-29 13:49:09 +00:00
const std::vector<std::string> *items_;
2012-04-10 10:36:38 +00:00
};
2012-04-11 15:07:28 +00:00
2018-12-18 09:10:53 +00:00
// Begins/flushes the two UI drawbuffers together.
void UIBegin(Draw::Pipeline *shaderSet);
2013-03-30 18:23:02 +00:00
void UIFlush();
2012-04-10 10:36:38 +00:00