Commit a8cdaca5 by Jessica Hawkwell

Started on Cairo renderer

1 parent f5e09c31
...@@ -83,6 +83,7 @@ bin/ ...@@ -83,6 +83,7 @@ bin/
obj/ obj/
generated-doc/ generated-doc/
*-prefix *-prefix
*-patched
# End of https://www.gitignore.io/api/codeblocks # End of https://www.gitignore.io/api/codeblocks
...@@ -30,6 +30,7 @@ None yet. :crying_cat_face: ...@@ -30,6 +30,7 @@ None yet. :crying_cat_face:
+ [`devel/boehm-gc`](https://www.freshports.org/devel/boehm-gc/) + [`devel/boehm-gc`](https://www.freshports.org/devel/boehm-gc/)
+ [`devel/boehm-gc-threaded`](https://www.freshports.org/devel/boehm-gc-threaded/) + [`devel/boehm-gc-threaded`](https://www.freshports.org/devel/boehm-gc-threaded/)
+ [`lang/rust`](https://www.freshports.org/lang/rust/) + [`lang/rust`](https://www.freshports.org/lang/rust/)
+ [`graphics/cairo`](https://www.freshports.org/graphics/cairo/)
--- ---
## Tooling ## Tooling
......
cmake_minimum_required (VERSION 3.10) cmake_minimum_required (VERSION 3.10)
execute_process(COMMAND sh apply-patches.sh WORKING_DIRECTORY deps)
find_library(RESVG resvg) find_library(RESVG resvg)
message("resvg " ${RESVG})
if(NOT ${RESVG} OR NOT EXISTS {$RESVG}) if(NOT ${RESVG} OR NOT EXISTS ${RESVG})
find_program(CARGO cargo) find_program(CARGO cargo)
include(ExternalProject) include(ExternalProject)
......
#!/bin/sh
if [ ! -f resvg-patched ]; then
patch -ts resvg/capi/include/resvg.h patches/resvg-FreeBSD.diff
touch resvg-patched
echo "ReSVG patched!"
else
echo "ReSVG already patched!"
fi
# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- a/<html>resvg.h (<b>Today 12:46:25 AM</b>)</html>
+++ b/<html><b>Current File</b></html>
@@ -8,7 +8,7 @@
#include <stdbool.h>
#ifdef RESVG_CAIRO_BACKEND
-#include <cairo.h>
+#include <cairo/cairo.h>
#endif
...@@ -64,7 +64,7 @@ namespace nitrogen { ...@@ -64,7 +64,7 @@ namespace nitrogen {
return rt; return rt;
} }
bool operator==(const NPosition<T>& other) const { bool operator==(const NPosition<T>& other) {
if (px != other.getX()) { if (px != other.getX()) {
return false; return false;
} }
......
...@@ -54,7 +54,7 @@ namespace nitrogen { ...@@ -54,7 +54,7 @@ namespace nitrogen {
return *this; return *this;
} }
bool operator==(const NSize<T>& other) const { bool operator==(const NSize<T>& other) {
if (pwidth != other.getWidth()) { if (pwidth != other.getWidth()) {
return false; return false;
} }
......
...@@ -26,11 +26,11 @@ nitrogen/nwt/GridLayout.cpp ...@@ -26,11 +26,11 @@ nitrogen/nwt/GridLayout.cpp
nitrogen/nwt/InputEvent.cpp nitrogen/nwt/InputEvent.cpp
nitrogen/nwt/Insets.cpp nitrogen/nwt/Insets.cpp
nitrogen/nwt/LayoutManager.cpp nitrogen/nwt/LayoutManager.cpp
nitrogen/nwt/NativeGraphics.cpp
nitrogen/nwt/MouseAdapter.cpp nitrogen/nwt/MouseAdapter.cpp
nitrogen/nwt/MouseEvent.cpp nitrogen/nwt/MouseEvent.cpp
nitrogen/nwt/MouseListener.cpp nitrogen/nwt/MouseListener.cpp
nitrogen/nwt/NWTEvent.cpp nitrogen/nwt/NWTEvent.cpp
nitrogen/nwt/NativeGraphics.cpp
nitrogen/nwt/Point.cpp nitrogen/nwt/Point.cpp
nitrogen/nwt/Rectangle.cpp nitrogen/nwt/Rectangle.cpp
......
...@@ -48,11 +48,11 @@ namespace nitrogen { ...@@ -48,11 +48,11 @@ namespace nitrogen {
virtual bool isBorderOpaque() = 0; virtual bool isBorderOpaque() = 0;
virtual void paintBorder(Component* comp, Graphics* g, int, int, unsigned int, unsigned int) = 0; virtual void paintBorder(Component* comp, Graphics* g, int, int, unsigned int, unsigned int) = 0;
virtual std::string* toString() const = 0; virtual std::string* toString() = 0;
virtual Border& operator()(Component& comp) const = 0; virtual Border& operator()(Component& comp) = 0;
virtual Border& operator=(Border& right) = 0; virtual Border& operator=(Border& right) = 0;
//virtual bool operator!=(Color& right) const = 0; //virtual bool operator!=(Color& right) = 0;
virtual bool operator==(Border& right) const = 0; virtual bool operator==(Border& right) = 0;
protected: protected:
Component* c; Component* c;
......
...@@ -49,6 +49,8 @@ namespace nitrogen { ...@@ -49,6 +49,8 @@ namespace nitrogen {
ml_list = new std::vector<MouseListener*>(); ml_list = new std::vector<MouseListener*>();
parent = nullptr; parent = nullptr;
preferredSize = new Rectangle(0, 0); preferredSize = new Rectangle(0, 0);
renderer = new util::ComponentRenderer(new std::string("Component"), this);
} }
Border* Component::getBorder() { Border* Component::getBorder() {
......
...@@ -46,18 +46,21 @@ ...@@ -46,18 +46,21 @@
#include <nitrogen/nwt/MouseListener.h> #include <nitrogen/nwt/MouseListener.h>
#include <nitrogen/nwt/NWTEvent.h> #include <nitrogen/nwt/NWTEvent.h>
#include <nitrogen/nwt/Rectangle.h> #include <nitrogen/nwt/Rectangle.h>
#include <nitrogen/util/ComponentRenderer.h>
#include <vector> #include <vector>
namespace nitrogen { namespace nitrogen {
namespace nwt { namespace nwt {
class Border; class Border;
//class ComponentRenderer;
class Graphics; class Graphics;
class NWTEvent; class NWTEvent;
class MouseEvent; class MouseEvent;
class MouseListener; class MouseListener;
class Component : public Object { class Component : public Object {
friend class util::ComponentRenderer;
friend class Container; friend class Container;
public: public:
virtual Border* getBorder(); virtual Border* getBorder();
...@@ -105,6 +108,8 @@ namespace nitrogen { ...@@ -105,6 +108,8 @@ namespace nitrogen {
std::vector<MouseListener*>* ml_list; std::vector<MouseListener*>* ml_list;
Rectangle* preferredSize; Rectangle* preferredSize;
util::ComponentRenderer* renderer;
Component(); Component();
virtual void processEvent(NWTEvent *e); virtual void processEvent(NWTEvent *e);
virtual void processMouseEvent(MouseEvent *e); virtual void processMouseEvent(MouseEvent *e);
......
...@@ -55,10 +55,10 @@ namespace nitrogen { ...@@ -55,10 +55,10 @@ namespace nitrogen {
virtual void drawString(std::string* str, int x, int y) = 0; virtual void drawString(std::string* str, int x, int y) = 0;
virtual void drawString(std::string& str, int x, int y) = 0; virtual void drawString(std::string& str, int x, int y) = 0;
virtual Color* getColor() const = 0; virtual Color* getColor() = 0;
virtual nitrogen::nwt::Font* getFont() const = 0; virtual nitrogen::nwt::Font* getFont() = 0;
virtual FontMetrics* getFontMetrics(nitrogen::nwt::Font* f) const = 0; virtual FontMetrics* getFontMetrics(nitrogen::nwt::Font* f) = 0;
virtual FontMetrics* getFontMetrics() const = 0; virtual FontMetrics* getFontMetrics() = 0;
virtual void setClip(int x, int y, unsigned int width, unsigned int height) = 0; virtual void setClip(int x, int y, unsigned int width, unsigned int height) = 0;
virtual void setColor(Color* c) = 0; virtual void setColor(Color* c) = 0;
...@@ -67,11 +67,11 @@ namespace nitrogen { ...@@ -67,11 +67,11 @@ namespace nitrogen {
virtual void translate(int x, int y) = 0; virtual void translate(int x, int y) = 0;
virtual void dispose() = 0; virtual void dispose() = 0;
virtual std::string* toString() const = 0; virtual std::string* toString() = 0;
virtual Graphics& operator()() const = 0; virtual Graphics& operator()() = 0;
virtual Graphics& operator=(Graphics& right) = 0; virtual Graphics& operator=(Graphics& right) = 0;
//virtual bool operator!=(Graphics& right) const = 0; //virtual bool operator!=(Graphics& right) = 0;
virtual bool operator==(Graphics& right) const = 0; virtual bool operator==(Graphics& right) = 0;
protected: protected:
static nitrogen::nwt::Font* ntk_font; static nitrogen::nwt::Font* ntk_font;
......
...@@ -33,10 +33,100 @@ ...@@ -33,10 +33,100 @@
#include "NativeGraphics.h" #include "NativeGraphics.h"
#include <X11/Xlib.h>
namespace nitrogen { namespace nitrogen {
namespace nwt { namespace nwt {
NativeGraphics::NativeGraphics() { NativeGraphics::NativeGraphics() {
} }
NativeGraphics::NativeGraphics(NativeGraphics&) {
}
Graphics* NativeGraphics::create() {
}
void NativeGraphics::drawPoint(int x, int y) {
}
void NativeGraphics::drawLine(int sx, int xy, int dx, int dy) {
}
void NativeGraphics::drawRect(int x, int y, unsigned int width, unsigned int height) {
}
void NativeGraphics::fillRect(int x, int y, unsigned int width, unsigned int height) {
}
void NativeGraphics::draw3DRect(int x, int y, unsigned int width, unsigned int height, bool) {
}
void NativeGraphics::fill3DRect(int x, int y, unsigned int width, unsigned int height) {
}
void NativeGraphics::drawString(std::string* str, int x, int y) {
}
void NativeGraphics::drawString(std::string& str, int x, int y) {
}
void NativeGraphics::setClip(int x, int y, unsigned int width, unsigned int height) {
}
void NativeGraphics::setColor(Color* c) {
}
void NativeGraphics::setFont(nitrogen::nwt::Font* f) {
}
Color* NativeGraphics::getColor() {
}
nitrogen::nwt::Font* NativeGraphics::getFont() {
}
FontMetrics* NativeGraphics::getFontMetrics() {
}
void NativeGraphics::translate(int x, int y) {
}
void NativeGraphics::dispose() {
}
void NativeGraphics::pDrawLine(int x1, int y1, int x2, int y2) {
}
void NativeGraphics::pDrawPoint(int, int) {
}
void NativeGraphics::initGC() {
}
void NativeGraphics::updateGC() {
}
void NativeGraphics::createClip() {
}
} }
} }
...@@ -36,20 +36,56 @@ ...@@ -36,20 +36,56 @@
#include <ntk.h> #include <ntk.h>
#include <nitrogen/nwt/Color.h>
#include <nitrogen/nwt/Font.h>
#include <nitrogen/nwt/FontMetrics.h>
#include <nitrogen/nwt/Graphics.h> #include <nitrogen/nwt/Graphics.h>
#include <nitrogen/nwt/Rectangle.h> #include <nitrogen/nwt/Rectangle.h>
#include <resvg.h>
namespace nitrogen { namespace nitrogen {
namespace nwt { namespace nwt {
class NativeGraphics : public Graphics { class NativeGraphics : public Graphics {
//friend class Frame; //friend class Frame;
public: public:
NativeGraphics(); NativeGraphics(NativeGraphics&);
Graphics* create() override;
void drawPoint(int x, int y) override;
void drawLine(int sx, int xy, int dx, int dy) override;
void drawRect(int x, int y, unsigned int width, unsigned int height) override;
void fillRect(int x, int y, unsigned int width, unsigned int height) override;
void draw3DRect(int x, int y, unsigned int width, unsigned int height, bool) override;
void fill3DRect(int x, int y, unsigned int width, unsigned int height) override;
void drawString(std::string* str, int x, int y) override;
void drawString(std::string& str, int x, int y) override;
void setClip(int x, int y, unsigned int width, unsigned int height) override;
void setColor(Color* c) override;
void setFont(nitrogen::nwt::Font* f) override;
Color* getColor() override;
nitrogen::nwt::Font* getFont() override;
FontMetrics* getFontMetrics() override;
void translate(int x, int y) override;
void dispose() override;
protected: protected:
unsigned long mask; unsigned long mask;
int cx;
int cy;
int tx;
int ty;
unsigned int width;
unsigned int height;
resvg_handle* svgh;
NativeGraphics();
virtual void pDrawLine(int, int, int, int);
virtual void pDrawPoint(int, int);
virtual void initGC();
virtual void updateGC();
virtual void createClip();
private: private:
......
/*
* Copyright (c) 2018, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: ComponentRenderer.cpp
* Author: jlhawkwell
*
* Created on March 25, 2018, 3:21 PM
*/
#include "ComponentRenderer.h"
namespace nitrogen {
namespace util {
ComponentRenderer::ComponentRenderer(std::string* componentName, nwt::Component* component) {
name = componentName;
comp = component;
init();
}
ComponentRenderer::ComponentRenderer(std::string& componentName, nwt::Component* component) {
name = componentName;
comp = component;
init();
}
void ComponentRenderer::init() {
if (nitrogen::disp == nullptr) {
nitrogen::disp = XOpenDisplay(nullptr);
}
// Window XCreateSimpleWindow(Display *display, Window
// parent, int x, int y, unsigned int width, unsigned
// int height, unsigned int border_width, unsigned
// long border, unsigned long background);
int x = comp->getX();
int y = comp->getY();
unsigned int width = comp->getSize()->getWidth();
unsigned int height = comp->getSize()->getHeight();
Window* w;
if (comp->getParent() == nullptr) {
w = nitrogen::root;
}
else {
w = comp->getParent()->renderer->getWindow();
}
window = XCreateSimpleWindow(nitrogen::disp, w, x, y, width, height, 0, nwt::Color::BLUE);
XWindowAttributes attrs;
XGetWindowAttributes(nitrogen::disp, window, &attrs);
XRenderPictFormat *pf = XRenderFindVisualFormat(nitrogen::disp, attrs.visual);
surface = cairo_xlib_surface_create_with_xrender_format(nitrogen::disp, window, attrs.screen, pf, width, height);
svg_handle = resvg_init();
}
std::string* ComponentRenderer::getName() {
return name;
}
Window* ComponentRenderer::getWindow() {
return &window;
}
nwt::Component* ComponentRenderer::getComponent() {
return comp;
}
void ComponentRenderer::renderComponent() {
//void resvg_cairo_render_to_canvas(const resvg_render_tree* rtree, const resvg_options* opt, resvg_size size, cairo_t* cr)
resvg_options ro;
ro.draw_background = false;
ro.fit_to = resvg_fit_to_type.RESVG_FIT_TO_ZOOM;
resvg_size rs;
rs.width = comp->getSize()->getWidth();
rs.height = comp->getSize()->getWidth();
resvg_cairo_render_to_canvas(svg_tree, ro, rs, surface);
}
}
}
/*
* Copyright (c) 2018, jlhawkwell
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* File: ComponentRenderer.h
* Author: jlhawkwell
*
* Created on March 25, 2018, 3:21 PM
*/
#ifndef COMPONENTRENDERER_H
#define COMPONENTRENDERER_H
#include <ntk.h>
#include <nitrogen/nwt/Component.h>
#define RESVG_CAIRO_BACKEND
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xrender.h>
#include <cairo/cairo-xlib-xrender.h>
#include <cairo/cairo-xlib.h>
#include <cairo/cairo.h>
#include <resvg.h>
namespace nitrogen {
namespace util {
class ComponentRenderer : public Object {
public:
ComponentRenderer(std::string* componentName, nwt::Component* component);
ComponentRenderer(std::string& componentName, nwt::Component* component);
std::string* getName();
Window* getWindow();
nwt::Component* getComponent();
virtual void renderComponent();
protected:
std::string* name;
Window window;
nwt::Component* comp;
cairo_surface_t* surface;
resvg_handle* svg_handle;
resvg_render_tree* svg_tree;
void init();
private:
};
}
}
#endif /* COMPONENTRENDERER_H */
...@@ -59,8 +59,10 @@ ...@@ -59,8 +59,10 @@
#endif #endif
namespace nitrogen { namespace nitrogen {
static Display *disp; static Display* disp;
void init(Display *d); static Window* root;
void init();
} }
#endif /* NTK_H */ #endif /* NTK_H */
...@@ -59,8 +59,10 @@ ...@@ -59,8 +59,10 @@
#endif #endif
namespace nitrogen { namespace nitrogen {
static Display *disp; static Display* disp;
void init(Display *d); static Window* root;
void init();
} }
#endif /* NTK_H */ #endif /* NTK_H */
...@@ -27,7 +27,12 @@ ...@@ -27,7 +27,12 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
namespace nitrogen { namespace nitrogen {
void init(Display *d) {
disp = d; /**
* Initialize the graphics system for Nitrogen.
*/
void init() {
disp = XOpenDisplay(nullptr);
root = &DefaultRootWindow(disp);
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!