void Viewport::render(SDL_Renderer& ren, int x, int y, SDL_Rect* extent){ SDL_Rect old_clip; SDL_Rect new_clip = { x ,//+ extent->x, y ,//+ extent->y, extent->w, extent->h }; SDL_RenderGetClipRect(&ren, &old_clip); SDL_RenderSetClipRect(&ren, &new_clip); SDL_Rect target_extent = { camera_coords.x() + extent->x, camera_coords.y() + extent->y, extent->w, extent->h }; this->wrappee->render(ren, x, y, &target_extent); this->render_viewport_children(ren, x, y, extent); SDL_Rect rect = { x - extent->x, y - extent->y, viewport_coord().w(), viewport_coord().h() }; if(has_focus()){ Util::render_rectangle(&ren, &rect, Util::colour_orange()); } else{ Util::render_rectangle(&ren, &rect, Util::colour_black()); } SDL_RenderSetClipRect(&ren, &old_clip); }
void bmx_SDL_RenderGetClipRect(SDL_Renderer * renderer, int * x, int * y, int * w, int * h) { SDL_Rect r; SDL_RenderGetClipRect(renderer, &r); *x = r.x; *y = r.y; *w = r.w; *h = r.h; }
void SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done) { int i; static SDL_MouseMotionEvent lastEvent; if (state->verbose & VERBOSE_EVENT) { SDLTest_PrintEvent(event); } switch (event->type) { case SDL_WINDOWEVENT: switch (event->window.event) { case SDL_WINDOWEVENT_CLOSE: { SDL_Window *window = SDL_GetWindowFromID(event->window.windowID); if (window) { SDL_DestroyWindow(window); } } break; } break; case SDL_KEYDOWN: switch (event->key.keysym.sym) { /* Add hotkeys here */ case SDLK_PRINTSCREEN: { SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { for (i = 0; i < state->num_windows; ++i) { if (window == state->windows[i]) { SDLTest_ScreenShot(state->renderers[i]); } } } } break; case SDLK_EQUALS: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-+ double the size of the window */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { int w, h; SDL_GetWindowSize(window, &w, &h); SDL_SetWindowSize(window, w*2, h*2); } } break; case SDLK_MINUS: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-- half the size of the window */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { int w, h; SDL_GetWindowSize(window, &w, &h); SDL_SetWindowSize(window, w/2, h/2); } } break; case SDLK_c: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-C copy awesome text! */ SDL_SetClipboardText("SDL rocks!\nYou know it!"); printf("Copied text to clipboard\n"); } if (event->key.keysym.mod & KMOD_ALT) { /* Alt-C toggle a render clip rectangle */ for (i = 0; i < state->num_windows; ++i) { int w, h; if (state->renderers[i]) { SDL_Rect clip; SDL_GetWindowSize(state->windows[i], &w, &h); SDL_RenderGetClipRect(state->renderers[i], &clip); if (SDL_RectEmpty(&clip)) { clip.x = w/4; clip.y = h/4; clip.w = w/2; clip.h = h/2; SDL_RenderSetClipRect(state->renderers[i], &clip); } else { SDL_RenderSetClipRect(state->renderers[i], NULL); } } } } break; case SDLK_v: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-V paste awesome text! */ char *text = SDL_GetClipboardText(); if (*text) { printf("Clipboard: %s\n", text); } else { printf("Clipboard is empty\n"); } SDL_free(text); } break; case SDLK_g: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-G toggle grab */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { SDL_SetWindowGrab(window, !SDL_GetWindowGrab(window) ? SDL_TRUE : SDL_FALSE); } } break; case SDLK_m: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-M maximize */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { Uint32 flags = SDL_GetWindowFlags(window); if (flags & SDL_WINDOW_MAXIMIZED) { SDL_RestoreWindow(window); } else { SDL_MaximizeWindow(window); } } } break; case SDLK_r: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-R toggle mouse relative mode */ SDL_SetRelativeMouseMode(!SDL_GetRelativeMouseMode() ? SDL_TRUE : SDL_FALSE); } break; case SDLK_z: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-Z minimize */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { SDL_MinimizeWindow(window); } } break; case SDLK_RETURN: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-Enter toggle fullscreen */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { Uint32 flags = SDL_GetWindowFlags(window); if (flags & SDL_WINDOW_FULLSCREEN) { SDL_SetWindowFullscreen(window, SDL_FALSE); } else { SDL_SetWindowFullscreen(window, SDL_TRUE); } } } else if (event->key.keysym.mod & KMOD_ALT) { /* Alt-Enter toggle fullscreen desktop */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { Uint32 flags = SDL_GetWindowFlags(window); if (flags & SDL_WINDOW_FULLSCREEN) { SDL_SetWindowFullscreen(window, SDL_FALSE); } else { SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); } } } break; case SDLK_b: if (event->key.keysym.mod & KMOD_CTRL) { /* Ctrl-B toggle window border */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { const Uint32 flags = SDL_GetWindowFlags(window); const SDL_bool b = ((flags & SDL_WINDOW_BORDERLESS) != 0) ? SDL_TRUE : SDL_FALSE; SDL_SetWindowBordered(window, b); } } break; case SDLK_0: if (event->key.keysym.mod & KMOD_CTRL) { SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Test Message", "You're awesome!", window); } break; case SDLK_1: if (event->key.keysym.mod & KMOD_CTRL) { FullscreenTo(0, event->key.windowID); } break; case SDLK_2: if (event->key.keysym.mod & KMOD_CTRL) { FullscreenTo(1, event->key.windowID); } break; case SDLK_ESCAPE: *done = 1; break; case SDLK_SPACE: { char message[256]; SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); SDL_snprintf(message, sizeof(message), "(%i, %i), rel (%i, %i)\n", lastEvent.x, lastEvent.y, lastEvent.xrel, lastEvent.yrel); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Last mouse position", message, window); break; } default: break; } break; case SDL_QUIT: *done = 1; break; case SDL_MOUSEMOTION: lastEvent = event->motion; break; } }
static void KWSDL_getClipRect(KW_RenderDriver * driver, KW_Rect * clip) { SDL_Rect c; SDL_RenderGetClipRect(((KWSDL *)driver->priv)->renderer, &c); clip->x = c.x; clip->y = c.y; clip->w = c.w; clip->h = c.h; }
void SdlBaseContainerView::Render() { if (!model.IsVisible() || model.IsEmpty()) return; SDL_Renderer *renderer = display.GetRenderer(); //TODO: Currently, we assume that the render target is the whole screen. SDL_Texture *oldRenderTarget = nullptr; if (rttTarget) { oldRenderTarget = SDL_GetRenderTarget(renderer); SDL_SetRenderTarget(renderer, rttTarget->Get()); SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); SDL_RenderClear(renderer); } bool clip = model.IsClip(); SDL_Rect oldClip = { 0, 0, 0, 0 }; if (clip) { // Translate our bounds into screen-space. Vec2 pos = display.LayoutUiPosition( model.GetAlignedPos(model.GetSize().x, model.GetSize().y)); const Vec2 &size = model.GetSize(); double w = size.x; double h = size.y; if (!model.IsLayoutUnscaled()) { double uiScale = display.GetUiScale(); w *= uiScale; h *= uiScale; } screenPos = pos; screenSize.x = w; screenSize.y = h; SDL_RenderGetClipRect(renderer, &oldClip); SDL_Rect ourClip = { static_cast<int>(pos.x), static_cast<int>(pos.y), static_cast<int>(w), static_cast<int>(h) }; SDL_Rect clipRect = { 0, 0, 0, 0 }; // If there's an existing clip area, then set the clip rect to be // the intersection of the two areas. if (oldClip.w == 0 || oldClip.h == 0) { clipRect = ourClip; } else { if (!SDL_IntersectRect(&oldClip, &ourClip, &clipRect)) { // If there's no intersection, set a tiny off-screen rect so // the existing clip area check still works. clipRect.x = -1; clipRect.y = -1; clipRect.w = 1; clipRect.h = 1; } } SDL_RenderSetClipRect(renderer, &clipRect); } const Vec2 &size = model.GetSize(); Vec2 origin = model.GetAlignedPos(size.x, size.y); origin += model.GetChildOffset(); Vec2 oldOrigin = display.AddUiOrigin(origin); auto oldFlags = display.AddUiLayoutFlags(model.GetLayoutFlags()); model.ForEachVisibleChild(std::mem_fn(&ViewModel::Render)); display.SetUiLayoutFlags(oldFlags); display.SetUiOrigin(oldOrigin); if (clip) { SDL_RenderSetClipRect(renderer, &oldClip); } if (rttTarget) { SDL_SetRenderTarget(renderer, oldRenderTarget); // Draw the render target with the selected opacity. SDL_Texture *tex = rttTarget->Get(); SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND); SDL_SetTextureAlphaMod(tex, static_cast<MR_UInt8>(255.0 * model.GetOpacity())); SDL_SetTextureColorMod(tex, 0xff, 0xff, 0xff); SDL_RenderCopy(renderer, tex, nullptr, nullptr); } }
SDL_Rect renderer::clipRect(renderer::DrawContext c){ register DrawContextPrivate* context = (DrawContextPrivate*)c; SDL_Rect r; SDL_RenderGetClipRect(context->renderer,&r); return r; }