Skip to content

Commit

Permalink
Android : Handle surface view resize
Browse files Browse the repository at this point in the history
  • Loading branch information
efyx committed Feb 1, 2017
1 parent d4e8d35 commit 00b9d20
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
49 changes: 37 additions & 12 deletions src/Interface/android/AndroidUIInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@

#include <SDL_config_android.h>
#include <SDL_syswm.h>
#include <SDL_events.h>

#include "System.h"
#include "Frontend/Context.h"
#include "Binding/JSWindow.h"


using Nidium::Binding::JSWindow;

namespace Nidium {
namespace Interface {
Expand All @@ -27,28 +33,47 @@ AndroidUIInterface::AndroidUIInterface()

void AndroidUIInterface::setGLContextAttribute()
{
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5 );
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5 );
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0 );
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32 );
//SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5 );
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5 );
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0 );
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32 );
//SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1 );

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);

}

int AndroidUIInterface::toLogicalSize(int size)
{
System *sys = static_cast<System *>(SystemInterface::GetInstance());
double pr = sys->backingStorePixelRatio();
return ceil(size/pr);
}

bool AndroidUIInterface::createWindow(int width, int height)
{
// Android has a fixed window size, so we ignore the width/height given
// (that comes from the NML) and set the size to the size of the view
System *sys = static_cast<System *>(SystemInterface::GetInstance());
double pr = sys->backingStorePixelRatio();
return UIInterface::createWindow((sys->getSurfaceWidth()/pr) + 1, (sys->getSurfaceHeight()/pr) + 1);
return UIInterface::createWindow(
this->toLogicalSize(sys->getSurfaceWidth()),
this->toLogicalSize(sys->getSurfaceHeight()));
}

void AndroidUIInterface::handleEvent(const SDL_Event *ev)
{
if (ev->type == SDL_WINDOWEVENT && ev->window.event == SDL_WINDOWEVENT_RESIZED) {
this->getNidiumContext()->setWindowSize(
this->toLogicalSize(ev->window.data1),
this->toLogicalSize(ev->window.data2));
} else {
UIInterface::handleEvent(ev);
}
}

void AndroidUIInterface::quitApplication()
Expand Down
2 changes: 2 additions & 0 deletions src/Interface/android/AndroidUIInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class AndroidUIInterface : public UIInterface
int flags = 0) override;
void setGLContextAttribute() override;
bool createWindow(int width, int height) override;
void handleEvent(const SDL_Event *ev) override;

DummyConsole *getConsole(bool create = false, bool *created = NULL) override
{
Expand All @@ -61,6 +62,7 @@ class AndroidUIInterface : public UIInterface

private:
DummyConsole *m_Console;
int toLogicalSize(int physicalSize);
};
// }}}

Expand Down

0 comments on commit 00b9d20

Please sign in to comment.