summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2011-10-18 14:49:43 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2011-10-18 14:49:43 +0200
commit3e85cc8bfccf63236e815eba64acd99fbe154daf (patch)
treec3988ded4857263cebff1515999fa5f44aa39b85 /plugingui
parentef47c71a29292ff9114a67d782e526ac662a1f32 (diff)
New Label and LED widgets.
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/Makefile.am2
-rw-r--r--plugingui/button.cc4
-rw-r--r--plugingui/globalcontext.h6
-rw-r--r--plugingui/gui.cc20
-rw-r--r--plugingui/label.cc21
-rw-r--r--plugingui/label.h16
-rw-r--r--plugingui/led.cc78
-rw-r--r--plugingui/painter.cc25
-rw-r--r--plugingui/painter.h3
-rw-r--r--plugingui/widget.cc43
10 files changed, 209 insertions, 9 deletions
diff --git a/plugingui/Makefile.am b/plugingui/Makefile.am
index 149f4a7..08c2d0c 100644
--- a/plugingui/Makefile.am
+++ b/plugingui/Makefile.am
@@ -9,6 +9,7 @@ plugingui_SOURCES = \
globalcontext.cc \
gui.cc \
colour.cc \
+ led.cc \
window.cc \
widget.cc \
lineedit.cc \
@@ -24,6 +25,7 @@ EXTRA_DIST = \
globalcontext.h \
gui.h \
colour.h \
+ led.h \
window.h \
widget.h \
lineedit.h \
diff --git a/plugingui/button.cc b/plugingui/button.cc
index a5c6947..a833ad3 100644
--- a/plugingui/button.cc
+++ b/plugingui/button.cc
@@ -60,11 +60,11 @@ void Button::repaint(RepaintEvent *e)
p.drawRectangle(0,0,width()-1,height()-1);
p.setColour(Colour(0.8));
- if(state == down) {
+ if(state == up) {
p.drawLine(1,1,1,height());
p.drawLine(1,1,width(),1);
}
- if(state == up) {
+ if(state == down) {
p.drawLine(width()-2,0, width()-2,height()-2);
p.drawLine(width()-2,height()-2,0, height()-2);
}
diff --git a/plugingui/globalcontext.h b/plugingui/globalcontext.h
index 625ba3d..2aa083b 100644
--- a/plugingui/globalcontext.h
+++ b/plugingui/globalcontext.h
@@ -31,6 +31,10 @@
#include <X11/Xlib.h>
#endif/*X11*/
+#ifdef WIN32
+#include <windows.h>
+#endif/*WIN32*/
+
#include <map>
class Widget;
@@ -44,9 +48,7 @@ public:
#ifdef X11
Display *display;
-
std::map<Window, Widget*> widgets;
-
#endif/*X11*/
};
diff --git a/plugingui/gui.cc b/plugingui/gui.cc
index 16a389f..37c318c 100644
--- a/plugingui/gui.cc
+++ b/plugingui/gui.cc
@@ -32,28 +32,40 @@
#include "button.h"
#include "lineedit.h"
+#include "label.h"
+#include "led.h"
GUI::GUI()
{
gctx = new GlobalContext();
eventhandler = new EventHandler(gctx);
window = new _Window(gctx);
- window->setSize(450, 40);
+ window->setSize(450 + 70, 40 + 40);
+
+ Label *lbl = new Label(gctx, window);
+ lbl->setText("Drumkit:");
+ lbl->move(10, 10);
+ lbl->setSize(70, 20);
LineEdit *l = new LineEdit(gctx, window);
l->setText("");
- l->move(10, 10);
+ l->move(10 + 70, 10);
l->setSize(210, 20);
Button *b1 = new Button(gctx, window);
b1->setText("OK");
- b1->move(230, 10);
+ b1->move(230 + 70, 10);
b1->setSize(100, 20);
Button *b2 = new Button(gctx, window);
b2->setText("Cancel");
- b2->move(340, 10);
+ b2->move(340 + 70, 10);
b2->setSize(100, 20);
+
+ LED *led = new LED(gctx, window);
+ led->move(10,30);
+ led->setSize(14, 14);
+ led->setState(false);
}
GUI::~GUI()
diff --git a/plugingui/label.cc b/plugingui/label.cc
index 8ec6330..a8ff0ae 100644
--- a/plugingui/label.cc
+++ b/plugingui/label.cc
@@ -26,6 +26,27 @@
*/
#include "label.h"
+#include "painter.h"
+
+Label::Label(GlobalContext *gctx, Widget *parent)
+ : Widget(gctx, parent)
+{
+}
+
+void Label::setText(std::string text)
+{
+ _text = text;
+ repaint(NULL);
+}
+
+void Label::repaint(RepaintEvent *e)
+{
+ Painter p(gctx, wctx);
+ p.setColour(Colour(1));
+ p.drawText(10, height() / 2 + 4, _text);
+}
+
+
#ifdef TEST_LABEL
//Additional dependency files
//deps:
diff --git a/plugingui/label.h b/plugingui/label.h
index d9087ab..d7ad6c9 100644
--- a/plugingui/label.h
+++ b/plugingui/label.h
@@ -26,4 +26,20 @@
*/
#ifndef __DRUMGIZMO_LABEL_H__
#define __DRUMGIZMO_LABEL_H__
+
+#include "widget.h"
+
+class Label : public Widget {
+public:
+ Label(GlobalContext *gctx, Widget *parent);
+
+ void setText(std::string text);
+
+protected:
+ virtual void repaint(RepaintEvent *e);
+
+private:
+ std::string _text;
+};
+
#endif/*__DRUMGIZMO_LABEL_H__*/
diff --git a/plugingui/led.cc b/plugingui/led.cc
new file mode 100644
index 0000000..a32dcb9
--- /dev/null
+++ b/plugingui/led.cc
@@ -0,0 +1,78 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * led.cc
+ *
+ * Sat Oct 15 19:12: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.
+ */
+#include "led.h"
+
+#include "painter.h"
+
+LED::LED(GlobalContext *gctx, Widget *parent)
+ : Widget(gctx, parent)
+{
+ state = true;
+}
+
+void LED::setState(bool state)
+{
+ if(this->state != state) {
+ this->state = state;
+ repaint(NULL);
+ }
+}
+
+void LED::repaint(RepaintEvent *e)
+{
+ size_t h = height() - 1;
+ size_t w = width() - 1;
+
+ Painter p(gctx, wctx);
+
+ if(state) p.setColour(Colour(0,1,0));
+ else p.setColour(Colour(1,0,0));
+
+ size_t size = w / 2;
+ if(h / 2 < size) size = h / 2;
+ p.drawFilledCircle(w/2, h/2, size);
+
+ p.setColour(Colour(1));
+ p.drawFilledCircle(w/3, h/3, size / 6);
+}
+
+#ifdef TEST_LED
+//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_LED*/
diff --git a/plugingui/painter.cc b/plugingui/painter.cc
index 3002c99..e207811 100644
--- a/plugingui/painter.cc
+++ b/plugingui/painter.cc
@@ -87,6 +87,31 @@ void Painter::drawText(int x, int y, std::string text)
#endif/*X11*/
}
+void Painter::drawPoint(int x, int y)
+{
+#ifdef X11
+ XDrawPoint(gctx->display, wctx->window, wctx->gc, x, y);
+#endif/*X11*/
+}
+
+void Painter::drawCircle(int x, int y, int r)
+{
+#ifdef X11
+ XDrawArc(gctx->display, wctx->window, wctx->gc, x, y, r, r, 0, 360 * 64);
+#endif/*X11*/
+}
+
+void Painter::drawFilledCircle(int x, int y, int r)
+{
+#ifdef X11
+ r *= 2;
+ for(int s = 1; s < r; s++)
+ XDrawArc(gctx->display, wctx->window, wctx->gc,
+ x - s / 2, y - s / 2, s, s,
+ 0, 360 * 64);
+#endif/*X11*/
+}
+
void Painter::flush()
{
#ifdef X11
diff --git a/plugingui/painter.h b/plugingui/painter.h
index ba9b7de..f114c21 100644
--- a/plugingui/painter.h
+++ b/plugingui/painter.h
@@ -47,6 +47,9 @@ public:
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);
+ void drawPoint(int x, int y);
+ void drawCircle(int x, int y, int r);
+ void drawFilledCircle(int x, int y, int r);
private:
GlobalContext *gctx;
diff --git a/plugingui/widget.cc b/plugingui/widget.cc
index 12100dc..04af3c2 100644
--- a/plugingui/widget.cc
+++ b/plugingui/widget.cc
@@ -87,7 +87,48 @@ Widget::Widget(GlobalContext *gctx, Widget *parent)
XNextEvent(gctx->display, &e);
if(e.type == MapNotify) break;
}
-#endif
+#endif/*X11*/
+
+#ifdef WIN32
+ WNDCLASSEX wcex;
+ WNDID wndId;
+
+ wctx->m_hwnd = 0;
+ wctx->m_className = NULL;
+
+ memset(&wcex, 0, sizeof(wcex));
+
+ /*
+ Time to register a window class. Generic flags and everything. cbWndExtra is the
+ size of a pointer to an object - we need this in the wndproc handler.
+ */
+ wcex.cbSize = sizeof(WNDCLASSEX);
+ wcex.style = class_style;
+ wcex.lpfnWndProc = (WNDPROC) data;
+ wcex.cbWndExtra = sizeof(CWindow *);
+ wcex.hInstance = GetModuleHandle(NULL);
+
+ // if(ex_style && WS_EX_TRANSPARENT == WS_EX_TRANSPARENT) {
+ // wcex.hbrBackground = NULL;
+ // } else {
+ wcex.hbrBackground = (HBRUSH) COLOR_BACKGROUND + 1;
+ // }
+
+ wcex.lpszClassName = wctx->m_className = strdup(className);
+
+ RegisterClassEx(&wcex);
+
+ if(parent) {
+ style = style | WS_CHILD;
+ wndId = parent->getWndId();
+ } else {
+ style = style | WS_OVERLAPPEDWINDOW;
+ wndId = 0;
+ }
+
+ wctx->m_hwnd = CreateWindowEx(ex_style, wctx->m_className, "DGBasisWidget", style, x, y, w, h,
+ wndId, NULL, GetModuleHandle(NULL), NULL);
+#endif/*WIN32*/
}
Widget::~Widget()