Skip to content

Instantly share code, notes, and snippets.

@mkamotsu
Created May 21, 2013 09:42
Show Gist options
  • Save mkamotsu/5618645 to your computer and use it in GitHub Desktop.
Save mkamotsu/5618645 to your computer and use it in GitHub Desktop.
// g++ -std=c++11 `pkg-config gtkmm-2.4 --cflags --libs` -o gtkmm gtkmm.cpp
#include <gtkmm/drawingarea.h>
#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <cairomm/context.h>
class IchimatsuArea : public Gtk::DrawingArea
{
public:
IchimatsuArea() {}
virtual ~IchimatsuArea() {}
protected:
virtual bool on_expose_event(GdkEventExpose* event) {
auto window = get_window();
if (window) {
auto allocation = get_allocation();
const int width = allocation.get_width();
const int height = allocation.get_height();
const int cell_width = width / 20;
const int cell_height = height / 20;
auto cr = window->create_cairo_context();
cr->set_source_rgb(0.8, 0.0, 0.0);
for (int i=0; i<400; ++i) {
int x = i % 20;
int y = i / 20;
if ((x+y) % 2 == 0) {
cr->rectangle(x * cell_width, y * cell_height, cell_width, cell_height);
}
}
cr->fill();
}
return true;
}
};
int main(int argc, char** argv)
{
Gtk::Main kit(argc, argv);
Gtk::Window win;
win.set_title("DrawingArea");
IchimatsuArea area;
win.add(area);
area.show();
Gtk::Main::run(win);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment