added views and temp circlefill
This commit is contained in:
parent
1354d7c915
commit
5750185bd8
2 changed files with 94 additions and 0 deletions
59
include/arc/graphics/view.h
Normal file
59
include/arc/graphics/view.h
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
#ifndef ARC_GRAPHICS_VIEW_H_
|
||||||
|
#define ARC_GRAPHICS_VIEW_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "arc/graphics/renderer.h"
|
||||||
|
#include "arc/math/rectangle.h"
|
||||||
|
|
||||||
|
typedef struct ARC_View {
|
||||||
|
ARC_Renderer *renderer;
|
||||||
|
ARC_Rect bounds;
|
||||||
|
} ARC_View;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief a function for ARC_View where contents of the function will be rendered within a view
|
||||||
|
*
|
||||||
|
* @param data data to be used within ARC_View_RenderFn
|
||||||
|
*/
|
||||||
|
typedef void (* ARC_View_RenderFn)(void *data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief creates ARC_View type
|
||||||
|
*
|
||||||
|
* @param view ARC_View to initialize
|
||||||
|
* @param renderer ARC_Renderer the view will render to
|
||||||
|
* @param bounds ARC_Rect bounds of the view within the renderer
|
||||||
|
*/
|
||||||
|
void ARC_View_Create(ARC_View **view, ARC_Renderer *renderer, ARC_Rect bounds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief destroys ARC_View type
|
||||||
|
*/
|
||||||
|
void ARC_View_Destroy(ARC_View *view);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief renders callbacks contents within an ARC_View
|
||||||
|
*
|
||||||
|
* @param view ARC_View to be renedered to
|
||||||
|
* @param renderFn function which contents will render to given ARC_View
|
||||||
|
* @param data data to be used in renderFn
|
||||||
|
*/
|
||||||
|
void ARC_View_Render(ARC_View *view, ARC_View_RenderFn renderFn, void *data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief gets bounds from ARC_View type
|
||||||
|
*
|
||||||
|
* @param view ARC_View to get bounds from
|
||||||
|
*
|
||||||
|
* @return bounds of the view
|
||||||
|
*/
|
||||||
|
ARC_Rect ARC_View_GetBounds(ARC_View *view);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // !ARC_GRAPHICS_VIEW_H_
|
||||||
35
src/graphics/sdl/view.c
Normal file
35
src/graphics/sdl/view.c
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
#include "arc/graphics/view.h"
|
||||||
|
|
||||||
|
#include "arc/std/errno.h"
|
||||||
|
#include <SDL.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void ARC_View_Create(ARC_View **view, ARC_Renderer *renderer, ARC_Rect bounds){
|
||||||
|
*view = (ARC_View *)malloc(sizeof(ARC_View));
|
||||||
|
(*view)->renderer = renderer;
|
||||||
|
(*view)->bounds = bounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ARC_View_Destroy(ARC_View *view){
|
||||||
|
free(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ARC_View_Render(ARC_View *view, ARC_View_RenderFn renderFn, void *data){
|
||||||
|
int err = SDL_RenderSetViewport((SDL_Renderer *)view->renderer, (const SDL_Rect *)&(view->bounds));
|
||||||
|
if(err){
|
||||||
|
ARC_DEBUG_LOG(ARC_ERRNO_DATA, "in src/graphics/sdl/view.c ARC_View_Render(view, renderFn), SDL_RenderSetViewport(...) returned: %d", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderFn(data);
|
||||||
|
|
||||||
|
err = SDL_RenderSetViewport((SDL_Renderer *)view->renderer, NULL);
|
||||||
|
if(err){
|
||||||
|
ARC_DEBUG_LOG(ARC_ERRNO_DATA, "in src/graphics/sdl/view.c ARC_View_Render(view, NULL), SDL_RenderSetViewport(...) returned: %d", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ARC_Rect ARC_View_GetBounds(ARC_View *view){
|
||||||
|
return view->bounds;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue