You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
867 lines
30 KiB
867 lines
30 KiB
#include "gui_sdl.h"
|
|
#include "core/coreWidget.h"
|
|
#include "../alg/generic/md5.h"
|
|
#include "joystickWrapper.h"
|
|
|
|
#define LOG( X ) m_pLog->Log( "SDL_GUI", this, X )
|
|
#define LOG_ERROR( X ) m_pLog->Log( "SDL_GUI", this, _LOG_ERROR, X )
|
|
//Thread Logging
|
|
#define SLOG( X ) mThis->m_pLog->Log( "SDL_GUI_S", mThis, X )
|
|
#define SLOG_ERROR( X ) mThis->m_pLog->Log( "SDL_GUI_S", mThis, _LOG_ERROR, X )
|
|
|
|
//https://www.parallelrealities.co.uk/tutorials/
|
|
|
|
extern "C" {
|
|
|
|
FILE* __cdecl __iob_func(void) {
|
|
FILE _iob[] = { *stdin, *stdout, *stderr };
|
|
return _iob;
|
|
}
|
|
|
|
}
|
|
|
|
static void SDL_LoadWindowIcon(SDL_Window* window){
|
|
//https://gist.github.com/noct/9884320
|
|
|
|
#if defined(_WIN32)
|
|
const unsigned int mask_r = 0x00ff0000;
|
|
const unsigned int mask_g = 0x0000ff00;
|
|
const unsigned int mask_b = 0x000000ff;
|
|
const unsigned int mask_a = 0xff000000;
|
|
const int res_id = 107;
|
|
const int size = 32;
|
|
const int bpp = 32;
|
|
|
|
HICON icon = (HICON)LoadImage(
|
|
GetModuleHandle(NULL),
|
|
MAKEINTRESOURCE(res_id),
|
|
IMAGE_ICON,
|
|
size, size,
|
|
LR_SHARED
|
|
);
|
|
|
|
if (icon) {
|
|
ICONINFO ici;
|
|
|
|
if (GetIconInfo(icon, &ici)) {
|
|
HDC dc = CreateCompatibleDC(NULL);
|
|
|
|
if (dc) {
|
|
SDL_Surface* surface = SDL_CreateRGBSurface(0, size, size, bpp, mask_r, mask_g, mask_b, mask_a);
|
|
|
|
if (surface) {
|
|
BITMAPINFO bmi;
|
|
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
bmi.bmiHeader.biWidth = size;
|
|
bmi.bmiHeader.biHeight = -size;
|
|
bmi.bmiHeader.biPlanes = 1;
|
|
bmi.bmiHeader.biBitCount = bpp;
|
|
bmi.bmiHeader.biCompression = BI_RGB;
|
|
bmi.bmiHeader.biSizeImage = 0;
|
|
|
|
SelectObject(dc, ici.hbmColor);
|
|
GetDIBits(dc, ici.hbmColor, 0, size, surface->pixels, &bmi, DIB_RGB_COLORS);
|
|
SDL_SetWindowIcon(window, surface);
|
|
SDL_FreeSurface(surface);
|
|
}
|
|
DeleteDC(dc);
|
|
}
|
|
DeleteObject(ici.hbmColor);
|
|
DeleteObject(ici.hbmMask);
|
|
}
|
|
DestroyIcon(icon);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
classGUI_SDL * classGUI_SDL::m_pInstance = NULL;
|
|
classGUI_SDL * classGUI_SDL::getInstance(void){
|
|
if (m_pInstance == NULL){
|
|
m_pInstance = new classGUI_SDL();
|
|
};
|
|
return m_pInstance;
|
|
};
|
|
|
|
classGUI_SDL::classGUI_SDL(): basicThread(){
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_pWindow = NULL;
|
|
|
|
m_pJoystickWraper = NULL;
|
|
m_pRenderer = NULL;
|
|
m_iCursorPosX = 100;
|
|
m_iCursorPosY = 100;
|
|
m_nWidth = SCREEN_WIDTH;
|
|
m_nHeight = SCREEN_HEIGHT;
|
|
m_nBackgroundMode = 1;
|
|
m_bWindowSystemOk = false;
|
|
m_bInitOk = false;
|
|
m_bUseAltBackground = false;
|
|
m_pMainLayout = NULL;
|
|
m_pProtector = NULL;
|
|
m_pSettings = basicSettingsProvider::getInstance()->getSubNode(NULL, (CSTR)"GUI");
|
|
m_pBackgroundTexture = NULL;
|
|
m_nBackgroundTextureWidth = 0;
|
|
m_nBackgroundTextureHeight = 0;
|
|
memset(&m_sBackgroundSolidColor, 0, sizeof(SDL_Color));
|
|
memset(m_aBackgroundGradientColor, 0, sizeof(uint32_t) * 4);
|
|
m_pAltBackgroundTexture = NULL;
|
|
m_nAltBackgroundTextureWidth = 0;
|
|
m_nAltBackgroundTextureHeight = 0;
|
|
memset(&m_sAltBackgroundSolidColor, 0, sizeof(SDL_Color));
|
|
memset(m_aAltBackgroundGradientColor, 0, sizeof(uint32_t) * 4);
|
|
if (m_pSettings != NULL) {
|
|
config_setting_t * pSetting;
|
|
pSetting = config_setting_get_member(m_pSettings, "FULL_SCREEN_MODE");
|
|
if (pSetting == NULL) {
|
|
pSetting = config_setting_add(m_pSettings, "FULL_SCREEN_MODE", CONFIG_TYPE_INT);
|
|
m_nWindowMode = 0;
|
|
if (pSetting != NULL) {
|
|
config_setting_set_int(pSetting, m_nWindowMode);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
} else {
|
|
m_nWindowMode = config_setting_get_int(pSetting);
|
|
};
|
|
if (m_nWindowMode < 2) { // 0 - Windowed, 1 - custom sized FS 2 - FS with desktop size
|
|
pSetting = config_setting_get_member(m_pSettings, "WIDTH");
|
|
if (pSetting == NULL) {
|
|
pSetting = config_setting_add(m_pSettings, "WIDTH", CONFIG_TYPE_INT);
|
|
if (pSetting != NULL) {
|
|
config_setting_set_int(pSetting, m_nWidth);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
} else {
|
|
m_nWidth = config_setting_get_int(pSetting);
|
|
};
|
|
pSetting = config_setting_get_member(m_pSettings, "HEIGHT");
|
|
if (pSetting == NULL) {
|
|
pSetting = config_setting_add(m_pSettings, "HEIGHT", CONFIG_TYPE_INT);
|
|
if (pSetting != NULL) {
|
|
config_setting_set_int(pSetting, m_nHeight);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
} else {
|
|
m_nHeight = config_setting_get_int(pSetting);
|
|
};
|
|
};
|
|
pSetting = config_setting_get_member(m_pSettings, "BACKGROUND_MODE");
|
|
if (pSetting == NULL) {
|
|
pSetting = config_setting_add(m_pSettings, "BACKGROUND_MODE", CONFIG_TYPE_INT);
|
|
m_nBackgroundMode = 0;
|
|
if (pSetting != NULL) {
|
|
config_setting_set_int(pSetting, m_nBackgroundMode);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
} else {
|
|
m_nBackgroundMode = config_setting_get_int(pSetting);
|
|
};
|
|
switch (m_nBackgroundMode) {
|
|
case 0: {
|
|
uint32_t tVal;
|
|
pSetting = config_setting_get_member(m_pSettings, "BACKGROUND_SOLID_COLOR");
|
|
if (pSetting == NULL) {
|
|
pSetting = config_setting_add(m_pSettings, "BACKGROUND_SOLID_COLOR", CONFIG_TYPE_INT);
|
|
tVal = 0x3483ae; // Not set Alpha channel!!
|
|
if (pSetting != NULL) {
|
|
config_setting_set_int(pSetting, tVal);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
} else {
|
|
tVal = config_setting_get_int(pSetting);
|
|
};
|
|
m_sBackgroundSolidColor.r = (tVal >> 16 ) & 0xFF;
|
|
m_sBackgroundSolidColor.g = (tVal >> 8) & 0xFF;
|
|
m_sBackgroundSolidColor.b = (tVal >> 0) & 0xFF;
|
|
m_sBackgroundSolidColor.a = 0xFF;
|
|
pSetting = config_setting_get_member(m_pSettings, "BACKGROUND_ALT_SOLID_COLOR");
|
|
if (pSetting == NULL) {
|
|
pSetting = config_setting_add(m_pSettings, "BACKGROUND_ALT_SOLID_COLOR", CONFIG_TYPE_INT);
|
|
tVal = 0x3483ae; // Not set Alpha channel!!
|
|
if (pSetting != NULL) {
|
|
config_setting_set_int(pSetting, tVal);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
} else {
|
|
tVal = config_setting_get_int(pSetting);
|
|
};
|
|
m_sAltBackgroundSolidColor.r = (tVal >> 16) & 0xFF;
|
|
m_sAltBackgroundSolidColor.g = (tVal >> 8) & 0xFF;
|
|
m_sAltBackgroundSolidColor.b = (tVal >> 0) & 0xFF;
|
|
m_sAltBackgroundSolidColor.a = 0xFF;
|
|
break;
|
|
};
|
|
case 1: {
|
|
uint32_t tVal;
|
|
pSetting = config_setting_get_member(m_pSettings, "BACKGROUND_GRADIENT_LT_COLOR");
|
|
if (pSetting == NULL) {
|
|
pSetting = config_setting_add(m_pSettings, "BACKGROUND_GRADIENT_LT_COLOR", CONFIG_TYPE_INT);
|
|
tVal = 0x3483ae; // Not set Alpha channel!!
|
|
if (pSetting != NULL) {
|
|
config_setting_set_int(pSetting, tVal);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
} else {
|
|
tVal = config_setting_get_int(pSetting);
|
|
};
|
|
m_aBackgroundGradientColor[0] = tVal << 8 | 0xFF;
|
|
pSetting = config_setting_get_member(m_pSettings, "BACKGROUND_GRADIENT_RT_COLOR");
|
|
if (pSetting == NULL) {
|
|
pSetting = config_setting_add(m_pSettings, "BACKGROUND_GRADIENT_RT_COLOR", CONFIG_TYPE_INT);
|
|
tVal = 0x3483ae; // Not set Alpha channel!!
|
|
if (pSetting != NULL) {
|
|
config_setting_set_int(pSetting, tVal);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
} else {
|
|
tVal = config_setting_get_int(pSetting);
|
|
};
|
|
m_aBackgroundGradientColor[1] = tVal << 8 | 0xFF;
|
|
pSetting = config_setting_get_member(m_pSettings, "BACKGROUND_GRADIENT_LB_COLOR");
|
|
if (pSetting == NULL) {
|
|
pSetting = config_setting_add(m_pSettings, "BACKGROUND_GRADIENT_LB_COLOR", CONFIG_TYPE_INT);
|
|
tVal = 0x0; // Not set Alpha channel!!
|
|
if (pSetting != NULL) {
|
|
config_setting_set_int(pSetting, tVal);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
} else {
|
|
tVal = config_setting_get_int(pSetting);
|
|
};
|
|
m_aBackgroundGradientColor[2] = tVal << 8 | 0xFF;
|
|
pSetting = config_setting_get_member(m_pSettings, "BACKGROUND_GRADIENT_RB_COLOR");
|
|
if (pSetting == NULL) {
|
|
pSetting = config_setting_add(m_pSettings, "BACKGROUND_GRADIENT_RB_COLOR", CONFIG_TYPE_INT);
|
|
tVal = 0x0; // Not set Alpha channel!!
|
|
if (pSetting != NULL) {
|
|
config_setting_set_int(pSetting, tVal);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
} else {
|
|
tVal = config_setting_get_int(pSetting);
|
|
};
|
|
m_aBackgroundGradientColor[3] = tVal << 8 | 0xFF;
|
|
|
|
pSetting = config_setting_get_member(m_pSettings, "BACKGROUND_ALT_GRADIENT_LT_COLOR");
|
|
if (pSetting == NULL) {
|
|
pSetting = config_setting_add(m_pSettings, "BACKGROUND_ALT_GRADIENT_LT_COLOR", CONFIG_TYPE_INT);
|
|
tVal = 0x3483ae; // Not set Alpha channel!!
|
|
if (pSetting != NULL) {
|
|
config_setting_set_int(pSetting, tVal);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
} else {
|
|
tVal = config_setting_get_int(pSetting);
|
|
};
|
|
m_aAltBackgroundGradientColor[0] = tVal << 8 | 0xFF;
|
|
pSetting = config_setting_get_member(m_pSettings, "BACKGROUND_ALT_GRADIENT_RT_COLOR");
|
|
if (pSetting == NULL) {
|
|
pSetting = config_setting_add(m_pSettings, "BACKGROUND_ALT_GRADIENT_RT_COLOR", CONFIG_TYPE_INT);
|
|
tVal = 0x3483ae; // Not set Alpha channel!!
|
|
if (pSetting != NULL) {
|
|
config_setting_set_int(pSetting, tVal);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
} else {
|
|
tVal = config_setting_get_int(pSetting);
|
|
};
|
|
m_aAltBackgroundGradientColor[1] = tVal << 8 | 0xFF;
|
|
pSetting = config_setting_get_member(m_pSettings, "BACKGROUND_ALT_GRADIENT_LB_COLOR");
|
|
if (pSetting == NULL) {
|
|
pSetting = config_setting_add(m_pSettings, "BACKGROUND_ALT_GRADIENT_LB_COLOR", CONFIG_TYPE_INT);
|
|
tVal = 0x0; // Not set Alpha channel!!
|
|
if (pSetting != NULL) {
|
|
config_setting_set_int(pSetting, tVal);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
} else {
|
|
tVal = config_setting_get_int(pSetting);
|
|
};
|
|
m_aAltBackgroundGradientColor[2] = tVal << 8 | 0xFF;
|
|
pSetting = config_setting_get_member(m_pSettings, "BACKGROUND_ALT_GRADIENT_RB_COLOR");
|
|
if (pSetting == NULL) {
|
|
pSetting = config_setting_add(m_pSettings, "BACKGROUND_ALT_GRADIENT_RB_COLOR", CONFIG_TYPE_INT);
|
|
tVal = 0x0; // Not set Alpha channel!!
|
|
if (pSetting != NULL) {
|
|
config_setting_set_int(pSetting, tVal);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
} else {
|
|
tVal = config_setting_get_int(pSetting);
|
|
};
|
|
m_aAltBackgroundGradientColor[3] = tVal << 8 | 0xFF;
|
|
break;
|
|
};
|
|
default: {
|
|
pSetting = config_setting_get_member(m_pSettings, "BACKGROUND_PICTURE");
|
|
if (pSetting == NULL) {
|
|
sprintf(m_pBackgroundFileName, "335566.jpg");
|
|
pSetting = config_setting_add(m_pSettings, "BACKGROUND_PICTURE", CONFIG_TYPE_STRING);
|
|
if (pSetting != NULL) {
|
|
config_setting_set_string(pSetting, m_pBackgroundFileName);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
} else {
|
|
sprintf(m_pBackgroundFileName,"%s",config_setting_get_string(pSetting));
|
|
};
|
|
pSetting = config_setting_get_member(m_pSettings, "BACKGROUND_ALT_PICTURE");
|
|
if (pSetting == NULL) {
|
|
sprintf(m_pAltBackgroundFileName, "335566.jpg");
|
|
pSetting = config_setting_add(m_pSettings, "BACKGROUND_ALT_PICTURE", CONFIG_TYPE_STRING);
|
|
if (pSetting != NULL) {
|
|
config_setting_set_string(pSetting, m_pAltBackgroundFileName);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
} else {
|
|
sprintf(m_pAltBackgroundFileName, "%s", config_setting_get_string(pSetting));
|
|
};
|
|
break;
|
|
};
|
|
};
|
|
basicSettingsProvider::getInstance()->validate();
|
|
};
|
|
m_bInitOk = basicThread::init();
|
|
while ( ( m_bWindowSystemOk == false ) && ( m_bThreadStatus < TH_ENDED ) ) SLEEP(1);
|
|
};
|
|
|
|
classGUI_SDL::~classGUI_SDL(){
|
|
m_bWindowSystemOk = false;
|
|
m_bInitOk = false;
|
|
if( m_pJoystickWraper != NULL)delete(m_pJoystickWraper);
|
|
if( m_pProtector != NULL)delete(m_pProtector);
|
|
if( m_pRenderer!=NULL){
|
|
SDL_DestroyRenderer(m_pRenderer);
|
|
};
|
|
//if (m_pScreenSurface != NULL){
|
|
// //Deallocate surface
|
|
// SDL_FreeSurface(m_pScreenSurface);
|
|
// m_pScreenSurface = NULL;
|
|
//};
|
|
if ( m_pWindow!= NULL ){
|
|
//Destroy window
|
|
SDL_DestroyWindow(m_pWindow);
|
|
m_pWindow = NULL;
|
|
};
|
|
//Quit SDL subsystems
|
|
SDL_Quit();
|
|
};
|
|
|
|
|
|
|
|
//https://www.facebook.com/missing.person.3158
|
|
//https://www.facebook.com/guga.wereteli.90
|
|
//https://www.facebook.com/mentul.ohmentul
|
|
//https://www.facebook.com/profile.php?id=100001772172980
|
|
//https://www.facebook.com/egagua
|
|
/* Collect Confirmation Codes
|
|
Contact your friends and ask them for their help.
|
|
1. Call three of these friends or talk to them in person.
|
|
Raphael LlamadoChantebis SamkaroMentul OhmentulEstrada Irish PotchEvgeny Gagua
|
|
2. Ask them to visit :
|
|
https ://www.facebook.com/recover
|
|
3. Each friend will give you a code.Enter them below :
|
|
*/
|
|
void classGUI_SDL::m_fThreadProc(void){
|
|
if (m_pProtector == NULL) m_pProtector = new basicMutex();
|
|
if (m_pProtector == NULL) {
|
|
SDL_Log("No Mutex Created! SDL Error: %s", SDL_GetError());
|
|
m_bInitOk = false;
|
|
m_bThreadStatus = TH_ENDED;
|
|
return;
|
|
};
|
|
if (SDL_Init(SDL_INIT_VIDEO| SDL_INIT_AUDIO| SDL_INIT_JOYSTICK| SDL_INIT_HAPTIC| SDL_INIT_GAMECONTROLLER| SDL_INIT_EVENTS) != 0) {
|
|
SDL_Log("SDL_Init Error: %s", SDL_GetError());
|
|
m_bInitOk = false;
|
|
m_bThreadStatus = TH_ENDED;
|
|
return;
|
|
};
|
|
int display_count = 0, display_index = 0, mode_index = 0;
|
|
SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };
|
|
if ((display_count = SDL_GetNumVideoDisplays()) < 1) {
|
|
SDL_Log("SDL_GetNumVideoDisplays returned: %i, %s", display_count, SDL_GetError());
|
|
};
|
|
SDL_Log("SDL_GetNumVideoDisplays returned: %i", display_count);
|
|
//if (SDL_GetDisplayMode(display_index, mode_index, &mode) != 0) {
|
|
// SDL_Log("SDL_GetDisplayMode failed: %s", SDL_GetError());
|
|
// m_bInitOk = false;
|
|
// m_bThreadStatus = TH_ENDED;
|
|
// return;
|
|
//};
|
|
//SDL_Log("SDL_GetDisplayMode(0, 0, &mode):\t\t%i bpp\t%i x %i", SDL_BITSPERPIXEL(mode.format), mode.w, mode.h);
|
|
|
|
if ((IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG | IMG_INIT_TIF) & (IMG_INIT_PNG | IMG_INIT_JPG | IMG_INIT_TIF))!= (IMG_INIT_PNG | IMG_INIT_JPG | IMG_INIT_TIF)){
|
|
SDL_Log("SDL_image could not initialize! SDL_image Error: %s", IMG_GetError());
|
|
m_bInitOk = false;
|
|
m_bThreadStatus = TH_ENDED;
|
|
return;
|
|
};
|
|
|
|
//Initialize SDL_ttf
|
|
if( TTF_Init() == -1 ){
|
|
SDL_Log("SDL_ttf could not initialize! SDL_ttf Error: %s", TTF_GetError());
|
|
m_bInitOk = false;
|
|
m_bThreadStatus = TH_ENDED;
|
|
return;
|
|
} else {
|
|
|
|
};
|
|
m_bInitOk = true;
|
|
// Set linear blending (haven't tried this with bilinear...)
|
|
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1");//2?
|
|
switch (m_nWindowMode) {
|
|
case 0: {
|
|
if (SDL_CreateWindowAndRenderer(m_nWidth, m_nHeight, SDL_WINDOW_RESIZABLE, &m_pWindow, &m_pRenderer)) {
|
|
SDL_Log("Window could not be created! SDL_Error: %s", SDL_GetError());
|
|
m_bThreadStatus = TH_ENDED;
|
|
m_bWindowSystemOk = false;
|
|
return;
|
|
} else {
|
|
SDL_LoadWindowIcon(m_pWindow);
|
|
SDL_GetRendererOutputSize(m_pRenderer, &m_nWidth, &m_nHeight);
|
|
m_bThreadStatus = TH_WORKING;
|
|
m_bWindowSystemOk = true;
|
|
};
|
|
break;
|
|
};
|
|
case 1: {
|
|
if (SDL_CreateWindowAndRenderer(m_nWidth, m_nHeight, SDL_WINDOW_FULLSCREEN, &m_pWindow, &m_pRenderer)) {
|
|
SDL_Log("Window could not be created! SDL_Error: %s", SDL_GetError());
|
|
m_bThreadStatus = TH_ENDED;
|
|
m_bWindowSystemOk = false;
|
|
return;
|
|
} else {
|
|
m_bThreadStatus = TH_WORKING;
|
|
m_bWindowSystemOk = true;
|
|
};
|
|
break;
|
|
};
|
|
default: {
|
|
m_nWidth = 0;
|
|
m_nHeight = 0;
|
|
if (SDL_CreateWindowAndRenderer(m_nWidth, m_nHeight, SDL_WINDOW_FULLSCREEN_DESKTOP, &m_pWindow, &m_pRenderer)) {
|
|
SDL_Log("Window could not be created! SDL_Error: %s", SDL_GetError());
|
|
m_bThreadStatus = TH_ENDED;
|
|
m_bWindowSystemOk = false;
|
|
return;
|
|
} else {
|
|
SDL_LoadWindowIcon(m_pWindow);
|
|
SDL_GetRendererOutputSize(m_pRenderer, &m_nWidth, &m_nHeight);
|
|
m_bThreadStatus = TH_WORKING;
|
|
m_bWindowSystemOk = true;
|
|
};
|
|
break;
|
|
};
|
|
};
|
|
// Set linear blending (haven't tried this with bilinear...)
|
|
//SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
|
|
|
|
// Create a 4x4 texture to serve as the source for our gradient.
|
|
uint32_t* bgpixels;
|
|
SDL_Texture* background = SDL_CreateTexture(m_pRenderer, SDL_PIXELFORMAT_RGBA8888,
|
|
SDL_TEXTUREACCESS_STREAMING, 4, 4);
|
|
|
|
uint32_t* altbgpixels;
|
|
SDL_Texture* altbackground = SDL_CreateTexture(m_pRenderer, SDL_PIXELFORMAT_RGBA8888,
|
|
SDL_TEXTUREACCESS_STREAMING, 4, 4);
|
|
// Set up the gradient colors.
|
|
// Each 2x2 quadrant of the texture has a separate color:
|
|
|
|
// AABB
|
|
// AABB
|
|
// CCDD
|
|
// CCDD
|
|
int i;
|
|
SDL_LockTexture(background, NULL, (void**)(&bgpixels), &i);
|
|
bgpixels[0] = m_aBackgroundGradientColor[0]; bgpixels[1] = m_aBackgroundGradientColor[0]; bgpixels[2] = m_aBackgroundGradientColor[1]; bgpixels[3] = m_aBackgroundGradientColor[1];
|
|
bgpixels[4] = m_aBackgroundGradientColor[0]; bgpixels[5] = m_aBackgroundGradientColor[0]; bgpixels[6] = m_aBackgroundGradientColor[1]; bgpixels[7] = m_aBackgroundGradientColor[1];
|
|
bgpixels[8] = m_aBackgroundGradientColor[2]; bgpixels[9] = m_aBackgroundGradientColor[2];bgpixels[10] = m_aBackgroundGradientColor[3];bgpixels[11] = m_aBackgroundGradientColor[3];
|
|
bgpixels[12] = m_aBackgroundGradientColor[2];bgpixels[13] = m_aBackgroundGradientColor[2];bgpixels[14] = m_aBackgroundGradientColor[3];bgpixels[15] = m_aBackgroundGradientColor[3];
|
|
SDL_UnlockTexture(background);
|
|
SDL_LockTexture(altbackground, NULL, (void**)(&altbgpixels), &i);
|
|
altbgpixels[0] = m_aAltBackgroundGradientColor[0]; altbgpixels[1] = m_aAltBackgroundGradientColor[0]; altbgpixels[2] = m_aAltBackgroundGradientColor[1]; altbgpixels[3] = m_aAltBackgroundGradientColor[1];
|
|
altbgpixels[4] = m_aAltBackgroundGradientColor[0]; altbgpixels[5] = m_aAltBackgroundGradientColor[0]; altbgpixels[6] = m_aAltBackgroundGradientColor[1]; altbgpixels[7] = m_aAltBackgroundGradientColor[1];
|
|
altbgpixels[8] = m_aAltBackgroundGradientColor[2]; altbgpixels[9] = m_aAltBackgroundGradientColor[2];altbgpixels[10] = m_aAltBackgroundGradientColor[3];altbgpixels[11] = m_aAltBackgroundGradientColor[3];
|
|
altbgpixels[12] = m_aAltBackgroundGradientColor[2];altbgpixels[13] = m_aAltBackgroundGradientColor[2];altbgpixels[14] = m_aAltBackgroundGradientColor[3];altbgpixels[15] = m_aAltBackgroundGradientColor[3];
|
|
SDL_UnlockTexture(altbackground);
|
|
|
|
if (m_nBackgroundMode > 1) {
|
|
SDL_Surface* tSurface;
|
|
tSurface = IMG_Load((CSTR)m_pBackgroundFileName);
|
|
if (tSurface != NULL) {
|
|
m_pBackgroundTexture = SDL_CreateTextureFromSurface(m_pRenderer, tSurface);
|
|
if (m_pBackgroundTexture != NULL) {
|
|
m_nBackgroundTextureWidth = tSurface->w;
|
|
m_nBackgroundTextureHeight = tSurface->h;
|
|
};
|
|
SDL_FreeSurface(tSurface);
|
|
};
|
|
tSurface = IMG_Load((CSTR)m_pAltBackgroundFileName);
|
|
if (tSurface != NULL) {
|
|
m_pAltBackgroundTexture = SDL_CreateTextureFromSurface(m_pRenderer, tSurface);
|
|
if (m_pAltBackgroundTexture != NULL) {
|
|
m_nAltBackgroundTextureWidth = tSurface->w;
|
|
m_nAltBackgroundTextureHeight = tSurface->h;
|
|
};
|
|
SDL_FreeSurface(tSurface);
|
|
};
|
|
};
|
|
while( m_bThreadStatus < TH_ENDED ){
|
|
//Event handler
|
|
SDL_Event mEvent;
|
|
//Handle events on queue
|
|
if( SDL_PollEvent(&mEvent) != 0 ){
|
|
m_pProtector->lock();
|
|
if (m_vGraphicElements.size()){
|
|
for (vectorGEL::iterator index = m_vGraphicElements.begin(); index < m_vGraphicElements.end(); index++) (*index)->dispatch(&mEvent);
|
|
};
|
|
m_pProtector->unlock();
|
|
// Global Window Event handler
|
|
switch (mEvent.type) {
|
|
case SDL_QUIT:
|
|
m_bThreadStatus = TH_ENDED;
|
|
break;
|
|
case SDL_KEYDOWN:
|
|
doKeyDown(&mEvent.key);
|
|
break;
|
|
case SDL_KEYUP:
|
|
doKeyUp(&mEvent.key);
|
|
break;
|
|
case SDL_JOYDEVICEADDED:
|
|
if (m_pJoystickWraper != NULL ) {
|
|
m_pJoystickWraper->setController(SDL_JoystickOpen(0));
|
|
};
|
|
break;
|
|
case SDL_JOYDEVICEREMOVED:
|
|
if (m_pJoystickWraper != NULL) {
|
|
m_pJoystickWraper->setController(NULL);
|
|
};
|
|
break;
|
|
default:
|
|
break;
|
|
};
|
|
};
|
|
//if (SDL_LockMutex(m_pProtector) == 0)
|
|
{
|
|
m_pProtector->lock();
|
|
switch (m_nBackgroundMode) {
|
|
case 0: { // Solid Color
|
|
if (m_bUseAltBackground) {
|
|
SDL_SetRenderDrawColor(m_pRenderer, m_sAltBackgroundSolidColor.r, m_sAltBackgroundSolidColor.g, m_sAltBackgroundSolidColor.b, m_sAltBackgroundSolidColor.a);
|
|
} else {
|
|
SDL_SetRenderDrawColor(m_pRenderer, m_sBackgroundSolidColor.r, m_sBackgroundSolidColor.g, m_sBackgroundSolidColor.b, m_sBackgroundSolidColor.a);
|
|
};
|
|
SDL_RenderClear(m_pRenderer);
|
|
break;
|
|
};
|
|
case 1: { // Gradient
|
|
// Blit it into place with the renderer.
|
|
SDL_Rect OP = { 1, 1, 2, 2 };
|
|
//SDL_Rect OP = { 0, 0, 4, 4 };
|
|
if (m_bUseAltBackground) {
|
|
SDL_RenderCopy(m_pRenderer, altbackground, &OP, NULL);
|
|
} else {
|
|
SDL_RenderCopy(m_pRenderer, background, &OP, NULL);
|
|
};
|
|
break;
|
|
};
|
|
case 2: { // Picture scaled
|
|
if (m_bUseAltBackground) {
|
|
SDL_RenderCopy(m_pRenderer, m_pAltBackgroundTexture, NULL, NULL);
|
|
} else {
|
|
SDL_RenderCopy(m_pRenderer, m_pBackgroundTexture, NULL, NULL);
|
|
};
|
|
break;
|
|
};
|
|
case 3: { // Picture tail
|
|
break;
|
|
};
|
|
case 4: { // Picture Centered
|
|
SDL_Rect SrcRect, DstRect;
|
|
if (m_bUseAltBackground) {
|
|
bool A = (m_nWidth > m_nAltBackgroundTextureWidth);
|
|
bool B = (m_nHeight > m_nAltBackgroundTextureHeight);
|
|
if (A && B) {
|
|
SrcRect.x = SrcRect.y = 0;
|
|
DstRect.w = SrcRect.w = m_nAltBackgroundTextureWidth;
|
|
DstRect.h = SrcRect.h = m_nAltBackgroundTextureHeight;
|
|
DstRect.x = (m_nWidth - m_nAltBackgroundTextureWidth) >> 1;
|
|
DstRect.y = (m_nHeight - m_nAltBackgroundTextureHeight) >> 1;
|
|
} else if (A) {
|
|
SrcRect.x = DstRect.y = 0;
|
|
DstRect.w = SrcRect.w = m_nAltBackgroundTextureWidth;
|
|
DstRect.h = SrcRect.h = m_nHeight;
|
|
DstRect.x = (m_nWidth - m_nAltBackgroundTextureWidth) >> 1;
|
|
SrcRect.y = (m_nAltBackgroundTextureHeight - m_nHeight) >> 1;
|
|
} else if (B) {
|
|
DstRect.x = SrcRect.y = 0;
|
|
DstRect.w = SrcRect.w = m_nWidth;
|
|
DstRect.h = SrcRect.h = m_nAltBackgroundTextureHeight;
|
|
SrcRect.x = (m_nAltBackgroundTextureWidth - m_nWidth) >> 1;
|
|
DstRect.y = (m_nHeight - m_nAltBackgroundTextureHeight) >> 1;
|
|
} else {
|
|
DstRect.x = DstRect.y = 0;
|
|
DstRect.w = SrcRect.w = m_nWidth;
|
|
DstRect.h = SrcRect.h = m_nHeight;
|
|
SrcRect.x = (m_nAltBackgroundTextureWidth - m_nWidth) >> 1;
|
|
SrcRect.y = (m_nAltBackgroundTextureHeight - m_nHeight) >> 1;
|
|
};
|
|
SDL_RenderCopy(m_pRenderer, m_pAltBackgroundTexture, &SrcRect, &DstRect);
|
|
} else {
|
|
bool A = (m_nWidth > m_nBackgroundTextureWidth);
|
|
bool B = (m_nHeight > m_nBackgroundTextureHeight);
|
|
if (A && B) {
|
|
SrcRect.x = SrcRect.y = 0;
|
|
DstRect.w = SrcRect.w = m_nBackgroundTextureWidth;
|
|
DstRect.h = SrcRect.h = m_nBackgroundTextureHeight;
|
|
DstRect.x = (m_nWidth - m_nBackgroundTextureWidth) >> 1;
|
|
DstRect.y = (m_nHeight - m_nBackgroundTextureHeight) >> 1;
|
|
} else if (A) {
|
|
SrcRect.x = DstRect.y = 0;
|
|
DstRect.w = SrcRect.w = m_nBackgroundTextureWidth;
|
|
DstRect.h = SrcRect.h = m_nHeight;
|
|
DstRect.x = (m_nWidth - m_nBackgroundTextureWidth) >> 1;
|
|
SrcRect.y = (m_nBackgroundTextureHeight - m_nHeight) >> 1;
|
|
} else if (B) {
|
|
DstRect.x = SrcRect.y = 0;
|
|
DstRect.w = SrcRect.w = m_nWidth;
|
|
DstRect.h = SrcRect.h = m_nBackgroundTextureHeight;
|
|
SrcRect.x = (m_nBackgroundTextureWidth - m_nWidth) >> 1;
|
|
DstRect.y = (m_nHeight - m_nBackgroundTextureHeight) >> 1;
|
|
} else {
|
|
DstRect.x = DstRect.y = 0;
|
|
DstRect.w = SrcRect.w = m_nWidth;
|
|
DstRect.h = SrcRect.h = m_nHeight;
|
|
SrcRect.x = (m_nBackgroundTextureWidth - m_nWidth) >> 1;
|
|
SrcRect.y = (m_nBackgroundTextureHeight - m_nHeight) >> 1;
|
|
};
|
|
SDL_RenderCopy(m_pRenderer, m_pBackgroundTexture, &SrcRect, &DstRect);
|
|
};
|
|
break;
|
|
};
|
|
};
|
|
if (m_vGraphicElements.size()) {
|
|
for (vectorGEL::iterator index = m_vGraphicElements.begin(); index < m_vGraphicElements.end(); index++) {
|
|
if ((*index)->m_bInitComplete) {
|
|
(*index)->render(m_pRenderer);
|
|
}
|
|
else {
|
|
if ((*index)->create())(*index)->render(m_pRenderer);
|
|
};
|
|
};
|
|
};
|
|
SDL_RenderPresent(m_pRenderer);
|
|
m_pProtector->unlock();
|
|
SLEEP(2);
|
|
};// else SDL_Log("Failure to lock Mutex! SDL_Error: %s", SDL_GetError());
|
|
};
|
|
};
|
|
//FOXCONN PVB120G12H-P01
|
|
//AVC MD413 BA13733B12H
|
|
|
|
void classGUI_SDL::registerGEL(sdlGraphicElement * tPtr){
|
|
while( !m_bWindowSystemOk ) SLEEP(1);
|
|
if( tPtr != NULL ){
|
|
m_pProtector->lock();
|
|
m_vGraphicElements.push_back(tPtr);
|
|
m_pProtector->unlock();
|
|
};
|
|
};
|
|
|
|
void classGUI_SDL::removeGEL(sdlGraphicElement* tPtr){
|
|
if (tPtr != NULL){
|
|
m_pProtector->lock();
|
|
for (vectorGEL::iterator index = m_vGraphicElements.begin(); index < m_vGraphicElements.end(); index++){
|
|
if ((*index) == tPtr){
|
|
(*index)->setVisibility(false);
|
|
m_vGraphicElements.erase(index);
|
|
break;
|
|
};
|
|
};
|
|
m_pProtector->unlock();
|
|
};
|
|
};
|
|
|
|
bool classGUI_SDL::setFullScreen( bool status ){
|
|
if (m_pWindow == NULL) return false;
|
|
if (status){
|
|
SDL_SetWindowFullscreen(m_pWindow, SDL_WINDOW_FULLSCREEN );
|
|
} else {
|
|
SDL_SetWindowFullscreen(m_pWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
|
};
|
|
return true;
|
|
};
|
|
|
|
TEXTURE_HEAP_ITEM* classGUI_SDL::loadTexture(char* filename) {
|
|
char *md5;
|
|
md5 = MD5String(filename);
|
|
if ( m_vTextureHeap.size() ) {
|
|
for (int i = 0; i < m_vTextureHeap.size(); i++) {
|
|
if (strncmp(md5, m_vTextureHeap.at(i)->key, 32) == 0) {
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "%s Found in Heap [%s]", filename, md5 );
|
|
return m_vTextureHeap.at(i);
|
|
};
|
|
};
|
|
};
|
|
SDL_Surface * tSurface;
|
|
TEXTURE_HEAP_ITEM * tVal;
|
|
tSurface = IMG_Load(filename);
|
|
if (tSurface != NULL) {
|
|
tVal = (TEXTURE_HEAP_ITEM*)malloc(sizeof(TEXTURE_HEAP_ITEM));
|
|
if (tVal != NULL) {
|
|
memset(tVal, 0, sizeof(TEXTURE_HEAP_ITEM));
|
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);
|
|
tVal->texture = SDL_CreateTextureFromSurface(m_pRenderer, tSurface);
|
|
if (tVal->texture != NULL) {
|
|
memcpy(tVal->key, md5, 32);
|
|
tVal->geopmetry.w = tSurface->w;
|
|
tVal->geopmetry.h = tSurface->h;
|
|
m_vTextureHeap.push_back(tVal);
|
|
return tVal;
|
|
} else {
|
|
free(tVal);
|
|
};
|
|
SDL_FreeSurface(tSurface);
|
|
};
|
|
}
|
|
return NULL;
|
|
};
|
|
|
|
TEXTURE_HEAP_ITEM* classGUI_SDL::createTexture(int width, int height){
|
|
TEXTURE_HEAP_ITEM* tVal = NULL;
|
|
tVal = (TEXTURE_HEAP_ITEM*)malloc(sizeof(TEXTURE_HEAP_ITEM));
|
|
if (tVal != NULL) {
|
|
memset(tVal, 0, sizeof(TEXTURE_HEAP_ITEM));
|
|
tVal->geopmetry.w = width;
|
|
tVal->geopmetry.h = height;
|
|
tVal->texture = SDL_CreateTexture(m_pRenderer,0, SDL_TEXTUREACCESS_TARGET, width, height);
|
|
if (tVal->texture == NULL) {
|
|
free(tVal);
|
|
tVal = NULL;
|
|
};
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
TEXTURE_HEAP_ITEM* classGUI_SDL::createYUV420PTexture(int width, int height, bool streaming) {
|
|
TEXTURE_HEAP_ITEM* tVal = NULL;
|
|
tVal = (TEXTURE_HEAP_ITEM*)malloc(sizeof(TEXTURE_HEAP_ITEM));
|
|
if (tVal != NULL) {
|
|
memset(tVal, 0, sizeof(TEXTURE_HEAP_ITEM));
|
|
tVal->geopmetry.w = width;
|
|
tVal->geopmetry.h = height;
|
|
if (streaming) {
|
|
tVal->texture = SDL_CreateTexture(m_pRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING | SDL_TEXTUREACCESS_TARGET, width, height);
|
|
} else {
|
|
tVal->texture = SDL_CreateTexture(m_pRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_TARGET, width, height);
|
|
};
|
|
if (tVal->texture == NULL) {
|
|
free(tVal);
|
|
tVal = NULL;
|
|
};
|
|
};
|
|
return tVal;
|
|
};
|
|
|
|
SDL_Surface* classGUI_SDL::loadSurface(CSTR path) {
|
|
//The final optimized image
|
|
SDL_Surface* optimizedSurface = NULL;
|
|
//Load image at specified path
|
|
SDL_Surface* loadedSurface = IMG_Load(path);
|
|
if (loadedSurface != NULL) {
|
|
//Convert surface to screen format
|
|
optimizedSurface = SDL_ConvertSurface(loadedSurface, SDL_GetWindowSurface(m_pWindow)->format, 0);
|
|
if (optimizedSurface == NULL) {
|
|
SDL_Log("Unable to optimize image %s! SDL Error: %s", path, SDL_GetError());
|
|
};
|
|
//Get rid of old loaded surface
|
|
SDL_FreeSurface(loadedSurface);
|
|
};
|
|
return optimizedSurface;
|
|
};
|
|
|
|
void classGUI_SDL::doKeyDown(SDL_KeyboardEvent* event) {
|
|
if (event->repeat == 0) {
|
|
if (event->keysym.scancode == SDL_SCANCODE_LCTRL){
|
|
LOG("Left CTRL pressed");
|
|
}
|
|
if (event->keysym.scancode == SDL_SCANCODE_UP) {
|
|
LOG("Key Up pressed");
|
|
//app.up = 1;
|
|
};
|
|
if (event->keysym.scancode == SDL_SCANCODE_DOWN) {
|
|
LOG("Key Down pressed");
|
|
//app.down = 1;
|
|
};
|
|
if (event->keysym.scancode == SDL_SCANCODE_LEFT) {
|
|
LOG("Key Left pressed");
|
|
//app.left = 1;
|
|
};
|
|
if (event->keysym.scancode == SDL_SCANCODE_RIGHT) {
|
|
LOG("Key Right pressed");
|
|
//app.right = 1;
|
|
};
|
|
};
|
|
};
|
|
|
|
void classGUI_SDL::doKeyUp(SDL_KeyboardEvent* event) {
|
|
if (event->repeat == 0) {
|
|
if (event->keysym.scancode == SDL_SCANCODE_ESCAPE) {
|
|
LOG("Key Escape released");
|
|
m_bThreadStatus = TH_ENDED;
|
|
}
|
|
if (event->keysym.scancode == SDL_SCANCODE_HOME) {
|
|
LOG("Key Home released");
|
|
//app.up = 0;
|
|
//app.down = 0;
|
|
//app.left = 0;
|
|
//app.right = 0;
|
|
m_iCursorPosY = 120;
|
|
m_iCursorPosX = 120;
|
|
};
|
|
if (event->keysym.scancode == SDL_SCANCODE_LCTRL){
|
|
LOG("Left CTRL released");
|
|
//app.fire = 0;
|
|
}
|
|
if (event->keysym.scancode == SDL_SCANCODE_UP) {
|
|
LOG("Key Up released");
|
|
//app.up = 0;
|
|
};
|
|
if (event->keysym.scancode == SDL_SCANCODE_DOWN) {
|
|
LOG("Key Down released");
|
|
//app.down = 0;
|
|
};
|
|
if (event->keysym.scancode == SDL_SCANCODE_LEFT) {
|
|
LOG("Key Left released");
|
|
//app.left = 0;
|
|
};
|
|
if (event->keysym.scancode == SDL_SCANCODE_RIGHT) {
|
|
LOG("Key Right released");
|
|
//app.right = 0;
|
|
};
|
|
};
|
|
};
|
|
|
|
void classGUI_SDL::registerJoystickWraper(sdlJoystickWrapper* Ptr) {
|
|
m_pJoystickWraper = Ptr;
|
|
if (m_pJoystickWraper != NULL) {
|
|
if (SDL_NumJoysticks() < 1) {
|
|
SDL_Log("SDL Warning: No joysticks connected!");
|
|
} else {
|
|
m_pJoystickWraper->setController(SDL_JoystickOpen(0));
|
|
};
|
|
};
|
|
};
|
|
|
|
|
|
void classGUI_SDL::setLayout(sdlCoreLayout* ll) {
|
|
if (ll == NULL)return;
|
|
if (m_pMainLayout == NULL) {
|
|
m_pMainLayout = ll;
|
|
} else {
|
|
|
|
};
|
|
};
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|
|
#undef SLOG
|
|
#undef SLOG_ERROR
|