2015-09-04 16:52:07 -05:00
|
|
|
// 4 september 2015
|
2015-09-07 14:34:14 -05:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <math.h>
|
2015-09-04 16:52:07 -05:00
|
|
|
#include "area.h"
|
|
|
|
|
2015-09-04 16:56:13 -05:00
|
|
|
// #qo pkg-config: gtk+-3.0
|
|
|
|
|
2015-09-04 16:52:07 -05:00
|
|
|
struct handler {
|
|
|
|
uiAreaHandler ah;
|
|
|
|
};
|
|
|
|
|
2015-09-04 20:27:32 -05:00
|
|
|
static GtkWidget *area;
|
2015-09-04 16:52:07 -05:00
|
|
|
static struct handler h;
|
|
|
|
static GtkWidget *nhspinb;
|
|
|
|
static GtkWidget *nvspinb;
|
|
|
|
|
2015-09-06 19:02:01 -05:00
|
|
|
static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p)
|
2015-09-06 15:20:37 -05:00
|
|
|
{
|
2015-09-06 19:02:01 -05:00
|
|
|
uiDrawStrokeParams sp;
|
|
|
|
|
2015-09-07 09:13:15 -05:00
|
|
|
uiDrawBeginPathRGB(p->Context, 0xFF, 0x00, 0x00);
|
2015-09-06 19:02:01 -05:00
|
|
|
uiDrawMoveTo(p->Context, p->ClipX + 5, p->ClipY + 5);
|
|
|
|
uiDrawLineTo(p->Context, (p->ClipX + p->ClipWidth) - 5, (p->ClipY + p->ClipHeight) - 5);
|
|
|
|
sp.Cap = uiDrawLineCapFlat;
|
|
|
|
sp.Join = uiDrawLineJoinMiter;
|
|
|
|
sp.Thickness = 1;
|
2015-09-06 21:48:25 -05:00
|
|
|
sp.MiterLimit = uiDrawDefaultMiterLimit;
|
2015-09-06 19:02:01 -05:00
|
|
|
uiDrawStroke(p->Context, &sp);
|
|
|
|
|
2015-09-07 09:25:59 -05:00
|
|
|
uiDrawBeginPathRGB(p->Context, 0x00, 0x00, 0xC0);
|
2015-09-06 19:02:01 -05:00
|
|
|
uiDrawMoveTo(p->Context, p->ClipX, p->ClipY);
|
|
|
|
uiDrawLineTo(p->Context, p->ClipX + p->ClipWidth, p->ClipY);
|
2015-09-06 21:48:25 -05:00
|
|
|
uiDrawLineTo(p->Context, 50, 150);
|
|
|
|
uiDrawLineTo(p->Context, 50, 50);
|
|
|
|
uiDrawCloseFigure(p->Context);
|
2015-09-06 19:02:01 -05:00
|
|
|
sp.Cap = uiDrawLineCapFlat;
|
2015-09-06 21:48:25 -05:00
|
|
|
sp.Join = uiDrawLineJoinRound;
|
|
|
|
sp.Thickness = 5;
|
2015-09-06 19:02:01 -05:00
|
|
|
uiDrawStroke(p->Context, &sp);
|
2015-09-07 09:13:15 -05:00
|
|
|
|
2015-09-07 09:25:59 -05:00
|
|
|
uiDrawBeginPathRGBA(p->Context, 0x00, 0xC0, 0x00, 0x80);
|
|
|
|
uiDrawRectangle(p->Context, 120, 80, 50, 50);
|
|
|
|
uiDrawFill(p->Context, uiDrawFillModeWinding);
|
|
|
|
|
2015-09-07 09:13:15 -05:00
|
|
|
uiDrawBeginPathRGB(p->Context, 0x00, 0x80, 0x00);
|
|
|
|
uiDrawMoveTo(p->Context, 5, 10);
|
|
|
|
uiDrawLineTo(p->Context, 5, 50);
|
|
|
|
sp.Cap = uiDrawLineCapFlat;
|
|
|
|
sp.Join = uiDrawLineJoinMiter;
|
|
|
|
sp.Thickness = 1;
|
|
|
|
sp.MiterLimit = uiDrawDefaultMiterLimit;
|
2015-09-07 14:34:14 -05:00
|
|
|
uiDrawStroke(p->Context, &sp);
|
|
|
|
|
|
|
|
uiDrawBeginPathRGB(p->Context, 0x80, 0xC0, 0x00);
|
|
|
|
uiDrawMoveTo(p->Context, 400, 100);
|
2015-09-08 15:28:08 -05:00
|
|
|
uiDrawArcTo(p->Context,
|
2015-09-07 14:34:14 -05:00
|
|
|
400, 100,
|
|
|
|
50,
|
|
|
|
30. * (M_PI / 180.),
|
|
|
|
// note the end angle here
|
|
|
|
// in GDI, the second angle to AngleArc() is relative to the start, not to 0
|
|
|
|
330. * (M_PI / 180.),
|
|
|
|
1);
|
|
|
|
// TODO add a checkbox for this
|
|
|
|
uiDrawLineTo(p->Context, 400, 100);
|
2015-09-08 15:28:08 -05:00
|
|
|
uiDrawArcTo(p->Context,
|
2015-09-07 14:34:14 -05:00
|
|
|
510, 100,
|
|
|
|
50,
|
|
|
|
30. * (M_PI / 180.),
|
|
|
|
330. * (M_PI / 180.),
|
|
|
|
0);
|
|
|
|
uiDrawCloseFigure(p->Context);
|
|
|
|
sp.Cap = uiDrawLineCapFlat;
|
|
|
|
sp.Join = uiDrawLineJoinMiter;
|
|
|
|
sp.Thickness = 1;
|
|
|
|
sp.MiterLimit = uiDrawDefaultMiterLimit;
|
2015-09-07 18:29:42 -05:00
|
|
|
uiDrawStroke(p->Context, &sp);
|
|
|
|
|
|
|
|
uiDrawBeginPathRGB(p->Context, 0x00, 0x80, 0xC0);
|
|
|
|
uiDrawMoveTo(p->Context, 300, 300);
|
|
|
|
uiDrawBezierTo(p->Context,
|
|
|
|
350, 320,
|
|
|
|
310, 390,
|
|
|
|
435, 372);
|
|
|
|
sp.Cap = uiDrawLineCapFlat;
|
|
|
|
sp.Join = uiDrawLineJoinMiter;
|
|
|
|
sp.Thickness = 1;
|
|
|
|
sp.MiterLimit = uiDrawDefaultMiterLimit;
|
2015-09-07 09:13:15 -05:00
|
|
|
uiDrawStroke(p->Context, &sp);
|
2015-09-06 15:20:37 -05:00
|
|
|
}
|
|
|
|
|
2015-09-05 19:05:48 -05:00
|
|
|
static uintmax_t handlerHScrollMax(uiAreaHandler *a, uiArea *area)
|
2015-09-04 16:52:07 -05:00
|
|
|
{
|
2015-09-05 19:05:48 -05:00
|
|
|
return gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(nhspinb));
|
2015-09-04 16:52:07 -05:00
|
|
|
}
|
|
|
|
|
2015-09-05 19:05:48 -05:00
|
|
|
static uintmax_t handlerVScrollMax(uiAreaHandler *a, uiArea *area)
|
2015-09-04 16:52:07 -05:00
|
|
|
{
|
2015-09-05 19:05:48 -05:00
|
|
|
return gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(nvspinb));
|
2015-09-04 16:52:07 -05:00
|
|
|
}
|
|
|
|
|
2015-09-10 20:17:00 -05:00
|
|
|
static int handlerRedrawOnResize(uiAreaHandler *a, uiArea *area)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-09-11 12:07:27 -05:00
|
|
|
static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e)
|
|
|
|
{
|
2015-09-11 15:01:54 -05:00
|
|
|
printf("mouse (%d,%d):(%d,%d) down:%d up:%d count:%d mods:%x held:%x\n",
|
2015-09-11 12:07:27 -05:00
|
|
|
(int) e->X,
|
|
|
|
(int) e->Y,
|
|
|
|
(int) e->HScrollPos,
|
|
|
|
(int) e->VScrollPos,
|
|
|
|
(int) e->Down,
|
|
|
|
(int) e->Up,
|
|
|
|
(int) e->Count,
|
|
|
|
(uint32_t) e->Modifiers,
|
|
|
|
e->Held1To64);
|
|
|
|
}
|
|
|
|
|
2015-09-11 21:59:59 -05:00
|
|
|
static void handlerDragBroken(uiAreaHandler *ah, uiArea *a)
|
|
|
|
{
|
|
|
|
printf("drag broken\n");
|
|
|
|
}
|
|
|
|
|
2015-09-12 22:21:34 -05:00
|
|
|
static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e)
|
|
|
|
{
|
|
|
|
char k[4];
|
|
|
|
|
|
|
|
k[0] = '\'';
|
|
|
|
k[1] = e->Key;
|
|
|
|
k[2] = '\'';
|
|
|
|
k[3] = '\0';
|
|
|
|
if (e->Key == 0) {
|
|
|
|
k[0] = '0';
|
|
|
|
k[1] = '\0';
|
|
|
|
}
|
|
|
|
printf("key key:%s extkey:%d mod:%d mods:%d up:%d\n",
|
|
|
|
k,
|
|
|
|
(int) e->ExtKey,
|
|
|
|
(int) e->Modifier,
|
|
|
|
(int) e->Modifiers;
|
|
|
|
e->Up);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-09-04 20:12:41 -05:00
|
|
|
static void recalcScroll(GtkSpinButton *sb, gpointer data)
|
|
|
|
{
|
2015-09-04 20:27:32 -05:00
|
|
|
areaUpdateScroll(area);
|
2015-09-04 20:12:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *makeSpinbox(int min)
|
|
|
|
{
|
|
|
|
GtkWidget *sb;
|
|
|
|
|
|
|
|
sb = gtk_spin_button_new_with_range(min, 100000, 1);
|
|
|
|
gtk_spin_button_set_digits(GTK_SPIN_BUTTON(sb), 0);
|
|
|
|
g_signal_connect(sb, "value-changed", G_CALLBACK(recalcScroll), NULL);
|
|
|
|
return sb;
|
|
|
|
}
|
|
|
|
|
2015-09-04 16:52:07 -05:00
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
GtkWidget *mainwin;
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *scroller;
|
|
|
|
GtkWidget *grid;
|
|
|
|
|
2015-09-06 15:20:37 -05:00
|
|
|
h.ah.Draw = handlerDraw;
|
2015-09-05 19:05:48 -05:00
|
|
|
h.ah.HScrollMax = handlerHScrollMax;
|
|
|
|
h.ah.VScrollMax = handlerVScrollMax;
|
2015-09-10 20:17:00 -05:00
|
|
|
h.ah.RedrawOnResize = handlerRedrawOnResize;
|
2015-09-11 12:07:27 -05:00
|
|
|
h.ah.MouseEvent = handlerMouseEvent;
|
2015-09-11 21:59:59 -05:00
|
|
|
h.ah.DragBroken = handlerDragBroken;
|
2015-09-12 22:21:34 -05:00
|
|
|
h.ah.KeyEvent = handlerKeyEvent;
|
2015-09-04 16:52:07 -05:00
|
|
|
|
|
|
|
gtk_init(NULL, NULL);
|
|
|
|
|
|
|
|
mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(mainwin), 12);
|
|
|
|
g_signal_connect(mainwin, "destroy", G_CALLBACK(gtk_main_quit), NULL);
|
|
|
|
|
|
|
|
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
|
|
|
|
gtk_container_add(GTK_CONTAINER(mainwin), box);
|
|
|
|
|
|
|
|
scroller = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
gtk_widget_set_hexpand(scroller, TRUE);
|
|
|
|
gtk_widget_set_halign(scroller, GTK_ALIGN_FILL);
|
|
|
|
gtk_widget_set_vexpand(scroller, TRUE);
|
|
|
|
gtk_widget_set_valign(scroller, GTK_ALIGN_FILL);
|
|
|
|
gtk_container_add(GTK_CONTAINER(box), scroller);
|
|
|
|
|
|
|
|
grid = gtk_grid_new();
|
|
|
|
gtk_widget_set_halign(grid, GTK_ALIGN_START);
|
|
|
|
gtk_container_add(GTK_CONTAINER(box), grid);
|
|
|
|
|
|
|
|
gtk_grid_attach(GTK_GRID(grid),
|
|
|
|
gtk_label_new("H Count"),
|
|
|
|
0, 0, 1, 1);
|
2015-09-04 20:12:41 -05:00
|
|
|
nhspinb = makeSpinbox(0);
|
|
|
|
gtk_grid_attach(GTK_GRID(grid), nhspinb,
|
|
|
|
1, 0, 1, 1);
|
2015-09-04 16:52:07 -05:00
|
|
|
|
|
|
|
gtk_grid_attach(GTK_GRID(grid),
|
|
|
|
gtk_label_new("V Count"),
|
2015-09-05 19:05:48 -05:00
|
|
|
0, 1, 1, 1);
|
2015-09-04 20:12:41 -05:00
|
|
|
nvspinb = makeSpinbox(0);
|
|
|
|
gtk_grid_attach(GTK_GRID(grid), nvspinb,
|
2015-09-05 19:05:48 -05:00
|
|
|
1, 1, 1, 1);
|
2015-09-04 20:12:41 -05:00
|
|
|
|
|
|
|
area = newArea((uiAreaHandler *) (&h));
|
|
|
|
gtk_container_add(GTK_CONTAINER(scroller), area);
|
2015-09-04 16:52:07 -05:00
|
|
|
|
|
|
|
gtk_widget_show_all(mainwin);
|
|
|
|
gtk_main();
|
|
|
|
return 0;
|
|
|
|
}
|