summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2011-10-14 18:03:51 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2011-10-14 18:03:51 +0200
commitef47c71a29292ff9114a67d782e526ac662a1f32 (patch)
treefca1dd5f56d89b46759cd8fcd0e6b9e803cf92f8 /plugingui
parent068bbbba9248fc11c7c852508c916579bd2621e2 (diff)
Inital implementation of X11 plugin gui.
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/Makefile.am45
-rw-r--r--plugingui/button.cc97
-rw-r--r--plugingui/button.h57
-rw-r--r--plugingui/checkbox.cc44
-rw-r--r--plugingui/checkbox.h29
-rw-r--r--plugingui/colour.cc92
-rw-r--r--plugingui/colour.h53
-rw-r--r--plugingui/combobox.cc44
-rw-r--r--plugingui/combobox.h29
-rw-r--r--plugingui/event.h92
-rw-r--r--plugingui/eventhandler.cc169
-rw-r--r--plugingui/eventhandler.h45
-rw-r--r--plugingui/globalcontext.cc60
-rw-r--r--plugingui/globalcontext.h53
-rw-r--r--plugingui/gui.cc120
-rw-r--r--plugingui/gui.h50
-rw-r--r--plugingui/label.cc44
-rw-r--r--plugingui/label.h29
-rw-r--r--plugingui/lineedit.cc119
-rw-r--r--plugingui/lineedit.h51
-rw-r--r--plugingui/painter.cc113
-rw-r--r--plugingui/painter.h58
-rw-r--r--plugingui/widget.cc152
-rw-r--r--plugingui/widget.h68
-rw-r--r--plugingui/widgetcontext.h42
-rw-r--r--plugingui/window.cc57
-rw-r--r--plugingui/window.h39
27 files changed, 1851 insertions, 0 deletions
diff --git a/plugingui/Makefile.am b/plugingui/Makefile.am
new file mode 100644
index 0000000..149f4a7
--- /dev/null
+++ b/plugingui/Makefile.am
@@ -0,0 +1,45 @@
+bin_PROGRAMS = plugingui
+
+plugingui_LDADD = $(SNDFILE_LIBS) $(PTHREAD_LIBS) $(EXPAT_LIBS) -ldl -lX11
+
+plugingui_CXXFLAGS = $(SNDFILE_CXXFLAGS) $(PTHREAD_CFLAGS) $(EXPAT_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)/src -DSTANDALONE -DX11
+
+plugingui_SOURCES = \
+ eventhandler.cc \
+ globalcontext.cc \
+ gui.cc \
+ colour.cc \
+ window.cc \
+ widget.cc \
+ lineedit.cc \
+ button.cc \
+ checkbox.cc \
+ combobox.cc \
+ label.cc \
+ painter.cc
+
+EXTRA_DIST = \
+ event.h \
+ eventhandler.h \
+ globalcontext.h \
+ gui.h \
+ colour.h \
+ window.h \
+ widget.h \
+ lineedit.h \
+ button.h \
+ checkbox.h \
+ combobox.h \
+ label.h \
+ painter.h
+
+################
+# Test Section #
+################
+
+TEST_SOURCE_DEPS = ${EXTRA_DIST}
+TEST_SCRIPT_DIR = $(top_srcdir)/tools
+
+include ${TEST_SCRIPT_DIR}/Makefile.am.test
+
+include Makefile.am.test
diff --git a/plugingui/button.cc b/plugingui/button.cc
new file mode 100644
index 0000000..a5c6947
--- /dev/null
+++ b/plugingui/button.cc
@@ -0,0 +1,97 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * button.cc
+ *
+ * Sun Oct 9 13:01:56 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "button.h"
+
+#include "painter.h"
+
+#include <stdio.h>
+
+Button::Button(GlobalContext *gctx, Widget *parent)
+ : Widget(gctx, parent)
+{
+ state = up;
+}
+
+void Button::button(ButtonEvent *e)
+{
+ if(e->direction == 1) {
+ state = down;
+ repaint(NULL);
+ }
+ if(e->direction == -1) {
+ state = up;
+ repaint(NULL);
+ clicked();
+ }
+}
+
+void Button::repaint(RepaintEvent *e)
+{
+ Painter p(gctx, wctx);
+
+ p.setColour(Colour(0.5));
+ p.drawFilledRectangle(1,1,width()-1,height()-1);
+
+ p.setColour(Colour(0.1));
+ p.drawRectangle(0,0,width()-1,height()-1);
+
+ p.setColour(Colour(0.8));
+ if(state == down) {
+ p.drawLine(1,1,1,height());
+ p.drawLine(1,1,width(),1);
+ }
+ if(state == up) {
+ p.drawLine(width()-2,0, width()-2,height()-2);
+ p.drawLine(width()-2,height()-2,0, height()-2);
+ }
+
+ p.setColour(Colour(0.9));
+ p.drawText(width()/2-(text.length()*3)+(state==up?0:1),
+ height()/2+4+(state==up?0:1), text);
+}
+
+void Button::setText(std::string text)
+{
+ this->text = text;
+}
+
+#ifdef TEST_BUTTON
+//Additional dependency files
+//deps:
+//Required cflags (autoconf vars may be used)
+//cflags:
+//Required link options (autoconf vars may be used)
+//libs:
+#include "test.h"
+
+TEST_BEGIN;
+
+// TODO: Put some testcode here (see test.h for usable macros).
+
+TEST_END;
+
+#endif/*TEST_BUTTON*/
diff --git a/plugingui/button.h b/plugingui/button.h
new file mode 100644
index 0000000..f050f3c
--- /dev/null
+++ b/plugingui/button.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * button.h
+ *
+ * Sun Oct 9 13:01:56 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_BUTTON_H__
+#define __DRUMGIZMO_BUTTON_H__
+
+#include <string>
+
+#include "widget.h"
+#include "globalcontext.h"
+
+class Button : public Widget {
+public:
+ Button(GlobalContext *gctx, Widget *parent);
+
+ void setText(std::string text);
+
+protected:
+ virtual void clicked() {}
+
+ virtual void repaint(RepaintEvent *e);
+ virtual void button(ButtonEvent *e);
+
+private:
+ typedef enum {
+ up,
+ down
+ } state_t;
+
+ std::string text;
+ state_t state;
+};
+
+#endif/*__DRUMGIZMO_BUTTON_H__*/
diff --git a/plugingui/checkbox.cc b/plugingui/checkbox.cc
new file mode 100644
index 0000000..72b7d3f
--- /dev/null
+++ b/plugingui/checkbox.cc
@@ -0,0 +1,44 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * checkbox.cc
+ *
+ * Sun Oct 9 13:02:01 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "checkbox.h"
+
+#ifdef TEST_CHECKBOX
+//Additional dependency files
+//deps:
+//Required cflags (autoconf vars may be used)
+//cflags:
+//Required link options (autoconf vars may be used)
+//libs:
+#include "test.h"
+
+TEST_BEGIN;
+
+// TODO: Put some testcode here (see test.h for usable macros).
+
+TEST_END;
+
+#endif/*TEST_CHECKBOX*/
diff --git a/plugingui/checkbox.h b/plugingui/checkbox.h
new file mode 100644
index 0000000..4576a66
--- /dev/null
+++ b/plugingui/checkbox.h
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * checkbox.h
+ *
+ * Sun Oct 9 13:02:01 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_CHECKBOX_H__
+#define __DRUMGIZMO_CHECKBOX_H__
+#endif/*__DRUMGIZMO_CHECKBOX_H__*/
diff --git a/plugingui/colour.cc b/plugingui/colour.cc
new file mode 100644
index 0000000..db2c8f6
--- /dev/null
+++ b/plugingui/colour.cc
@@ -0,0 +1,92 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * colour.cc
+ *
+ * Fri Oct 14 09:38:28 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "colour.h"
+
+#include "globalcontext.h"
+
+Colour::Colour()
+{
+ red = blue = green = alpha = 1.0;
+}
+
+Colour::Colour(float grey, float a)
+{
+ red = green = blue = grey;
+ alpha = a;
+}
+
+Colour::Colour(float r, float g, float b, float a)
+{
+ red = r;
+ green = g;
+ blue = b;
+ alpha = a;
+}
+
+#ifdef X11
+int Colour::getColour(GlobalContext *gctx)
+{
+ XColor col;
+ Colormap colormap = DefaultColormap(gctx->display, 0);
+ // XParseColor(gctx->display, colormap, "#00FF00", &col);
+ col.red = 65535 * red;
+ col.green = 65535 * green;
+ col.blue = 65535 * blue;
+ col.flags = DoRed | DoGreen | DoBlue;
+
+ XAllocColor(gctx->display, colormap, &col);
+
+ return col.pixel;
+ /*
+ int colour;
+
+ if(red == 1.0 && green == 1.0 && blue == 1.0)
+ colour = WhitePixel(gctx->display, DefaultScreen(gctx->display));
+ else
+ colour = BlackPixel(gctx->display, DefaultScreen(gctx->display));
+
+ return colour;
+ */
+}
+#endif/*X11*/
+
+#ifdef TEST_COLOUR
+//Additional dependency files
+//deps:
+//Required cflags (autoconf vars may be used)
+//cflags:
+//Required link options (autoconf vars may be used)
+//libs:
+#include "test.h"
+
+TEST_BEGIN;
+
+// TODO: Put some testcode here (see test.h for usable macros).
+
+TEST_END;
+
+#endif/*TEST_COLOUR*/
diff --git a/plugingui/colour.h b/plugingui/colour.h
new file mode 100644
index 0000000..5778702
--- /dev/null
+++ b/plugingui/colour.h
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * colour.h
+ *
+ * Fri Oct 14 09:38:28 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_COLOUR_H__
+#define __DRUMGIZMO_COLOUR_H__
+
+class GlobalContext;
+
+class Colour {
+public:
+ Colour();
+
+ Colour(float grey, float alpha = 1.0);
+
+ Colour(float red,
+ float green,
+ float blue,
+ float alpha = 1.0);
+
+ float red;
+ float green;
+ float blue;
+ float alpha;
+
+#ifdef X11
+ int getColour(GlobalContext *gctx);
+#endif/*X11*/
+};
+
+#endif/*__DRUMGIZMO_COLOUR_H__*/
diff --git a/plugingui/combobox.cc b/plugingui/combobox.cc
new file mode 100644
index 0000000..1e47c8a
--- /dev/null
+++ b/plugingui/combobox.cc
@@ -0,0 +1,44 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * combobox.cc
+ *
+ * Sun Oct 9 13:02:08 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "combobox.h"
+
+#ifdef TEST_COMBOBOX
+//Additional dependency files
+//deps:
+//Required cflags (autoconf vars may be used)
+//cflags:
+//Required link options (autoconf vars may be used)
+//libs:
+#include "test.h"
+
+TEST_BEGIN;
+
+// TODO: Put some testcode here (see test.h for usable macros).
+
+TEST_END;
+
+#endif/*TEST_COMBOBOX*/
diff --git a/plugingui/combobox.h b/plugingui/combobox.h
new file mode 100644
index 0000000..7bdd5bb
--- /dev/null
+++ b/plugingui/combobox.h
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * combobox.h
+ *
+ * Sun Oct 9 13:02:08 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_COMBOBOX_H__
+#define __DRUMGIZMO_COMBOBOX_H__
+#endif/*__DRUMGIZMO_COMBOBOX_H__*/
diff --git a/plugingui/event.h b/plugingui/event.h
new file mode 100644
index 0000000..1779112
--- /dev/null
+++ b/plugingui/event.h
@@ -0,0 +1,92 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * event.h
+ *
+ * Sun Oct 9 16:11:47 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_EVENT_H__
+#define __DRUMGIZMO_EVENT_H__
+
+#include <unistd.h>
+
+#include <string>
+
+#ifdef X11
+#include <X11/Xlib.h>
+#endif/*X11*/
+
+class Event {
+public:
+ typedef enum {
+ MouseMove,
+ Repaint,
+ Button,
+ Key
+ } Type;
+
+ virtual Type type() = 0;
+
+#ifdef X11
+ Window window_id;
+#endif/*X11*/
+};
+
+class MouseMoveEvent : public Event {
+public:
+ virtual Type type() { return MouseMove; }
+
+ size_t x;
+ size_t y;
+};
+
+class ButtonEvent : public Event {
+public:
+ virtual Type type() { return Button; }
+
+ size_t x;
+ size_t y;
+
+ int direction;
+ int button;
+};
+
+class RepaintEvent : public Event {
+public:
+ virtual Type type() { return Repaint; }
+
+ size_t x;
+ size_t y;
+ size_t width;
+ size_t height;
+};
+
+class KeyEvent : public Event {
+public:
+ virtual Type type() { return Key; }
+
+ int direction;
+ int keycode;
+ std::string text;
+};
+
+#endif/*__DRUMGIZMO_EVENT_H__*/
diff --git a/plugingui/eventhandler.cc b/plugingui/eventhandler.cc
new file mode 100644
index 0000000..8936f14
--- /dev/null
+++ b/plugingui/eventhandler.cc
@@ -0,0 +1,169 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * eventhandler.cc
+ *
+ * Sun Oct 9 18:58:29 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "eventhandler.h"
+
+#include "globalcontext.h"
+
+#include <stdio.h>
+
+#ifdef X11
+#include <X11/Xutil.h>
+#endif/*X11*/
+
+/**
+ * KeyPress 2
+ * KeyRelease 3
+ * ButtonPress 4
+ * ButtonRelease 5
+ * MotionNotify 6
+ * EnterNotify 7
+ * LeaveNotify 8
+ * FocusIn 9
+ * FocusOut 10
+ * KeymapNotify 11
+ * Expose 12
+ * GraphicsExpose 13
+ * NoExpose 14
+ * VisibilityNotify 15
+ * CreateNotify 16
+ * DestroyNotify 17
+ * UnmapNotify 18
+ * MapNotify 19
+ * MapRequest 20
+ * ReparentNotify 21
+ * ConfigureNotify 22
+ * ConfigureRequest 23
+ * GravityNotify 24
+ * ResizeRequest 25
+ * CirculateNotify 26
+ * CirculateRequest 27
+ * PropertyNotify 28
+ * SelectionClear 29
+ * SelectionRequest 30
+ * SelectionNotify 31
+ * ColormapNotify 32
+ * ClientMessage 33
+ * MappingNotify 34
+ * GenericEvent 35
+ * LASTEvent 36 // must be bigger than any event #
+ **/
+
+EventHandler::EventHandler(GlobalContext *gctx)
+{
+ this->gctx = gctx;
+}
+
+bool EventHandler::hasEvent()
+{
+#ifdef X11
+ return XPending(gctx->display);
+#endif/*X11*/
+ return false;
+}
+
+Event *EventHandler::getNextEvent()
+{
+ Event *event = NULL;
+#ifdef X11
+ XEvent xe;
+ XNextEvent(gctx->display, &xe);
+
+ if(xe.type == MotionNotify) {
+ MouseMoveEvent *e = new MouseMoveEvent();
+ e->window_id = xe.xmotion.window;
+ e->x = xe.xmotion.x;
+ e->y = xe.xmotion.y;
+ event = e;
+ }
+
+ if(xe.type == Expose && xe.xexpose.count == 0) {
+ RepaintEvent *e = new RepaintEvent();
+ e->window_id = xe.xexpose.window;
+ e->x = xe.xexpose.x;
+ e->y = xe.xexpose.y;
+ e->width = xe.xexpose.width;
+ e->height = xe.xexpose.height;
+ event = e;
+ }
+
+ if(xe.type == ButtonPress || xe.type == ButtonRelease) {
+ ButtonEvent *e = new ButtonEvent();
+ e->window_id = xe.xbutton.window;
+ e->x = xe.xbutton.x;
+ e->y = xe.xbutton.y;
+ e->button = 0;
+ e->direction = xe.type == ButtonPress?1:-1;
+ event = e;
+ }
+
+ if(xe.type == KeyPress || xe.type == KeyRelease) {
+ // printf("key: %d\n", e.xkey.keycode);
+ KeyEvent *e = new KeyEvent();
+ e->window_id = xe.xkey.window;
+
+ char buf[1024];
+ int sz = XLookupString(&xe.xkey, buf, sizeof(buf), NULL, NULL);
+
+ e->keycode = xe.xkey.keycode;
+ e->text.append(buf, sz);
+ e->direction = xe.type == KeyPress?1:-1;
+ event = e;
+ }
+
+#if 0
+ printf("event: %d\n", e.type);
+
+ if(e.type == DestroyNotify) {
+ }
+ if(e.type == ClientMessage &&
+ e.xclient.data.l[0] == wdg->wmDeleteMessage) {
+ }
+#endif
+
+#endif/*X11*/
+
+ return event;
+}
+
+
+
+#ifdef TEST_EVENTHANDLER
+//Additional dependency files
+//deps:
+//Required cflags (autoconf vars may be used)
+//cflags:
+//Required link options (autoconf vars may be used)
+//libs:
+#include "test.h"
+
+TEST_BEGIN;
+
+// TODO: Put some testcode here (see test.h for usable macros).
+
+TEST_END;
+
+#endif/*TEST_EVENTHANDLER*/
diff --git a/plugingui/eventhandler.h b/plugingui/eventhandler.h
new file mode 100644
index 0000000..a0ccd63
--- /dev/null
+++ b/plugingui/eventhandler.h
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * eventhandler.h
+ *
+ * Sun Oct 9 18:58:29 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_EVENTHANDLER_H__
+#define __DRUMGIZMO_EVENTHANDLER_H__
+
+#include "event.h"
+
+class GlobalContext;
+
+class EventHandler {
+public:
+ EventHandler(GlobalContext *gctx);
+
+ bool hasEvent();
+ Event *getNextEvent();
+
+private:
+ GlobalContext *gctx;
+};
+
+#endif/*__DRUMGIZMO_EVENTHANDLER_H__*/
diff --git a/plugingui/globalcontext.cc b/plugingui/globalcontext.cc
new file mode 100644
index 0000000..ce97959
--- /dev/null
+++ b/plugingui/globalcontext.cc
@@ -0,0 +1,60 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * globalcontext.cc
+ *
+ * Sun Oct 9 19:16:47 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "globalcontext.h"
+
+GlobalContext::GlobalContext()
+{
+ keyboardFocus = NULL;
+
+#ifdef X11
+ display = XOpenDisplay(NULL);
+#endif/*X11*/
+}
+
+GlobalContext::~GlobalContext()
+{
+#ifdef X11
+ XCloseDisplay(display);
+#endif/*X11*/
+}
+
+#ifdef TEST_GLOBALCONTEXT
+//Additional dependency files
+//deps:
+//Required cflags (autoconf vars may be used)
+//cflags:
+//Required link options (autoconf vars may be used)
+//libs:
+#include "test.h"
+
+TEST_BEGIN;
+
+// TODO: Put some testcode here (see test.h for usable macros).
+
+TEST_END;
+
+#endif/*TEST_GLOBALCONTEXT*/
diff --git a/plugingui/globalcontext.h b/plugingui/globalcontext.h
new file mode 100644
index 0000000..625ba3d
--- /dev/null
+++ b/plugingui/globalcontext.h
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * globalcontext.h
+ *
+ * Sun Oct 9 19:16:47 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_GLOBALCONTEXT_H__
+#define __DRUMGIZMO_GLOBALCONTEXT_H__
+
+#ifdef X11
+#include <X11/Xlib.h>
+#endif/*X11*/
+
+#include <map>
+
+class Widget;
+
+class GlobalContext {
+public:
+ GlobalContext();
+ ~GlobalContext();
+
+ Widget *keyboardFocus;
+
+#ifdef X11
+ Display *display;
+
+ std::map<Window, Widget*> widgets;
+
+#endif/*X11*/
+};
+
+#endif/*__DRUMGIZMO_GLOBALCONTEXT_H__*/
diff --git a/plugingui/gui.cc b/plugingui/gui.cc
new file mode 100644
index 0000000..16a389f
--- /dev/null
+++ b/plugingui/gui.cc
@@ -0,0 +1,120 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * gui.cc
+ *
+ * Mon Oct 3 13:40:49 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "gui.h"
+
+#include <stdio.h>
+
+#include "globalcontext.h"
+
+#include "button.h"
+#include "lineedit.h"
+
+GUI::GUI()
+{
+ gctx = new GlobalContext();
+ eventhandler = new EventHandler(gctx);
+ window = new _Window(gctx);
+ window->setSize(450, 40);
+
+ LineEdit *l = new LineEdit(gctx, window);
+ l->setText("");
+ l->move(10, 10);
+ l->setSize(210, 20);
+
+ Button *b1 = new Button(gctx, window);
+ b1->setText("OK");
+ b1->move(230, 10);
+ b1->setSize(100, 20);
+
+ Button *b2 = new Button(gctx, window);
+ b2->setText("Cancel");
+ b2->move(340, 10);
+ b2->setSize(100, 20);
+}
+
+GUI::~GUI()
+{
+ delete window;
+ delete eventhandler;
+ delete gctx;
+}
+
+void GUI::show()
+{
+ window->show();
+}
+
+void GUI::hide()
+{
+ window->hide();
+}
+
+void GUI::processEvents()
+{
+ while(eventhandler->hasEvent()) {
+ Event *event = eventhandler->getNextEvent();
+
+ if(event == NULL) continue;
+
+ Widget *widget = gctx->widgets[event->window_id];
+ switch(event->type()) {
+ case Event::Repaint:
+ widget->repaint((RepaintEvent*)event);
+ break;
+ case Event::MouseMove:
+ widget->mouseMove((MouseMoveEvent*)event);
+ break;
+ case Event::Button:
+ widget->button((ButtonEvent*)event);
+ break;
+ case Event::Key:
+ //widget->key((KeyEvent*)event);
+ if(gctx->keyboardFocus) gctx->keyboardFocus->key((KeyEvent*)event);
+ break;
+ }
+
+ delete event;
+ }
+}
+
+#ifdef STANDALONE
+
+int main()
+{
+ GUI gui;
+
+ gui.show();
+
+ while(true) {
+ gui.processEvents();
+ usleep(1000);
+ }
+
+ return 0;
+}
+
+#endif/*STANDALONE*/
diff --git a/plugingui/gui.h b/plugingui/gui.h
new file mode 100644
index 0000000..0e6fbb6
--- /dev/null
+++ b/plugingui/gui.h
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * gui.h
+ *
+ * Mon Oct 3 13:40:49 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_GUI_H__
+#define __DRUMGIZMO_GUI_H__
+
+#include "window.h"
+#include "eventhandler.h"
+
+class GlobalContext;
+
+class GUI {
+public:
+ GUI();
+ ~GUI();
+
+ void show();
+ void hide();
+ void processEvents();
+
+private:
+ _Window *window;
+ EventHandler *eventhandler;
+ GlobalContext *gctx;
+};
+
+#endif/*__DRUMGIZMO_GUI_H__*/
diff --git a/plugingui/label.cc b/plugingui/label.cc
new file mode 100644
index 0000000..8ec6330
--- /dev/null
+++ b/plugingui/label.cc
@@ -0,0 +1,44 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * label.cc
+ *
+ * Sun Oct 9 13:02:18 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "label.h"
+
+#ifdef TEST_LABEL
+//Additional dependency files
+//deps:
+//Required cflags (autoconf vars may be used)
+//cflags:
+//Required link options (autoconf vars may be used)
+//libs:
+#include "test.h"
+
+TEST_BEGIN;
+
+// TODO: Put some testcode here (see test.h for usable macros).
+
+TEST_END;
+
+#endif/*TEST_LABEL*/
diff --git a/plugingui/label.h b/plugingui/label.h
new file mode 100644
index 0000000..d9087ab
--- /dev/null
+++ b/plugingui/label.h
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * label.h
+ *
+ * Sun Oct 9 13:02:17 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_LABEL_H__
+#define __DRUMGIZMO_LABEL_H__
+#endif/*__DRUMGIZMO_LABEL_H__*/
diff --git a/plugingui/lineedit.cc b/plugingui/lineedit.cc
new file mode 100644
index 0000000..510c551
--- /dev/null
+++ b/plugingui/lineedit.cc
@@ -0,0 +1,119 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * lineedit.cc
+ *
+ * Sun Oct 9 13:01:52 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "lineedit.h"
+
+#include <stdio.h>
+
+#include "painter.h"
+#include "globalcontext.h"
+
+#define BORDER 10
+
+LineEdit::LineEdit(GlobalContext *gctx, Widget *parent)
+ : Widget(gctx, parent)
+{
+ pos = 0;
+ gctx->keyboardFocus = this;
+}
+
+void LineEdit::setText(std::string text)
+{
+ _text = text;
+}
+
+std::string LineEdit::text()
+{
+ return _text;
+}
+
+void LineEdit::key(KeyEvent *e)
+{
+ // printf("%d\n", e->keycode);
+ if(e->direction == -1) {
+
+ if(e->keycode == 113) { // left key
+ if(pos) pos--;
+
+ } else if(e->keycode == 114) { // right key
+ if(pos < _text.length()) pos++;
+
+ } else if(e->keycode == 119) { // delete
+ if(pos < _text.length()) {
+ std::string t = _text.substr(0, pos);
+ t += _text.substr(pos + 1, std::string::npos);
+ _text = t;
+ }
+
+ } else if(e->keycode == 22) { // backspace
+ if(pos > 0) {
+ std::string t = _text.substr(0, pos - 1);
+ t += _text.substr(pos, std::string::npos);
+ _text = t;
+ pos--;
+ }
+
+ } else if(e->keycode >= 10 && e->keycode <= 61) {
+ _text += e->text;
+ pos++;
+ }
+
+ repaint(NULL);
+ }
+}
+
+void LineEdit::repaint(RepaintEvent *e)
+{
+ Painter p(gctx, wctx);
+
+ p.setColour(Colour(0));
+ p.drawFilledRectangle(3,3,width()-3,height()-3);
+
+ p.setColour(Colour(1,1,1));
+ p.drawRectangle(0,0,width()-1,height()-1);
+ p.drawRectangle(2,2,width()-5,height()-5);
+ p.drawText(BORDER, height()/2+4, _text);
+
+ p.setColour(Colour(0.8));
+ p.drawLine(pos * 6 + BORDER - 1, 4, pos * 6 + BORDER - 1, height() - 5);
+}
+
+#ifdef TEST_LINEEDIT
+//Additional dependency files
+//deps:
+//Required cflags (autoconf vars may be used)
+//cflags:
+//Required link options (autoconf vars may be used)
+//libs:
+#include "test.h"
+
+TEST_BEGIN;
+
+// TODO: Put some testcode here (see test.h for usable macros).
+
+TEST_END;
+
+#endif/*TEST_LINEEDIT*/
diff --git a/plugingui/lineedit.h b/plugingui/lineedit.h
new file mode 100644
index 0000000..9e3e209
--- /dev/null
+++ b/plugingui/lineedit.h
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * lineedit.h
+ *
+ * Sun Oct 9 13:01:52 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_LINEEDIT_H__
+#define __DRUMGIZMO_LINEEDIT_H__
+
+
+#include <string>
+
+#include "widget.h"
+
+class LineEdit : public Widget {
+public:
+ LineEdit(GlobalContext *gctx, Widget *parent);
+
+ std::string text();
+ void setText(std::string text);
+
+protected:
+ void key(KeyEvent *e);
+ void repaint(RepaintEvent *e);
+
+private:
+ std::string _text;
+ size_t pos;
+};
+
+#endif/*__DRUMGIZMO_LINEEDIT_H__*/
diff --git a/plugingui/painter.cc b/plugingui/painter.cc
new file mode 100644
index 0000000..3002c99
--- /dev/null
+++ b/plugingui/painter.cc
@@ -0,0 +1,113 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * painter.cc
+ *
+ * Wed Oct 12 19:48:45 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "painter.h"
+
+#include "globalcontext.h"
+#include "widgetcontext.h"
+
+Painter::Painter(GlobalContext *gctx, WidgetContext *wctx)
+{
+ this->gctx = gctx;
+ this->wctx = wctx;
+}
+
+Painter::~Painter()
+{
+ flush();
+}
+
+void Painter::setColour(Colour colour)
+{
+ this->colour = colour;
+#ifdef X11
+ // Tell the GC we draw using the white color
+ XSetForeground(gctx->display, wctx->gc, colour.getColour(gctx));
+#endif/*X11*/
+}
+
+void Painter::drawLine(int x1, int y1, int x2, int y2)
+{
+#ifdef X11
+ XDrawLine(gctx->display, wctx->window, wctx->gc, x1, y1, x2, y2);
+#endif/*X11*/
+}
+
+void Painter::drawRectangle(int x1, int y1, int x2, int y2)
+{
+#ifdef X11
+ XDrawRectangle(gctx->display, wctx->window, wctx->gc, x1, y1, x2, y2);
+#endif/*X11*/
+}
+
+void Painter::drawFilledRectangle(int x1, int y1, int x2, int y2)
+{
+#ifdef X11
+ for(int i = x1; i < x2; i++) {
+ for(int j = y1; j < y2; j++) {
+ XDrawPoint(gctx->display, wctx->window, wctx->gc, i, j);
+ }
+ }
+#endif/*X11*/
+}
+
+void Painter::drawText(int x, int y, std::string text)
+{
+#ifdef X11
+ XTextItem item;
+ item.chars = (char*)text.data();
+ item.nchars = text.length();
+ item.delta = 0;
+ item.font = None;
+
+ XDrawText(gctx->display, wctx->window, wctx->gc, x, y, &item, 1);
+#endif/*X11*/
+}
+
+void Painter::flush()
+{
+#ifdef X11
+ // Send the "DrawLine" request to the server
+ XFlush(gctx->display);
+#endif/*X11*/
+}
+
+#ifdef TEST_PAINTER
+//Additional dependency files
+//deps:
+//Required cflags (autoconf vars may be used)
+//cflags:
+//Required link options (autoconf vars may be used)
+//libs:
+#include "test.h"
+
+TEST_BEGIN;
+
+// TODO: Put some testcode here (see test.h for usable macros).
+
+TEST_END;
+
+#endif/*TEST_PAINTER*/
diff --git a/plugingui/painter.h b/plugingui/painter.h
new file mode 100644
index 0000000..ba9b7de
--- /dev/null
+++ b/plugingui/painter.h
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * painter.h
+ *
+ * Wed Oct 12 19:48:45 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_PAINTER_H__
+#define __DRUMGIZMO_PAINTER_H__
+
+#include <string>
+
+#include "colour.h"
+
+class GlobalContext;
+class WidgetContext;
+
+class Painter {
+public:
+ Painter(GlobalContext *gctx, WidgetContext *wctx);
+ ~Painter();
+
+ void flush();
+
+ void setColour(Colour colour);
+
+ void drawLine(int x1, int y1, int x2, int y2);
+ void drawText(int x, int y, std::string text);
+ void drawRectangle(int x1, int y1, int x2, int y2);
+ void drawFilledRectangle(int x1, int y1, int x2, int y2);
+
+private:
+ GlobalContext *gctx;
+ WidgetContext *wctx;
+ Colour colour;
+};
+
+
+#endif/*__DRUMGIZMO_PAINTER_H__*/
diff --git a/plugingui/widget.cc b/plugingui/widget.cc
new file mode 100644
index 0000000..12100dc
--- /dev/null
+++ b/plugingui/widget.cc
@@ -0,0 +1,152 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * widget.cc
+ *
+ * Sun Oct 9 13:01:44 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "widget.h"
+
+#include "globalcontext.h"
+#include "widgetcontext.h"
+
+#include <stdio.h>
+
+#include <X11/Xatom.h>
+
+Widget::Widget(GlobalContext *gctx, Widget *parent)
+{
+ this->gctx = gctx;
+ this->parent = parent;
+ wctx = new WidgetContext();
+
+ _x = _y = _width = _height = 10;
+
+#ifdef X11
+
+ // Get some colors
+ int blackColor = BlackPixel(gctx->display, DefaultScreen(gctx->display));
+
+ Window w;
+ if(parent == NULL) w = DefaultRootWindow(gctx->display);
+ else w = parent->wctx->window;
+
+
+ // Create the window
+ wctx->window = XCreateSimpleWindow(gctx->display,
+ w, _x, _y, _width, _height, 0,
+ blackColor, blackColor);
+
+ gctx->widgets[wctx->window] = this;
+
+ // We want to get MapNotify events
+ XSelectInput(gctx->display, wctx->window,
+ StructureNotifyMask |
+ PointerMotionMask |
+ ButtonPressMask |
+ ButtonReleaseMask |
+ KeyPressMask |
+ KeyReleaseMask|
+ ExposureMask |
+ StructureNotifyMask);
+
+ /*
+ // register interest in the delete window message
+ wdg->wmDeleteMessage = XInternAtom(wdg->dpy, "WM_DELETE_WINDOW", false);
+ XSetWMProtocols(wdg->dpy, wdg->w, &wdg->wmDeleteMessage, 1);
+ */
+
+ // "Map" the window (that is, make it appear on the screen)
+ XMapWindow(gctx->display, wctx->window);
+
+ // Create a "Graphics Context"
+ wctx->gc = XCreateGC(gctx->display, wctx->window, 0, NULL);
+
+ // Wait for the MapNotify event
+ for(;;) {
+ XEvent e;
+ XNextEvent(gctx->display, &e);
+ if(e.type == MapNotify) break;
+ }
+#endif
+}
+
+Widget::~Widget()
+{
+#ifdef X11
+ gctx->widgets.erase(wctx->window);
+#endif/*X11*/
+ delete wctx;
+}
+
+void Widget::show()
+{
+}
+
+void Widget::hide()
+{
+}
+
+void Widget::addChild(Widget *widget)
+{
+ children.push_back(widget);
+}
+
+void Widget::setSize(size_t width, size_t height)
+{
+ _width = width;
+ _height = height;
+#ifdef X11
+ XResizeWindow(gctx->display, wctx->window, width, height);
+#endif/*X11*/
+}
+
+void Widget::move(size_t x, size_t y)
+{
+ _x = x;
+ _y = y;
+#ifdef X11
+ XMoveWindow(gctx->display, wctx->window, x, y);
+#endif/*X11*/
+}
+
+size_t Widget::x() { return _x; }
+size_t Widget::y() { return _y; }
+size_t Widget::width() { return _width; }
+size_t Widget::height() { return _height; }
+
+#ifdef TEST_WIDGET
+//Additional dependency files
+//deps:
+//Required cflags (autoconf vars may be used)
+//cflags:
+//Required link options (autoconf vars may be used)
+//libs:
+#include "test.h"
+
+TEST_BEGIN;
+
+// TODO: Put some testcode here (see test.h for usable macros).
+
+TEST_END;
+
+#endif/*TEST_WIDGET*/
diff --git a/plugingui/widget.h b/plugingui/widget.h
new file mode 100644
index 0000000..9a3baa6
--- /dev/null
+++ b/plugingui/widget.h
@@ -0,0 +1,68 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * widget.h
+ *
+ * Sun Oct 9 13:01:44 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_WIDGET_H__
+#define __DRUMGIZMO_WIDGET_H__
+
+#include <vector>
+
+class GlobalContext;
+class WidgetContext;
+
+#include "event.h"
+
+class Widget {
+public:
+ Widget(GlobalContext *gctx, Widget *parent);
+ ~Widget();
+
+ void show();
+ void hide();
+
+ void setSize(size_t width, size_t height);
+ void move(size_t x, size_t y);
+
+ size_t x();
+ size_t y();
+ size_t width();
+ size_t height();
+
+ void addChild(Widget *widget);
+
+ virtual void repaint(RepaintEvent *e) {}
+ virtual void mouseMove(MouseMoveEvent *e) {}
+ virtual void button(ButtonEvent *e) {}
+ virtual void key(KeyEvent *e) {}
+
+protected:
+ GlobalContext *gctx;
+ WidgetContext *wctx;
+ std::vector<Widget*> children;
+ Widget *parent;
+ size_t _x, _y, _width, _height;
+};
+
+#endif/*__DRUMGIZMO_WIDGET_H__*/
diff --git a/plugingui/widgetcontext.h b/plugingui/widgetcontext.h
new file mode 100644
index 0000000..e555777
--- /dev/null
+++ b/plugingui/widgetcontext.h
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * widgetcontext.h
+ *
+ * Sun Oct 9 19:16:33 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_WIDGETCONTEXT_H__
+#define __DRUMGIZMO_WIDGETCONTEXT_H__
+
+#ifdef X11
+#include <X11/Xlib.h>
+#endif/*X11*/
+
+class WidgetContext {
+public:
+#ifdef X11
+ Window window;
+ GC gc;
+#endif/*X11*/
+};
+
+#endif/*__DRUMGIZMO_WIDGETCONTEXT_H__*/
diff --git a/plugingui/window.cc b/plugingui/window.cc
new file mode 100644
index 0000000..db302a5
--- /dev/null
+++ b/plugingui/window.cc
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * window.cc
+ *
+ * Sun Oct 9 13:11:53 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "window.h"
+
+#include "globalcontext.h"
+#include "widgetcontext.h"
+
+#include "painter.h"
+
+_Window::_Window(GlobalContext *gctx) : Widget(gctx, 0)
+{
+}
+
+void _Window::repaint(RepaintEvent *e)
+{
+}
+
+#ifdef TEST_WINDOW
+//Additional dependency files
+//deps:
+//Required cflags (autoconf vars may be used)
+//cflags:
+//Required link options (autoconf vars may be used)
+//libs:
+#include "test.h"
+
+TEST_BEGIN;
+
+// TODO: Put some testcode here (see test.h for usable macros).
+
+TEST_END;
+
+#endif/*TEST_WINDOW*/
diff --git a/plugingui/window.h b/plugingui/window.h
new file mode 100644
index 0000000..de36160
--- /dev/null
+++ b/plugingui/window.h
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * window.h
+ *
+ * Sun Oct 9 13:11:52 CEST 2011
+ * Copyright 2011 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __DRUMGIZMO_WINDOW_H__
+#define __DRUMGIZMO_WINDOW_H__
+
+#include "widget.h"
+
+class _Window : public Widget {
+public:
+ _Window(GlobalContext *gctx);
+
+ void repaint(RepaintEvent *e);
+};
+
+#endif/*__DRUMGIZMO_WINDOW_H__*/