1 #!/usr/bin/perl -w
2 use strict;
3 use IO::Handle;
4 autoflush STDOUT 1;
5 autoflush STDERR 1;
6 use tmstub;
7 use Tk;
8 #use Tk::FontDialog;
9 my $title = 'piduino menu';
10 my $version = "v0.2 2012-07-29";
11
12 my $mw = new MainWindow();
13 # PAL resolution 656x512@16
14 $mw->overrideredirect(1);
15 my ($scr_w, $scr_h) = $mw->maxsize();
16 t "maxsize says: $scr_w x $scr_h";
17 $mw->geometry("656x512+0+0");
18
19 #~ $mw->geometry(($mw->maxsize())[0] .'x'.($mw->maxsize())[1] . "+0+0");
20 my $c = $mw->Canvas(-bg => "red", -width => 650, -height => 400)->pack;
21 # in theory we should be able to scroll infinitely but let's stick to something reasonable
22 #$c->configure(-scrollregion => [0,0, 600, 400]);
23 my $font = $mw->fontCreate('menufont', -family => 'Village', -size => 38, -weight=>'bold');
24
25 my $menu_w = 400;
26 my $menu_h = 100;
27
28
29 # handy font chooser
30 #~ $mw->Button(
31 #~ -font => $font,
32 #~ -text => "Font",
33 #~ -command => sub{choose_font()},
34 #~ )->pack();
35
36 # debug grid...
37 $c->createGrid(0, 0, 10, 10);
38 $c->createGrid(0, 0, 50, 50, -lines => 1, -dash => '-.');
39 $c->createGrid(0, 0, 100, 100, -width => 3, -lines => 1);
40
41 # TODO - load settings from file
42 menubox("Music", 0, 0);
43 menubox("Controls", 0, 1);
44 menubox("Vehicle", 0, 2);
45 menubox("System", 0, 3);
46 menubox("Settings", 0, 3);
47 # menubox("More...", 1, 0);
48
49 #~ music selection
50 #~ playlists
51 #~ artists by name
52 #~ albums
53 #~ directories
54
55 #~ controls
56 #~ volume
57 #~ bass
58 #~ treble
59 #~ balance
60 #~ system reboot
61 #~ system shutdown
62 #~ app quit
63 #~ app restart
64
65
66
67 sub menubox {
68 my($t, $mx, $my) = @_;
69 my $x1 = $mx * $menu_w;
70 my $y1 = $my * $menu_h;
71 my $x2 = $x1 + $menu_w;
72 my $y2 = $y1 + $menu_h;
73
74 $c->createRectangle($x1, $y1, $x2, $y2,
75 -fill => "blue",
76 -activefill => "green",
77 -outline => "green",
78 -activeoutline => "orange",
79 );
80 $c->createText($x1 + ($menu_w/2), $y1+ ($menu_h/2),
81 -text => "$t",
82 -font => $font,
83 -fill => "black",
84 );
85 }
86
87
88 =for docs
89
90 options:
91
92 * canvas width and height to cover the whole menu system
93 * sub-menus can't all be visible simultaneously so we'd have to hide them
94 * group items together
95
96 do top level menu first
97
98 menu level zero at 0,0
99 menu level one appears at 1*menu_w, selected item * menu_h
100
101
102
103 =cut
104
105
106
107
108 sub choose_font
109 {
110 # t $mw->GetDescriptiveFontName($font);
111
112 # my $f = $mw->FontDialog->Show(
113 #-initfont => $font,
114 #-nicefont => 1
115 # );
116 # return unless defined $f;
117 # $mw->RefontTree(-font => $f, -canvas => 1);
118 # my $d = $mw->GetDescriptiveFontName($f);
119 # t $d;
120 # $font = $f;
121
122 }
123
124
125 MainLoop();