1 /*
2  * ===========================
3  * VDK Visual Development Kit
4  * Version 2.0.3
5  * January 2003
6  * ===========================
7  *
8  * Copyright (C) 1998, Mario Motta
9  * Developed by Mario Motta <mmotta@guest.net>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  * 02111-1307, USA.
25  */
26 #include <vdk/vdkhlbutton.h>
27 
28 #define PIXELATE 3.0
29 #define DARKENED 0.50
30 DEFINE_EVENT_LIST (VDKHLButton, VDKCustomButton);
31 /*
32 */
VDKHLButton(VDKForm * owner,const char * pixfile,const char * label,unsigned int type,GtkPositionType position)33 VDKHLButton::VDKHLButton (
34                   VDKForm  *owner,
35                   const char *pixfile,
36                   const char *label,
37                   unsigned int type,
38                   GtkPositionType position):
39     VDKCustomButton (owner, pixfile, label ,type,position)
40 {
41   normal_pix = new VDKPixbuf (this, pixfile);
42   pixellated_pix = new VDKPixbuf (this, pixfile);
43   darkened_pix = new VDKPixbuf (this, pixfile);
44   GdkPixbuf* pixbuf = pixellated_pix->AsGdkPixbuf();
45   gdk_pixbuf_saturate_and_pixelate(pixbuf,pixbuf,PIXELATE,FALSE);
46   pixbuf = darkened_pix->AsGdkPixbuf();
47   gdk_pixbuf_saturate_and_pixelate(pixbuf,pixbuf,DARKENED,FALSE);
48 }
49 /*
50 */
VDKHLButton(VDKForm * owner,const char ** pixdata,const char * label,unsigned int type,GtkPositionType position)51 VDKHLButton::VDKHLButton (
52                    VDKForm *owner,
53                    const char **pixdata,
54                    const char *label,
55                    unsigned int type,
56                    GtkPositionType position):
57     VDKCustomButton (owner, pixdata, label,type, position)
58 {
59   normal_pix = new VDKPixbuf (this, pixdata);
60   pixellated_pix = new VDKPixbuf (this, pixdata);
61   darkened_pix = new VDKPixbuf (this, pixdata);
62   GdkPixbuf* pixbuf = pixellated_pix->AsGdkPixbuf();
63   gdk_pixbuf_saturate_and_pixelate(pixbuf,pixbuf,PIXELATE,FALSE);
64   pixbuf = darkened_pix->AsGdkPixbuf();
65   gdk_pixbuf_saturate_and_pixelate(pixbuf,pixbuf,DARKENED,FALSE);
66 }
67 
68 /*
69 */
70 void
Setup(void)71 VDKHLButton::Setup (void)
72 {
73   Relief = (GtkReliefStyle) 2;
74   EventConnect("enter_notify_event",&VDKHLButton::OnEnter);
75   EventConnect("leave_notify_event",&VDKHLButton ::OnLeave);
76   EventConnect("button_release_event",&VDKHLButton ::OnClickRelease);
77   EventConnect("button_press_event",&VDKHLButton ::OnClickPress);
78 }
79 /*
80 */
81 bool
OnClickRelease(VDKObject *,GdkEvent * event)82 VDKHLButton::OnClickRelease (VDKObject*,  GdkEvent* event)
83 {
84   GdkEventButton* e = (GdkEventButton*) event;
85   double w = GTK_WIDGET (WrappedWidget ())->allocation.width;
86   double h = GTK_WIDGET (WrappedWidget ())->allocation.height;
87   VDKRect rect(0, 0, int (w), int (h) );
88   VDKPoint p (int (e->x), int (e->y));
89   if ( rect.Contains (p) )
90     {
91     VDKImage* image = Pixmap;
92     image->SetImage (pixellated_pix);
93     gtk_widget_queue_draw (image->WrappedWidget ());
94     SignalEmit (clicked_signal);
95     SignalEmit ("clicked");
96     }
97   return false;
98 }
99 /*
100 */
101 bool
OnClickPress(VDKObject *,GdkEvent * event)102 VDKHLButton::OnClickPress (VDKObject*,  GdkEvent* event)
103 {
104   VDKImage* image = Pixmap;
105   image->SetImage (darkened_pix);
106   gtk_widget_queue_draw (image->WrappedWidget ());
107   return false;
108 }
109 
110 /*
111 */
112 bool
OnEnter(VDKObject *,GdkEvent *)113 VDKHLButton::OnEnter (VDKObject*,  GdkEvent*)
114 {
115   VDKImage* image = Pixmap;
116   image->SetImage (pixellated_pix);
117   // Cursor = curHandPtr;
118   gtk_widget_queue_draw (image->WrappedWidget ());
119   SignalEmit (enter_signal);
120   SignalEmit ("enter");
121   return true;
122   }
123 /*
124 */
125 bool
OnLeave(VDKObject *,GdkEvent *)126 VDKHLButton::OnLeave (VDKObject*,  GdkEvent*)
127 {
128   VDKImage* image = Pixmap;
129   image->SetImage (normal_pix);
130   // Cursor = curDefault;
131   gtk_widget_queue_draw (image->WrappedWidget ());
132   SignalEmit (leave_signal);
133   SignalEmit ("leave");
134   return true;
135 }
136