1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
|
#include "c_sdl2_windows.hpp"
planning_windows::planning_windows(){}
void planning_windows::get_win_size (SDL_Window* pwin,
int &posup,
int &posleft,
int &up,
int &len)
{
SDL_GetWindowPosition(pwin,&posleft,&posup);
SDL_GetWindowSize(pwin,&len,&up);
}
void planning_windows::set_picture(SDL_Renderer* pRenderer,
const std::string &pathpicture,
const int &posup,
const int &posleft,
const int &lenup,
const int &lenwid){
SDL_Surface* pSurface = nullptr;
SDL_Texture* pTexture = nullptr;
pSurface = SDL_LoadBMP(pathpicture.c_str());
if (pSurface)
{
pTexture = SDL_CreateTextureFromSurface(pRenderer,pSurface);
if ( pTexture )
{
//en test
std::cout <<PosistionGauche << ":" <<OldPosistionSuperieur << ":"
<< WinLargeur << ":"<< Winhauteur << std::endl;
SDL_Rect dest; //= {PosistionGauche,OldPosistionSuperieur, WinLargeur,Winhauteur};
dest.x = posup;
dest.y = posleft;
dest.w = lenwid;
dest.h = lenup;
SDL_RenderCopy(pRenderer,pTexture,NULL,&dest); // Copie du sprite grâce au SDL_Renderer
SDL_RenderPresent(pRenderer);
SDL_DestroyTexture(pTexture); // Libération de la mémoire associée à la texture
}
else
{
std::cout <<"Erreur dans la fonction SetPicture" <<
"pointeur pTexture : " << pTexture << " : " << pathpicture << std::endl;
}
}
else
{
std::cout <<"Erreur dans la fonction SetPicture" <<
"pointeur pSurface : " << pSurface << " : " << pathpicture << std::endl;
}
}
SDL_Renderer* planning_windows::get_renderer() { return pRenderer;}
SDL_Window* planning_windows::get_window() { return pWindow;}
void planning_windows::set_window_opacity(float opacity,int coldownshow)
{
for (float i=0; i < opacity; i= i + 0.01)
{
//C_MeSDL2Windows::M_SetUpdateScreen();
//Sleep(coldownShow);
pause(coldownshow);
//std::cout << i << std::endl;
SDL_SetWindowOpacity(pWindow,i);
}
}
bool planning_windows::initilize(const bool & initvideo,
const bool & initaudio,
const bool & initevent,
const bool & inittimer)
{
if ((initvideo == true) && SDL_Init(SDL_INIT_VIDEO) != 0 )
{
fprintf(stdout,"Échec de l'initialisation de la SDL (SDL_INIT_VIDEO) (%s)\n",SDL_GetError());
return false;
}
if ((initaudio == true) && SDL_Init(SDL_INIT_AUDIO) != 0 )
{
fprintf(stdout,"Échec de l'initialisation de la SDL (SDL_INIT_AUDIO) (%s)\n",SDL_GetError());
return false;
}
if ((initevent == true) && SDL_Init(SDL_INIT_EVENTS) != 0 )
{
fprintf(stdout,"Échec de l'initialisation de la SDL (SDL_INIT_EVENTS) (%s)\n",SDL_GetError());
return false;
}
if ((inittimer == true) && SDL_Init(SDL_INIT_TIMER) != 0 )
{
fprintf(stdout,"Échec de l'initialisation de la SDL (SDL_INIT_TIMER) (%s)\n",SDL_GetError());
return false;
}
return true;
}
void planning_windows::set_exit_sdl(){
if ( pWindow != nullptr ) { pWindow=nullptr; }
if ( pRenderer != nullptr ) { pRenderer=nullptr ;}
SDL_Quit();
}
int planning_windows::create_windows(const std::string & wtitre,
const int & taillevertical,
const int & taillehorizontal,
const bool & aucentre,
const bool & visible,
const bool & decoration){
int vHideOrShows=-1;
if (visible == true){
vHideOrShows=SDL_WINDOW_SHOWN;
WindowsVisible=true;
}
else
{
vHideOrShows=SDL_WINDOW_HIDDEN;
WindowsVisible=false;
}
if (aucentre)
{
if (decoration==false)
{
pWindow = SDL_CreateWindow(wtitre.c_str(),
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
taillehorizontal,
taillevertical,
vHideOrShows | SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL);
}
else
{
pWindow = SDL_CreateWindow(wtitre.c_str(),
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
taillehorizontal,
taillevertical,
vHideOrShows | SDL_WINDOW_OPENGL);
}
}
else
{
if (decoration==false)
{
pWindow = SDL_CreateWindow(wtitre.c_str(),
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
taillehorizontal,
taillevertical,
vHideOrShows | SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL);
}
else
{
pWindow = SDL_CreateWindow(wtitre.c_str(),
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
taillehorizontal,
taillevertical,
vHideOrShows | SDL_WINDOW_OPENGL);
}
}
if( pWindow == NULL) {
std::cout << "Erreur: pointeur null suite a la creation de la fenêtre";
WindowsVisible = false;
return -1;
}
else
{
planning_windows::SetGpuRenderer();
return 0;
}
}
int planning_windows::pause(const Uint32 & Time){
if( pWindow )
{
SDL_Delay(Time);
}
else
{
fprintf(stderr,"Erreur de pause ?: %s\n",SDL_GetError());
}
}
void planning_windows::destruction_windows(){
if( pWindow )
{
SDL_DestroyWindow(pWindow);
}
pWindow=nullptr;
}
bool planning_windows::set_full_screen(){
if( pWindow )
{
if (SDL_SetWindowFullscreen(
pWindow,
SDL_WINDOW_FULLSCREEN_DESKTOP ) == 0 )
{
return true;
}
else
{
return false;
}
}
return false;
}
int planning_windows::get_resolution(std::vector<int> & vechauteur,
std::vector<int> & veclargeur,
std::vector<int> & vecfrequance)
{
int modeNumber = SDL_GetNumDisplayModes(0);
int error = 0;
if (modeNumber < 0)
{
fprintf(stdout,"Échec lors de la récupération du nombre de modes (%s)\n",SDL_GetError());
// return -2;
}
fprintf(stdout,"Vous avez %d mode(s) d'affichage\n", modeNumber);
// Affichage des différents modes
SDL_DisplayMode displayMode;
for (int i = 0 ; i < modeNumber ; i++)
{
error = SDL_GetDisplayMode(0, i, &displayMode);
if (error < 0)
{
fprintf(stdout, "Échec lors de la récupération du mode d'affichage (%s)\n", SDL_GetError());
return -3;
}
/*
std::cout << "Ligne: " << i <<
" Largeur: " << displayMode.w <<
"Hauteur" << displayMode.h <<
" Frequance " << displayMode.refresh_rate <<
std::endl;
*/
vechauteur.push_back(displayMode.h);
veclargeur.push_back(displayMode.w);
vecfrequance.push_back(displayMode.refresh_rate);
//fprintf(stdout, "Mode %d : %dx%dx%d\n", i, displayMode.w, displayMode.h, displayMode.refresh_rate);
}
return -4;
}
void planning_windows::SetGpuRenderer(){
pRenderer = SDL_CreateRenderer(pWindow, -1, SDL_RENDERER_ACCELERATED);
}
void planning_windows::set_luminositer(const float & lum){
if( pWindow )
{
SDL_SetWindowBrightness(pWindow,lum);
}
else
{
std::cout << "Erreur pointeur invalide M_SetLuminositer " << std::endl;
}
}
void planning_windows::set_update_screen(){
if( pWindow )
{
SDL_RenderPresent(pRenderer);
}
else
{
std::cout << "Erreur pointeur invalide M_SetUpdateScreen " << std::endl;
}
}
void planning_windows::set_windows_show(){
SDL_ShowWindow(pWindow);
WindowsVisible = true;
}
void planning_windows::set_windows_hide(){
SDL_HideWindow(pWindow);
WindowsVisible = false;
}
void planning_windows::couleur_de_fond( const int & rouge,
const int & vert ,
const int & bleu,
const int & transparence)
{
SDL_SetRenderDrawColor(pRenderer, rouge, vert, bleu, transparence);
SDL_RenderClear(pRenderer);
}
void planning_windows::set_permit_change_size(){
if( pWindow )
{
SDL_SetWindowResizable(pWindow,SDL_TRUE);
}
}
std::string planning_windows::get_event()
{
SDL_Event event;
while ( SDL_PollEvent(&event) != 0 )
{
switch (event.type)
{
case SDL_KEYDOWN:
if ( event.key.keysym.scancode == SDL_SCANCODE_ESCAPE )
{
return "exit";
}
//return event.key.keysym.scancode;
break;
case SDL_KEYUP:
// fprintf(stdout, "Un relachement d une touche :\n");
// fprintf(stdout, "\trépétition ? : %d\n",event.key.repeat);
// fprintf(stdout, "\tscancode : %d\n",event.key.keysym.scancode);
// fprintf(stdout, "\tkey : %d\n",event.key.keysym.sym);
if ( event.key.keysym.scancode == SDL_SCANCODE_ESCAPE )
{
return "exit";
}
case SDL_MOUSEMOTION:
break;
case SDL_MOUSEBUTTONUP:
break;
case SDL_MOUSEBUTTONDOWN:
std::cout << "Windows SDL_MOUSEBUTTONDOWN" << std::endl;
break;
case SDL_MOUSEWHEEL:
case SDL_WINDOWEVENT:
SDL_GetWindowPosition(pWindow,&PosistionGauche,&PosistionSuperieur);
if (PosistionGauche != OldPosistionGauche)
{
std::cout << "La Position a gauche a changer" << PosistionGauche << std::endl;
OldPosistionGauche = PosistionGauche;
planning_windows::set_update_screen();
}
if (PosistionSuperieur != OldPosistionSuperieur)
{
std::cout << "La Posistion sur la hauteur a changer" << PosistionSuperieur << std::endl;
OldPosistionSuperieur = PosistionSuperieur;
planning_windows::set_update_screen();
}
SDL_GetWindowSize(pWindow,&WinLargeur,&Winhauteur);
if (WinLargeur != OldWinLargeur)
{
std::cout << "La largeur a changer" << WinLargeur << std::endl;
OldWinLargeur = WinLargeur;
planning_windows::set_update_screen();
}
if (Winhauteur != OldWinhauteur)
{
std::cout << "La hauteur a changer" << Winhauteur << std::endl;
OldWinhauteur = Winhauteur;
planning_windows::set_update_screen();
}
if (event.window.event == SDL_WINDOWEVENT_CLOSE){ return "exit"; }
break;
default:
std::cout << event.type << std::endl;
}
}
return "continue";//sans ce type de retour sa provoque: process returned -1073741819 (0xC0000005)
}
void planning_windows::set_windows_priority_show()
{
SDL_RaiseWindow(pWindow);
} |