31
int iMusic::get_width ( void ){return 450;}
32
int iMusic::get_height ( void ){return 280;}
42
int iMusic::get_width( void )
46
int iMusic::get_height( void )
48
return ICON_SIZE*2+TOOLBAR_HEIGHT;
34
51
// ================================== DRAW =================================== //
35
52
void iMusic::draw (GtkContainer * container)
37
draw_cover ( GTK_CONTAINER(container ));
38
draw_file_info ( GTK_CONTAINER(container ));
39
draw_controls ( GTK_CONTAINER(container ));
54
cover = gtk_image_new_from_pixbuf (pix_cover);
55
reflection = gtk_image_new_from_pixbuf (pix_reflection);
56
gtk_fixed_put(GTK_FIXED(container),cover, 25, 50);
57
gtk_fixed_put(GTK_FIXED(container),reflection,25, 50 + ICON_SIZE);
59
string text = get_song_name() + "\n\n" + get_song_artist() + "\n\n" + get_song_album();
60
draw_properties ( container, text, 200 , 75 );
62
draw_controls(container);
41
m_timeout_id = g_timeout_add (50, &iMusic::trick2, this); //Get new position
44
// =========================== DRAW IMAGE ================================= //
45
void iMusic::draw_cover(GtkContainer * container)
48
GtkWidget *image = gtk_image_new_from_pixbuf (m_pixbuf);
49
GtkWidget *image_container = gtk_fixed_new ();
50
GtkWidget *reflection = gtk_image_new_from_pixbuf (m_reflection);
51
GtkWidget *reflection_container = gtk_fixed_new ();
53
int x = SHADOW_WIDTH; //Default values are at top left
54
int y = HEADER_HEIGHT + SHADOW_WIDTH; //and 20 from top (For the header)
56
if(gdk_pixbuf_get_width(m_pixbuf) < 300) //Minum width
58
x = (150 + SHADOW_WIDTH ) - gdk_pixbuf_get_width(m_pixbuf)/2;
60
if(gdk_pixbuf_get_height(m_pixbuf) < 300) //Minium height
62
y = (150 + SHADOW_WIDTH + HEADER_HEIGHT) - gdk_pixbuf_get_height(m_pixbuf)/2;
66
gtk_fixed_put (GTK_FIXED(image_container),image,25+SHADOW_WIDTH, 50 + SHADOW_WIDTH + HEADER_HEIGHT);
67
gtk_fixed_put (GTK_FIXED(reflection_container),reflection,25+SHADOW_WIDTH, 50 + SHADOW_WIDTH + HEADER_HEIGHT + gdk_pixbuf_get_height(m_pixbuf));
68
gtk_container_add (GTK_CONTAINER(container),image_container);
69
gtk_container_add (GTK_CONTAINER(container),reflection_container);
70
gtk_widget_show (image_container);
71
gtk_widget_show (image);
72
gtk_widget_show (reflection_container);
73
gtk_widget_show (reflection);
78
// ================================== DRAW FILE INFO =================================== //
79
void iMusic::draw_file_info(GtkContainer * container)
81
string text = get_song_name() + "\n\n" + get_song_artist() + "\n\n" + get_song_album();
82
draw_properties ( container, text, 200 , 75 + SHADOW_WIDTH + HEADER_HEIGHT);
66
timeout_id = g_timeout_add (200, &iMusic::draw_position, this);
68
gtk_widget_show_all( GTK_WIDGET(container) );
85
71
// ================================== DRAW CONTROLS =================================== //
86
72
void iMusic::draw_controls(GtkContainer * container)
89
75
gdk_color_parse ("white", &color);
91
string buttonstr = (string)PACKAGE_DATA_PATH + "/media-pause.svg";
93
m_play_pause_button = gtk_image_new_from_file(buttonstr.c_str());
94
m_event_box = gtk_event_box_new();
95
gtk_event_box_set_visible_window(GTK_EVENT_BOX(m_event_box),false);
96
gtk_container_add(GTK_CONTAINER(m_event_box),m_play_pause_button);
98
m_duration_label = gtk_label_new("--:--");
99
m_current_time_label = gtk_label_new("00:00");
101
//Set white color to labels
102
gtk_widget_modify_fg (m_duration_label, GTK_STATE_NORMAL, &color);
103
gtk_widget_modify_fg (m_current_time_label, GTK_STATE_NORMAL, &color);
105
//m_adjustment = gtk_adjustment_new (0, 0, 101, 1, 5, 25);
106
//m_scale = gtk_hscale_new (GTK_ADJUSTMENT (m_adjustment));
107
m_scale = gtk_hscale_new_with_range (0, 100, 1);
108
gtk_scale_set_draw_value (GTK_SCALE(m_scale), false); //Do not draw the numbers
110
GtkWidget * vbox = gtk_vbox_new (false,3);
111
GtkWidget * hbox = gtk_hbox_new (false,3);
112
GtkWidget * hbox2 = gtk_hbox_new (false,3);
115
gtk_box_pack_end (GTK_BOX (hbox), m_event_box , true, false, 2);
116
gtk_box_pack_start (GTK_BOX (hbox2), m_current_time_label, false, false, 2);
117
gtk_box_pack_start (GTK_BOX (hbox2), m_scale, true, true, 2);
118
gtk_box_pack_end (GTK_BOX (hbox2), m_duration_label, false, false, 2);
119
gtk_box_pack_start (GTK_BOX (vbox), hbox, false, false, 2);
120
gtk_box_pack_end (GTK_BOX (vbox), hbox2, true, true, 2);
124
gtk_fixed_put ( GTK_FIXED(container),vbox, 25 , get_height() -5 );
125
gtk_widget_set_usize ( hbox, get_width()-20, 35);
126
gtk_widget_show_all ( vbox );
77
button = gtk_image_new_from_pixbuf(pix_pause);
78
button_box = gtk_event_box_new();
79
gtk_event_box_set_visible_window(GTK_EVENT_BOX(button_box),false);
80
gtk_container_add(GTK_CONTAINER(button_box),button);
82
gtk_fixed_put( GTK_FIXED(container),button_box, get_width()/2-16 , get_height()-80 );
84
duration = gtk_label_new("--:--");
85
current_time = gtk_label_new("00:00");
86
gtk_widget_modify_fg (duration, GTK_STATE_NORMAL, &color);
87
gtk_widget_modify_fg (current_time, GTK_STATE_NORMAL, &color);
88
seekbar = gtk_hscale_new_with_range (0, 100, 1);
89
gtk_scale_set_draw_value (GTK_SCALE(seekbar), false); //Do not draw the numbers
91
hbox = gtk_hbox_new (false,3);
92
gtk_widget_set_size_request( hbox, get_width(), 35);
93
gtk_box_pack_start(GTK_BOX (hbox), current_time , false, false, 2);
94
gtk_box_pack_start(GTK_BOX (hbox), seekbar , true, true, 2);
95
gtk_box_pack_start(GTK_BOX (hbox), duration , false, false, 2);
96
gtk_fixed_put( GTK_FIXED(container),hbox, 0 , get_height() - 35 );
97
gtk_widget_show_all( hbox );
128
99
//When the seek bar is moved, change the position
129
g_signal_connect (G_OBJECT (m_scale), "change-value", G_CALLBACK (&iMusic::trick), this);
130
g_signal_connect (G_OBJECT (m_event_box), "button-press-event", G_CALLBACK (&iMusic::play_pause_trick), this);
133
// ================================== DRAW POSITION =================================== //
134
// Request the postion to the plugin and puts the range to this new position
135
void iMusic::draw_position( void )
137
//g_debug("POSITION => %f\n", get_position());
138
gtk_range_set_value (GTK_RANGE (m_scale), get_position());
139
//g_debug("DURATION => %s\n", get_duration().c_str());
140
gtk_label_set_text (GTK_LABEL(m_duration_label) ,get_duration().c_str() );
141
gtk_label_set_text (GTK_LABEL(m_current_time_label) ,get_current_time().c_str() );
100
g_signal_connect (G_OBJECT (seekbar), "change-value",
101
G_CALLBACK (&iMusic::seekbar_change_cb), this);
102
g_signal_connect (G_OBJECT (seekbar), "button-press-event",
103
G_CALLBACK (&iMusic::seekbar_press_cb), this);
104
g_signal_connect (G_OBJECT (seekbar), "button-release-event",
105
G_CALLBACK (&iMusic::seekbar_release_cb), this);
106
g_signal_connect (G_OBJECT (button_box), "button-press-event",
107
G_CALLBACK (&iMusic::button_play_pause), this);
145
110
//============================== PLAY PAUSE ========================= //
146
111
void iMusic::play_pause( void )
148
113
g_debug("Play Pause clicked");
149
//gtk_button_set_label (GTK_BUTTON(m_play_pause_button) ,"JOJO" );
154
string buttonstr = (string)PACKAGE_DATA_PATH + "/media-play.svg";
155
gtk_image_set_from_file(GTK_IMAGE(m_play_pause_button),buttonstr.c_str() );
117
gtk_image_set_from_pixbuf(GTK_IMAGE(button) , pix_play );
161
string buttonstr = (string)PACKAGE_DATA_PATH + "/media-pause.svg";
162
gtk_image_set_from_file(GTK_IMAGE(m_play_pause_button),buttonstr.c_str() );
121
gtk_image_set_from_pixbuf(GTK_IMAGE(button) , pix_pause );
168
// ====================== FULLSCREEN ================= //
169
bool iMusic::can_fullscreen ( void ){ return false;} //Returns true if the plugin can do fullscreen
170
126
void iMusic::draw_fullscreen ( GtkContainer * container )
128
int x = ( ui->get_screen_width()-get_width() ) / 2;
129
int y = ( ui->get_screen_height()-get_height() ) / 2;
130
gtk_fixed_move( GTK_FIXED(container),cover, x+25, y+50 );
131
gtk_fixed_move( GTK_FIXED(container),reflection,x+25, y+50 + ICON_SIZE );
132
gtk_fixed_move( GTK_FIXED(container),button_box, x+get_width()/2-16 , y+get_height()-80 );
133
gtk_fixed_move( GTK_FIXED(container),hbox, x , y+get_height() - 35 );
134
gtk_fixed_move( GTK_FIXED(container), m_info , x+200 , y+75 );
173
137
void iMusic::draw_unfullscreen ( GtkContainer * container )
177
// ============================ DRAW FLOATING CONTROLS ================================ //
178
void iMusic::draw_toolbar ( GtkWidget * container )
180
g_debug("iMusic toolbar buttons\n");
182
draw_default_toolbar(container);
139
gtk_fixed_move( GTK_FIXED(container),cover, 25, 50 );
140
gtk_fixed_move( GTK_FIXED(container),reflection,25, 50 + ICON_SIZE );
141
gtk_fixed_move( GTK_FIXED(container),button_box, get_width()/2-16 , get_height()-80 );
142
gtk_fixed_move( GTK_FIXED(container),hbox, 0 , get_height() - 35 );
143
gtk_fixed_move( GTK_FIXED(container), m_info , 200 , 75 );
146
void iMusic::button_play_pause(GtkWidget *widget,
147
GdkEventButton *event,
150
((iMusic*)data)->play_pause();
153
gboolean iMusic::seekbar_press_cb(GtkWidget *widget,
154
GdkEventButton *event,
157
/* HACK: we want the behaviour you get with the middle button, so we
158
* mangle the event. clicking with other buttons moves the slider in
159
* step increments, clicking with the middle button moves the slider to
160
* the location of the click.
161
* thanks to totem devs :D
167
gboolean iMusic::seekbar_release_cb(GtkWidget *widget,
168
GdkEventButton *event,
175
gboolean iMusic::seekbar_change_cb(GtkRange * range,
176
GtkScrollType scroll,
180
((iMusic*)data)->seek(value);
184
gboolean iMusic::draw_position( gpointer data )
186
iMusic * music = (iMusic*)data;
187
gtk_range_set_value(GTK_RANGE(music->seekbar) , music->get_position());
188
gtk_label_set_text(GTK_LABEL(music->duration), music->get_duration().c_str());
189
gtk_label_set_text(GTK_LABEL(music->current_time), music->get_current_time().c_str());