51 lines
1.5 KiB
C
51 lines
1.5 KiB
C
#include "arc/console/buffer/view.h"
|
|
|
|
#include "arc/console/view.h"
|
|
#include "arc/math/point.h"
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
|
|
struct ARC_ConsoleViewBuffer {
|
|
ARC_Point bounds;
|
|
char **buffer;
|
|
};
|
|
|
|
void ARC_ConsoleViewBuffer_Create(ARC_ConsoleViewBuffer **buffer, ARC_ConsoleView *view){
|
|
*buffer = (ARC_ConsoleViewBuffer *)malloc(sizeof(ARC_ConsoleViewBuffer));
|
|
|
|
ARC_Rect viewBounds = ARC_ConsoleView_GetBounds(view);
|
|
(*buffer)->bounds = (ARC_Point){ viewBounds.w - viewBounds.x, viewBounds.h - viewBounds.y };
|
|
|
|
//create the buffer array
|
|
(*buffer)->buffer = (char **)malloc(sizeof(char *) * (*buffer)->bounds.y);
|
|
for(int32_t y = 0; y < (*buffer)->bounds.y ; y++){
|
|
(*buffer)->buffer[y] = (char *)malloc(sizeof(char) * (*buffer)->bounds.x);
|
|
}
|
|
|
|
ARC_ConsoleViewBuffer_Clear(*buffer);
|
|
}
|
|
|
|
void ARC_ConsoleViewBuffer_Destroy(ARC_ConsoleViewBuffer *buffer){
|
|
for(int32_t y = 0; y < buffer->bounds.y; y++){
|
|
free(buffer->buffer[y]);
|
|
}
|
|
|
|
free(buffer->buffer);
|
|
free(buffer);
|
|
}
|
|
|
|
void ARC_ConsoleViewBuffer_Clear(ARC_ConsoleViewBuffer *buffer){
|
|
for(int32_t y = 0; y < buffer->bounds.y ; y++){
|
|
for(int32_t x = 0; x < buffer->bounds.x; x++){
|
|
buffer->buffer[y][x] = ' ';
|
|
}
|
|
}
|
|
}
|
|
|
|
void ARC_ConsoleViewBuffer_Render(ARC_ConsoleViewBuffer *buffer, ARC_ConsoleView *view){
|
|
for(int32_t y = 0; y < buffer->bounds.y ; y++){
|
|
for(int32_t x = 0; x < buffer->bounds.x; x++){
|
|
ARC_ConsoleView_RenderCharAt(view, buffer->buffer[y][x], (ARC_Point){ x, y });
|
|
}
|
|
}
|
|
}
|