Back to index

easystroke  0.5.5.1
fire.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008-2009, Thomas Jaeger <ThJaeger@gmail.com>
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00009  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00010  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
00011  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00012  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
00013  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
00014  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 #include "fire.h"
00017 #include <X11/Xlib.h>
00018 #include <math.h>
00019 #include <stdio.h>
00020 
00021 Fire::Fire() {
00022        const char *ofc = "org.freedesktop.compiz";
00023        GError *error = 0;
00024        bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
00025        if (!bus) {
00026               g_error_free(error);
00027               throw DBusException();
00028        }
00029        char add[256];
00030        char clear[256];
00031        snprintf(add, sizeof(add), "/org/freedesktop/compiz/firepaint/screen%d/add_particle", DefaultScreen(dpy));
00032        snprintf(clear, sizeof(clear), "/org/freedesktop/compiz/firepaint/screen%d/clear_key", DefaultScreen(dpy));
00033 
00034        point_proxy = dbus_g_proxy_new_for_name(bus, ofc, add, ofc);
00035        clear_proxy = dbus_g_proxy_new_for_name(bus, ofc, clear, ofc);
00036 }
00037 
00038 void Fire::add_point(float x, float y) {
00039        dbus_g_proxy_call_no_reply(point_proxy, "activate",
00040                      G_TYPE_STRING, "root", G_TYPE_INT,    gint(ROOT),
00041                      G_TYPE_STRING, "x",   G_TYPE_DOUBLE, gdouble(x),
00042                      G_TYPE_STRING, "y",   G_TYPE_DOUBLE, gdouble(y),
00043                      G_TYPE_INVALID);
00044 }
00045 
00046 void Fire::draw(Point p, Point q) {
00047        float dist = hypot(p.x-q.x, p.y-q.y);
00048        leftover -= dist;
00049        while (leftover < 0.01) {
00050               add_point(q.x + (q.x-p.x)*leftover/dist, q.y + (q.y-p.y)*leftover/dist);
00051               leftover += 5.0;
00052        }
00053 }
00054 void Fire::timeout() {
00055        dbus_g_proxy_call_no_reply(clear_proxy, "activate",
00056                      G_TYPE_STRING, "root", G_TYPE_INT,    gint(ROOT),
00057                      G_TYPE_INVALID);
00058 }