mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 13:30:02 +00:00
Add UIContext, to make it easier to pass around what's needed to draw.
Not used in PPSSPP yet, for the curious.
This commit is contained in:
parent
1968e8c529
commit
16e3d67063
@ -48,6 +48,7 @@ LOCAL_SRC_FILES :=\
|
||||
gfx/texture_gen.cpp \
|
||||
image/zim_load.cpp \
|
||||
ui/ui.cpp \
|
||||
ui/ui_context.cpp \
|
||||
ui/screen.cpp \
|
||||
ui/virtual_input.cpp \
|
||||
util/random/perlin.cpp
|
||||
|
@ -170,11 +170,11 @@ int main(int argc, char *argv[]) {
|
||||
//pixel_xres = 1580 * zoom;
|
||||
//pixel_yres = 1000 * zoom;
|
||||
if (tablet) {
|
||||
pixel_xres = 480 * zoom;
|
||||
pixel_yres = 800 * zoom;
|
||||
} else {
|
||||
pixel_xres = 800 * zoom;
|
||||
pixel_yres = 1280 * zoom;
|
||||
} else {
|
||||
pixel_xres = 480 * zoom;
|
||||
pixel_yres = 800 * zoom;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v100</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
@ -173,6 +174,7 @@
|
||||
<None Include="file\CMakeLists.txt" />
|
||||
<None Include="README.md" />
|
||||
<None Include="tools\CMakeLists.txt" />
|
||||
<None Include="ui\CMakeLists.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="android\native-audio-so.h" />
|
||||
@ -240,6 +242,7 @@
|
||||
<ClInclude Include="profiler\profiler.h" />
|
||||
<ClInclude Include="ui\screen.h" />
|
||||
<ClInclude Include="ui\ui.h" />
|
||||
<ClInclude Include="ui\ui_context.h" />
|
||||
<ClInclude Include="ui\virtual_input.h" />
|
||||
<ClInclude Include="util\bits\bits.h" />
|
||||
<ClInclude Include="util\random\perlin.h" />
|
||||
@ -332,6 +335,7 @@
|
||||
<ClCompile Include="profiler\profiler.cpp" />
|
||||
<ClCompile Include="ui\screen.cpp" />
|
||||
<ClCompile Include="ui\ui.cpp" />
|
||||
<ClCompile Include="ui\ui_context.cpp" />
|
||||
<ClCompile Include="ui\virtual_input.cpp" />
|
||||
<ClCompile Include="util\bits\bits.cpp" />
|
||||
<ClCompile Include="util\random\perlin.cpp">
|
||||
|
@ -15,6 +15,9 @@
|
||||
<None Include="tools\CMakeLists.txt">
|
||||
<Filter>tools</Filter>
|
||||
</None>
|
||||
<None Include="ui\CMakeLists.txt">
|
||||
<Filter>ui</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="gfx\gl_debug_log.h">
|
||||
@ -224,6 +227,9 @@
|
||||
<ClInclude Include="math\curves.h">
|
||||
<Filter>math</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ui\ui_context.h">
|
||||
<Filter>ui</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="gfx\gl_debug_log.cpp">
|
||||
@ -397,11 +403,8 @@
|
||||
<ClCompile Include="math\curves.cpp">
|
||||
<Filter>math</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="base\PCMain.cpp">
|
||||
<Filter>base</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="base\BlackberryMain.cpp">
|
||||
<Filter>base</Filter>
|
||||
<ClCompile Include="ui\ui_context.cpp">
|
||||
<Filter>ui</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@ -463,4 +466,4 @@
|
||||
<UniqueIdentifier>{4515306f-4664-46bf-a89b-abfec5520a15}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -26,6 +26,7 @@
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v100</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
|
@ -26,6 +26,7 @@
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v100</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
|
@ -1,5 +1,6 @@
|
||||
set(SRCS
|
||||
ui.cpp
|
||||
ui_context.cpp
|
||||
screen.cpp
|
||||
virtual_input.cpp
|
||||
)
|
||||
|
@ -2,12 +2,13 @@
|
||||
#include "input/input_state.h"
|
||||
#include "ui/screen.h"
|
||||
|
||||
Screen::Screen() : screenManager_(0) { }
|
||||
Screen::Screen(bool isUiScreen) : screenManager_(0), isUiScreen_(isUiScreen) { }
|
||||
Screen::~Screen() { }
|
||||
|
||||
ScreenManager::ScreenManager() {
|
||||
currentScreen_ = 0;
|
||||
nextScreen_ = 0;
|
||||
uiContext_ = 0;
|
||||
}
|
||||
|
||||
ScreenManager::~ScreenManager() {
|
||||
|
21
ui/screen.h
21
ui/screen.h
@ -29,10 +29,11 @@ enum DialogResult {
|
||||
};
|
||||
|
||||
class ScreenManager;
|
||||
class UIContext;
|
||||
|
||||
class Screen {
|
||||
public:
|
||||
Screen();
|
||||
Screen(bool isUiScreen = false);
|
||||
virtual ~Screen();
|
||||
virtual void update(InputState &input) = 0;
|
||||
virtual void render() {}
|
||||
@ -45,6 +46,7 @@ public:
|
||||
|
||||
private:
|
||||
ScreenManager *screenManager_;
|
||||
bool isUiScreen_;
|
||||
DISALLOW_COPY_AND_ASSIGN(Screen);
|
||||
};
|
||||
|
||||
@ -53,6 +55,11 @@ public:
|
||||
Transition() {}
|
||||
};
|
||||
|
||||
enum {
|
||||
LAYER_SIDEMENU = 1,
|
||||
LAYER_TRANSPARENT = 2,
|
||||
};
|
||||
|
||||
class ScreenManager {
|
||||
public:
|
||||
ScreenManager();
|
||||
@ -60,6 +67,10 @@ public:
|
||||
|
||||
void switchScreen(Screen *screen);
|
||||
void update(InputState &input);
|
||||
|
||||
void setUIContext(UIContext *context) { uiContext_ = context; }
|
||||
UIContext *getUIContext() { return uiContext_; }
|
||||
|
||||
void render();
|
||||
void deviceLost();
|
||||
void shutdown();
|
||||
@ -76,10 +87,18 @@ public:
|
||||
private:
|
||||
void pop();
|
||||
Screen *topScreen();
|
||||
|
||||
// Base screen. These don't "stack" and you can move in any order between them.
|
||||
Screen *currentScreen_;
|
||||
Screen *nextScreen_;
|
||||
|
||||
UIContext *uiContext_;
|
||||
|
||||
struct Layer {
|
||||
Screen *screen;
|
||||
int flags; // From LAYER_ enum above
|
||||
};
|
||||
|
||||
// Dialog stack. These are shown "on top" of base screens and the Android back button works as expected.
|
||||
// Used for options, in-game menus and other things you expect to be able to back out from onto something.
|
||||
std::list<Screen *> dialog_;
|
||||
|
12
ui/ui.cpp
12
ui/ui.cpp
@ -15,6 +15,7 @@ DrawBuffer ui_draw2d_front;
|
||||
|
||||
// This one, though, is OK.
|
||||
UIState uistate;
|
||||
UIState savedUistate;
|
||||
|
||||
// Theme.
|
||||
static const Atlas *themeAtlas;
|
||||
@ -28,6 +29,17 @@ void UIInit(const Atlas *atlas, const UITheme &ui_theme) {
|
||||
memset(&uistate, 0, sizeof(uistate));
|
||||
}
|
||||
|
||||
void UIDisableBegin()
|
||||
{
|
||||
savedUistate = uistate;
|
||||
memset(&uistate, 0, sizeof(uistate));
|
||||
}
|
||||
|
||||
void UIDisableEnd()
|
||||
{
|
||||
uistate = savedUistate;
|
||||
}
|
||||
|
||||
void UIUpdateMouse(int i, float x, float y, bool down) {
|
||||
if (down && !uistate.mousedown[i]) {
|
||||
uistate.mousepressed[i] = 1;
|
||||
|
4
ui/ui.h
4
ui/ui.h
@ -133,6 +133,10 @@ struct UITheme {
|
||||
// The atlas needs to stick around, the theme is copied.
|
||||
void UIInit(const Atlas *atlas, const UITheme &theme);
|
||||
|
||||
// Between these, UI components won't see pointer events.
|
||||
void UIDisableBegin();
|
||||
void UIDisableEnd();
|
||||
|
||||
// Just lets you retrieve the theme that was passed into UIInit, for your own controls for example.
|
||||
UITheme &UIGetTheme();
|
||||
|
||||
|
41
ui/ui_context.cpp
Normal file
41
ui/ui_context.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include "ui.h"
|
||||
#include "ui_context.h"
|
||||
#include "gfx/texture.h"
|
||||
#include "gfx_es2/draw_buffer.h"
|
||||
#include "gfx_es2/glsl_program.h"
|
||||
|
||||
void UIContext::Begin()
|
||||
{
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
if (uishader_)
|
||||
glsl_bind(uishader_);
|
||||
if (uitexture_)
|
||||
uitexture_->Bind(0);
|
||||
|
||||
UIBegin();
|
||||
/*
|
||||
if (uidrawbuffer_ && uishader_)
|
||||
uidrawbuffer_->Begin();
|
||||
if (uidrawbufferTop_ && uishader_)
|
||||
uidrawbufferTop_->Begin();*/
|
||||
}
|
||||
|
||||
void UIContext::End()
|
||||
{
|
||||
UIEnd();
|
||||
if (uidrawbuffer_)
|
||||
{
|
||||
uidrawbuffer_->End();
|
||||
if (uishader_)
|
||||
uidrawbuffer_->Flush(uishader_);
|
||||
}
|
||||
if (uidrawbufferTop_)
|
||||
{
|
||||
uidrawbuffer_->End();
|
||||
if (uishader_)
|
||||
uidrawbufferTop_->Flush(uishader_);
|
||||
}
|
||||
}
|
30
ui/ui_context.h
Normal file
30
ui/ui_context.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
// Everything you need to draw a UI collected into a single unit that can be passed around.
|
||||
// Everything forward declared so this header is safe everywhere.
|
||||
|
||||
struct GLSLProgram;
|
||||
class Texture;
|
||||
class DrawBuffer;
|
||||
|
||||
class UIContext {
|
||||
public:
|
||||
UIContext() : uishader_(0), uitexture_(0), uidrawbuffer_(0), uidrawbufferTop_(0) {}
|
||||
|
||||
void Init(const GLSLProgram *uishader, Texture *uitexture, DrawBuffer *uidrawbuffer, DrawBuffer *uidrawbufferTop) {
|
||||
uishader_ = uishader;
|
||||
uitexture_ = uitexture;
|
||||
uidrawbuffer_ = uidrawbuffer;
|
||||
uidrawbufferTop_ = uidrawbufferTop;
|
||||
}
|
||||
|
||||
void Begin();
|
||||
void End();
|
||||
|
||||
private:
|
||||
// TODO: Collect these into a UIContext
|
||||
const GLSLProgram *uishader_;
|
||||
Texture *uitexture_;
|
||||
DrawBuffer *uidrawbuffer_;
|
||||
DrawBuffer *uidrawbufferTop_;
|
||||
};
|
Loading…
Reference in New Issue
Block a user