2008-04-14 23:51:59 +02:00
|
|
|
/*
|
2008-04-19 21:47:53 +02:00
|
|
|
video-display-widget.cpp - Implementation of the video viewer widget
|
2008-04-14 23:51:59 +02:00
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Joel Holdsworth <joel@airwebreathe.org.uk>
|
|
|
|
|
|
|
|
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
#include <gdkmm/drawable.h>
|
|
|
|
|
#include <gdkmm/general.h>
|
2008-04-18 22:35:10 +02:00
|
|
|
#include <cairomm-1.0/cairomm/cairomm.h>
|
2008-04-14 23:51:59 +02:00
|
|
|
|
2008-05-12 14:02:14 +02:00
|
|
|
#include "../output/xvdisplayer.hpp"
|
|
|
|
|
#include "../output/gdkdisplayer.hpp"
|
|
|
|
|
|
2008-04-19 21:47:53 +02:00
|
|
|
#include "video-display-widget.hpp"
|
2008-04-14 23:51:59 +02:00
|
|
|
|
|
|
|
|
namespace lumiera {
|
|
|
|
|
namespace gui {
|
|
|
|
|
namespace widgets {
|
|
|
|
|
|
2008-05-08 21:56:55 +02:00
|
|
|
VideoDisplayWidget::VideoDisplayWidget() :
|
|
|
|
|
gdkWindow(NULL),
|
2008-05-12 14:02:14 +02:00
|
|
|
displayer(NULL)
|
2008-05-08 21:56:55 +02:00
|
|
|
{
|
|
|
|
|
set_flags(Gtk::NO_WINDOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoDisplayWidget::~VideoDisplayWidget()
|
|
|
|
|
{
|
2008-05-12 14:02:14 +02:00
|
|
|
if(displayer != NULL)
|
|
|
|
|
delete displayer;
|
2008-05-08 21:56:55 +02:00
|
|
|
}
|
2008-04-14 23:51:59 +02:00
|
|
|
|
|
|
|
|
void
|
2008-04-19 21:47:53 +02:00
|
|
|
VideoDisplayWidget::on_realize()
|
2008-05-08 21:56:55 +02:00
|
|
|
{
|
2008-05-09 00:34:28 +02:00
|
|
|
set_flags(Gtk::NO_WINDOW);
|
|
|
|
|
|
2008-05-08 21:56:55 +02:00
|
|
|
//Call base class:
|
|
|
|
|
Gtk::Widget::on_realize();
|
|
|
|
|
|
2008-05-09 00:34:28 +02:00
|
|
|
//Create the GdkWindow:
|
|
|
|
|
GdkWindowAttr attributes;
|
|
|
|
|
memset(&attributes, 0, sizeof(attributes));
|
2008-05-08 21:56:55 +02:00
|
|
|
|
2008-05-09 00:34:28 +02:00
|
|
|
Gtk::Allocation allocation = get_allocation();
|
2008-04-14 23:51:59 +02:00
|
|
|
|
2008-05-09 00:34:28 +02:00
|
|
|
//Set initial position and size of the Gdk::Window:
|
|
|
|
|
attributes.x = allocation.get_x();
|
|
|
|
|
attributes.y = allocation.get_y();
|
|
|
|
|
attributes.width = allocation.get_width();
|
|
|
|
|
attributes.height = allocation.get_height();
|
2008-05-08 21:56:55 +02:00
|
|
|
|
2008-05-09 00:34:28 +02:00
|
|
|
attributes.event_mask = get_events () | Gdk::EXPOSURE_MASK;
|
|
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
|
|
|
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
2008-05-08 21:56:55 +02:00
|
|
|
|
2008-05-09 00:34:28 +02:00
|
|
|
gdkWindow = Gdk::Window::create(get_window() /* parent */, &attributes,
|
|
|
|
|
GDK_WA_X | GDK_WA_Y);
|
|
|
|
|
unset_flags(Gtk::NO_WINDOW);
|
|
|
|
|
set_window(gdkWindow);
|
2008-05-08 21:56:55 +02:00
|
|
|
|
2008-05-09 00:34:28 +02:00
|
|
|
//set colors
|
2008-05-13 18:33:18 +02:00
|
|
|
modify_bg(Gtk::STATE_NORMAL, Gdk::Color("black"));
|
2008-05-08 21:56:55 +02:00
|
|
|
|
2008-05-09 00:34:28 +02:00
|
|
|
//make the widget receive expose events
|
|
|
|
|
gdkWindow->set_user_data(gobj());
|
2008-04-14 23:51:59 +02:00
|
|
|
|
2008-05-12 14:02:14 +02:00
|
|
|
if(displayer != NULL)
|
|
|
|
|
delete displayer;
|
|
|
|
|
displayer = createDisplayer(this, 320, 240);
|
2008-05-08 21:56:55 +02:00
|
|
|
|
|
|
|
|
add_events(Gdk::ALL_EVENTS_MASK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
VideoDisplayWidget::on_unrealize()
|
|
|
|
|
{
|
|
|
|
|
gdkWindow.clear();
|
|
|
|
|
|
|
|
|
|
//Call base class:
|
|
|
|
|
Gtk::Widget::on_unrealize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
VideoDisplayWidget::on_button_press_event (GdkEventButton* event)
|
|
|
|
|
{
|
|
|
|
|
unsigned char buffer[320 * 240 * 4];
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 320*240*4; i++)
|
|
|
|
|
buffer[i] = rand();
|
|
|
|
|
|
2008-05-12 14:02:14 +02:00
|
|
|
displayer->put((void*)buffer);
|
2008-05-08 21:56:55 +02:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-14 23:51:59 +02:00
|
|
|
bool
|
2008-04-19 21:47:53 +02:00
|
|
|
VideoDisplayWidget::on_expose_event(GdkEventExpose* event)
|
2008-05-08 21:56:55 +02:00
|
|
|
{
|
|
|
|
|
// This is where we draw on the window
|
|
|
|
|
/*Glib::RefPtr<Gdk::Window> window = get_window();
|
|
|
|
|
if(window)
|
2008-04-14 23:51:59 +02:00
|
|
|
{
|
2008-05-08 21:56:55 +02:00
|
|
|
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
|
|
|
|
|
if(event)
|
2008-04-14 23:51:59 +02:00
|
|
|
{
|
2008-05-08 21:56:55 +02:00
|
|
|
// clip to the area that needs to be re-exposed so we don't draw any
|
|
|
|
|
// more than we need to.
|
|
|
|
|
cr->rectangle(event->area.x, event->area.y,
|
|
|
|
|
event->area.width, event->area.height);
|
|
|
|
|
cr->clip();
|
2008-04-14 23:51:59 +02:00
|
|
|
}
|
2008-05-08 21:56:55 +02:00
|
|
|
|
|
|
|
|
// Paint the background
|
|
|
|
|
cr->set_source_rgb(0.0, 0.0, 0.0);
|
|
|
|
|
cr->paint();
|
|
|
|
|
}*/
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-04-14 23:51:59 +02:00
|
|
|
|
2008-05-12 14:02:14 +02:00
|
|
|
Displayer*
|
|
|
|
|
VideoDisplayWidget::createDisplayer( Gtk::Widget *drawingArea, int width, int height )
|
|
|
|
|
{
|
|
|
|
|
Displayer *displayer = NULL;
|
|
|
|
|
|
|
|
|
|
displayer = new XvDisplayer( drawingArea, width, height );
|
|
|
|
|
if ( !displayer->usable() )
|
|
|
|
|
{
|
|
|
|
|
delete displayer;
|
|
|
|
|
displayer = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( displayer == NULL )
|
|
|
|
|
{
|
|
|
|
|
displayer = new GdkDisplayer( drawingArea, width, height );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return displayer;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-14 23:51:59 +02:00
|
|
|
} // namespace widgets
|
|
|
|
|
} // namespace gui
|
|
|
|
|
} // namespace lumiera
|
|
|
|
|
|