[cairo] Some questions...

Loïc Faure-Lacroix loicfl at gmail.com
Sat Jul 14 13:16:42 PDT 2007


I'm working with gtkmm + cairomm

I don't know if its a bug or not.

I do override the expose-event function of my window.
But now anything added over my window isn't rendered except drawing area
that their on_expose_event is overrided too.

it's like if the window was rendering over everything.

My main goal is to make a borderless window with rounded corner.
And a custom skin for the widgets.

I can use a custom skin with Gtk::RC rc("myfile.gtkrc");
But my last and only problem is to make a window that doesn't render over
every widget...
I done that with gtk+ and cairo.
But i don't exactly understand why in cairomm it doesn't work.

here is what i want to do with cairomm...
http://img54.imageshack.us/img54/6558/steambm1.png

-----------------------------------
CairoWindow.cc--------------------------------------------------
#include "cairo-window.h"
#include "cairo.h"

CairoWindow::CairoWindow(){
    this->on_screen_changed(this->get_screen());
}
CairoWindow::~CairoWindow(){}

bool CairoWindow::on_expose_event(GdkEventExpose* event){
  Glib::RefPtr<Gdk::Window> window = get_window();
  if(window)
  {
    Gtk::Allocation allocation = get_allocation();
    const int width = allocation.get_width();
    const int height = allocation.get_height();

    Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();

    cr->set_source_rgba(0.0, 0.0, 0.0, 0.0);
    cr->set_operator(Cairo::OPERATOR_SOURCE );
    cr->rectangle(event->area.x, event->area.y,
            event->area.width, event->area.height);

    cr->clip();

    cr->save();
    cr->paint();

    int distance = 10;


    cr->set_source_rgba(0.27f, 0.27f, 0.27f,1);

    cr->move_to(distance,0);
    cr->line_to(width-distance,0);
    cr->curve_to(width-distance,0, width, 0, width,distance);
    cr->line_to(width,height-distance);
    cr->curve_to(width,height-distance,width,height,width-distance,height);
    cr->line_to(distance,height);
    cr->curve_to(distance,height,0,height,0,height - distance);
    cr->line_to(0,distance);
    cr->curve_to(0,distance,0,0,distance,0);
    cr->fill();

    cr->set_source_rgba(0.35f, 0.42f, 0.31f,1);
    cr->move_to(distance,0);
    cr->line_to(width-distance,0);
    cr->curve_to(width-distance,0, width, 0, width,distance);
    cr->line_to(width, distance * 3);
    cr->line_to(0, distance * 3);
    cr->line_to(0, distance);
    cr->curve_to(0,distance, 0, 0, distance,0);
    /*cairo_curve_to(cr,0, height - 5, 0, height, 5,height);
    cairo_line_to(cr,0, height);
    cairo_line_to(cr,width,height);
    cairo_line_to(cr,width,0);*/

    /*cairo_arc(cr, width / 2, height / 2, (width < height ? width : height)
/ 2 - 8 , 0, 2 * 3.14);*/
    cr->fill();
    cr->stroke();
    cr->restore();
  }
}

void CairoWindow::on_screen_changed( const Glib::RefPtr<Gdk::Screen>&
previous_screen ){
    const Glib::RefPtr<Gdk::Screen> screen = this->get_screen();
    const Glib::RefPtr<Gdk::Colormap> colormap =
screen->get_rgba_colormap();

    if(colormap){
        std::cout << "Screen support alpha channel";
    }else{
        std::cout << "Screen support alpha channel";
    }
    this->set_colormap(colormap);
};

----------------------------------------------------------------------------------------------------------
------------------------------------------
CairoWindow.h--------------------------------------------
#ifndef GTKMM_CAIRO_WINDOW_H
#define GTKMM_CAIRO_WINDOW_H

#include <gtkmm/window.h>
#include <iostream>

class CairoWindow : public Gtk::Window
{
    public:
        CairoWindow();
        virtual ~CairoWindow();

    protected:
        //Override default signal handler:
       virtual bool on_expose_event(GdkEventExpose* event);
        virtual void on_screen_changed( const Glib::RefPtr<Gdk::Screen>&
previous_screen);
};

#endif // GTKMM_EXAMPLE_CLOCK_H

-----------------------------------------------------------------------------------------------------------

I may be missing something but i believe this is fairly simple
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20070714/24beabc8/attachment.htm 


More information about the cairo mailing list