#!/usr/bin/php -c/etc/gtk/php.ini
vol = $volume;
$this->label = $label;
$this->buf = OpenALBuffer::newFromFile($file);
$this->src = new OpenALSource;
$this->src->buffer = $this->buf;
$this->src->pitch = 1.0;
$this->src->gain = 0.0;
$this->src->position = array(0.0,0.0,0.0);
$this->src->velocity = array(0.0,0.0,0.0);
$this->src->looping = true;
$this->src->play();
return;
}
public function adjust_volume($range) {
$this->vol = $range->get_value();
$this->src->gain = ($this->vol / 100);
return;
}
public function stop() {
$this->src->stop();
return;
}
public function destroy() {
$this->src->stop();
unset($this->src,$this->buf);
return;
}
}
class ambstStatus extends GtkStatusBar {
public function __construct() {
parent::__construct();
$this->set_has_resize_grip(false);
return;
}
public function msg($text) {
$this->pop(0);
$this->push(0,$text);
return;
}
}
class ambstAboutDialog extends GtkDialog {
public function __construct($parent) {
parent::__construct();
$this->close = new GtkButton('Close');
$this->label = new GtkLabel;
$this->set_transient_for($parent);
$this->set_modal(true);
$this->set_position(Gtk::WIN_POS_CENTER);
$this->set_title('About');
$this->label->set_line_wrap(true);
$this->label->set_markup(sprintf(
"AmbST v%s
Bob Majdak Jr <bob@kateos.org>
Who needs babbling brooks, trickling waterfalls, or tranquil meadows when you have warp engines?
Created: 20070501 - Updated: 20071001",
VERSION
));
$this->connect_simple('delete-event',array($this,'response'),Gtk::RESPONSE_CANCEL);
$this->close->connect_simple('clicked',array($this,'response'),Gtk::RESPONSE_CANCEL);
$this->vbox->pack_start($this->label,true,true,3);
$this->action_area->pack_start($this->close,true,true,3);
$this->show_all();
return;
}
}
class ambstWindow extends GtkWindow {
public $soundset = array();
public $sound = array();
public $slide = array();
public $label = array();
private $time = array();
private $tray;
public function __construct() {
parent::__construct();
$this->vbox = new GtkVBox;
$this->hbox = new GtkHBox;
$this->bbox = new GtkVBox;
$this->image = GtkImage::new_from_file(EXECROOT.'/share/ambst/gfx/main01.png');
$this->button = array( 'About' => new Gtkbutton, 'Quit' => new GtkButton);
$this->status = new ambstStatus;
$this->combo = GtkComboBox::new_text();
$this->model = $this->combo->get_model();
// $this->icon = new GtkStatusIcon;
$this->set_title('Star Trek Ambiance Machine');
$this->set_position(Gtk::WIN_POS_CENTER);
$this->set_size_request(300,-1);
$this->set_resizable(false);
$this->set_icon_from_file(EXECROOT.'/share/ambst/gfx/icon.png');
$this->quitsig = $this->connect_simple('delete-event',array($this,'quit'));
$this->button['About']->connect_simple('clicked',array($this,'about'));
$this->button['Quit']->connect_simple('clicked',array($this,'quit'));
$this->combo->connect_simple('changed',array($this,'set_location'));
$this->model->append(array('Bridge'));
$this->model->append(array('Engineering'));
$this->model->append(array('Sickbay'));
$this->hbox->pack_start($this->image,false,false,0);
$this->bbox->pack_start($this->combo,false,false,3);
foreach($this->button as $id => $btn) {
$this->button[$id]->set_label($id);
$this->bbox->pack_start($this->button[$id],true,true,3);
}
$this->hbox->pack_start($this->bbox,true,true,0);
$this->vbox->pack_start($this->hbox,true,true,0);
$this->vbox->pack_start($this->status,true,true,0);
$this->add($this->vbox);
$this->combo->set_active(0);
$this->combo->grab_focus();
$this->time['start'] = time();
$this->time['last'] = $this->time['start'];
gtk::timeout_add(15000,array($this,'timer'));
$this->timer();
$this->show_all();
return;
}
public function set_tray($tray) {
$this->tray = $tray;
$this->disconnect($this->quitsig);
$this->connect_simple('delete-event',array($this->tray,'on_activate'));
$this->timer();
return;
}
public function quit() {
foreach($this->sound as $id => $snd) {
$this->sound[$id]->stop();
$this->sound[$id]->destroy();
$this->sound[$id] = null;
}
ambst_quit();
return;
}
public function about() {
$this->set_sensitive(false);
$dialog = new ambstAboutDialog($this);
$dialog->run();
$dialog->hide(); $dialog->destroy(); $dialog = null;
$this->set_sensitive(true);
return;
}
public function timer() {
$time = time();
$this->time['total'] = file_get_contents($_SERVER['HOME'].'/'.ambst::TIMELOG);
$this->time['total'] += ($time - $this->time['last']);
$this->time['last'] = $time;
file_put_contents($_SERVER['HOME'].'/'.ambst::TIMELOG,$this->time['total']);
$this->status->msg($string = sprintf(
' Flight time logged: %s (Current mission: %s)',
ambst_uptime($this->time['total']),
ambst_uptime($time - $this->time['start'])
));
if(is_object($this->tray)) {
$this->tray->set_tooltip($string);
}
return true;
}
public function set_location() {
foreach($this->sound as $id => $snd) {
if($this->sound[$id]) {
$this->sound[$id]->stop();
$this->sound[$id]->destroy();
$this->sound[$id] = null;
$this->slide[$id]->hide();
$this->slide[$id]->destroy();
$this->slide[$id] = null;
$this->label[$id]->hide();
$this->label[$id]->destroy();
$this->label[$id] = null;
unset($this->sound[$id],$this->slide[$id],$this->label[$id]);
}
}
switch($this->combo->get_active_text()) {
case('Bridge'): {
$this->sound[0] = new soundPoint(EXECROOT.'/share/ambst/snd/bridge-engine-drone.wav','Engine Drone',15);
break;
}
case('Engineering'): {
$this->sound[0] = new soundPoint(EXECROOT.'/share/ambst/snd/engineering-engine-drone.wav','Engine Drone',30);
break;
}
case('Sickbay'): {
$this->sound[0] = new soundPoint(EXECROOT.'/share/ambst/snd/sickbay-engine-drone.wav','Engine Drone',24);
break;
}
}
$a = 0;
foreach($this->sound as $snd) {
$this->label[$a] = new GtkLabel;
$this->label[$a]->set_markup(sprintf('%s',$this->sound[$a]->label));
$this->label[$a]->set_angle(90);
$this->slide[$a] = GtkVScale::new_with_range(0,100,1);
$this->slide[$a]->set_inverted(true);
$this->slide[$a]->connect('value-changed',array($this->sound[$a],'adjust_volume'));
$this->slide[$a]->set_value($this->sound[$a]->vol);
$this->hbox->pack_start($this->label[$a],false,false,3);
$this->hbox->pack_start($this->slide[$a],false,false,3);
++$a;
}
$this->hbox->reorder_child($this->bbox,3);
$this->hbox->show_all();
return;
}
}
class ambstTrayIcon extends GtkStatusIcon {
private $wreg = array();
private $wstate = array();
public function __construct() {
parent::__construct();
$this->set_from_file(EXECROOT.'/share/ambst/gfx/icon.png');
$this->connect_simple('popup-menu',array($this,'on_activate'));
$this->connect_simple('activate',array($this,'on_activate'));
return;
}
public function is_alive() {
while(Gtk::events_pending() || Gdk::events_pending()) {
Gtk::main_iteration_do(true);
}
if($this->is_embedded()) {
return true;
} else {
return false;
}
}
public function on_activate() {
$window = reset($this->wreg);
if($this->wstate[$window->get_title()]) {
$window->hide();
$this->wstate[$window->get_title()] = false;
} else {
$window->show();
$this->wstate[$window->get_title()] = true;
}
return true;
}
public function window_register($window) {
if(!array_key_exists($window->get_title(),$this->wreg)) {
$this->wreg[$window->get_title()] = $window;
$this->wstate[$window->get_title()] = true;
} else {
$a = 1;
while(array_key_exists($window->get_title()." {$a}",$this->wreg)) {
$a++;
}
$this->wreg[$window->get_title()." {$a}"] = $window;
$this->wstate[$window->get_title()." {$a}"] = true;
}
$window->set_tray($this);
$window->show();
return;
}
}
$t = new ambstTrayIcon;
$w = new ambstWindow;
if(!$t->is_alive()) {
echo("error initating the tray icon.\n");
} else {
$t->window_register($w);
}
Gtk::main();
?>