mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-29 00:59:44 -06:00
Removes the Java ButtonManager for one in the C++ source so the OSD class can call in to it each frame for drawing the buttons. Copy our assets to the dolphin-emu directory for now. Remove NativeRenderer, ButtonManager, and Button Java classes since they aren't used anymore. Buttons A, B, and Start all work and are drawn on screen now. Button input on Android is still a bit hacky, needs a proper controller interface still. Android specific button drawing code is still hanging out in SWRenderer.cpp
This commit is contained in:
90
Source/Core/DolphinWX/Src/Android/ButtonManager.cpp
Normal file
90
Source/Core/DolphinWX/Src/Android/ButtonManager.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
// Copyright (C) 2003 Dolphin Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include <vector>
|
||||
#include "GLInterface.h"
|
||||
#include "Android/TextureLoader.h"
|
||||
#include "Android/ButtonManager.h"
|
||||
|
||||
extern void DrawButton(GLuint tex, float *coords);
|
||||
|
||||
namespace ButtonManager
|
||||
{
|
||||
std::vector<Button*> m_buttons;
|
||||
|
||||
// XXX: This needs to not be here so we can load the locations from file
|
||||
// This will allow customizable button locations in the future
|
||||
// These are the OpenGL on screen coordinates
|
||||
float m_coords[][8] = { // X, Y, X, EY, EX, EY, EX, Y
|
||||
{0.75f, -1.0f, 0.75f, -0.75f, 1.0f, -0.75f, 1.0f, -1.0f}, // A
|
||||
{0.50f, -1.0f, 0.50f, -0.75f, 0.75f, -0.75f, 0.75f, -1.0f}, // B
|
||||
{-0.10f, -1.0f, -0.10f, -0.80f, 0.10f, -0.80f, 0.10f, -1.0f}, // Start
|
||||
};
|
||||
|
||||
void Init()
|
||||
{
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// Initialize our buttons
|
||||
m_buttons.push_back(new Button("ButtonA.png", BUTTON_A, m_coords[0]));
|
||||
m_buttons.push_back(new Button("ButtonB.png", BUTTON_B, m_coords[1]));
|
||||
m_buttons.push_back(new Button("ButtonStart.png", BUTTON_START, m_coords[2]));
|
||||
}
|
||||
bool GetButtonPressed(ButtonType button)
|
||||
{
|
||||
for (auto it = m_buttons.begin(); it != m_buttons.end(); ++it)
|
||||
if ((*it)->GetButtonType() == button)
|
||||
return (*it)->Pressed();
|
||||
return false;
|
||||
}
|
||||
void TouchEvent(int action, float x, float y)
|
||||
{
|
||||
// Actions
|
||||
// 0 is press
|
||||
// 1 is let go
|
||||
// 2 is move
|
||||
for (auto it = m_buttons.begin(); it != m_buttons.end(); ++it)
|
||||
{
|
||||
float *coords = (*it)->GetCoords();
|
||||
if ( x >= coords[0] &&
|
||||
x <= coords[4] &&
|
||||
y >= coords[1] &&
|
||||
y <= coords[3])
|
||||
{
|
||||
if (action == 0)
|
||||
(*it)->SetState(BUTTON_PRESSED);
|
||||
if (action == 1)
|
||||
(*it)->SetState(BUTTON_RELEASED);
|
||||
if (action == 2)
|
||||
; // XXX: Be used later for analog stick
|
||||
}
|
||||
}
|
||||
}
|
||||
void Shutdown()
|
||||
{
|
||||
for(auto it = m_buttons.begin(); it != m_buttons.end(); ++it)
|
||||
delete *it;
|
||||
}
|
||||
|
||||
void DrawButtons()
|
||||
{
|
||||
for(auto it = m_buttons.begin(); it != m_buttons.end(); ++it)
|
||||
DrawButton((*it)->GetTexture(), (*it)->GetCoords());
|
||||
}
|
||||
|
||||
}
|
63
Source/Core/DolphinWX/Src/Android/ButtonManager.h
Normal file
63
Source/Core/DolphinWX/Src/Android/ButtonManager.h
Normal file
@ -0,0 +1,63 @@
|
||||
// Copyright (C) 2003 Dolphin Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include <string>
|
||||
#include "CommonPaths.h"
|
||||
#include "Android/TextureLoader.h"
|
||||
|
||||
namespace ButtonManager
|
||||
{
|
||||
enum ButtonType
|
||||
{
|
||||
BUTTON_A = 0,
|
||||
BUTTON_B,
|
||||
BUTTON_START,
|
||||
};
|
||||
enum ButtonState
|
||||
{
|
||||
BUTTON_RELEASED = 0,
|
||||
BUTTON_PRESSED = 1
|
||||
};
|
||||
class Button
|
||||
{
|
||||
private:
|
||||
GLuint m_tex;
|
||||
ButtonType m_button;
|
||||
ButtonState m_state;
|
||||
float m_coords[8];
|
||||
public:
|
||||
Button(std::string filename, ButtonType button, float *coords)
|
||||
{
|
||||
m_tex = LoadPNG((std::string(DOLPHIN_DATA_DIR "/") + filename).c_str());
|
||||
m_button = button;
|
||||
memcpy(m_coords, coords, sizeof(float) * 8);
|
||||
m_state = BUTTON_RELEASED;
|
||||
}
|
||||
void SetState(ButtonState state) { m_state = state; }
|
||||
bool Pressed() { return m_state == BUTTON_PRESSED; }
|
||||
ButtonType GetButtonType() { return m_button; }
|
||||
GLuint GetTexture() { return m_tex; }
|
||||
float *GetCoords() { return m_coords; }
|
||||
|
||||
~Button() { glDeleteTextures(1, &m_tex); }
|
||||
};
|
||||
void Init();
|
||||
void DrawButtons();
|
||||
bool GetButtonPressed(ButtonType button);
|
||||
void TouchEvent(int action, float x, float y);
|
||||
void Shutdown();
|
||||
}
|
192
Source/Core/DolphinWX/Src/Android/TextureLoader.cpp
Normal file
192
Source/Core/DolphinWX/Src/Android/TextureLoader.cpp
Normal file
@ -0,0 +1,192 @@
|
||||
// Copyright (C) 2003 Dolphin Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "GLInterface.h"
|
||||
#include <png.h>
|
||||
|
||||
GLuint OpenGL_ReportGLError()
|
||||
{
|
||||
GLint err = glGetError();
|
||||
if (err != GL_NO_ERROR)
|
||||
{
|
||||
ERROR_LOG(VIDEO, "OpenGL error 0x%x\n", err);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
GLuint LoadPNG(const char *filename)
|
||||
{
|
||||
FILE *infile; /* PNG file pointer */
|
||||
png_structp png_ptr; /* internally used by libpng */
|
||||
png_infop info_ptr; /* user requested transforms */
|
||||
|
||||
char *image_data; /* raw png image data */
|
||||
char sig[8]; /* PNG signature array */
|
||||
/*char **row_pointers; */
|
||||
|
||||
int bit_depth;
|
||||
int color_type;
|
||||
|
||||
png_uint_32 width; /* PNG image width in pixels */
|
||||
png_uint_32 height; /* PNG image height in pixels */
|
||||
unsigned int rowbytes; /* raw bytes at row n in image */
|
||||
|
||||
image_data = NULL;
|
||||
unsigned int i;
|
||||
png_bytepp row_pointers = NULL;
|
||||
|
||||
/* Open the file. */
|
||||
infile = fopen(filename, "rb");
|
||||
if (!infile)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* 13.3 readpng_init()
|
||||
*/
|
||||
|
||||
/* Check for the 8-byte signature */
|
||||
fread(sig, 1, 8, infile);
|
||||
|
||||
if (!png_check_sig((unsigned char *) sig, 8)) {
|
||||
fclose(infile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the PNG structs
|
||||
*/
|
||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!png_ptr) {
|
||||
fclose(infile);
|
||||
return 4; /* out of memory */
|
||||
}
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr) {
|
||||
png_destroy_read_struct(&png_ptr, (png_infopp) NULL, (png_infopp) NULL);
|
||||
fclose(infile);
|
||||
return 4; /* out of memory */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* block to handle libpng errors,
|
||||
* then check whether the PNG file had a bKGD chunk
|
||||
*/
|
||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
fclose(infile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* takes our file stream pointer (infile) and
|
||||
* stores it in the png_ptr struct for later use.
|
||||
*/
|
||||
/* png_ptr->io_ptr = (png_voidp)infile;*/
|
||||
png_init_io(png_ptr, infile);
|
||||
|
||||
/*
|
||||
* lets libpng know that we already checked the 8
|
||||
* signature bytes, so it should not expect to find
|
||||
* them at the current file pointer location
|
||||
*/
|
||||
png_set_sig_bytes(png_ptr, 8);
|
||||
|
||||
/* Read the image */
|
||||
|
||||
/*
|
||||
* reads and processes not only the PNG file's IHDR chunk
|
||||
* but also any other chunks up to the first IDAT
|
||||
* (i.e., everything before the image data).
|
||||
*/
|
||||
|
||||
/* read all the info up to the image data */
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
|
||||
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
|
||||
&color_type, NULL, NULL, NULL);
|
||||
|
||||
/* Set up some transforms. */
|
||||
if (bit_depth > 8)
|
||||
png_set_strip_16(png_ptr);
|
||||
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
png_set_gray_to_rgb(png_ptr);
|
||||
|
||||
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
png_set_palette_to_rgb(png_ptr);
|
||||
|
||||
/* Update the png info struct.*/
|
||||
png_read_update_info(png_ptr, info_ptr);
|
||||
|
||||
/* Rowsize in bytes. */
|
||||
rowbytes = png_get_rowbytes(png_ptr, info_ptr);
|
||||
|
||||
|
||||
/* Allocate the image_data buffer. */
|
||||
if ((image_data = (char *) malloc(rowbytes * height))==NULL) {
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
return 4;
|
||||
}
|
||||
|
||||
if ((row_pointers = (png_bytepp)malloc(height*sizeof(png_bytep))) == NULL) {
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
free(image_data);
|
||||
image_data = NULL;
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
/* set the individual row_pointers to point at the correct offsets */
|
||||
|
||||
for (i = 0; i < height; ++i)
|
||||
row_pointers[i] = (png_byte*)(image_data + i*rowbytes);
|
||||
|
||||
|
||||
/* now we can go ahead and just read the whole image */
|
||||
png_read_image(png_ptr, row_pointers);
|
||||
|
||||
/* and we're done! (png_read_end() can be omitted if no processing of
|
||||
* post-IDAT text/time/etc. is desired) */
|
||||
|
||||
/* Clean up. */
|
||||
free(row_pointers);
|
||||
|
||||
/* Clean up. */
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
fclose(infile);
|
||||
|
||||
GLuint Texture = 0;
|
||||
glGenTextures(1, &Texture);
|
||||
|
||||
/* create a new texture object
|
||||
* and bind it to texname (unsigned integer > 0)
|
||||
*/
|
||||
glBindTexture(GL_TEXTURE_2D, Texture);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, image_data);
|
||||
WARN_LOG(COMMON, "Errors below if any");
|
||||
OpenGL_ReportGLError();
|
||||
|
||||
return Texture;
|
||||
}
|
21
Source/Core/DolphinWX/Src/Android/TextureLoader.h
Normal file
21
Source/Core/DolphinWX/Src/Android/TextureLoader.h
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright (C) 2003 Dolphin Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#include "GLInterface.h"
|
||||
|
||||
GLuint LoadPNG(const char *filename);
|
||||
|
@ -33,19 +33,17 @@
|
||||
#include "ConfigManager.h"
|
||||
#include "LogManager.h"
|
||||
#include "BootManager.h"
|
||||
#include "OnScreenDisplay.h"
|
||||
|
||||
#include "Android/ButtonManager.h"
|
||||
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
#include <android/native_window_jni.h>
|
||||
JNIEnv *g_env = NULL;
|
||||
ANativeWindow* surf;
|
||||
int g_width, g_height;
|
||||
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "Dolphinemu", __VA_ARGS__))
|
||||
|
||||
bool rendererHasFocus = true;
|
||||
bool running = true;
|
||||
bool KeyStates[15];
|
||||
|
||||
void Host_NotifyMapLoaded() {}
|
||||
void Host_RefreshDSPDebuggerWindow() {}
|
||||
|
||||
@ -77,7 +75,7 @@ void Host_UpdateBreakPointView(){}
|
||||
|
||||
bool Host_GetKeyState(int keycode)
|
||||
{
|
||||
return KeyStates[keycode];
|
||||
return ButtonManager::GetButtonPressed((ButtonManager::ButtonType)keycode);
|
||||
}
|
||||
|
||||
void Host_GetRenderWindowSize(int& x, int& y, int& width, int& height)
|
||||
@ -123,26 +121,29 @@ void Host_SysMessage(const char *fmt, ...)
|
||||
|
||||
void Host_SetWiiMoteConnectionState(int _State) {}
|
||||
|
||||
extern void DrawButton(int tex, int ID);
|
||||
extern void SetButtonCoords(float *Coords);
|
||||
void OSDCallbacks(u32 UserData)
|
||||
{
|
||||
switch(UserData)
|
||||
{
|
||||
case 0: // Init
|
||||
ButtonManager::Init();
|
||||
break;
|
||||
case 1: // Draw
|
||||
ButtonManager::DrawButtons();
|
||||
break;
|
||||
case 2: // Shutdown
|
||||
ButtonManager::Shutdown();
|
||||
break;
|
||||
default:
|
||||
WARN_LOG(COMMON, "Error, wrong OSD type");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeRenderer_SetButtonCoords(JNIEnv *env, jobject obj, jfloatArray Coords)
|
||||
{
|
||||
jfloat* flt1 = env->GetFloatArrayElements(Coords, 0);
|
||||
SetButtonCoords((float*)flt1);
|
||||
env->ReleaseFloatArrayElements(Coords, flt1, 0);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeRenderer_DrawButton(JNIEnv *env, jobject obj,
|
||||
jint GLTex, jint ID
|
||||
)
|
||||
{
|
||||
DrawButton((int)GLTex, (int)ID);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeGLSurfaceView_UnPauseEmulation(JNIEnv *env, jobject obj)
|
||||
{
|
||||
PowerPC::Start();
|
||||
@ -156,10 +157,9 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeGLSurfaceView_StopEm
|
||||
{
|
||||
PowerPC::Stop();
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_DolphinEmulator_SetKey(JNIEnv *env, jobject obj, jint Value, jint Key)
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_DolphinEmulator_onTouchEvent(JNIEnv *env, jobject obj, jint Action, jfloat X, jfloat Y)
|
||||
{
|
||||
WARN_LOG(COMMON, "Key %d with action %d\n", (int)Key, (int)Value);
|
||||
KeyStates[(int)Key] = (int)Value == 0 ? true : false;
|
||||
ButtonManager::TouchEvent(Action, X, Y);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeGLSurfaceView_main(JNIEnv *env, jobject obj, jstring jFile, jobject _surf, jint _width, jint _height)
|
||||
@ -167,16 +167,19 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeGLSurfaceView_main(J
|
||||
surf = ANativeWindow_fromSurface(env, _surf);
|
||||
g_width = (int)_width;
|
||||
g_height = (int)_height;
|
||||
g_env = env;
|
||||
|
||||
|
||||
// Install our callbacks
|
||||
OSD::AddCallback(OSD::OSD_INIT, OSDCallbacks, 0);
|
||||
OSD::AddCallback(OSD::OSD_ONFRAME, OSDCallbacks, 1);
|
||||
OSD::AddCallback(OSD::OSD_SHUTDOWN, OSDCallbacks, 2);
|
||||
|
||||
LogManager::Init();
|
||||
SConfig::Init();
|
||||
VideoBackend::PopulateList();
|
||||
VideoBackend::ActivateBackend(SConfig::GetInstance().
|
||||
m_LocalCoreStartupParameter.m_strVideoBackend);
|
||||
VideoBackend::ActivateBackend(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend);
|
||||
WiimoteReal::LoadSettings();
|
||||
|
||||
const char *File = env->GetStringUTFChars(jFile, NULL);
|
||||
const char *File = env->GetStringUTFChars(jFile, NULL);
|
||||
// No use running the loop when booting fails
|
||||
if ( BootManager::BootCore( File ) )
|
||||
while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN)
|
||||
|
Reference in New Issue
Block a user