/* GTK - GIMP工具包
* 版权 (C) 1995-1997 Peter Mattis, Spencer Kimball 和 Josh MacDonald 所有
*
* 本程序是自由软件。你可以在自由软件基金发布的 GNU GPL 的条款下重新分发
* 或修改它。GPL 可以使用版本 2 或(由你选择)任何随后的版本。
*
* 本程序分发的目的是它可能对其他人有用,但不提供任何的担保,包括隐含的
* 和适合特定用途的保证。请查阅GNU通用公共许可证获得详细的信息。
*
* 你应该已经随该软件一起收到一份GNU通用公共许可。如果还没有,请写信给
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <math.h>
#include <stdio.h>
#include <gtk/gtkmain.h>
#include <gtk/gtksignal.h>
#include "gtkdial.h"
#define SCROLL_DELAY_LENGTH 300
#define DIAL_DEFAULT_SIZE 100
/* 声明 */
static void gtk_dial_class_init (GtkDialClass *klass);
static void gtk_dial_init (GtkDial *dial);
static void gtk_dial_destroy (GtkObject *object);
static void gtk_dial_realize (GtkWidget *widget);
static void gtk_dial_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void gtk_dial_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static gint gtk_dial_expose (GtkWidget *widget,
GdkEventExpose *event);
static gint gtk_dial_button_press (GtkWidget *widget,
GdkEventButton *event);
static gint gtk_dial_button_release (GtkWidget *widget,
GdkEventButton *event);
static gint gtk_dial_motion_notify (GtkWidget *widget,
GdkEventMotion *event);
static gint gtk_dial_timer (GtkDial *dial);
static void gtk_dial_update_mouse (GtkDial *dial, gint x, gint y);
static void gtk_dial_update (GtkDial *dial);
static void gtk_dial_adjustment_changed (GtkAdjustment *adjustment,
gpointer data);
static void gtk_dial_adjustment_value_changed (GtkAdjustment *adjustment,
gpointer data);
/* 局部数据 */
static GtkWidgetClass *parent_class = NULL;
GType
gtk_dial_get_type ()
{
static GType dial_type = 0;
if (!dial_type)
{
static const GTypeInfo dial_info =
{
sizeof (GtkDialClass),
NULL,
NULL,
(GClassInitFunc) gtk_dial_class_init,
NULL,
NULL,
sizeof (GtkDial),
0,
(GInstanceInitFunc) gtk_dial_init,
};
dial_type = g_type_register_static (GTK_TYPE_WIDGET, "GtkDial", &dial_info, 0);
}
return dial_type;
}
static void
gtk_dial_class_init (GtkDialClass *class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = (GtkObjectClass*) class;
widget_class = (GtkWidgetClass*) class;
parent_class = gtk_type_class (gtk_widget_get_type ());
object_class->destroy = gtk_dial_destroy;
widget_class->realize = gtk_dial_realize;
widget_class->expose_event = gtk_dial_expose;
widget_class->size_request = gtk_dial_size_request;
widget_class->size_allocate = gtk_dial_size_allocate;
widget_class->button_press_event = gtk_dial_button_press;
widget_class->button_release_event = gtk_dial_button_release;
widget_class->motion_notify_event = gtk_dial_motion_notify;
}
static void
gtk_dial_init (GtkDial *dial)
{
dial->button = 0;
dial->policy = GTK_UPDATE_CONTINUOUS;
dial->timer = 0;
dial->radius = 0;
dial->pointer_width = 0;
dial->angle = 0.0;
dial->old_value = 0.0;
dial->old_lower = 0.0;
dial->old_upper = 0.0;
dial->adjustment = NULL;
}
GtkWidget*
gtk_dial_new (GtkAdjustment *adjustment)
{
GtkDial *dial;
dial = g_object_new (gtk_dial_get_type (), NULL);
if (!adjustment)
adjustment = (GtkAdjustment*) gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
gtk_dial_set_adjustment (dial, adjustment);
return GTK_WIDGET (dial);
}
static void
gtk_dial_destroy (GtkObject *object)
{
GtkDial *dial;
g_return_if_fail (object != NULL);
g_return_if_fail (GTK_IS_DIAL (object));
dial = GTK_DIAL (object);
if (dial->adjustment)
g_object_unref (GTK_OBJECT (dial->adjustment));
if (GTK_OBJECT_CLASS (parent_class)->destroy)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
GtkAdjustment*
gtk_dial_get_adjustment (GtkDial *dial)
{
g_return_val_if_fail (dial != NULL, NULL);
g_return_val_if_fail (GTK_IS_DIAL (dial), NULL);
return dial->adjustment;
}
void
gtk_dial_set_update_policy (GtkDial *dial,
GtkUpdateType policy)
{
g_return_if_fail (dial != NULL);
g_return_if_fail (GTK_IS_DIAL (dial));
dial->policy = policy;
}
void
gtk_dial_set_adjustment (GtkDial *dial,
GtkAdjustment *adjustment)
{
g_return_if_fail (dial != NULL);
g_return_if_fail (GTK_IS_DIAL (dial));
if (dial->adjustment)
{
g_signal_handlers_disconnect_by_func (GTK_OBJECT (dial->adjustment), NULL, (gpointer) dial);
g_object_unref (GTK_OBJECT (dial->adjustment));
}
dial->adjustment = adjustment;
g_object_ref (GTK_OBJECT (dial->adjustment));
g_signal_connect (GTK_OBJECT (adjustment), "changed",
GTK_SIGNAL_FUNC (gtk_dial_adjustment_changed),
(gpointer) dial);
g_signal_connect (GTK_OBJECT (adjustment), "value_changed",
GTK_SIGNAL_FUNC (gtk_dial_adjustment_value_changed),
(gpointer) dial);
dial->old_value = adjustment->value;
dial->old_lower = adjustment->lower;
dial->old_upper = adjustment->upper;
gtk_dial_update (dial);
}
static void
gtk_dial_realize (GtkWidget *widget)
{
GtkDial *dial;
GdkWindowAttr attributes;
gint attributes_mask;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_DIAL (widget));
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
dial = GTK_DIAL (widget);
attributes.x = widget->allocation.x;
attributes.y = widget->allocation.y;
attributes.width = widget->allocation.width;
attributes.height = widget->allocation.height;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.window_type = GDK_WINDOW_CHILD;
attributes.event_mask = gtk_widget_get_events (widget) |
GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK;
attributes.visual = gtk_widget_get_visual (widget);
attributes.colormap = gtk_widget_get_colormap (widget);
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask);
widget->style = gtk_style_attach (widget->style, widget->window);
gdk_window_set_user_data (widget->window, widget);
gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE);
}
static void
gtk_dial_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
requisition->width = DIAL_DEFAULT_SIZE;
requisition->height = DIAL_DEFAULT_SIZE;
}
static void
gtk_dial_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkDial *dial;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_DIAL (widget));
g_return_if_fail (allocation != NULL);
widget->allocation = *allocation;
dial = GTK_DIAL (widget);
if (GTK_WIDGET_REALIZED (widget))
{
gdk_window_move_resize (widget->window,
allocation->x, allocation->y,
allocation->width, allocation->height);
}
dial->radius = MIN (allocation->width, allocation->height) * 0.45;
dial->pointer_width = dial->radius / 5;
}
static gint
gtk_dial_expose (GtkWidget *widget,
GdkEventExpose *event)
{
GtkDial *dial;
GdkPoint points[6];
gdouble s,c;
gdouble theta, last, increment;
GtkStyle *blankstyle;
gint xc, yc;
gint upper, lower;
gint tick_length;
gint i, inc;
g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (GTK_IS_DIAL (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
if (event->count > 0)
return FALSE;
dial = GTK_DIAL (widget);
/* gdk_window_clear_are
没有合适的资源?快使用搜索试试~ 我知道了~
gtk入门案例程序gtk的各种控件的使用案
共90个文件
c:42个
makefile:38个
o:2个
4星 · 超过85%的资源 需积分: 10 25 下载量 120 浏览量
2009-11-10
11:27:01
上传
评论
收藏 86KB RAR 举报
温馨提示
1天内学会gtk。gtk的各种控件的使用案例。简单易学。交大志盟www.zmemb.com 交大志盟
资源推荐
资源详情
资源评论
收起资源包目录
GTK.rar (90个子文件)
GTK
rangewidgets
Makefile 301B
rangewidgets.c 10KB
text
Makefile 277B
text.c 5KB
calendar
Makefile 276B
calendar.c 12KB
fixed
Makefile 266B
fixed.c 2KB
filesel
Makefile 276B
filesel.c 1KB
Makefile 677B
aspectframe
Makefile 296B
aspectframe.c 1KB
menu
Makefile 408B
menu.c 4KB
itemfactory.c 4KB
find-examples.sh 183B
statusbar
Makefile 286B
statusbar.c 2KB
rulers
Makefile 271B
rulers.c 3KB
selection
Makefile 450B
gettargets.c 2KB
setselection.c 3KB
gtkdial
gtkdial.c 16KB
Makefile 506B
gtkdial.h 2KB
dial_test.c 2KB
table
Makefile 267B
table.c 2KB
paned
Makefile 266B
paned.c 4KB
README.1ST 1KB
radiobuttons
Makefile 301B
radiobuttons.c 2KB
list
Makefile 277B
list.c 8KB
scribble-xinput
Makefile 316B
scribble-xinput.c 7KB
helloworld
Makefile 291B
helloworld.c 3KB
helloworld2
Makefile 296B
helloworld2.c 2KB
clist
Makefile 256B
clist.c 6KB
label
Makefile 266B
label.c 4KB
notebook
Makefile 281B
notebook.c 5KB
tree
Makefile 277B
tree.c 6KB
scrolledwin
Makefile 296B
scrolledwin.c 3KB
tictactoe
ttt_test 19KB
tictactoe.h 1KB
Makefile 513B
tictactoe.o 4KB
ttt_test.o 2KB
tictactoe.c 4KB
ttt_test.c 826B
progressbar
Makefile 296B
progressbar.c 6KB
arrow
Makefile 271B
arrow.c 2KB
pixmap
Makefile 286B
pixmap.c 2KB
colorsel
colorsel.c 3KB
entry
Makefile 266B
entry.c 3KB
eventbox
eventbox.c 1KB
Makefile 281B
extract.awk 2KB
spinbutton
Makefile 291B
spinbutton.c 7KB
scribble-simple
Makefile 316B
scribble-simple.c 4KB
base
base.c 259B
Makefile 261B
buttonbox
Makefile 286B
buttonbox.c 3KB
packbox
Makefile 276B
packbox.c 9KB
frame
Makefile 265B
frame.c 1KB
extract.sh 728B
buttons
info.xpm 2KB
Makefile 284B
buttons.c 2KB
wheelbarrow
Makefile 296B
wheelbarrow.c 6KB
共 90 条
- 1
资源评论
- 古原争霸2013-04-07可以作为参考!
- mindom2013-03-25有36个例子,看样子应该是比较全的,Linux下的,不过用不上了
user202
- 粉丝: 35
- 资源: 80
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功