diff --git a/.gitignore b/.gitignore index 8cea25d..c69b9a1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,7 @@ *.orig .DS_Store ux-src/ +**/o/ +**/*.o +**/*.a diff --git a/src/cpp/fb b/src/cpp/fb index 8207609..b9914ac 100644 --- a/src/cpp/fb +++ b/src/cpp/fb @@ -35,7 +35,8 @@ FrameBuffer::FrameBuffer(unsigned int h_dim, unsigned int v_dim, std::shared_ptr : renderStrategy(strategy), width(h_dim), height(v_dim) {} // Add a layer to the framebuffer -void FrameBuffer::addLayer(const std::shared_ptr& layer) { +void FrameBuffer::addLayer(const std::shared_ptr& layer) +{ layers.push_back(layer); } @@ -45,19 +46,22 @@ void FrameBuffer::addLayer(std::shared_ptr&& layer) { } // Add a layer to the framebuffer -void FrameBuffer::addLayer() { +void FrameBuffer::addLayer() +{ layers.push_back(std::make_shared(width, height, renderStrategy, currentMemoryManager)); } // Remove a layer from the framebuffer by index -void FrameBuffer::removeLayer(size_t index) { +void FrameBuffer::removeLayer(size_t index) +{ if (index < layers.size()) { layers.erase(layers.begin() + index); } } // Accessor for layer by index -std::shared_ptr FrameBuffer::getLayer(size_t index) const { +std::shared_ptr FrameBuffer::getLayer(size_t index) const +{ // 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."); @@ -66,7 +70,8 @@ std::shared_ptr FrameBuffer::getLayer(size_t index) const { } // Set the render strategy for the framebuffer and all its layers -void FrameBuffer::setRenderStrategy(std::shared_ptr strategy) { +void FrameBuffer::setRenderStrategy(std::shared_ptr strategy) +{ renderStrategy = strategy; // Update the render strategy for all existing layers for (auto& layer : layers) { @@ -75,7 +80,8 @@ void FrameBuffer::setRenderStrategy(std::shared_ptr strategy) { } // Set the memory manager for the framebuffer and all its layers -void FrameBuffer::setMemoryManager(std::shared_ptr manager) { +void FrameBuffer::setMemoryManager(std::shared_ptr manager) +{ currentMemoryManager = manager; // Update the memory manager for all existing layers for (auto& layer : layers) { @@ -84,7 +90,8 @@ void FrameBuffer::setMemoryManager(std::shared_ptr manager) { } // Placeholder for the actual implementation of merging all layers -void FrameBuffer::mergeLayers() { +void FrameBuffer::mergeLayers() +{ // This could involve blending pixels from each layer based on their opacity, // and visibility, or simply stacking them in order. // TODO: This is a placeholder for the actual implementation diff --git a/src/cpp/layer b/src/cpp/layer index 7a2a4a1..c1f639e 100644 --- a/src/cpp/layer +++ b/src/cpp/layer @@ -18,6 +18,7 @@ * please refer to the official license documentation. */ +#include #include // For std::shared_ptr // Include MicroFB libraries @@ -31,93 +32,126 @@ // Constructor implementation Layer::Layer(pixel_t width, pixel_t height, std::shared_ptr strategy, std::shared_ptr currMemoryManager) - : currentRenderStrategy(strategy), opacity(1.0f), visible(true), width(width), height(height) { - + : currentRenderStrategy(strategy), opacity(1.0f), visible(true), width(width), height(height) +{ if (currentMemoryManager == nullptr) { + if (currMemoryManager == nullptr) { + throw std::runtime_error("MemoryManager cannot be null"); + } currentMemoryManager = currMemoryManager; } // Initialize pixel buffer with default color (0) pixels = static_cast(currentMemoryManager->allocate(width * height * sizeof(color_t))); - } // Destructor implementation -Layer::~Layer() { +Layer::~Layer() +{ // Not much for now } // Set the render strategy -void Layer::setRenderStrategy(std::shared_ptr strategy) { - currentRenderStrategy = strategy; // Set the render strategy +void Layer::setRenderStrategy(std::shared_ptr strategy) +{ + // Set the render strategy + currentRenderStrategy = strategy; } // Set the memory manager -void Layer::setMemoryManager(std::shared_ptr manager) { - currentMemoryManager = manager; // Set the memory manager +void Layer::setMemoryManager(std::shared_ptr manager) +{ + // Set the memory manager + currentMemoryManager = manager; } // Clear the layer with a specific color -void Layer::clear(color_t color) { - currentRenderStrategy->clear(*this, color); // Use the render strategy to clear the layer +void Layer::clear(color_t color) +{ + // Use the render strategy to clear the layer + currentRenderStrategy->clear(*this, color); } // Direct pixel manipulation void Layer::setPixel(pixel_t x, pixel_t y, color_t color) { - currentRenderStrategy->setPixel(*this, x, y, color); // Use the render strategy to set the pixel + // Use the render strategy to set the pixel + currentRenderStrategy->setPixel(*this, x, y, color); } // Draw a line -void Layer::drawLine(pixel_t x1, pixel_t y1, pixel_t x2, pixel_t y2, color_t color) { - currentRenderStrategy->drawLine(*this, x1, y1, x2, y2, color); // Use the render strategy to draw the line +void Layer::drawLine(pixel_t x1, pixel_t y1, pixel_t x2, pixel_t y2, color_t color) +{ + // Use the render strategy to draw the line + currentRenderStrategy->drawLine(*this, x1, y1, x2, y2, color); } // Draw a rectangle -void Layer::drawRect(pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color) { - currentRenderStrategy->drawRect(*this, x, y, w, h, color); // Use the render strategy to draw the rectangle +void Layer::drawRect(pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color) +{ + // Use the render strategy to draw the rectangle + currentRenderStrategy->drawRect(*this, x, y, w, h, color); } // Fill a rectangle -void Layer::fillRect(pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color) { - currentRenderStrategy->fillRect(*this, x, y, w, h, color); // Use the render strategy to fill the rectangle +void Layer::fillRect(pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color) +{ + // Use the render strategy to fill the rectangle + currentRenderStrategy->fillRect(*this, x, y, w, h, color); } // Draw a circle -void Layer::drawCircle(pixel_t x, pixel_t y, pixel_t r, color_t color) { - currentRenderStrategy->drawCircle(*this, x, y, r, color); // Use the render strategy to draw the circle +void Layer::drawCircle(pixel_t x, pixel_t y, pixel_t r, color_t color) +{ + // Use the render strategy to draw the circle + currentRenderStrategy->drawCircle(*this, x, y, r, color); } // Fill a circle -void Layer::fillCircle(pixel_t x, pixel_t y, pixel_t r, color_t color) { - currentRenderStrategy->fillCircle(*this, x, y, r, color); // Use the render strategy to fill the circle +void Layer::fillCircle(pixel_t x, pixel_t y, pixel_t r, color_t color) +{ + // Use the render strategy to fill the circle + currentRenderStrategy->fillCircle(*this, x, y, r, color); } // Draw an ellipse -void Layer::drawEllipse(pixel_t x, pixel_t y, pixel_t rx, pixel_t ry, color_t color) { - currentRenderStrategy->drawEllipse(*this, x, y, rx, ry, color); // Use the render strategy to draw the ellipse +void Layer::drawEllipse(pixel_t x, pixel_t y, pixel_t rx, + pixel_t ry, color_t color) +{ + // Use the render strategy to draw the ellipse + currentRenderStrategy->drawEllipse(*this, x, y, rx, ry, color); } // Fill an ellipse -void Layer::fillEllipse(pixel_t x, pixel_t y, pixel_t rx, pixel_t ry, color_t color) { - currentRenderStrategy->fillEllipse(*this, x, y, rx, ry, color); // Use the render strategy to fill the ellipse +void Layer::fillEllipse(pixel_t x, pixel_t y, pixel_t rx, + pixel_t ry, color_t color) +{ + // Use the render strategy to fill the ellipse + currentRenderStrategy->fillEllipse(*this, x, y, rx, ry, color); } // Draw a polygon void Layer::drawPolygon(const std::vector& points, color_t color) { - currentRenderStrategy->drawPolygon(*this, points, color); // Use the render strategy to draw the polygon + // Use the render strategy to draw the polygon + currentRenderStrategy->drawPolygon(*this, points, color); } // Fill a polygon -void Layer::fillPolygon(const std::vector& points, color_t color) { - currentRenderStrategy->fillPolygon(*this, points, color); // Use the render strategy to fill the polygon +void Layer::fillPolygon(const std::vector& points, color_t color) +{ + // Use the render strategy to fill the polygon + currentRenderStrategy->fillPolygon(*this, points, color); } // Draw text -void Layer::drawText(pixel_t x, pixel_t y, const char* text, color_t color) { - currentRenderStrategy->drawText(*this, x, y, text, color); // Use the render strategy to draw the text +void Layer::drawText(pixel_t x, pixel_t y, const char* text, color_t color) +{ + // Use the render strategy to draw the text + currentRenderStrategy->drawText(*this, x, y, text, color); } // Draw an image -void Layer::drawImage(pixel_t x, pixel_t y, const Layer& image) { - currentRenderStrategy->drawImage(*this, x, y, image); // Use the render strategy to draw the image +void Layer::drawImage(pixel_t x, pixel_t y, const Layer& image) +{ + // Use the render strategy to draw the image + currentRenderStrategy->drawImage(*this, x, y, image); } diff --git a/src/h/fb b/src/h/fb index a7fa2fd..265e580 100644 --- a/src/h/fb +++ b/src/h/fb @@ -34,7 +34,8 @@ #include "render_strategy.h" #include "mem_manager.h" -class FrameBuffer { +class FrameBuffer +{ private: std::shared_ptr currentMemoryManager; std::vector> layers; // Use shared pointers for layers diff --git a/src/h/layer b/src/h/layer index 8971b4d..62b2587 100644 --- a/src/h/layer +++ b/src/h/layer @@ -37,7 +37,8 @@ typedef uint32_t color_t; // 32-bit color typedef uint32_t pixel_t; // 32-bit pixel, assuming it represents dimensions -class Layer { +class Layer +{ private: std::shared_ptr currentMemoryManager; std::shared_ptr currentRenderStrategy; diff --git a/src/h/mem_manager b/src/h/mem_manager index 7751b81..be2af60 100644 --- a/src/h/mem_manager +++ b/src/h/mem_manager @@ -1,20 +1,20 @@ /* - * This file is part of: + * This file is part of: * MicroFB, a minimal framebuffer library for RISC OS * - * Description: + * 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 + * 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, + * 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. */ @@ -24,7 +24,8 @@ #include // Abstracted memory manager interface -class MemoryManager { +class MemoryManager +{ public: virtual ~MemoryManager() {} virtual void* allocate(size_t size) = 0; diff --git a/src/h/render_strategy b/src/h/render_strategy index e9064a7..3494924 100644 --- a/src/h/render_strategy +++ b/src/h/render_strategy @@ -1,20 +1,20 @@ /* - * This file is part of: + * This file is part of: * MicroFB, a minimal framebuffer library for RISC OS * - * Description: + * 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 + * 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, + * 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. */ @@ -31,9 +31,10 @@ 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 { +class RenderStrategy +{ public: - virtual ~RenderStrategy() {} + virtual ~RenderStrategy() {}; // Pure virtual functions for rendering operations virtual void clear(Layer& layer, color_t color) = 0;