generated from RISC-OS-Community/StandardRepoTemplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from pzaino/develop
Work in progress
- Loading branch information
Showing
7 changed files
with
339 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* This file is part of: | ||
* MicroFB, a minimal framebuffer library for RISC OS | ||
* | ||
* Description: | ||
* This project aims to provide a simple and efficient way to manage | ||
* the framebuffer on RISC OS using C++11. It abstracts the direct | ||
* interaction with the GraphicsV API, offering a higher-level | ||
* interface for drawing operations and framebuffer manipulation. | ||
* | ||
* Author: | ||
* Paolo Fabio Zaino, all rights reserved. | ||
* Distributed under License: | ||
* CDDL v1.1 (Common Development and Distribution License Version | ||
* 1.1) The use of this project is subject to the terms of the | ||
* CDDL v1.1. This project can be used and distributed according | ||
* to the terms of this license. For details on the CDDL v1.1, | ||
* please refer to the official license documentation. | ||
*/ | ||
|
||
#include "fb.hpp" | ||
#include "layer.hpp" // Ensure this is included if not already included in fb.hpp | ||
|
||
// Constructor | ||
FrameBuffer::FrameBuffer(unsigned int width, unsigned int height, std::shared_ptr<RenderStrategy> strategy) | ||
: width(width), height(height), renderStrategy(strategy) {} | ||
|
||
// Add a layer to the framebuffer | ||
void FrameBuffer::addLayer(const Layer& layer) { | ||
layers.push_back(layer); | ||
// Assuming Layer copy constructor or assignment operator handles the strategy correctly | ||
} | ||
|
||
// Remove a layer from the framebuffer by index | ||
void FrameBuffer::removeLayer(size_t index) { | ||
if (index < layers.size()) { | ||
layers.erase(layers.begin() + index); | ||
} | ||
} | ||
|
||
// Accessor for layer by index | ||
Layer& FrameBuffer::getLayer(size_t index) { | ||
// Simple bounds checking, throw std::out_of_range if index is invalid | ||
if (index >= layers.size()) { | ||
throw std::out_of_range("Layer index is out of range."); | ||
} | ||
return layers[index]; | ||
} | ||
|
||
// Set the render strategy for the framebuffer and all its layers | ||
void FrameBuffer::setRenderStrategy(std::shared_ptr<RenderStrategy> strategy) { | ||
renderStrategy = strategy; | ||
// Update the render strategy for all existing layers | ||
for (auto& layer : layers) { | ||
layer.setRenderStrategy(renderStrategy); | ||
} | ||
} | ||
|
||
// Placeholder for the actual implementation of merging all layers | ||
void FrameBuffer::mergeLayers() { | ||
// Implementation depends on how you want to combine the layers | ||
// This could involve blending pixels from each layer based on their opacity, | ||
// and visibility, or simply stacking them in order. | ||
// For simplicity, we're not providing a specific implementation here. | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* This file is part of: | ||
* MicroFB, a minimal framebuffer library for RISC OS | ||
* | ||
* Description: | ||
* This project aims to provide a simple and efficient way to manage | ||
* the framebuffer on RISC OS using C++11. It abstracts the direct | ||
* interaction with the GraphicsV API, offering a higher-level | ||
* interface for drawing operations and framebuffer manipulation. | ||
* | ||
* Author: | ||
* Paolo Fabio Zaino, all rights reserved. | ||
* Distributed under License: | ||
* CDDL v1.1 (Common Development and Distribution License Version | ||
* 1.1) The use of this project is subject to the terms of the | ||
* CDDL v1.1. This project can be used and distributed according | ||
* to the terms of this license. For details on the CDDL v1.1, | ||
* please refer to the official license documentation. | ||
*/ | ||
|
||
#include "layer.hpp" | ||
|
||
// Constructor implementation | ||
Layer::Layer(pixel_t width, pixel_t height, std::shared_ptr<RenderStrategy> strategy) | ||
: width(width), height(height), opacity(1.0f), visible(true), currentRenderStrategy(strategy) { | ||
pixels.resize(width * height, 0); // Initialize pixel buffer with default color (0) | ||
} | ||
|
||
// Destructor implementation | ||
Layer::~Layer() { | ||
// No manual resource management needed here due to use of smart pointers and vectors | ||
} | ||
|
||
// Clear the layer with a specific color | ||
void Layer::clear(color_t color) { | ||
currentRenderStrategy->clear(pixels, color); // Use the render strategy to clear the layer | ||
} | ||
|
||
// Direct pixel manipulation | ||
void Layer::setPixel(pixel_t x, pixel_t y, color_t color) { | ||
currentRenderStrategy->setPixel(pixels, x, y, color); // Use the render strategy to set the pixel | ||
} | ||
|
||
// Draw a line (placeholder for actual line drawing algorithm, e.g., Bresenham's) | ||
void Layer::drawLine(pixel_t x1, pixel_t y1, pixel_t x2, pixel_t y2, color_t color) { | ||
currentRenderStrategy->drawLine(pixels, x1, y1, x2, y2, color); // Use the render strategy to draw the line | ||
} | ||
|
||
// Draw a rectangle (simple example) | ||
void Layer::drawRect(pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color) { | ||
currentRenderStrategy->drawRect(pixels, x, y, w, h, color); // Use the render strategy to draw the rectangle | ||
} | ||
|
||
// Fill a rectangle | ||
void Layer::fillRect(pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color) { | ||
currentRenderStrategy->fillRect(pixels, x, y, w, h, color); // Use the render strategy to fill the rectangle | ||
} | ||
|
||
// Draw a circle | ||
void Layer::drawCircle(pixel_t x, pixel_t y, pixel_t r, color_t color) { | ||
currentRenderStrategy->drawCircle(pixels, x, y, r, color); // Use the render strategy to draw the circle | ||
} | ||
|
||
// Fill a circle | ||
void Layer::fillCircle(pixel_t x, pixel_t y, pixel_t r, color_t color) { | ||
currentRenderStrategy->fillCircle(pixels, x, y, r, color); // Use the render strategy to fill the circle | ||
} | ||
|
||
// Draw an ellipse | ||
void Layer::drawEllipse(pixel_t x, pixel_t y, pixel_t rx, pixel_t ry, color_t color) { | ||
currentRenderStrategy->drawEllipse(pixels, x, y, rx, ry, color); // Use the render strategy to draw the ellipse | ||
} | ||
|
||
// Fill an ellipse | ||
void Layer::fillEllipse(pixel_t x, pixel_t y, pixel_t rx, pixel_t ry, color_t color) { | ||
currentRenderStrategy->fillEllipse(pixels, x, y, rx, ry, color); // Use the render strategy to fill the ellipse | ||
} | ||
|
||
// Draw a polygon | ||
void Layer::drawPolygon(const std::vector<pixel_t>& points, color_t color) { | ||
currentRenderStrategy->drawPolygon(pixels, points, color); // Use the render strategy to draw the polygon | ||
} | ||
|
||
// Fill a polygon | ||
void Layer::fillPolygon(const std::vector<pixel_t>& points, color_t color) { | ||
currentRenderStrategy->fillPolygon(pixels, points, color); // Use the render strategy to fill the polygon | ||
} | ||
|
||
// Draw text | ||
void Layer::drawText(pixel_t x, pixel_t y, const char* text, color_t color) { | ||
currentRenderStrategy->drawText(pixels, x, y, text, color); // Use the render strategy to draw the text | ||
} | ||
|
||
// Draw an image | ||
void Layer::drawImage(pixel_t x, pixel_t y, const Layer& image) { | ||
currentRenderStrategy->drawImage(pixels, x, y, image); // Use the render strategy to draw the image | ||
} |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* This file is part of: | ||
* MicroFB, a minimal framebuffer library for RISC OS | ||
* | ||
* Description: | ||
* This project aims to provide a simple and efficient way to manage | ||
* the framebuffer on RISC OS using C++11. It abstracts the direct | ||
* interaction with the GraphicsV API, offering a higher-level | ||
* interface for drawing operations and framebuffer manipulation. | ||
* | ||
* Author: | ||
* Paolo Fabio Zaino, all rights reserved. | ||
* Distributed under License: | ||
* CDDL v1.1 (Common Development and Distribution License Version | ||
* 1.1) The use of this project is subject to the terms of the | ||
* CDDL v1.1. This project can be used and distributed according | ||
* to the terms of this license. For details on the CDDL v1.1, | ||
* please refer to the official license documentation. | ||
*/ | ||
|
||
#ifndef FB_HPP | ||
#define FB_HPP | ||
|
||
#include <vector> | ||
#include <memory> // For std::shared_ptr | ||
|
||
#include "layer.hpp" | ||
#include "render_strategy.hpp" | ||
|
||
class FrameBuffer { | ||
private: | ||
std::vector<Layer> layers; // Collection of layers | ||
std::shared_ptr<RenderStrategy> renderStrategy; // Shared rendering strategy | ||
unsigned int width, height; // Dimensions of the framebuffer | ||
|
||
public: | ||
// Constructor that initializes the framebuffer with dimensions and a rendering strategy | ||
FrameBuffer(unsigned int width, unsigned int height, std::shared_ptr<RenderStrategy> strategy) | ||
|
||
// Add a layer to the framebuffer | ||
void addLayer(const Layer& layer); | ||
|
||
// Remove a layer from the framebuffer by index | ||
void removeLayer(size_t index); | ||
|
||
// Accessor for layer by index | ||
Layer& getLayer(size_t index); | ||
|
||
// Set the render strategy for the framebuffer and all its layers | ||
void setRenderStrategy(std::shared_ptr<RenderStrategy> strategy); | ||
|
||
// Method to merge all layers - Placeholder for actual implementation | ||
void mergeLayers(); | ||
|
||
}; | ||
|
||
#endif // FB_HPP |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* This file is part of: | ||
* MicroFB, a minimal framebuffer library for RISC OS | ||
* | ||
* Description: | ||
* This project aims to provide a simple and efficient way to manage | ||
* the framebuffer on RISC OS using C++11. It abstracts the direct | ||
* interaction with the GraphicsV API, offering a higher-level | ||
* interface for drawing operations and framebuffer manipulation. | ||
* | ||
* Author: | ||
* Paolo Fabio Zaino, all rights reserved. | ||
* Distributed under License: | ||
* CDDL v1.1 (Common Development and Distribution License Version | ||
* 1.1) The use of this project is subject to the terms of the | ||
* CDDL v1.1. This project can be used and distributed according | ||
* to the terms of this license. For details on the CDDL v1.1, | ||
* please refer to the official license documentation. | ||
*/ | ||
|
||
#ifndef LAYER_HPP | ||
#define LAYER_HPP | ||
|
||
#include <vector> | ||
#include <cstdint> | ||
#include <memory> // For std::shared_ptr | ||
|
||
#include "render_strategy.hpp" | ||
|
||
typedef uint32_t color_t; // 32-bit color | ||
typedef uint32_t pixel_t; // 32-bit pixel, assuming it represents dimensions | ||
|
||
class Layer { | ||
private: | ||
std::shared_ptr<RenderStrategy> currentRenderStrategy; | ||
|
||
public: | ||
std::vector<color_t> pixels; // Pixel data for this layer | ||
float opacity; // Layer opacity | ||
bool visible; // Layer visibility | ||
pixel_t width, height; // Dimensions of the layer | ||
|
||
// Constructor and destructor | ||
Layer(pixel_t width, pixel_t height, std::shared_ptr<RenderStrategy> strategy); | ||
~Layer(); | ||
|
||
// Drawing operations | ||
void clear(color_t color); // Clear the layer with a specific color | ||
void setPixel(pixel_t x, pixel_t y, color_t color); // Direct pixel manipulation | ||
void drawLine(pixel_t x1, pixel_t y1, pixel_t x2, pixel_t y2, color_t color); // Draw a line | ||
void drawRect(pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color); // Draw a rectangle | ||
void fillRect(pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color); // Fill a rectangle | ||
void drawCircle(pixel_t x, pixel_t y, pixel_t r, color_t color); // Draw a circle | ||
void fillCircle(pixel_t x, pixel_t y, pixel_t r, color_t color); // Fill a circle | ||
void drawEllipse(pixel_t x, pixel_t y, pixel_t rx, pixel_t ry, color_t color); // Draw an ellipse | ||
void fillEllipse(pixel_t x, pixel_t y, pixel_t rx, pixel_t ry, color_t color); // Fill an ellipse | ||
void drawPolygon(const std::vector<pixel_t>& points, color_t color); // Draw a polygon | ||
void fillPolygon(const std::vector<pixel_t>& points, color_t color); // Fill a polygon | ||
void drawText(pixel_t x, pixel_t y, const char* text, color_t color); // Draw text | ||
void drawImage(pixel_t x, pixel_t y, const Layer& image); // Draw an image | ||
}; | ||
|
||
#endif // LAYER_HPP |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* This file is part of: | ||
* MicroFB, a minimal framebuffer library for RISC OS | ||
* | ||
* Description: | ||
* This project aims to provide a simple and efficient way to manage | ||
* the framebuffer on RISC OS using C++11. It abstracts the direct | ||
* interaction with the GraphicsV API, offering a higher-level | ||
* interface for drawing operations and framebuffer manipulation. | ||
* | ||
* Author: | ||
* Paolo Fabio Zaino, all rights reserved. | ||
* Distributed under License: | ||
* CDDL v1.1 (Common Development and Distribution License Version | ||
* 1.1) The use of this project is subject to the terms of the | ||
* CDDL v1.1. This project can be used and distributed according | ||
* to the terms of this license. For details on the CDDL v1.1, | ||
* please refer to the official license documentation. | ||
*/ | ||
|
||
#ifndef RENDERSTRATEGY_HPP | ||
#define RENDERSTRATEGY_HPP | ||
|
||
#include <memory> | ||
#include <vector> | ||
#include <cstdint> // For pixel_t and color_t types | ||
|
||
// Forward declaration of Layer to resolve circular dependency | ||
class Layer; | ||
|
||
typedef uint32_t color_t; // 32-bit color, assuming it represents ARGB or similar | ||
typedef uint32_t pixel_t; // 32-bit pixel, for dimensions | ||
|
||
class RenderStrategy { | ||
public: | ||
virtual ~RenderStrategy() {} | ||
|
||
// Pure virtual functions for rendering operations | ||
virtual void setPixel(Layer& layer, pixel_t x, pixel_t y, color_t color) = 0; | ||
virtual void drawLine(Layer& layer, pixel_t x1, pixel_t y1, pixel_t x2, pixel_t y2, color_t color) = 0; | ||
virtual void drawRect(Layer& layer, pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color) = 0; | ||
virtual void fillRect(Layer& layer, pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color) = 0; | ||
virtual void drawCircle(Layer& layer, pixel_t x, pixel_t y, pixel_t r, color_t color) = 0; | ||
virtual void fillCircle(Layer& layer, pixel_t x, pixel_t y, pixel_t r, color_t color) = 0; | ||
virtual void drawEllipse(Layer& layer, pixel_t x, pixel_t y, pixel_t rx, pixel_t ry, color_t color) = 0; | ||
virtual void fillEllipse(Layer& layer, pixel_t x, pixel_t y, pixel_t rx, pixel_t ry, color_t color) = 0; | ||
virtual void drawPolygon(Layer& layer, const std::vector<pixel_t>& points, color_t color) = 0; | ||
virtual void fillPolygon(Layer& layer, const std::vector<pixel_t>& points, color_t color) = 0; | ||
virtual void drawText(Layer& layer, pixel_t x, pixel_t y, const char* text, color_t color) = 0; | ||
virtual void drawImage(Layer& layer, pixel_t x, pixel_t y, const Layer& image) = 0; | ||
|
||
// Additional methods for setup, teardown, or state management can be added here | ||
}; | ||
|
||
#endif // RENDERSTRATEGY_HPP |