Esempio n. 1
0
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);
}
Esempio n. 2
0
File: glue.c Progetto: GWRon/sdl.mod
int bmx_SDL_RenderSetClipRect(SDL_Renderer * renderer, int x, int y, int w, int h) {
	if (x < 0 || y < 0 || w < 0 || h < 0) {
		return SDL_RenderSetClipRect(renderer, 0);
	} else {
		SDL_Rect r = { x, y, w, h };
		return SDL_RenderSetClipRect(renderer, &r);
	}
}
Esempio n. 3
0
void Painter::setClip(SDL_Rect clip) {
	status.clip = clip;
	if (clip.w > 0 && clip.h > 0) {
		SDL_RenderSetClipRect(renderer, &clip);
	} else {
		SDL_RenderSetClipRect(renderer, NULL);
	}
}
Esempio n. 4
0
void SdlEngine::draw(const Picture &picture, const int dx, const int dy, Rect* clipRect )
{
  if( !picture.isValid() )
      return;

  int t = DateTime::elapsedTime();
  _d->drawCall++;

  if( clipRect != 0 )
  {
    SDL_Rect r = { clipRect->left(), clipRect->top(), clipRect->width(), clipRect->height() };
    SDL_RenderSetClipRect( _d->renderer, &r );
  }

  const Impl::MaskInfo& mask = _d->mask;
  SDL_Texture* ptx = picture.texture();
  const Rect& orect = picture.originRect();
  Size picSize = orect.size();
  const Point& offset = picture.offset();

  if( mask.enabled )
  {
    SDL_SetTextureColorMod( ptx, mask.red >> 16, mask.green >> 8, mask.blue );
    SDL_SetTextureAlphaMod( ptx, mask.alpha >> 24 );
  }
Esempio n. 5
0
void Painter::setClip(int x, int y, int w, int h) {
	status.clip.x = x;
	status.clip.y = y;
	status.clip.w = w;
	status.clip.h = h;

	SDL_RenderSetClipRect(renderer, &status.clip);
}
Esempio n. 6
0
void Painter::removeClip() {
	status.clip.w = 0;
	status.clip.x = 0;
	status.clip.y = 0;
	status.clip.h = 0;

	SDL_RenderSetClipRect(renderer, NULL);
}
Esempio n. 7
0
void SDLRenderer::impl::setClipRect(int x, int y, int w, int h)
{
	SDL_Rect cr;
	cr.x = x;
	cr.y = y;
	cr.w = w;
	cr.h = h;
	SDL_RenderSetClipRect(ren, &cr);
}
Esempio n. 8
0
void drawMedalsMenu()
{
	int i;
	SDL_Rect rect;

	drawImage(menu.background, menu.x, menu.y, FALSE, 196);

	rect.x = menu.x + 5;
	rect.y = menu.y + 5;
	rect.w = menu.w;
	rect.h = menu.h;

	SDL_RenderSetClipRect(game.renderer, &rect);

	for (i=0;i<menu.widgetCount;i++)
	{
		drawWidget(menu.widgets[i], &menu, -1);
	}

	SDL_RenderSetClipRect(game.renderer, NULL);
}
Esempio n. 9
0
void SDLRenderer::setClipRect(const Rect* const rect) {
    if (rect != nullptr) {
#if SDL_VERSION_ATLEAST(2, 0, 4) || defined(WINDOWS)
        SDL_Rect sdlRect = { rect->x, rect->y, rect->w, rect->h };
#else
        /* Workaround für Bug in SDL (bis v2.0.3)
         * @see https://bugzilla.libsdl.org/show_bug.cgi?id=2700
         *
         * SDL misst das Rechteck unter Linux von UNTEN. Unter Windows verhält sich SDL_RenderSetClipRect() wie erwartet.
         * Problem ist, dass SDL nicht korrekt vom OpenGL-Koordinatensystem abstrahiert und das hat den Nullpunkt
         * unten-links.
         */
        int fixedY = getWindowHeight() - (rect->y + rect->h);
        SDL_Rect sdlRect = { rect->x, fixedY, rect->w, rect->h };
#endif

        SDL_RenderSetClipRect(renderer, &sdlRect);
    } else {
        SDL_RenderSetClipRect(renderer, nullptr);
    }
}
Esempio n. 10
0
static void KWSDL_setClipRect(KW_RenderDriver * driver, const KW_Rect * clip, int force) {
  SDL_Renderer * renderer = ((KWSDL *)driver->priv)->renderer;
  SDL_Rect viewport, cliprect;
  static SDL_RendererInfo info;
  static int isopengl = -1;
  cliprect.x = clip->x; cliprect.y = clip->y; cliprect.w = clip->w; cliprect.h = clip->h;
  if (isopengl < 0) {
    SDL_GetRendererInfo(renderer, &info);
    isopengl = (strcmp(info.name, "opengl") >= 0) ? 1 : 0;
  }

  if (isopengl && !force) {
    /* fix for SDL buggy opengl scissor test. See SDL bug 2269.
     * Not sure about other renderers. */
    SDL_RenderGetViewport(renderer, &viewport);
    cliprect.x += viewport.x;  cliprect.y -= viewport.y;
  }

  if (KW_IsRectEmpty((*clip)))
    SDL_RenderSetClipRect(renderer, NULL);
  else
    SDL_RenderSetClipRect(renderer, &cliprect);
}
Esempio n. 11
0
		void DoRender()
		{
			//Primer
			SDL_RenderSetClipRect(s_sdlRen, null);//clear out any scissor rects
			SDL_Color background = util::Color::other::AUBURN.SDL();
			background.r = background.g = background.b = 76;
			background.a = 255;
			SDL_SetRenderDrawColor(s_sdlRen, background.r, background.g, background.b, background.a);
			SDL_SetRenderTarget(s_sdlRen, NULL);
			SDL_RenderClear(s_sdlRen);

			util::math::Type2<int> logical_size;
			SDL_GetRendererOutputSize(s_sdlRen, &logical_size.w, &logical_size.h);
			util::math::Type2<int> half_size = logical_size / 2;
			util::math::vec2 origin(logical_size.x * 0.5f, logical_size.y * 0.5f);

			//RenderGrid(half_size);
			RenderCrossSection(logical_size);
			
			SDL_SetRenderDrawColor(s_sdlRen, 32, 32, 32, 255);

			//	render::CRenderNodeLine line;
			//	line.SetColor(util::Color::WHITE.SDL());
			//	util::shape::Segment seg;
			//	seg.start = node.GetAABB().m_max;
			//	seg.end = node.GetAABB().m_min;
			//	line.SetLine(seg);


			////	const util::Time t = util::Time::GetTimeSinceEpoch();

			//	util::math::Matrix2D cam =util::math::Matrix2D(vec2(0,0), vec2(1,1), 0);
			//	const util::math::Matrix2D inv_cam = util::math::Matrix2D::Matrix_Inverse(cam);

			//	//node(s_sdlRen, inv_cam);
			//	line(s_sdlRen, inv_cam);
			//	node.SetAABB(line.CalcAABB());
			//	node(s_sdlRen, inv_cam);

			CRenderLayer::RenderAllLayers(s_sdlRen);

			//Present
			SDL_RenderPresent(s_sdlRen);
		}
Esempio n. 12
0
 void SDL2Renderer::StartClip()
 {
     const Gwen::Rect &rect = ClipRegion();
     const SDL_Rect clip = { rect.x,rect.y, rect.w,rect.h };
     SDL_RenderSetClipRect(m_renderer, &clip);
 }
Esempio n. 13
0
void SDLRenderer::impl::resetClipRect()
{
	SDL_RenderSetClipRect(ren, NULL);
}
Esempio n. 14
0
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);
	}
}
Esempio n. 15
0
 void SDL2Renderer::EndClip()
 {
     SDL_RenderSetClipRect(m_renderer, NULL);
 }
Esempio n. 16
0
void renderer::setClipRect(renderer::DrawContext c, SDL_Rect *r){
    register DrawContextPrivate* context = (DrawContextPrivate*)c;
    SDL_RenderSetClipRect(context->renderer,r);
}
Esempio n. 17
0
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;
    }
}
void View_Game_Trade_Dialog::render(){
	// TODO: this is repeated code.
	int x_offset = 0;
	int y_offset = 0;
	SDL_Rect rect = { 0, 0, 0, 0 };
	SDL_Color colour = { 180, 90, 0, 255 };
	std::string resource_strings[5] = {"Bricks:", "Ore:", "Sheep:", "Wheat:", "Wood:"};
	SDL_Rect pane_rect = { this->x, this->y, this->w, this->h };

	// TODO: This might be a little ineffienct, clearing and drawing
	// the area again, but we will see.
	SDL_RenderSetClipRect(&view.ren, &new_clip);
	SDL_RenderClear(&view.ren);
	//SDL_RenderSetClipRect(&view.ren, &old_clip);

	// -- -- -- -- --  L E F T  -- -- -- -- -- -- --
	// render the player's name
	int player_num = _model->get_current_player();
	Player* p = _model->get_player(player_num);
	if(p != nullptr){
		Util::render_text(&view.ren, font_carbon_12, 5 + this->x, 5 + this->y, font_carbon_12_colour,
			"%d : %s", player_num, p->name.c_str());
	}


	// render the text fields and labels
	rect = { this->x+1 , this->y+1, this->w / 2-1, this->h -1};
	Util::render_rectangle(&view.ren, &rect, Util::colour_green());
	x_offset = 0;
	y_offset = 0;
	for(int i = 0; i < (int)left_textfields.size(); ++i){
		x_offset = this->x;
		y_offset = this->y  + left_textfields[i]->y;
		Util::render_text(&view.ren, font_carbon_12,x_offset, y_offset, font_carbon_12_colour,
			"%s", resource_strings[i].c_str());
		
		left_textfields[i]->render(view.ren, *font_carbon_12, font_carbon_12_colour, pane_rect);
	}



	// -- - - - -- - R I G H T -- - - - -- - -
	// render the text fields and labels
	rect = { this->x + this->w / 2 + 1, this->y+1, this->w / 2-1, this->h -1};
	Util::render_rectangle(&view.ren, &rect, Util::colour_blue());
	x_offset = 0;
	y_offset = 0;
	for(int i = 0; i < (int)right_textfields.size(); ++i){
		x_offset = this->x + this->w/2;
		y_offset = this->y + right_textfields[i]->y;
		Util::render_text(&view.ren, font_carbon_12, x_offset, y_offset, font_carbon_12_colour,
			"%s", resource_strings[i].c_str());

		right_textfields[i]->render(view.ren, *font_carbon_12, font_carbon_12_colour, pane_rect);
	}

	// render the combo-box
	for(int i = 0; i < (int)right_dropdown_list.size(); ++i){
		right_dropdown_list[i]->render(view.ren, *font_carbon_12, font_carbon_12_colour, pane_rect);
	}

	// render the buttons
	std::vector<View_Game_Trade_Dialog_Button*>::iterator it;
	for(it = button_list.begin(); it != button_list.end(); ++it){
		rect = { 
			(*it)->x + this->x,
			(*it)->y + this->y - 5,
			(*it)->w, (*it)->h };

		if((*it)->hit_flag){
			Util::render_rectangle(&view.ren, &rect, Util::colour_blue());
		} else{
			Util::render_rectangle(&view.ren, &rect, Util::colour_green());
		}
		Util::render_text(&view.ren, font_carbon_12, rect.x, rect.y, font_carbon_12_colour, "%s", (*it)->text.c_str());
	}


	// draw a bounding box around the dialog.
	rect = { this->x, this->y, this->w, this->h };
	Util::render_rectangle(&view.ren, &rect, colour);

	SDL_RenderSetClipRect(&view.ren, &old_clip);
}
Esempio n. 19
0
void SDLFrontend::disableScissor ()
{
	assert(_renderer);
	SDL_RenderSetClipRect(_renderer, nullptr);
}
Esempio n. 20
0
void SDLFrontend::enableScissor (int x, int y, int width, int height)
{
	assert(_renderer);
	const SDL_Rect rect = {x, y, width, height};
	SDL_RenderSetClipRect(_renderer, &rect);
}