~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to ext/native/ui/ui.h

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Simple immediate mode UI implementation.
 
2
//
 
3
// Heavily inspired by Sol's tutorial at http://sol.gfxile.net/imgui/.
 
4
//
 
5
// A common pattern is Adapter classes for changing how things are drawn
 
6
// in lists, for example.
 
7
//
 
8
// Immediate UI works great for overlay UI for games, for example, but is actually
 
9
// not really a good idea for full app UIs. Also, animations are difficult because
 
10
// there's not really any good place to store state.
 
11
//
 
12
// hrydgard@gmail.com
 
13
 
 
14
#pragma once
 
15
 
 
16
// Simple ID generators. Absolutely no guarantee of collision avoidance if you implement
 
17
// multiple parts of a single screen of UI over multiple files unless you use IMGUI_SRC_ID.
 
18
#ifdef IMGUI_SRC_ID
 
19
#define GEN_ID (int)((IMGUI_SRC_ID) + (__LINE__))
 
20
#define GEN_ID_LOOP(i) (int)((IMGUI_SRC_ID) + (__LINE__) + (i) * 13612)
 
21
#else
 
22
#define GEN_ID (__LINE__)
 
23
#define GEN_ID_LOOP(i) ((__LINE__) + ((int)i) * 13612)
 
24
#endif
 
25
 
 
26
#include <string>
 
27
#include <vector>
 
28
 
 
29
#include "gfx_es2/draw_buffer.h"
 
30
#include "input/input_state.h"
 
31
 
 
32
class UIContext;
 
33
 
 
34
struct Atlas;
 
35
 
 
36
// This is the drawbuffer used for UI. Remember to flush it at the end of the frame.
 
37
// TODO: One should probably pass it in through UIInit.
 
38
extern DrawBuffer ui_draw2d;
 
39
extern DrawBuffer ui_draw2d_front;      // for things that need to be on top of the rest
 
40
 
 
41
// TODO: These don't really belong here.
 
42
 
 
43
// Implement this interface to style your lists
 
44
class UIListAdapter {
 
45
public:
 
46
        virtual size_t getCount() const = 0;
 
47
        virtual void drawItem(int item, int x, int y, int w, int h, bool active) const = 0;
 
48
        virtual float itemHeight(int itemIndex) const { return 64; }
 
49
        virtual bool itemEnabled(int itemIndex) const { return true; }
 
50
};
 
51
 
 
52
class StringVectorListAdapter : public UIListAdapter {
 
53
public:
 
54
        StringVectorListAdapter(const std::vector<std::string> *items) : items_(items) {}
 
55
        virtual size_t getCount() const { return items_->size(); }
 
56
        virtual void drawItem(int item, int x, int y, int w, int h, bool active) const;
 
57
 
 
58
private:
 
59
        const std::vector<std::string> *items_;
 
60
};
 
61
 
 
62
 
 
63
// Call at start of frame
 
64
void UIBegin(Thin3DShaderSet *shaderSet);
 
65
 
 
66
// Call at end of frame.
 
67
 
 
68
void UIEnd();
 
69
void UIFlush();
 
70