Help with cairo and pointers
I am trying to create a c++ widgets toolkit. I am having problems with accessing the cairo_t object to draw on. I am trying to make a copy of the pointer so that it can be stored in a button class. Here is the code
main.cpp
Code:
#include <X11/Xlib.h>
#include "ys_window.h"
int main(){
//window object
ys_window wind;
wind.showwindow(true);
while(1){
//XEvent e;
}
return 0;
}
ys_window.h
Code:
#ifndef YS_WINDOW_H_INCLUDED
#define YS_WINDOW_H_INCLUDED
#include <X11/Xlib.h>
#include <cairo.h>
#include <cairo-xlib.h>
//widget includes
#include "ys_button.h"
class ys_window{
private:
int xsize;
int ysize;
int xpos;
int ypos;
bool visible;
//cairo variables
cairo_surface_t *cs;
cairo_t *c;
//xlib variables
Display *dpy;
int blackcolour;
Window w;
public:
//widget objects
ys_button butt;
ys_window(){
//set the default values to create the window
xsize = 500;
ysize = 500;
xpos = 200;
ypos = 200;
visible = false;
//the xlib display variable
dpy = XOpenDisplay(0);
//colour used to blackout the window
blackcolour = BlackPixel(dpy, DefaultScreen(dpy));
//create the window
w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), xpos, ypos, xsize, ysize, 0, blackcolour, blackcolour);
cs = cairo_xlib_surface_create(dpy, w, DefaultVisual(dpy, 0), xsize, ysize);
c = cairo_create(cs);
XFlush(dpy);
};
void showwindow(bool vis);
void windowposition(int x, int y);
void windowsize(int x, int y);
void addbutton();
};
void ys_window::showwindow(bool vis)
{
if(vis == true){
XMapWindow(dpy, w);
}else{
XUnmapWindow(dpy, w);
}
XFlush(dpy);
butt.surfaceset(c);
butt.redraw();
visible = vis;
}
void ys_window::windowposition(int x, int y)
{
xpos = x;
ypos = y;
XMoveWindow(dpy, w, xpos, ypos);
XFlush(dpy);
}
void ys_window::windowsize(int x, int y)
{
xsize = x;
ysize = y;
XResizeWindow(dpy, w, xsize, ysize);
cairo_surface_destroy(cs);
cs = cairo_xlib_surface_create(dpy, w, DefaultVisual(dpy, 0), xsize, ysize);
c = cairo_create(cs);
XFlush(dpy);
}
#endif // YS_WINDOW_H_INCLUDED
ys_button.h
Code:
#ifndef YS_BUTTON_H_INCLUDED
#define YS_BUTTON_H_INCLUDED
#include <X11/Xlib.h>
#include <cairo.h>
#include <cairo-xlib.h>
class ys_button{
private:
int xpos;
int ypos;
int xsize;
int ysize;
bool visible;
cairo_t *surface;
public:
ys_button(){
xpos = 200;
ypos = 200;
xsize = 0;
ysize = 0;
visible = false;
};
void surfaceset(cairo_t* c);
void redraw();
};
void ys_button::surfaceset(cairo_t* c)
{
surface = c;
cairo_set_source_rgba(surface, 1, 1, 1, 1);
cairo_move_to (surface, 50.0, 75.0);
cairo_line_to (surface, 200.0, 75.0);
cairo_set_line_width (surface, 30.0);
cairo_stroke (surface);
}
void ys_button::redraw()
{
cairo_set_source_rgba(surface, 1, 1, 1, 1);
cairo_move_to (surface, 50.0, 75.0);
cairo_line_to (surface, 200.0, 75.0);
cairo_set_line_width (surface, 30.0);
cairo_set_line_cap (surface, CAIRO_LINE_CAP_ROUND);
cairo_stroke (surface);
}
#endif // YS_BUTTON_H_INCLUDED
currently im trying to create a copy of the c pointer from ys_window in ys_button but it isn't working
Re: Help with cairo and pointers
Code:
class ys_window{
private:
int xsize;
int ysize;
int xpos;
int ypos;
bool visible;
//cairo variables
cairo_surface_t *cs;
cairo_t *c;
//xlib variables
Display *dpy;
int blackcolour;
Window w;
cairo_t *c; is a private data member of your ys_window class and cannot be passed to the ys_button object. If you make cairo_t *c; public this should work.
Re: Help with cairo and pointers
Nope that has made no difference.