static int best_display(const SDL_Rect *rect) { int result = SDL_WINDOWPOS_UNDEFINED; int display_cnt = SDL_GetNumVideoDisplays(); for (int i = 0; i < display_cnt; i++) { SDL_Rect bounds; SDL_GetDisplayBounds(i, &bounds); if (bounds.h == rect->h && bounds.w >= rect->w) { result = SDL_WINDOWPOS_UNDEFINED_DISPLAY(i); if (bounds.w == rect->w) break; // exact match } } return result; }
static int lua_SDL_GetDisplayModes(lutok::state& state){ Lua_SDL_DisplayMode & dm = LOBJECT_INSTANCE(Lua_SDL_DisplayMode); Lua_SDL_Rect & r = LOBJECT_INSTANCE(Lua_SDL_Rect); state.new_table();// displays for (int display=0; display < SDL_GetNumVideoDisplays(); display++){ state.push_integer(display+1); state.new_table(); //display int modes=1; state.push_literal("modes"); state.new_table(); //modes for (int i=0; i<SDL_GetNumDisplayModes(display); i++){ SDL_DisplayMode * mode = new SDL_DisplayMode; if (SDL_GetDisplayMode(display, i, mode) == 0){ state.push_integer(modes++); dm.push(mode); state.set_table(); }else{ delete mode; } } state.set_table(); SDL_Rect * rect = new SDL_Rect; SDL_GetDisplayBounds(display, rect); state.push_literal("bounds"); r.push(rect); state.set_table(); state.set_table(); } return 1; }
bool autoWindowSize(int& width, int& height) override { std::vector<WindowMode> res; int num_displays = SDL_GetNumVideoDisplays(); if(num_displays < 0) { LOG_ERROR("Error enumerating number of displays: " << std::string(SDL_GetError())); return false; } for(int n = 0; n != num_displays; ++n) { SDL_Rect display_bounds; SDL_GetDisplayBounds(n, &display_bounds); int num_modes = SDL_GetNumDisplayModes(n); if(num_modes < 0) { LOG_ERROR("Error enumerating number of display modes for display " << n << ": " << std::string(SDL_GetError())); return false; } for(int m = 0; m != num_modes; ++m) { SDL_DisplayMode mode; int err = SDL_GetDisplayMode(n, m, &mode); if(err < 0) { LOG_ERROR("Couldn't get display mode information for display: " << n << " mode: " << m << " : " << std::string(SDL_GetError())); } else { WindowMode new_mode = { mode.w, mode.h, std::make_shared<SDLPixelFormat>(mode.format), mode.refresh_rate }; res.emplace_back(new_mode); LOG_DEBUG("added mode w: " << mode.w << ", h: " << mode.h << ", refresh: " << mode.refresh_rate); } } } if(!res.empty()) { width = static_cast<int>(res.front().width * 0.8f); height = static_cast<int>(res.front().height * 0.8f); return true; } return false; }
void EventosMouse::corrigirPosicaoFullscreen() { if(!janela.estaEmTelaCheia()) return; SDL_Rect display; SDL_GetDisplayBounds(0, &display); float ratio = (float)janela.getLarguraTela()/(float)janela.getAlturaTela(); float larguraEscalada; float alturaEscalada; if(janela.getLarguraTela()/(float)display.w < janela.getAlturaTela()/(float)display.h) // tarjas nas laterais { larguraEscalada = display.h*ratio; alturaEscalada = larguraEscalada/ratio; } else if(janela.getAlturaTela()/(float)display.h < janela.getLarguraTela()/(float)display.w) // tarjas em cima e em baixo { alturaEscalada = display.w/ratio; larguraEscalada = alturaEscalada*ratio; } else // sem tarjas { larguraEscalada = display.h*ratio; alturaEscalada = display.w/ratio; } x = x - (display.w - larguraEscalada)/2; x = x*(janela.getLarguraTela()/(float)larguraEscalada); y = y - (display.h - alturaEscalada)/2; y = y*(janela.getAlturaTela()/(float)alturaEscalada); }
void CInput::processMouse(SDL_Event& ev) { #if SDL_VERSION_ATLEAST(1, 3, 0) SDL_Rect screenRect; if(SDL_GetDisplayBounds(0, &screenRect) == 0) { // transform mouse coordinates // WARNING: I don't really understand that. It's probably somehow iPhoneRotateScreen + SDL stuff. ev.button.y -= screenRect.h - 200; } #endif // NOTE: The ev.button.which / the multitouch support was removed in SDL 1.3 trunk // with changeset 4465:3e69e077cb95 on May09. It is planned to add a real multitouch API // at some later time (maybe Aug2010). // As long as we don't have that, we must use the old SDL 1.3 revision 4464. switch(ev.type) { case SDL_MOUSEBUTTONDOWN: processMouse(ev.button.x, ev.button.y, true, ev.button.which); break; case SDL_MOUSEBUTTONUP: processMouse(ev.button.x, ev.button.y, false, ev.button.which); break; case SDL_MOUSEMOTION: processMouse(ev.motion.x - ev.motion.xrel, ev.motion.y - ev.motion.yrel, false, ev.motion.which); processMouse(ev.motion.x, ev.motion.y, true, ev.motion.which); break; } }
SDL_Rect CVideo::bound() const { SDL_Rect rc; int display = window? SDL_GetWindowDisplayIndex(window): 0; SDL_GetDisplayBounds(display, &rc); return rc; }
bool KPSdl2UserInterface::IsWindowResolutionSupported( int width, int height) const { int index; SDL_Rect rect; if (window == nullptr) { // If there is no window opened yet we just can make a guess. index = 0; } else { index = SDL_GetWindowDisplayIndex(window); } if (index < 0) { BLogger::Log("*** SDL_GetWindowDisplayIndex error: ", SDL_GetError()); return false; } auto result = SDL_GetDisplayBounds(index, &rect); if (result < 0) { BLogger::Log("*** SDL_GetDisplayBounds error: ", SDL_GetError()); return false; } return width <= rect.w && (height <= rect.h); }
std::vector<VideoMode> GetAvailableVideoModes() { std::vector<VideoMode> modes; const int num_displays = SDL_GetNumVideoDisplays(); for(int display_index = 0; display_index < num_displays; display_index++) { const int num_modes = SDL_GetNumDisplayModes(display_index); SDL_Rect display_bounds; SDL_GetDisplayBounds(display_index, &display_bounds); for (int display_mode = 0; display_mode < num_modes; display_mode++) { SDL_DisplayMode mode; SDL_GetDisplayMode(display_index, display_mode, &mode); // insert only if unique resolution if( modes.end()==std::find(modes.begin(), modes.end(), VideoMode(mode.w, mode.h)) ) { modes.push_back(VideoMode(mode.w, mode.h)); } } } if( num_displays==0 ) { modes.push_back(VideoMode(800, 600)); } return modes; }
void Window::getPosition(int &x, int &y, int &displayindex) { if (!window) { x = y = 0; displayindex = 0; return; } displayindex = std::max(SDL_GetWindowDisplayIndex(window), 0); SDL_GetWindowPosition(window, &x, &y); // In SDL <= 2.0.3, fullscreen windows are always reported as 0,0. In every // other case we need to convert the position from global coordinates to the // monitor's coordinate space. if (x != 0 || y != 0) { SDL_Rect displaybounds = {}; SDL_GetDisplayBounds(displayindex, &displaybounds); x -= displaybounds.x; y -= displaybounds.y; } }
Platform::Platform( const std::shared_ptr<input::Manager> &input_manager, const graphics::Rect &static_display_frame, bool single_window) : input_manager_(input_manager), event_thread_running_(false), single_window_(single_window) { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_EVENTS) < 0) { const auto message = utils::string_format("Failed to initialize SDL: %s", SDL_GetError()); BOOST_THROW_EXCEPTION(std::runtime_error(message)); } auto display_frame = graphics::Rect::Invalid; if (static_display_frame == graphics::Rect::Invalid) { for (auto n = 0; n < SDL_GetNumVideoDisplays(); n++) { SDL_Rect r; if (SDL_GetDisplayBounds(n, &r) != 0) continue; graphics::Rect frame{r.x, r.y, r.x + r.w, r.y + r.h}; if (display_frame == graphics::Rect::Invalid) display_frame = frame; else display_frame.merge(frame); } if (display_frame == graphics::Rect::Invalid) BOOST_THROW_EXCEPTION( std::runtime_error("No valid display configuration found")); } else { display_frame = static_display_frame; window_size_immutable_ = true; } graphics::emugl::DisplayInfo::get()->set_resolution(display_frame.width(), display_frame.height()); pointer_ = input_manager->create_device(); pointer_->set_name("anbox-pointer"); pointer_->set_driver_version(1); pointer_->set_input_id({BUS_VIRTUAL, 2, 2, 2}); pointer_->set_physical_location("none"); pointer_->set_key_bit(BTN_MOUSE); // NOTE: We don't use REL_X/REL_Y in reality but have to specify them here // to allow InputFlinger to detect we're a cursor device. pointer_->set_rel_bit(REL_X); pointer_->set_rel_bit(REL_Y); pointer_->set_rel_bit(REL_HWHEEL); pointer_->set_rel_bit(REL_WHEEL); pointer_->set_prop_bit(INPUT_PROP_POINTER); keyboard_ = input_manager->create_device(); keyboard_->set_name("anbox-keyboard"); keyboard_->set_driver_version(1); keyboard_->set_input_id({BUS_VIRTUAL, 3, 3, 3}); keyboard_->set_physical_location("none"); keyboard_->set_key_bit(BTN_MISC); keyboard_->set_key_bit(KEY_OK); event_thread_ = std::thread(&Platform::process_events, this); }
void Player::Update(float updateInterval) { m_xPos += m_xVelocity * (updateInterval / 100000); m_yPos += m_yVelocity * (updateInterval / 100000); SDL_Rect displayRect; SDL_GetDisplayBounds(0, &displayRect); if (m_xPos >= displayRect.w - (m_surface->w / 2)){ m_xPos = displayRect.w - (m_surface->w / 2); m_xVelocity *= -1; } if (m_xPos <= m_surface->w / 2){ m_xPos = m_surface->w / 2; m_xVelocity *= -1; } if (m_yPos >= displayRect.h - (m_surface->h / 2)){ m_yPos = displayRect.h - (m_surface->h / 2); m_yVelocity *= -1; } if (m_yPos <= m_surface->h / 2){ m_yPos = m_surface->h / 2; m_yVelocity *= -1; } UpdateTexturePos(); }
Window::Window(int displayNum){ Context* otherContext = new Context(); if (NumberOfWindows == 0){ SDL_Init(SDL_INIT_VIDEO); SDL_GL_SetAttribute(SDL_GL_STEREO, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); } NumberOfWindows++; SDL_GetDisplayBounds(displayNum, &bounds); //win = SDL_CreateWindow("SDL2window", bounds.x, bounds.y, bounds.w, bounds.h, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL); win = SDL_CreateWindow("SDL2window", bounds.x, bounds.y, bounds.w, bounds.h, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_SHOWN); glContext = SDL_GL_CreateContext(win); myContext = new Context(); otherContext -> share(myContext); glClearDepth(1.0f); glViewport(0, 0, bounds.w, bounds.h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, 1, 0, 1, 1, -1); glMatrixMode(GL_MODELVIEW); glEnable(GL_TEXTURE_2D); glLoadIdentity(); otherContext->activate(); delete otherContext; }
void Purity::WindowManipulator::resizeWindow() { Vector2u windowSize = mWindow->getSize(); Vector2i windowPos = mWindow->getPosition(); Vector2u newWindowSize = windowSize; Vector2i newWindowPos = windowPos; Vector2u mousePos = static_cast<Vector2u>(Mouse::getPosition()); SDL_Rect displayBounds; // TODO: test on multiple monitors with different resolutions if (SDL_GetDisplayBounds(0, &displayBounds) != 0) { std::cerr << SDL_GetError() << std::endl; } // right if (mRightBorderGrabbed) { newWindowSize.x = mousePos.x - windowPos.x + mWindowResizeOffsetRightBottom.x; // TODO: is this necessary on windows? if ((newWindowSize.x + windowPos.x) == static_cast<unsigned int>((displayBounds.w - 1))) { newWindowSize.x += 1; } } // bottom if (mBottomBorderGrabbed) { newWindowSize.y = mousePos.y - windowPos.y + mWindowResizeOffsetRightBottom.y; // TODO: is this necessary on windows? if ((newWindowSize.y + windowPos.y) == static_cast<unsigned int>((displayBounds.h - 1))) { newWindowSize.y += 1; } } // left if (mLeftBorderGrabbed) { newWindowPos.x = mousePos.x - mWindowResizeOffsetLeftTop.x; newWindowSize.x += windowPos.x - newWindowPos.x; } // top if (mTopBorderGrabbed) { newWindowPos.y = mousePos.y - mWindowResizeOffsetLeftTop.y; newWindowSize.y += windowPos.y - newWindowPos.y; } mWindow->setSize(newWindowSize); mWindow->setPosition(newWindowPos); }
bool CheckAvailableVideoModes() { // Get available fullscreen/hardware modes const int numDisplays = SDL_GetNumVideoDisplays(); SDL_DisplayMode ddm = {0, 0, 0, 0, nullptr}; SDL_DisplayMode cdm = {0, 0, 0, 0, nullptr}; // ddm is virtual, contains all displays in multi-monitor setups // for fullscreen windows with non-native resolutions, ddm holds // the original screen mode and cdm is the changed mode SDL_GetDesktopDisplayMode(0, &ddm); SDL_GetCurrentDisplayMode(0, &cdm); LOG( "[GL::%s] desktop={%ix%ix%ibpp@%iHz} current={%ix%ix%ibpp@%iHz}", __func__, ddm.w, ddm.h, SDL_BPP(ddm.format), ddm.refresh_rate, cdm.w, cdm.h, SDL_BPP(cdm.format), cdm.refresh_rate ); for (int k = 0; k < numDisplays; ++k) { const int numModes = SDL_GetNumDisplayModes(k); if (numModes <= 0) { LOG("\tdisplay=%d bounds=N/A modes=N/A", k + 1); continue; } SDL_DisplayMode cm = {0, 0, 0, 0, nullptr}; SDL_DisplayMode pm = {0, 0, 0, 0, nullptr}; SDL_Rect db; SDL_GetDisplayBounds(k, &db); LOG("\tdisplay=%d modes=%d bounds={x=%d, y=%d, w=%d, h=%d}", k + 1, numModes, db.x, db.y, db.w, db.h); for (int i = 0; i < numModes; ++i) { SDL_GetDisplayMode(k, i, &cm); const float r0 = (cm.w * 9.0f) / cm.h; const float r1 = (cm.w * 10.0f) / cm.h; const float r2 = (cm.w * 16.0f) / cm.h; // skip legacy (3:2, 4:3, 5:4, ...) and weird (10:6, ...) ratios if (r0 != 16.0f && r1 != 16.0f && r2 != 25.0f) continue; // show only the largest refresh-rate and bit-depth per resolution if (cm.w == pm.w && cm.h == pm.h && (SDL_BPP(cm.format) < SDL_BPP(pm.format) || cm.refresh_rate < pm.refresh_rate)) continue; LOG("\t\t[%2i] %ix%ix%ibpp@%iHz", int(i + 1), cm.w, cm.h, SDL_BPP(cm.format), cm.refresh_rate); pm = cm; } } // we need at least 24bpp or window-creation will fail return (SDL_BPP(ddm.format) >= 24); }
/** * initSDL() - create and configure native windowing systemDimensions * @return bool true if initialization is a success */ bool GLManager::initSDL() { bool success = true; //Initialize SDL if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { printf("SDL could not initialize! SDL Error: %s\n", SDL_GetError()); success = false; //Use OpenGL 3.3 core } else { 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_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2); // allow for multisampling of frame buffer glEnable(GL_MULTISAMPLE); // use native width and height of screen if possible SDL_Rect r; if (SDL_GetDisplayBounds(0, &r) == 0) { this->screenWidth = r.w;// * 0.8f; this->screenHeight = r.h;// * 0.8f; } //Create window window = SDL_CreateWindow("opulence v1.0", 20, // SDL_WINDOWPOS_UNDEFINED, 30, // SDL_WINDOWPOS_UNDEFINED, this->screenWidth, this->screenHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN); surface = SDL_GetWindowSurface(window); SDL_GL_CreateContext(window); // initialize GLEW system independence glewExperimental = GL_TRUE; GLenum glewError = glewInit(); if (glewError != GLEW_OK) { printf("Error: Glew failed to initialize!\n"); exit(EXIT_FAILURE); } //Use Vsync if (SDL_GL_SetSwapInterval(1) < 0) { printf("Warning: Unable to set VSync! SDL Error: %s\n", SDL_GetError()); } } return success; }
static int lua_SDL_GetDisplayBounds(lutok::state& state){ Lua_SDL_Rect & r = LOBJECT_INSTANCE(Lua_SDL_Rect); SDL_Rect * rect = new SDL_Rect; if (SDL_GetDisplayBounds(state.to_integer(1), rect) == 0){ r.push(rect); return 1; }else{ return 0; } }
void UIInterface::getScreenSize(int *width, int *height) { SDL_Rect bounds; int displayIndex = SDL_GetWindowDisplayIndex(this->m_Win); SDL_GetDisplayBounds(displayIndex, &bounds); if (width) *width = bounds.w; if (height) *height = bounds.h; }
int main(int argc, char *argv[]) { SDL_DisplayMode mode; int num_displays, dpy; /* Enable standard application logging */ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); /* Load the SDL library */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; } SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver()); num_displays = SDL_GetNumVideoDisplays(); SDL_Log("See %d displays.\n", num_displays); for (dpy = 0; dpy < num_displays; dpy++) { const int num_modes = SDL_GetNumDisplayModes(dpy); SDL_Rect rect = { 0, 0, 0, 0 }; int m; SDL_GetDisplayBounds(dpy, &rect); SDL_Log("%d: \"%s\" (%dx%d, (%d, %d)), %d modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes); if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " CURRENT: failed to query (%s)\n", SDL_GetError()); } else { print_mode("CURRENT", &mode); } if (SDL_GetDesktopDisplayMode(dpy, &mode) == -1) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DESKTOP: failed to query (%s)\n", SDL_GetError()); } else { print_mode("DESKTOP", &mode); } for (m = 0; m < num_modes; m++) { if (SDL_GetDisplayMode(dpy, m, &mode) == -1) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " MODE %d: failed to query (%s)\n", m, SDL_GetError()); } else { char prefix[64]; SDL_snprintf(prefix, sizeof (prefix), " MODE %d", m); print_mode(prefix, &mode); } } SDL_Log("\n"); } return 0; }
bool gutGetDisplayBounds(unsigned index, unsigned *width, unsigned *height) { chkwin; SDL_Rect bnds; if (SDL_GetDisplayBounds((int) index, &bnds) == 0) return false; if (bnds.w < 0 || bnds.h < 0) return false; if (width) *width = bnds.w; if (height) *height = bnds.h; return true; }
// Converts co-ordinates for a specific display to those for whole desktop static void VID_AbsolutePositionFromRelative(int* x, int* y, int* display) { SDL_Rect bounds; // Try and get bounds for the specified display - default back to main display if there's an issue if (SDL_GetDisplayBounds(*display, &bounds)) { *display = 0; if (SDL_GetDisplayBounds(*display, &bounds)) { // Still an issue - reset back to top-left of screen Com_Printf("Error detecting resolution...\n"); *x = *y = 0; return; } } // Adjust co-ordinates, making sure some of the window will always be visible *x = bounds.x + min(*x, bounds.w - 30); *y = bounds.y + min(*y, bounds.h - 30); }
void Renderer::createWindow() { Config& config = Core::get().config(); int displayNum = config.getInt("Renderer.displayNum", 0); string windowMode = config.getString("Renderer.windowMode", "windowed"); int width = config.getInt("Renderer.width", 1024); int height = config.getInt("Renderer.height", 768); if(displayNum < 0 || displayNum >= SDL_GetNumVideoDisplays()) { throw runtime_error("Bad value for Renderer.displayNum"); } SDL_Rect displayBounds; SDL_GetDisplayBounds(displayNum, &displayBounds); SDL_Rect windowBounds; Uint32 windowFlags = SDL_WINDOW_OPENGL; if(windowMode == "fullscreen") { windowBounds.x = displayBounds.x; windowBounds.y = displayBounds.y; windowBounds.w = width; windowBounds.h = height; windowFlags |= SDL_WINDOW_FULLSCREEN; } else if(windowMode == "fullscreenDesktop") { windowBounds = displayBounds; windowFlags |= SDL_WINDOW_BORDERLESS; } else if(windowMode == "windowed") { windowBounds.x = displayBounds.x + (displayBounds.w - width) / 2; windowBounds.y = displayBounds.y + (displayBounds.h - height) / 2; windowBounds.w = width; windowBounds.h = height; } else { throw runtime_error("Bad value for Renderer.windowMode"); } window_ = SDL_CreateWindow("Bael'Zharon's Respite", windowBounds.x, windowBounds.y, windowBounds.w, windowBounds.h, windowFlags); if(window_ == nullptr) { throwSDLError(); } }
//Creates a window with the specified title. //If fullscreen is true, sets window mode to fullscreen, else //Creates a window that is 100 pixels less than the desktop screen int SpriteBatch::Initialize(std::string title, bool fullScreen) { //if full screen, draw with full screen if(fullScreen) return Initialize(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_FULLSCREEN); else { //otherwise draw a square 100 pixels less than the monitor all the way around SDL_Rect size; SDL_GetDisplayBounds(0, &size); return Initialize(title, 100, 100, size.w, size.h, SDL_WINDOW_OPENGL); } }
// Check the display bounds of the display referred to by 'video_display' and // set x and y to a location that places the window in the center of that // display. static void CenterWindow(int *x, int *y, int w, int h) { SDL_Rect bounds; if (SDL_GetDisplayBounds(video_display, &bounds) < 0) { fprintf(stderr, "CenterWindow: Failed to read display bounds " "for display #%d!\n", video_display); return; } *x = bounds.x + SDL_max((bounds.w - w) / 2, 0); *y = bounds.y + SDL_max((bounds.h - h) / 2, 0); }
void ViewerSdl::Init(const std::string& title) { this->Clear(); SDL_Rect window_rect; SDL_GetDisplayBounds(0, &window_rect); this->window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_rect.w, window_rect.h, SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN); if(!this->window) { LogSdlError("SDL_CreateWindow"); } this->renderer = SDL_CreateRenderer(this->window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if(!this->renderer) { LogSdlError("SDL_CreateRenderer"); } }
value desktop_get_display_bounds(int display) { SDL_Rect _rect; SDL_GetDisplayBounds(display, &_rect); bounds_rect bounds; bounds.x = _rect.x; bounds.y = _rect.y; bounds.width = _rect.w; bounds.height = _rect.h; return display_bounds_to_hx(bounds); } //desktop_get_display_bounds
Rect Window::getDisplayBounds() const { const i32_t index = this->getDisplayIndex(); Rect rect; if (index >= 0) { SDL_Rect sdl_rect; SDL_GetDisplayBounds(index, &sdl_rect); rect.x = sdl_rect.x; rect.y = sdl_rect.y; rect.width = sdl_rect.w; rect.height = sdl_rect.h; } return rect; }
int init()/*{{{*/ { SDL_Rect d_bounds; SDL_DisplayMode d_mode; if(SDL_Init(SDL_INIT_VIDEO) != 0) // SDL_INIT_AUDIO if needed { printf("SDL_Init Error: %s\n", SDL_GetError()); return 1; } int should_be_zero = SDL_GetCurrentDisplayMode(d_sel, &d_mode); if(should_be_zero != 0) SDL_Log("Could not get display mode for video display #%d: %s", d_sel, SDL_GetError()); else if(SDL_GetDisplayBounds(d_sel, &d_bounds) != 0) { SDL_Log("SDL_GetDisplayBounds failed: %s", SDL_GetError()); return 1; } win = SDL_CreateWindow ( "An SDL2 win", d_bounds.x, d_bounds.y, d_bounds.w, d_bounds.h, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE ); if(win == NULL) { SDL_Log("Could not create window: %s\n", SDL_GetError()); return 1; } rend = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED); if(rend == NULL) { SDL_Log("Could not create renerer: %s\n", SDL_GetError()); return 1; } return 0; }/*}}}*/
static void video_discover_displays( ) { int i, j, num_modes; struct rectangle bounds; video_num_displays = SDL_GetNumVideoDisplays( ); video_displays = (struct video_display*)SDL_calloc( video_num_displays, sizeof(struct video_display) ); for ( i = 0; i < video_num_displays; ++i ) { SDL_GetDisplayBounds( i, (SDL_Rect*)&video_displays[i].location ); //SDL_GetDisplayDPI( i, &video_displays[i].dpi[0], &video_displays[i].dpi[1], &video_displays[i].dpi[2] ); video_displays[i].num_modes = SDL_GetNumDisplayModes( i ); video_displays[i].modes = (struct video_mode*)SDL_calloc( video_displays[i].num_modes, sizeof(struct video_mode) ); for ( j = 0; j < video_displays[i].num_modes; ++j ) { SDL_GetDisplayMode( i, j, (SDL_DisplayMode*)&video_displays[i].modes[j] ); } } }
bool FLinuxWindow::GetFullScreenInfo( int32& X, int32& Y, int32& Width, int32& Height ) const { SDL_Rect DisplayRect; int DisplayIdx = SDL_GetWindowDisplayIndex(HWnd); if (DisplayIdx >= 0 && SDL_GetDisplayBounds(DisplayIdx, &DisplayRect) == 0) { X = DisplayRect.x; Y = DisplayRect.y; Width = DisplayRect.w; Height = DisplayRect.h; return true; } return false; }
rect sdl_basic_services::desktop_rect(uint32_t aDisplayIndex) const { iDesktopWorkAreas.clear(); #ifdef WIN32 EnumDisplayMonitors(NULL, NULL, &enum_display_monitors_proc, reinterpret_cast<LPARAM>(this)); #else for (int i = 0; i < display_count(); ++i) { SDL_Rect rectDisplayBounds; SDL_GetDisplayBounds(i, &rectDisplayBounds); iDesktopWorkAreas.push_back(rect{ point{ rectDisplayBounds.x, rectDisplayBounds.y }, size{ rectDisplayBounds.w, rectDisplayBounds.h } }); } #endif if (aDisplayIndex >= iDesktopWorkAreas.size()) throw bad_display_index(); return iDesktopWorkAreas[aDisplayIndex]; }