From 3b9d05a67d8570c7fb2135ee7dbd85ce0e05ec60 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 7 Jun 2008 13:53:17 +0100 Subject: [PATCH] Made use of boost and nobug, added some documentation, and tidied code --- src/gui/dialogs/render.cpp | 6 +- src/gui/gtk-lumiera.cpp | 9 +- src/gui/gtk-lumiera.hpp | 3 + src/gui/output/displayer.cpp | 55 ++-- src/gui/output/displayer.hpp | 36 +- src/gui/output/gdkdisplayer.cpp | 64 ++-- src/gui/output/gdkdisplayer.hpp | 2 +- src/gui/output/xvdisplayer.cpp | 311 +++++++++--------- src/gui/widgets/timeline-widget.cpp | 20 +- src/gui/widgets/timeline-widget.hpp | 2 +- src/gui/widgets/timeline/header-container.cpp | 30 +- src/gui/widgets/timeline/timeline-body.cpp | 43 ++- src/gui/widgets/video-display-widget.cpp | 21 +- src/gui/workspace/actions.hpp | 2 +- src/gui/workspace/workspace-window.cpp | 32 +- 15 files changed, 338 insertions(+), 298 deletions(-) diff --git a/src/gui/dialogs/render.cpp b/src/gui/dialogs/render.cpp index 6fadd82fb..25dafdc88 100644 --- a/src/gui/dialogs/render.cpp +++ b/src/gui/dialogs/render.cpp @@ -41,7 +41,7 @@ namespace dialogs { videoFrame(_("Video")) { VBox *v_box = get_vbox(); - g_assert(v_box != NULL); + ASSERT(v_box != NULL); // The Output File Row outputFileHBox.pack_start(outputFileLabel, PACK_SHRINK); @@ -91,9 +91,9 @@ namespace dialogs { dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); int result = dialog.run(); - g_message("%d", result); + INFO(gui, "%d", result); if(result == RESPONSE_OK) - g_message("RESPONSE_OK"); + INFO(gui, "%d", "RESPONSE_OK"); } } // namespace dialogs diff --git a/src/gui/gtk-lumiera.cpp b/src/gui/gtk-lumiera.cpp index 7178c4170..69cfe0a4a 100644 --- a/src/gui/gtk-lumiera.cpp +++ b/src/gui/gtk-lumiera.cpp @@ -21,6 +21,7 @@ * *****************************************************/ #include +#include #ifdef ENABLE_NLS # include @@ -31,6 +32,8 @@ #include "workspace/workspace-window.hpp" #include "model/project.hpp" +NOBUG_CPP_DEFINE_FLAG(gui); + using namespace Gtk; using namespace lumiera::gui; using namespace lumiera::gui::workspace; @@ -38,8 +41,8 @@ using namespace lumiera::gui::model; GtkLumiera the_application; - int - main (int argc, char *argv[]) +int +main (int argc, char *argv[]) { return the_application.main(argc, argv); } @@ -52,6 +55,8 @@ namespace gui { int GtkLumiera::main(int argc, char *argv[]) { + NOBUG_INIT; + Main kit(argc, argv); Glib::set_application_name(AppTitle); diff --git a/src/gui/gtk-lumiera.hpp b/src/gui/gtk-lumiera.hpp index a3586e0d1..6cf7d3acc 100644 --- a/src/gui/gtk-lumiera.hpp +++ b/src/gui/gtk-lumiera.hpp @@ -29,6 +29,9 @@ #define GTK_LUMIERA_HPP #include +#include + +NOBUG_DECLARE_FLAG(gui); #ifdef ENABLE_NLS # include diff --git a/src/gui/output/displayer.cpp b/src/gui/output/displayer.cpp index 567bc8748..f2b036116 100644 --- a/src/gui/output/displayer.cpp +++ b/src/gui/output/displayer.cpp @@ -22,6 +22,7 @@ * *****************************************************/ +#include "../gtk-lumiera.hpp" #include "displayer.hpp" #include "xvdisplayer.hpp" #include "gdkdisplayer.hpp" @@ -32,43 +33,53 @@ namespace output { bool Displayer::usable() -{ - return false; -} + { + return false; + } DisplayerInput Displayer::format() -{ - return DISPLAY_NONE; -} + { + return DISPLAY_NONE; + } int Displayer::preferredWidth() -{ - return imageWidth; -} + { + return imageWidth; + } int Displayer::preferredHeight() -{ - return imageHeight; -} + { + return imageHeight; + } void Displayer::calculateVideoLayout( int widget_width, int widget_height, int image_width, int image_height, int &video_x, int &video_y, int &video_width, int &video_height ) -{ - double ratio_width = ( double ) widget_width / ( double ) image_width; - double ratio_height = ( double ) widget_height / ( double ) image_height; - double ratio_constant = ratio_height < ratio_width ? - ratio_height : ratio_width; - video_width = ( int ) ( image_width * ratio_constant + 0.5 ); - video_height = ( int ) ( image_height * ratio_constant + 0.5 ); - video_x = ( widget_width - video_width ) / 2; - video_y = ( widget_height - video_height ) / 2; -} + { + REQUIRE(widget_width >= 0); + REQUIRE(widget_height >= 0); + REQUIRE(image_width >= 0); + REQUIRE(image_height >= 0); + + double ratio_width = ( double ) widget_width / ( double ) image_width; + double ratio_height = ( double ) widget_height / ( double ) image_height; + double ratio_constant = ratio_height < ratio_width ? + ratio_height : ratio_width; + video_width = ( int ) ( image_width * ratio_constant + 0.5 ); + video_height = ( int ) ( image_height * ratio_constant + 0.5 ); + video_x = ( widget_width - video_width ) / 2; + video_y = ( widget_height - video_height ) / 2; + + ENSURE(video_x >= 0 && video_x < widget_width) + ENSURE(video_y >= 0 && video_y < widget_height) + ENSURE(video_width <= widget_width) + ENSURE(video_width <= widget_width) + } } // namespace output } // namespace gui diff --git a/src/gui/output/displayer.hpp b/src/gui/output/displayer.hpp index c117d5cb9..2441c0798 100644 --- a/src/gui/output/displayer.hpp +++ b/src/gui/output/displayer.hpp @@ -38,8 +38,7 @@ namespace output { #define MAX_HEIGHT 576 /** Supported Displayer formats - */ - + */ typedef enum { DISPLAY_NONE, DISPLAY_YUV, @@ -68,14 +67,14 @@ namespace output { If the widget being written to doesn't need a fixed size, then rewrite the two other put methods as required. - */ + */ class Displayer { public: /** Indicates if an object can be used to render images on the running system. - */ + */ virtual bool usable(); /** Indicates the format required by the abstract put method. @@ -83,22 +82,37 @@ namespace output { virtual DisplayerInput format(); /** Expected width of input to put. - */ + */ virtual int preferredWidth(); /** Expected height of input to put. - */ + */ virtual int preferredHeight(); - /** Put an image of a given width and height with the expected input - format (as indicated by the format method). - - \param image image of correct format and specified width/height - */ + /** + * Put an image of a given width and height with the expected input + * format (as indicated by the format method). + * + * @param image image of correct format and specified width/height + */ virtual void put( void * ) = 0; protected: + /** + * Calculates the coordinates for placing a video image inside a widget + * + * @param[in] widget_width The width of the display widget + * @param[in] widget_height The height of the display widget + * @param[in] image_width The width of the video image + * @param[in] image_height The height of the video image + * @param[out] video_x The x-coordinate of the top left corner of + * the scaled video image + * @param[out] video_y The y-coordinate of the top left corner of + * the scaled video image + * @param[out] video_width The width of the scale video image + * @param[out] video_height The height of the scale video image + */ static void calculateVideoLayout( int widget_width, int widget_height, int image_width, int image_height, diff --git a/src/gui/output/gdkdisplayer.cpp b/src/gui/output/gdkdisplayer.cpp index 262d28d5b..68ad6d545 100644 --- a/src/gui/output/gdkdisplayer.cpp +++ b/src/gui/output/gdkdisplayer.cpp @@ -22,11 +22,8 @@ * *****************************************************/ -#ifdef HAVE_CONFIG_H -#include -#endif +#include "../gtk-lumiera.hpp" -#include #include #include using std::cerr; @@ -40,36 +37,49 @@ namespace output { GdkDisplayer::GdkDisplayer( Gtk::Widget *drawing_area, int width, int height ) : drawingArea( drawing_area ) -{ - imageWidth = width, imageHeight = height; -} + { + REQUIRE(drawing_area != NULL); + REQUIRE(imageWidth > 0); + REQUIRE(imageHeight > 0); + + imageWidth = width, imageHeight = height; + } bool GdkDisplayer::usable() -{ - return true; -} + { + return true; + } void GdkDisplayer::put( void *image ) -{ - int video_x = 0, video_y = 0, video_width = 0, video_height = 0; - calculateVideoLayout( - drawingArea->get_width(), - drawingArea->get_height(), - preferredWidth(), preferredHeight(), - video_x, video_y, video_width, video_height ); + { + int video_x = 0, video_y = 0, video_width = 0, video_height = 0; + calculateVideoLayout( + drawingArea->get_width(), + drawingArea->get_height(), + preferredWidth(), preferredHeight(), + video_x, video_y, video_width, video_height ); - GdkWindow *window = drawingArea->get_window()->gobj(); - GdkGC *gc = gdk_gc_new( window ); - GdkPixbuf *pix = gdk_pixbuf_new_from_data( (const guchar*)image, GDK_COLORSPACE_RGB, FALSE, 8, - preferredWidth(), preferredHeight(), preferredWidth() * 3, NULL, NULL ); - GdkPixbuf *im = gdk_pixbuf_scale_simple( pix, video_width, video_height, GDK_INTERP_NEAREST ); - gdk_draw_pixbuf( window, gc, im, 0, 0, video_x, video_y, -1, -1, GDK_RGB_DITHER_NORMAL, 0, 0 ); - g_object_unref( im ); - g_object_unref( pix ); - g_object_unref( gc ); -} + GdkWindow *window = drawingArea->get_window()->gobj(); + ASSERT(window != NULL); + + GdkGC *gc = gdk_gc_new( window ); + ASSERT(gc != NULL); + + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_data( (const guchar*)image, GDK_COLORSPACE_RGB, FALSE, 8, + preferredWidth(), preferredHeight(), preferredWidth() * 3, NULL, NULL ); + ASSERT(pixbuf != NULL); + + GdkPixbuf *scaled_image = gdk_pixbuf_scale_simple( pixbuf, video_width, video_height, GDK_INTERP_NEAREST ); + ASSERT(scaled_image != NULL); + + gdk_draw_pixbuf( window, gc, scaled_image, 0, 0, video_x, video_y, -1, -1, GDK_RGB_DITHER_NORMAL, 0, 0 ); + + g_object_unref( scaled_image ); + g_object_unref( pixbuf ); + g_object_unref( gc ); + } } // namespace output } // namespace gui diff --git a/src/gui/output/gdkdisplayer.hpp b/src/gui/output/gdkdisplayer.hpp index 7e72fa24e..40ef3b547 100644 --- a/src/gui/output/gdkdisplayer.hpp +++ b/src/gui/output/gdkdisplayer.hpp @@ -41,7 +41,7 @@ namespace lumiera { namespace gui { namespace output { - class GdkDisplayer : public Displayer +class GdkDisplayer : public Displayer { public: GdkDisplayer( Gtk::Widget *drawing_area, int width, int height ); diff --git a/src/gui/output/xvdisplayer.cpp b/src/gui/output/xvdisplayer.cpp index 428decc62..cf7eeb53f 100644 --- a/src/gui/output/xvdisplayer.cpp +++ b/src/gui/output/xvdisplayer.cpp @@ -22,15 +22,9 @@ * *****************************************************/ -#ifdef HAVE_CONFIG_H -#include -#endif +#include "../gtk-lumiera.hpp" -#include #include -#include -using std::cerr; -using std::endl; #include "xvdisplayer.hpp" @@ -42,191 +36,190 @@ XvDisplayer::XvDisplayer( Gtk::Widget *drawing_area, int width, int height ) : xvImage( NULL ), drawingArea( drawing_area ), gotPort( false ) -{ - cerr << ">> Trying XVideo at " << width << "x" << height << endl; - - imageWidth = width, imageHeight = height; - - shmInfo.shmaddr = NULL; - - Glib::RefPtr area_window = drawing_area->get_window(); - - window = gdk_x11_drawable_get_xid( area_window->gobj() ); - display = gdk_x11_drawable_get_xdisplay( area_window->gobj() ); - - unsigned int count; - XvAdaptorInfo *adaptorInfo; - - if ( XvQueryAdaptors( display, window, &count, &adaptorInfo ) == Success ) { + INFO(gui, "Trying XVideo at %d x %d", width, height); - cerr << ">>> XvQueryAdaptors count: " << count << endl; - for ( unsigned int n = 0; gotPort == false && n < count; ++n ) - { - // Diagnostics - cerr << ">>> Xv: " << adaptorInfo[ n ].name - << ": ports " << adaptorInfo[ n ].base_id - << " - " << adaptorInfo[ n ].base_id + - adaptorInfo[ n ].num_ports - 1 - << endl; + imageWidth = width, imageHeight = height; - for ( port = adaptorInfo[ n ].base_id; - port < adaptorInfo[ n ].base_id + adaptorInfo[ n ].num_ports; - port ++ ) + shmInfo.shmaddr = NULL; + + Glib::RefPtr area_window = drawing_area->get_window(); + + window = gdk_x11_drawable_get_xid( area_window->gobj() ); + display = gdk_x11_drawable_get_xdisplay( area_window->gobj() ); + + unsigned int count; + XvAdaptorInfo *adaptorInfo; + + if ( XvQueryAdaptors( display, window, &count, &adaptorInfo ) == Success ) { - if ( XvGrabPort( display, port, CurrentTime ) == Success ) - { - g_message("XvGrabPort == 0"); - int formats; - XvImageFormatValues *list; - list = XvListImageFormats( display, port, &formats ); - - cerr << ">>> formats supported: " << formats << endl; - - for ( int i = 0; i < formats; i ++ ) + INFO(gui, "XvQueryAdaptors count: %d", count); + for ( unsigned int n = 0; gotPort == false && n < count; ++n ) { - fprintf( stderr, ">>> 0x%x (%c%c%c%c) %s\n", - list[ i ].id, - ( list[ i ].id ) & 0xff, - ( list[ i ].id >> 8 ) & 0xff, - ( list[ i ].id >> 16 ) & 0xff, - ( list[ i ].id >> 24 ) & 0xff, - ( list[ i ].format == XvPacked ) ? "packed" : "planar" ); - if ( list[ i ].id == 0x32595559 && !gotPort ) - gotPort = true; + // Diagnostics + INFO(gui, "%s, %d, %d, %d", adaptorInfo[ n ].name, + adaptorInfo[ n ].base_id, adaptorInfo[ n ].num_ports - 1); + + for ( port = adaptorInfo[ n ].base_id; + port < adaptorInfo[ n ].base_id + adaptorInfo[ n ].num_ports; + port ++ ) + { + if ( XvGrabPort( display, port, CurrentTime ) == Success ) + { + int formats; + XvImageFormatValues *list; + + list = XvListImageFormats( display, port, &formats ); + + INFO(gui, "formats supported: %d", formats); + + for ( int i = 0; i < formats; i ++ ) + { + INFO(gui, "0x%x (%c%c%c%c) %s", + list[ i ].id, + ( list[ i ].id ) & 0xff, + ( list[ i ].id >> 8 ) & 0xff, + ( list[ i ].id >> 16 ) & 0xff, + ( list[ i ].id >> 24 ) & 0xff, + ( list[ i ].format == XvPacked ) ? "packed" : "planar" ); + if ( list[ i ].id == 0x32595559 && !gotPort ) + gotPort = true; + } + + if ( !gotPort ) + { + XvUngrabPort( display, port, CurrentTime ); + } + else + { + grabbedPort = port; + break; + } + } + } } - if ( !gotPort ) + if ( gotPort ) { - XvUngrabPort( display, port, CurrentTime ); + int num; + unsigned int unum; + XvEncodingInfo *enc; + + XvQueryEncodings( display, grabbedPort, &unum, &enc ); + for ( unsigned int index = 0; index < unum; index ++ ) + { + INFO(gui, "%d: %s, %ldx%ld rate = %d/%d", index, enc->name, + enc->width, enc->height, enc->rate.numerator, + enc->rate.denominator ); + } + + XvAttribute *xvattr = XvQueryPortAttributes( display, port, &num ); + for ( int k = 0; k < num; k++ ) + { + if ( xvattr[k].flags & XvSettable ) + { + if ( strcmp( xvattr[k].name, "XV_AUTOPAINT_COLORKEY") == 0 ) + { + Atom val_atom = XInternAtom( display, xvattr[k].name, False ); + if ( XvSetPortAttribute( display, port, val_atom, 1 ) != Success ) + ERROR(gui, "Couldn't set Xv attribute %s\n", xvattr[k].name); + } + else if ( strcmp( xvattr[k].name, "XV_COLORKEY") == 0 ) + { + Atom val_atom = XInternAtom( display, xvattr[k].name, False ); + if ( XvSetPortAttribute( display, port, val_atom, 0x010102 ) != Success ) + ERROR(gui, "Couldn't set Xv attribute %s\n", xvattr[k].name); + } + } + } } - else + + if ( gotPort ) { - grabbedPort = port; - break; - } - } - } - } + gc = XCreateGC( display, window, 0, &values ); - if ( gotPort ) - { - int num; - unsigned int unum; - XvEncodingInfo *enc; - - XvQueryEncodings( display, grabbedPort, &unum, &enc ); - for ( unsigned int index = 0; index < unum; index ++ ) - { - fprintf( stderr, ">>> %d: %s, %ldx%ld rate = %d/%d\n", index, enc->name, - enc->width, enc->height, enc->rate.numerator, - enc->rate.denominator ); - } - - XvAttribute *xvattr = XvQueryPortAttributes( display, port, &num ); - for ( int k = 0; k < num; k++ ) - { - if ( xvattr[k].flags & XvSettable ) - { - if ( strcmp( xvattr[k].name, "XV_AUTOPAINT_COLORKEY") == 0 ) - { - Atom val_atom = XInternAtom( display, xvattr[k].name, False ); - if ( XvSetPortAttribute( display, port, val_atom, 1 ) != Success ) - fprintf(stderr, "Couldn't set Xv attribute %s\n", xvattr[k].name); - } - else if ( strcmp( xvattr[k].name, "XV_COLORKEY") == 0 ) - { - Atom val_atom = XInternAtom( display, xvattr[k].name, False ); - if ( XvSetPortAttribute( display, port, val_atom, 0x010102 ) != Success ) - fprintf(stderr, "Couldn't set Xv attribute %s\n", xvattr[k].name); - } - } - } - } + xvImage = ( XvImage * ) XvShmCreateImage( display, port, 0x32595559, 0, width, height, &shmInfo ); - if ( gotPort ) - { - gc = XCreateGC( display, window, 0, &values ); - - xvImage = ( XvImage * ) XvShmCreateImage( display, port, 0x32595559, 0, width, height, &shmInfo ); - - shmInfo.shmid = shmget( IPC_PRIVATE, xvImage->data_size, IPC_CREAT | 0777 ); - if (shmInfo.shmid < 0) { - perror("shmget"); - gotPort = false; - } else { - shmInfo.shmaddr = ( char * ) shmat( shmInfo.shmid, 0, 0 ); - xvImage->data = shmInfo.shmaddr; - shmInfo.readOnly = 0; - if ( !XShmAttach( gdk_display, &shmInfo ) ) - { - gotPort = false; - } - XSync( display, false ); - shmctl( shmInfo.shmid, IPC_RMID, 0 ); + shmInfo.shmid = shmget( IPC_PRIVATE, xvImage->data_size, IPC_CREAT | 0777 ); + if (shmInfo.shmid < 0) { + perror("shmget"); + gotPort = false; + } + else + { + shmInfo.shmaddr = ( char * ) shmat( shmInfo.shmid, 0, 0 ); + xvImage->data = shmInfo.shmaddr; + shmInfo.readOnly = 0; + if ( !XShmAttach( gdk_display, &shmInfo ) ) + { + gotPort = false; + } + XSync( display, false ); + shmctl( shmInfo.shmid, IPC_RMID, 0 ); #if 0 - xvImage = ( XvImage * ) XvCreateImage( display, port, 0x32595559, pix, width , height ); + xvImage = ( XvImage * ) XvCreateImage( display, port, 0x32595559, pix, width , height ); #endif + } + } + } + else + { + gotPort = false; } - } } - else - { - gotPort = false; - } -} XvDisplayer::~XvDisplayer() -{ - cerr << ">> Destroying XV Displayer" << endl; - - if ( gotPort ) { - XvUngrabPort( display, grabbedPort, CurrentTime ); - } + ERROR(gui, "Destroying XV Displayer"); - //if ( xvImage != NULL ) - // XvStopVideo( display, port, window ); + if ( gotPort ) + { + XvUngrabPort( display, grabbedPort, CurrentTime ); + } - if ( shmInfo.shmaddr != NULL ) - { - XShmDetach( display, &shmInfo ); - shmctl( shmInfo.shmid, IPC_RMID, 0 ); - shmdt( shmInfo.shmaddr ); + //if ( xvImage != NULL ) + // XvStopVideo( display, port, window ); + + if ( shmInfo.shmaddr != NULL ) + { + XShmDetach( display, &shmInfo ); + shmctl( shmInfo.shmid, IPC_RMID, 0 ); + shmdt( shmInfo.shmaddr ); + } + + if ( xvImage != NULL ) + XFree( xvImage ); } - - if ( xvImage != NULL ) - XFree( xvImage ); -} bool XvDisplayer::usable() -{ - return gotPort; -} + { + return gotPort; + } void XvDisplayer::put( void *image ) -{ - g_assert(drawingArea != NULL); - - if(xvImage != NULL) { - int video_x = 0, video_y = 0, video_width = 0, video_height = 0; - calculateVideoLayout( - drawingArea->get_width(), - drawingArea->get_height(), - preferredWidth(), preferredHeight(), - video_x, video_y, video_width, video_height ); + REQUIRE(image != NULL); + ASSERT(drawingArea != NULL); + + if(xvImage != NULL) + { + int video_x = 0, video_y = 0, video_width = 0, video_height = 0; + calculateVideoLayout( + drawingArea->get_width(), + drawingArea->get_height(), + preferredWidth(), preferredHeight(), + video_x, video_y, video_width, video_height ); - memcpy( xvImage->data, image, xvImage->data_size ); + memcpy( xvImage->data, image, xvImage->data_size ); - XvShmPutImage( display, port, window, gc, xvImage, - 0, 0, preferredWidth(), preferredHeight(), - video_x, video_y, video_width, video_height, false ); + XvShmPutImage( display, port, window, gc, xvImage, + 0, 0, preferredWidth(), preferredHeight(), + video_x, video_y, video_width, video_height, false ); + } } -} } // namespace output } // namespace gui diff --git a/src/gui/widgets/timeline-widget.cpp b/src/gui/widgets/timeline-widget.cpp index 799f1c736..240cb09fb 100644 --- a/src/gui/widgets/timeline-widget.cpp +++ b/src/gui/widgets/timeline-widget.cpp @@ -22,6 +22,8 @@ #include "timeline-widget.hpp" +#include + using namespace Gtk; using namespace std; using namespace lumiera::gui::widgets::timeline; @@ -43,9 +45,9 @@ TimelineWidget::TimelineWidget() : ruler("ruler") { body = new TimelineBody(this); - g_assert(body != NULL); + ASSERT(body != NULL); headerContainer = new HeaderContainer(this); - g_assert(headerContainer != NULL); + ASSERT(headerContainer != NULL); verticalAdjustment.signal_value_changed().connect( sigc::mem_fun(this, &TimelineWidget::on_scroll) ); @@ -64,9 +66,9 @@ TimelineWidget::TimelineWidget() : TimelineWidget::~TimelineWidget() { - g_assert(body != NULL); + ASSERT(body != NULL); body->unreference(); - g_assert(headerContainer != NULL); + ASSERT(headerContainer != NULL); headerContainer->unreference(); } @@ -87,16 +89,14 @@ TimelineWidget::on_size_allocate(Allocation& allocation) void TimelineWidget::update_tracks() { - g_assert(headerContainer != NULL); + ASSERT(headerContainer != NULL); headerContainer->update_headers(); // Recalculate the total height of the timeline scrolled area totalHeight = 0; - vector::iterator i; - for(i = tracks.begin(); i != tracks.end(); i++) + BOOST_FOREACH( Track* track, tracks ) { - timeline::Track *track = *i; - g_assert(track != NULL); + ASSERT(track != NULL); totalHeight += track->get_height() + TrackPadding; } } @@ -104,7 +104,7 @@ TimelineWidget::update_tracks() void TimelineWidget::update_scroll() { - g_assert(body != NULL); + ASSERT(body != NULL); const Allocation body_allocation = body->get_allocation(); //----- Vertical Scroll -----// diff --git a/src/gui/widgets/timeline-widget.hpp b/src/gui/widgets/timeline-widget.hpp index 502b3c535..a53ef6368 100644 --- a/src/gui/widgets/timeline-widget.hpp +++ b/src/gui/widgets/timeline-widget.hpp @@ -26,12 +26,12 @@ #ifndef TIMELINE_WIDGET_HPP #define TIMELINE_WIDGET_HPP +#include "../gtk-lumiera.hpp" #include "timeline/header-container.hpp" #include "timeline/timeline-body.hpp" #include "timeline/track.hpp" #include "timeline/video-track.hpp" -#include #include namespace lumiera { diff --git a/src/gui/widgets/timeline/header-container.cpp b/src/gui/widgets/timeline/header-container.cpp index a33562841..a52393860 100644 --- a/src/gui/widgets/timeline/header-container.cpp +++ b/src/gui/widgets/timeline/header-container.cpp @@ -20,6 +20,8 @@ * *****************************************************/ +#include + #include "header-container.hpp" #include "track.hpp" #include "../timeline-widget.hpp" @@ -35,6 +37,8 @@ namespace timeline { HeaderContainer::HeaderContainer(lumiera::gui::widgets::TimelineWidget *timeline_widget) : timelineWidget(timeline_widget) { + REQUIRE(timeline_widget != NULL); + set_flags(Gtk::NO_WINDOW); // This widget will not have a window at first set_redraw_on_allocate(false); @@ -47,14 +51,11 @@ HeaderContainer::HeaderContainer(lumiera::gui::widgets::TimelineWidget *timeline void HeaderContainer::update_headers() { - g_assert(timelineWidget != NULL); + ASSERT(timelineWidget != NULL); - vector< Track* > &tracks = timelineWidget->tracks; - vector< Track* >::iterator i; - for(i = tracks.begin(); i != tracks.end(); i++) + BOOST_FOREACH( Track* track, timelineWidget->tracks ) { - timeline::Track *track = *i; - g_assert(track != NULL); + ASSERT(track != NULL); Glib::RefPtr headerFrame(new Gtk::Frame()); headerFrame->add(track->get_header_widget()); @@ -146,11 +147,9 @@ void HeaderContainer::forall_vfunc(gboolean /* include_internals */, GtkCallback callback, gpointer callback_data) { - vector< RootHeader >::iterator i; - for(i = rootHeaders.begin(); i != rootHeaders.end(); i++) + BOOST_FOREACH( RootHeader &header, rootHeaders ) { - RootHeader header = *i; - g_assert(header.widget); + ASSERT(header.widget); callback(header.widget->gobj(), callback_data); } } @@ -166,21 +165,20 @@ HeaderContainer::on_scroll() void HeaderContainer::layout_headers() { - g_assert(timelineWidget != NULL); + ASSERT(timelineWidget != NULL); int offset = 0; const int y_scroll_offset = timelineWidget->get_y_scroll_offset(); const Allocation container_allocation = get_allocation(); - vector< RootHeader >::iterator i; - for(i = rootHeaders.begin(); i != rootHeaders.end(); i++) + BOOST_FOREACH( RootHeader &header, rootHeaders ) { - RootHeader header = *i; - g_assert(header.widget); - g_assert(header.track != NULL); + ASSERT(header.widget); + ASSERT(header.track != NULL); const int height = header.track->get_height(); + ASSERT(height >= 0); Gtk::Allocation header_allocation; header_allocation.set_x (0); diff --git a/src/gui/widgets/timeline/timeline-body.cpp b/src/gui/widgets/timeline/timeline-body.cpp index 859abb0e8..bbcca9a02 100644 --- a/src/gui/widgets/timeline/timeline-body.cpp +++ b/src/gui/widgets/timeline/timeline-body.cpp @@ -21,6 +21,7 @@ * *****************************************************/ #include +#include #include "timeline-body.hpp" #include "../timeline-widget.hpp" @@ -39,7 +40,7 @@ TimelineBody::TimelineBody(lumiera::gui::widgets::TimelineWidget *timeline_widge Glib::ObjectBase("TimelineBody"), timelineWidget(timeline_widget) { - g_assert(timelineWidget != NULL); + REQUIRE(timelineWidget != NULL); // Connect up some events timelineWidget->horizontalAdjustment.signal_value_changed().connect( @@ -84,28 +85,26 @@ TimelineBody::on_expose_event(GdkEventExpose* event) -(int)timelineWidget->verticalAdjustment.get_value()); // Interate drawing each track - vector::iterator i; - for(i = timelineWidget->tracks.begin(); - i != timelineWidget->tracks.end(); i++) - { - timeline::Track *track = *i; - g_assert(track != NULL); + BOOST_FOREACH( Track* track, timelineWidget->tracks ) + { + ASSERT(track != NULL); - const int track_height = track->get_height(); - - // Draw the track background - cairo->rectangle(0, 0, allocation.get_width(), track_height); - gdk_cairo_set_source_color(cairo->cobj(), &track_background); - cairo->fill(); - - // Render the track - cairo->save(); - track->draw_track(cairo); - cairo->restore(); + const int height = track->get_height(); + ASSERT(height >= 0); - // Shift for the next track - cairo->translate(0, track_height + TimelineWidget::TrackPadding); - } + // Draw the track background + cairo->rectangle(0, 0, allocation.get_width(), height); + gdk_cairo_set_source_color(cairo->cobj(), &track_background); + cairo->fill(); + + // Render the track + cairo->save(); + track->draw_track(cairo); + cairo->restore(); + + // Shift for the next track + cairo->translate(0, height + TimelineWidget::TrackPadding); + } return true; } @@ -122,7 +121,7 @@ TimelineBody::read_styles() track_background = *colour; else { - g_warning("track_background style value failed to load"); + WARN(gui, "track_background style value failed to load"); track_background.red = 0x0000; track_background.green = 0x0000; track_background.blue = 0x0000; diff --git a/src/gui/widgets/video-display-widget.cpp b/src/gui/widgets/video-display-widget.cpp index 2c7be8111..cbd4b38fd 100644 --- a/src/gui/widgets/video-display-widget.cpp +++ b/src/gui/widgets/video-display-widget.cpp @@ -24,6 +24,8 @@ #include #include +#include "../gtk-lumiera.hpp" + #include "../output/xvdisplayer.hpp" #include "../output/gdkdisplayer.hpp" @@ -137,19 +139,22 @@ VideoDisplayWidget::on_expose_event(GdkEventExpose* event) Displayer* VideoDisplayWidget::createDisplayer( Gtk::Widget *drawingArea, int width, int height ) { + REQUIRE(drawingArea != NULL); + REQUIRE(width >= 0 && height >= 0); + Displayer *displayer = NULL; - + displayer = new XvDisplayer( drawingArea, width, height ); if ( !displayer->usable() ) - { - delete displayer; - displayer = NULL; - } + { + delete displayer; + displayer = NULL; + } if ( displayer == NULL ) - { - displayer = new GdkDisplayer( drawingArea, width, height ); - } + { + displayer = new GdkDisplayer( drawingArea, width, height ); + } return displayer; } diff --git a/src/gui/workspace/actions.hpp b/src/gui/workspace/actions.hpp index c68ce8de4..891ae7757 100644 --- a/src/gui/workspace/actions.hpp +++ b/src/gui/workspace/actions.hpp @@ -29,7 +29,7 @@ #ifndef ACTIONS_HPP #define ACTIONS_HPP -#include +#include "../gtk-lumiera.hpp" namespace lumiera { namespace gui { diff --git a/src/gui/workspace/workspace-window.cpp b/src/gui/workspace/workspace-window.cpp index c2c46d61b..3e72d20d6 100644 --- a/src/gui/workspace/workspace-window.cpp +++ b/src/gui/workspace/workspace-window.cpp @@ -42,22 +42,24 @@ namespace lumiera { namespace gui { namespace workspace { - WorkspaceWindow::WorkspaceWindow(Project *source_project) : - project(source_project), - actions(*this) +WorkspaceWindow::WorkspaceWindow(Project *source_project) : + project(source_project), + actions(*this) { + REQUIRE(source_project != NULL); + layout = NULL; create_ui(); } - WorkspaceWindow::~WorkspaceWindow() +WorkspaceWindow::~WorkspaceWindow() { if(layout != NULL) g_object_unref(layout); } - void - WorkspaceWindow::create_ui() +void +WorkspaceWindow::create_ui() { //----- Configure the Window -----// set_title(AppTitle); @@ -106,23 +108,23 @@ namespace workspace { ""; try - { - uiManager->add_ui_from_string(ui_info); - } + { + uiManager->add_ui_from_string(ui_info); + } catch(const Glib::Error& ex) - { - g_error("Building menus failed: %s", ex.what().data()); - return; - } + { + ERROR(gui, "Building menus failed: %s", ex.what().data()); + return; + } //----- Set up the Menu Bar -----// Gtk::Widget* menu_bar = uiManager->get_widget("/MenuBar"); - g_assert(menu_bar != NULL); + ASSERT(menu_bar != NULL); base_container.pack_start(*menu_bar, Gtk::PACK_SHRINK); //----- Set up the Tool Bar -----// Gtk::Toolbar* toolbar = dynamic_cast(uiManager->get_widget("/ToolBar")); - g_assert(toolbar != NULL); + ASSERT(toolbar != NULL); toolbar->set_toolbar_style(TOOLBAR_ICONS); base_container.pack_start(*toolbar, Gtk::PACK_SHRINK);