LMMS
Loading...
Searching...
No Matches
ctl_curve.h
Go to the documentation of this file.
1/* Calf DSP Library
2 * Barely started curve editor widget. Standard GtkCurve is
3 * unreliable and deprecated, so I need to make my own.
4 *
5 * Copyright (C) 2008 Krzysztof Foltman
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this program; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301 USA
21 */
22#ifndef CALF_CTL_CURVE_H
23#define CALF_CTL_CURVE_H
24
25#include <gtk/gtk.h>
26#include <vector>
27
28G_BEGIN_DECLS
29
30#define CALF_TYPE_CURVE (calf_curve_get_type())
31#define CALF_CURVE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CALF_TYPE_CURVE, CalfCurve))
32#define CALF_IS_CURVE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CALF_TYPE_CURVE))
33#define CALF_CURVE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CALF_TYPE_CURVE, CalfCurveClass))
34#define CALF_IS_CURVE_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((klass), CALF_TYPE_CURVE))
35
40{
42 typedef std::pair<float, float> point;
44 typedef std::vector<point> point_vector;
45
47 struct EventSink
48 {
50 virtual void curve_changed(CalfCurve *src, const point_vector &data) = 0;
52 virtual void clip(CalfCurve *src, int pt, float &x, float &y, bool &hide) = 0;
53 virtual ~EventSink() {}
54 };
55
57 struct EventAdapter: public EventSink
58 {
59 virtual void curve_changed(CalfCurve *src, const point_vector &data) {}
60 virtual void clip(CalfCurve *src, int pt, float &x, float &y, bool &hide) {}
61 };
62
65 {
66 virtual void curve_changed(CalfCurve *src, const point_vector &data) {
67 for(size_t i = 0; i < data.size(); i++)
68 g_message("Point %d: (%f, %f)", (int)i, data[i].first, data[i].second);
69 }
70 };
71
73 GtkWidget parent;
77 float x0, y0, x1, y1;
79 int cur_pt;
85 GdkCursor *hand_cursor;
87 GdkCursor *pencil_cursor;
89 GdkCursor *arrow_cursor;
91 unsigned int point_limit;
92
94 void log2phys(float &x, float &y);
96 void phys2log(float &x, float &y);
102 void clip(int pt, float &x, float &y, bool &hide);
103};
104
106{
107 GtkWidgetClass parent_class;
108};
109
111extern GtkWidget *calf_curve_new(unsigned int point_limit = -1);
112
114extern GType calf_curve_get_type();
115
117extern void calf_curve_set_points(GtkWidget *widget, const CalfCurve::point_vector &src);
118
119G_END_DECLS
120
121#endif
122
GType calf_curve_get_type()
Return a GObject type for class CalfCurve.
Definition ctl_curve.cpp:335
void calf_curve_set_points(GtkWidget *widget, const CalfCurve::point_vector &src)
Set points and update the widget.
Definition ctl_curve.cpp:323
GtkWidget * calf_curve_new(unsigned int point_limit=-1)
Create a CalfCurve.
Definition ctl_curve.cpp:30
int y
Definition inflate.c:1588
register unsigned i
Definition inflate.c:1575
unsigned x[BMAX+1]
Definition inflate.c:1586
JSAMPIMAGE data
Definition jpeglib.h:945
Null implementation of EventSink.
Definition ctl_curve.h:58
virtual void curve_changed(CalfCurve *src, const point_vector &data)
Called when a point has been edited, added or removed.
Definition ctl_curve.h:59
virtual void clip(CalfCurve *src, int pt, float &x, float &y, bool &hide)
Called to clip/snap/otherwise adjust candidate point coordinates.
Definition ctl_curve.h:60
User callbacks for handling curve events.
Definition ctl_curve.h:48
virtual void curve_changed(CalfCurve *src, const point_vector &data)=0
Called when a point has been edited, added or removed.
virtual void clip(CalfCurve *src, int pt, float &x, float &y, bool &hide)=0
Called to clip/snap/otherwise adjust candidate point coordinates.
virtual ~EventSink()
Definition ctl_curve.h:53
Debug implementation of EventSink.
Definition ctl_curve.h:65
virtual void curve_changed(CalfCurve *src, const point_vector &data)
Called when a point has been edited, added or removed.
Definition ctl_curve.h:66
Definition ctl_curve.h:106
GtkWidgetClass parent_class
Definition ctl_curve.h:107
Definition ctl_curve.h:40
float y1
Definition ctl_curve.h:77
GdkCursor * arrow_cursor
Cached arrow (do not add point) cursor.
Definition ctl_curve.h:89
void log2phys(float &x, float &y)
Convert logical (mapping) to physical (screen) coordinates.
Definition ctl_curve.cpp:288
void phys2log(float &x, float &y)
Convert physical (screen) to logical (mapping) coordinates.
Definition ctl_curve.cpp:293
unsigned int point_limit
Maximum number of points.
Definition ctl_curve.h:91
point_vector * points
Array of points.
Definition ctl_curve.h:75
int cur_pt
Currently selected point (when dragging/adding), or -1 if none is selected.
Definition ctl_curve.h:79
void clip(int pt, float &x, float &y, bool &hide)
Definition ctl_curve.cpp:298
float x1
Definition ctl_curve.h:77
GdkCursor * hand_cursor
Cached hand (drag) cursor.
Definition ctl_curve.h:85
GtkWidget parent
Base class instance members.
Definition ctl_curve.h:73
float y0
Definition ctl_curve.h:77
bool hide_current
If currently selected point is a candidate for deletion (ie. outside of graph+margin range).
Definition ctl_curve.h:81
std::vector< point > point_vector
A collection of points.
Definition ctl_curve.h:44
GdkCursor * pencil_cursor
Cached pencil (add point) cursor.
Definition ctl_curve.h:87
EventSink * sink
Interface for notification.
Definition ctl_curve.h:83
std::pair< float, float > point
A point with floating point X and Y coordinates.
Definition ctl_curve.h:42
float x0
Coordinate ranges (in logical coordinates for top left and bottom right).
Definition ctl_curve.h:77