-
Notifications
You must be signed in to change notification settings - Fork 1
/
Header.vala
146 lines (125 loc) · 4.61 KB
/
Header.vala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* Squishybox
* Copyright (C) 2010-2011 Qball Cow <qball@sarine.nl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
using SDL;
using SDLTTF;
using SDLImage;
using MPD;
using Posix;
using SDLMpc;
class Header : SDLWidget, SDLWidgetDrawing
{
private const int OFFSET = 5;
/* Pointer to the main object */
private weak Main m;
/* Surface that draws the background of the header */
private Surface sf;
/* Quit button */
private SDLMpc.Button quit_button;
private SDLMpc.Button up_button;
/* Label */
private SDLMpc.Label title_label;
/** Turn the top label into a clock */
Time old_time;
public override void Tick (time_t now)
{
Time new_time = Time.local(now);
if(old_time.minute != new_time.minute ||
old_time.hour != new_time.hour ||
old_time.second != new_time.second
)
{
string strtm = new_time.format("%T %x");
title_label.set_text(strtm);
old_time = new_time;
}
}
public override unowned string get_name()
{
return "Header";
}
public Header(Main m,int x, int y, int w, int h, int bpp)
{
/* Set constructor variables to SDLWidget */
this.m = m;
this.x = x; this.y = y; this.w = w; this.h = h;
/* Create surface */
// sf = new Surface.RGB(0, w,h,bpp,(uint32)0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
sf = SDLImage.load("Data/header.png");
sf = sf.DisplayFormat();
/* Draw background /
SDL.Rect rect = {0,0,(uint16)sf.w,(uint16)sf.h};
sf.fill(rect, sf.format.map_rgba(0,0,0,200));
SDL.Rect rect_line = {0,(int16)(this.h-2), (uint16)w, 2};
sf.fill(rect_line, sf.format.map_rgba(255,255,255,255));
*/
/* Quit button */
quit_button = new SDLMpc.Button(m,
(int16) this.x,
(int16) this.y,
(uint16)this.h,
(uint16)this.h,
"Q");
this.children.append(quit_button);
quit_button.b_clicked.connect((source) => {
SDLMpc.Event ev = new SDLMpc.Event();
ev.type = SDLMpc.EventType.COMMANDS;
ev.command = SDLMpc.EventCommand.POWER;
m.push_event((owned)ev);
});
/* Up button */
up_button = new SDLMpc.Button(m, (int16) (this.x+(this.w-this.h)),
(int16) this.y,
(uint16)this.h,
(uint16)this.h,
"U");
this.children.append(up_button);
up_button.b_clicked.connect((source) => {
SDLMpc.Event ev = new SDLMpc.Event();
ev.type = SDLMpc.EventType.KEY;
ev.command = SDLMpc.EventCommand.BROWSE;
m.push_event((owned)ev);
});
title_label = new SDLMpc.Label (this.m,
FontSize.NORMAL,
(int16)(this.x+this.h+OFFSET),
(int16)this.y,
(uint16)(this.w-this.x-this.h-this.h-2*OFFSET),
(uint16)this.h-2);
title_label.center = true;
this.children.append(title_label);
title_label.set_text("SDLMPC");
}
public void draw_drawing(Surface screen, SDL.Rect *orect)
{
SDL.Rect dest_rect = {0,0,0,0};
SDL.Rect src_rect = {0,0,0,0};
src_rect.x = int16.max((int16)(orect.x-this.x),0);
src_rect.y = int16.max((int16)(orect.y-this.y), 0);
src_rect.w = uint16.min(orect.w,(uint16)this.w);
src_rect.h = uint16.min(orect.h,(uint16)this.h);
dest_rect.x = (int16)(src_rect.x+this.x);
dest_rect.y = (int16)(src_rect.y+this.y);
dest_rect.w = (int16)(src_rect.w);
dest_rect.h = (int16)(src_rect.h);
sf.blit_surface(src_rect, screen, dest_rect);
}
public void set_title(string title)
{
title_label.set_text(title);
}
}