Last active
December 14, 2017 18:05
-
-
Save lincerely/033ebc9fe0cbb6209664e3c9a3e2abcc to your computer and use it in GitHub Desktop.
A function to render rectangle with width in SDL2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @brief Render rectangle with width | |
* @details It is created by overlapping two filled rects | |
* | |
* @param renderer current renderer | |
* @param dest Destination | |
* @param width Stroke width | |
* @param rR rectangle's color red component | |
* @param gR rectangle's color green component | |
* @param bR rectangle's color blue component | |
* @param aR rectangle's color alpha component | |
* @param rB background's color red component | |
* @param gB background's color green component | |
* @param bB background's color blue component | |
* @param aB background's color alpha component | |
*/ | |
void DrawRectWithWidth(SDL_Renderer *renderer, const SDL_Rect *dest, int width, | |
Uint8 rR, Uint8 gR, Uint8 bR, Uint8 aR, Uint8 rB, | |
Uint8 gB, Uint8 bB, Uint8 aB) | |
{ | |
// draw the positive color | |
SDL_Rect outter = (*dest); | |
outter.x -= width / 2; | |
outter.y -= width / 2; | |
outter.w += width; | |
outter.h += width; | |
SDL_Rect inner = (*dest); | |
inner.x += width / 2; | |
inner.y += width / 2; | |
inner.w -= width; | |
inner.h -= width; | |
SDL_SetRenderDrawColor(renderer, rR, gR, bR, aR); | |
SDL_RenderFillRect(renderer, &outter); | |
SDL_SetRenderDrawColor(renderer, rB, gB, bB, aB); | |
SDL_RenderFillRect(renderer, &inner); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment