Skip to content

Commit

Permalink
Merge pull request #67 from DaedalusX64/Fixes_LINUX_WINDOWS_UI
Browse files Browse the repository at this point in the history
UI and control fixes
  • Loading branch information
wally4000 authored Jun 29, 2024
2 parents 7b343c0 + 4455472 commit 187d8c2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 145 deletions.
2 changes: 1 addition & 1 deletion Source/SysGL/Graphics/DrawTextSDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ u32 CDrawText::Render(EFont font_type, s32 x, s32 y, float scale, const char *p_
{
SDL_Color c {colour.GetR(), colour.GetG(), colour.GetB()};
SDL_Color dc {drop_colour.GetR(), drop_colour.GetG(), drop_colour.GetB()};
SDL_Surface *surface = TTF_RenderUTF8_Shaded(font, p_str, c, dc);
SDL_Surface *surface = TTF_RenderUTF8_Blended(font, p_str, c);
SDL_Texture* Message = SDL_CreateTextureFromSurface(gSdlRenderer, surface);

SDL_Rect Message_rect; //create a rect
Expand Down
25 changes: 7 additions & 18 deletions Source/SysGL/Graphics/GraphicsContextGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,32 +85,20 @@ bool GraphicsContextGL::Initialise()
return false;
}

// Decide GL+GLSL versions
#if defined(IMGUI_IMPL_OPENGL_ES2)
// GL ES 2.0 + GLSL 100
const char* glsl_version = "#version 100";
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
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);
#elif defined(__APPLE__)
#if defined(__APPLE__)
// GL 3.2 Core + GLSL 150
const char* glsl_version = "#version 150";
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); // Always required on Mac
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
#else
// GL 3.0 + GLSL 130
const char* glsl_version = "#version 130";
// Simplified context creation
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
#endif
// SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 3 );
// SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 3 );
// SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

Expand Down Expand Up @@ -225,10 +213,11 @@ void GraphicsContextGL::UpdateFrame( bool wait_for_vbl )
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);


if (gSdlRenderer == nullptr) {
SDL_GL_SwapWindow(gWindow);
}

// if( gCleanSceneEnabled ) //TODO: This should be optional
// {
// ClearColBuffer( c32(0xff000000) ); // ToDo : Use gFillColor instead?
Expand Down
133 changes: 7 additions & 126 deletions Source/SysGL/Input/InputManagerGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,78 +32,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <iostream>
SDL_GameController *controller;

//Windows Xinput support
#ifdef DAEDALUS_W32

#include <Windows.h>
#include <Xinput.h>

class CXBOXController
{
private:
XINPUT_STATE _controllerState;
int _controllerNum;
public:
CXBOXController(int playerNumber);
XINPUT_STATE GetState();
bool IsConnected();
void Vibrate(int leftVal = 0, int rightVal = 0);
};

CXBOXController::CXBOXController(int playerNumber)
{
// Set the Controller Number
_controllerNum = playerNumber - 1;
}

XINPUT_STATE CXBOXController::GetState()
{
// Zeroise the state
ZeroMemory(&_controllerState, sizeof(XINPUT_STATE));

// Get the state
XInputGetState(_controllerNum, &_controllerState);

return _controllerState;
}

bool CXBOXController::IsConnected()
{
// Zeroise the state
ZeroMemory(&_controllerState, sizeof(XINPUT_STATE));

// Get the state
DWORD Result = XInputGetState(_controllerNum, &_controllerState);

if (Result == ERROR_SUCCESS)
{
return true;
}
else
{
return false;
}
}

void CXBOXController::Vibrate(int leftVal, int rightVal)
{
// Create a Vibraton State
XINPUT_VIBRATION Vibration;

// Zeroise the Vibration
ZeroMemory(&Vibration, sizeof(XINPUT_VIBRATION));

// Set the Vibration Values
Vibration.wLeftMotorSpeed = leftVal;
Vibration.wRightMotorSpeed = rightVal;

// Vibrate the controller
XInputSetState(_controllerNum, &Vibration);
}

#endif


class IInputManager : public CInputManager
{
public:
Expand All @@ -128,15 +56,6 @@ class IInputManager : public CInputManager
bool mGamePadAvailable;
//SDL_GameController *controller;

#ifdef DAEDALUS_W32

CXBOXController* Player1;
CXBOXController* Player2;
CXBOXController* Player3;
CXBOXController* Player4;

#endif

};

IInputManager::~IInputManager()
Expand Down Expand Up @@ -168,16 +87,6 @@ static void CheckPadStatusVblHandler( void * arg )
bool IInputManager::Initialise()
{

#ifdef DAEDALUS_W32
Player1 = new CXBOXController(1);
if (Player1->IsConnected()){
std::cout << "Xinput device detected! ";
}
else{
std::cout << "Xinput device not detected!";
}
#endif


//Init Joystick / Gamepad
CPU_RegisterVblCallback( &CheckPadStatusVblHandler, this );
Expand Down Expand Up @@ -288,6 +197,13 @@ void IInputManager::GetState( OSContPad pPad[4] )
{
const u8* keys = SDL_GetKeyboardState( NULL );

// Override the keyboard with the gamepad if it's available.
//if(mGamePadAvailable)
//{
GetJoyPad(&pPad[0]);
//}


if (keys [ SDL_SCANCODE_UP ] ) {pPad[0].stick_y = +80;}
if (keys [ SDL_SCANCODE_DOWN ] ) {pPad[0].stick_y = -80;}
if (keys [ SDL_SCANCODE_LEFT ] ) {pPad[0].stick_x = -80;}
Expand All @@ -313,42 +229,7 @@ void IInputManager::GetState( OSContPad pPad[4] )
if (keys [ SDL_SCANCODE_PAGEDOWN ] ){ pPad[0].button |= R_CBUTTONS;}
}

#ifdef DAEDALUS_W32
if (Player1->IsConnected())
{
#define XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE 7849
#define XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE 8689
if (Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_A){ pPad[0].button |= A_BUTTON;}
if (Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B){ pPad[0].button |= B_BUTTON;}
if (Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_START) { pPad[0].button |= START_BUTTON; }
if (Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) { pPad[0].button |= L_TRIG; }
if (Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) { pPad[0].button |= R_TRIG; }
if (Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) { pPad[0].button |= L_JPAD; }
if (Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) { pPad[0].button |= R_JPAD; }
if (Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) { pPad[0].button |= U_JPAD; }
if (Player1->GetState().Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN) { pPad[0].button |= D_JPAD; }

if (Player1->GetState().Gamepad.bLeftTrigger > 30) { pPad[0].button |= Z_TRIG; }
if (Player1->GetState().Gamepad.bRightTrigger > 30 ) { pPad[0].button |= Z_TRIG; }

pPad[0].stick_x = s8(Player1->GetState().Gamepad.sThumbLX / 500);
pPad[0].stick_y = s8(Player1->GetState().Gamepad.sThumbLY / 500);

//Xinput Righstick to C buttons
if (s8(Player1->GetState().Gamepad.sThumbRX / 500 ) < -40) pPad[0].button |= L_CBUTTONS;
if (s8(Player1->GetState().Gamepad.sThumbRX / 500 ) > 40) pPad[0].button |= R_CBUTTONS;
if (s8(Player1->GetState().Gamepad.sThumbRY / 500 ) < -40) pPad[0].button |= D_CBUTTONS;
if (s8(Player1->GetState().Gamepad.sThumbRY / 500 ) > 40) pPad[0].button |= U_CBUTTONS;

}
#endif


// Override the keyboard with the gamepad if it's available.
//if(mGamePadAvailable)
//{
GetJoyPad(&pPad[0]);
//}

}

Expand Down

0 comments on commit 187d8c2

Please sign in to comment.