29#include "../../objects/PColor.h"
30#include "../../utility/PError.h"
31#include "../../base/PList.h"
32#include "../../base/PComplexData.h"
54 scolor.r = pcolor.
GetRed();
65 return PColor(scolor.r, scolor.g, scolor.b, scolor.a);
75 cerr <<
"drawing " << x <<
","<< y << endl;
78 cerr <<
"Line renderer: " << renderer << endl;
80 cerr <<
"renderer is null\n";
97 SDL_RenderPresent(renderer);
100 SDL_RenderDrawPoint(renderer,(
int)(widget->
GetX()+x),(
int)(widget->
GetY()+y));
108 int x1,
int y1,
int x2,
int y2,
PColor pcolor)
112 int out = SDL_SetRenderTarget(renderer, widget->
GetSDL_Texture());
116 cerr <<
"setrendertarget result in drawline: "<< out <<endl;
117 cerr << SDL_GetError() <<endl;
120 SDL_SetRenderDrawColor(renderer,
134 SDL_RenderDrawLine(renderer,newX1,newY1,newX2,newY2);
135 SDL_SetRenderTarget(renderer,
NULL);
147 int bpp = surface->format->BytesPerPixel;
149 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
159 if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
160 return p[0] << 16 | p[1] << 8 | p[2];
162 return p[0] | p[1] << 8 | p[2] << 16;
181 SDL_GetRGB(pxl, surface->format, &r,&g,&b);
203 SDL_SetTextureBlendMode(texture,SDL_BLENDMODE_BLEND);
204 SDL_QueryTexture(texture,&format,&w,&h,&pitch);
205 SDL_LockTexture(texture,
NULL,&pixels,&pitch);
206 Uint32 * upixels = (Uint32*) pixels;
212 int i = pitch*(w*x+y);
215 Uint32 pixel = upixels[i];
216 SDL_UnlockTexture(texture);
221 int bpp = surface->format->BytesPerPixel;
223 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
233 if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
234 return p[0] << 16 | p[1] << 8 | p[2];
236 return p[0] | p[1] << 8 | p[2] << 16;
264 SDL_SetTextureBlendMode(texture,SDL_BLENDMODE_BLEND);
265 SDL_QueryTexture(texture,&format,&w,&h,&pitch);
266 int success = SDL_LockTexture(texture,
NULL,&pixels,&pitch);
269 cerr << SDL_GetError() << endl;
271 Uint32 * upixels = (Uint32*) pixels;
272 SDL_PixelFormat* fmt= SDL_AllocFormat(format);
277 int i = pitch*(w*y+x);
280 Uint32 pixel = upixels[i];
281 SDL_UnlockTexture(texture);
291 SDL_GetRGBA(pixel,fmt, &r,&g,&b,&a);
308 SDL_Surface *sshot = SDL_CreateRGBSurface(0, rect->w,rect->h, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
309 SDL_RenderReadPixels(renderer, rect, SDL_PIXELFORMAT_ARGB8888, sshot->pixels, sshot->pitch);
312 int result =IMG_SavePNG(sshot, fname.c_str());
313 SDL_FreeSurface(sshot);
328 SDL_DisplayMode current;
331 for(i = 0; i < SDL_GetNumVideoDisplays(); ++i){
333 int should_be_zero = SDL_GetCurrentDisplayMode(i, ¤t);
335 if(should_be_zero != 0)
337 SDL_Log(
"Could not get display mode for video display #%d: %s", i, SDL_GetError());
341 SDL_Log(
"Display #%d: current display mode is %dx%dpx @ %dhz. \n", i, current.w, current.h, current.refresh_rate);
349 SDL_DisplayMode info;
350 int success = SDL_GetCurrentDisplayMode(0,&info);
352 cerr <<
"SUCCESS at getting display mode?:" <<success << endl;
357 cerr << info.w <<
"," << info.h <<
"," << info.refresh_rate << endl;
360 rate =info.refresh_rate;
363 cerr <<
"SDL_Init failed: " << SDL_GetError() << endl;
382 int out = SDL_SetClipboardText(text.c_str());
392 if(SDL_HasClipboardText())
394 char * text = SDL_GetClipboardText();
408 return SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
409 "An error occurred\n",
417 std::cerr << SDL_GetPerformanceCounter() <<
"/"<< SDL_GetPerformanceFrequency() <<std::endl;
418 return ((
long double)SDL_GetPerformanceCounter())/(
long double)SDL_GetPerformanceFrequency()*1000.0;
430 std::cerr <<
"=================================================\n";
431 std::cerr <<
" Available drivers\n";
432 std::cerr <<
"=================================================\n";
435 int numdrivers = SDL_GetNumRenderDrivers ();
436 if(printout) std::cerr <<
"Render driver count: " << numdrivers << endl;
437 for (
int i=0; i<numdrivers; i++)
439 SDL_RendererInfo drinfo;
440 SDL_GetRenderDriverInfo (i, &drinfo);
443 cerr <<
"Driver name ("<<i<<
"): " << drinfo.name << endl;
444 if (drinfo.flags & SDL_RENDERER_SOFTWARE) std::cerr <<
" the renderer is a software fallback" << endl;
445 if (drinfo.flags & SDL_RENDERER_ACCELERATED) std::cerr <<
" the renderer uses hardware acceleration" << endl;
446 if (drinfo.flags & SDL_RENDERER_PRESENTVSYNC) std::cerr <<
" present is synchronized with the refresh rate" << endl;
447 if (drinfo.flags & SDL_RENDERER_TARGETTEXTURE) std::cerr <<
" the renderer supports rendering to texture" << endl;
452 if(printout) std::cerr <<
"=================================================\n";
void PushBack(const Variant &v)
void SignalWarning(const std::string &message)
void SignalFatalError(const std::string &message)
Variant GetDriverList(bool printout=true)
PColor SDLColorToPColor(SDL_Color scolor)
This converts between an SDL Color and a PColor
Variant CopyFromClipboard()
int WritePNG(SDL_Renderer *renderer, SDL_Rect *rect, const std::string fname)
void CopyToClipboard(std::string text)
int PopupErrorBox(PlatformWindow *pwindow, const char *message)
SDL_Color PColorToSDLColor(PColor pcolor)
This converts between a PColor and an SDL color.
void DrawLine(SDL_Renderer *renderer, PlatformWidget *pwidget, int x1, int y1, int x2, int y2, PColor color)
This sets a pixel to be a certain color.
Variant GetCurrentScreenResolution()
void DrawPixel(SDL_Renderer *renderer, PlatformWidget *pwidget, int x, int y, PColor color)
This sets a pixel to be a certain color.
PColor GetPixelColor(SDL_Surface *surface, int x, int y)
This extracts the color of a pixel.
Uint32 GetPixel(SDL_Surface *surface, int x, int y)