gcamview.cpp
来自「一个语言识别引擎」· C++ 代码 · 共 630 行 · 第 1/2 页
CPP
630 行
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
/*
* Copyright (C) 2006 Matteo Brunettini
* CopyPolicy: Released under the terms of the GNU GPL v2.0.
*
*/
// gCamView.cpp : Defines the entry point for the application.
//
#include "gCamView.h"
#include <yarp/os/Property.h>
#include <yarp/os/Network.h>
// Image Receiver
extern YARPImgRecv *ptr_imgRecv;
// Image to Display
extern yarp::sig::ImageOf<yarp::sig::PixelRgb> *ptr_inputImg;
// Semaphore
extern yarp::os::Semaphore *ptr_semaphore;
static void createObjects() {
ptr_imgRecv = new YARPImgRecv;
ptr_inputImg = new yarp::sig::ImageOf<yarp::sig::PixelRgb>;
ptr_semaphore = new yarp::os::Semaphore;
}
static void deleteObjects() {
delete ptr_imgRecv;
delete ptr_inputImg;
delete ptr_semaphore;
}
//-------------------------------------------------
// Main Window Callbacks
//-------------------------------------------------
static gint timeout_CB (gpointer data)
{
if ( (!_freezed) && getImage() )
{
int imageWidth, imageHeight, pixbufWidth, pixbufHeight;
imageWidth = _inputImg.width();
imageHeight = _inputImg.height();
pixbufWidth = gdk_pixbuf_get_width(frame);
pixbufHeight = gdk_pixbuf_get_height(frame);
if ( (imageWidth != pixbufWidth) || (imageHeight != pixbufHeight) )
{
g_object_unref(frame);
frame = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, imageWidth, imageHeight);
}
_frameN++;
gtk_widget_queue_draw (da);
if (_savingSet)
saveCurrentFrame();
}
return TRUE;
}
static gboolean delete_event( GtkWidget *widget, GdkEvent *event, gpointer data )
{
// If you return FALSE in the "delete_event" signal handler,
// GTK will emit the "destroy" signal. Returning TRUE means
// you don't want the window to be destroyed.
// This is useful for popping up 'are you sure you want to quit?'
// type dialogs.
cleanExit();
return TRUE;
}
static gint expose_CB (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
if ((frame) && (mainWindow))
{
guchar *pixels;
unsigned int rowstride;
unsigned int imageWidth, imageHeight, areaWidth, areaHeight;
_semaphore.wait();
yarpImage2pixbuf(&_inputImg, frame);
_semaphore.post();
imageWidth = _inputImg.width();
imageHeight = _inputImg.height();
areaWidth = event->area.width;
areaHeight = event->area.height;
if ( (areaWidth != imageWidth) || (areaHeight != imageHeight) )
{
GdkPixbuf *scaledFrame;
scaledFrame = gdk_pixbuf_scale_simple( frame,
areaWidth,
areaHeight,
GDK_INTERP_BILINEAR); // Best quality
//GDK_INTERP_NEAREST); // Best speed
pixels = gdk_pixbuf_get_pixels (scaledFrame);
rowstride = gdk_pixbuf_get_rowstride(scaledFrame);
gdk_draw_rgb_image (widget->window,
widget->style->black_gc,
event->area.x, event->area.y,
event->area.width, event->area.height,
GDK_RGB_DITHER_NORMAL,
pixels,
rowstride);
g_object_unref(scaledFrame);
}
else
{
pixels = gdk_pixbuf_get_pixels (frame);
rowstride = gdk_pixbuf_get_rowstride(frame);
gdk_draw_rgb_image (widget->window,
widget->style->black_gc,
event->area.x, event->area.y,
event->area.width, event->area.height,
GDK_RGB_DITHER_NORMAL,
pixels,
rowstride);
}
}
return TRUE;
}
static gint menuFileQuit_CB(GtkWidget *widget, gpointer data)
{
cleanExit();
return TRUE;
}
static gint menuHelpAbout_CB(GtkWidget *widget, gpointer data)
{
#if GTK_CHECK_VERSION(2,6,0)
const gchar *authors[] =
{
"EmmeBi",
NULL
};
const gchar *license =
"Released under the terms of the GNU GPL v2.0.\n"
"The complete license description is contained in the\n"
"COPYING file included in this distribution.\n"
"Please refer to this file for complete\n"
"information about the licensing of YARP.\n"
"\n"
"DISCLAIMERS: LICENSOR WARRANTS THAT THE COPYRIGHT IN AND TO THE\n"
"SOFTWARE IS OWNED BY THE LICENSOR OR THAT THE SOFTWARE IS\n"
"DISTRIBUTED BY LICENSOR UNDER A VALID CURRENT LICENSE. EXCEPT AS\n"
"EXPRESSLY STATED IN THE IMMEDIATELY PRECEDING SENTENCE, THE\n"
"SOFTWARE IS PROVIDED BY THE LICENSOR, CONTRIBUTORS AND COPYRIGHT\n"
"OWNERS AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED\n"
"INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n"
"FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO\n"
"EVENT SHALL THE LICENSOR, CONTRIBUTORS OR COPYRIGHT OWNERS BE\n"
"LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\n"
"ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n"
"ONNECTION WITH THE SOFTWARE.\n";
gtk_show_about_dialog(GTK_WINDOW(mainWindow),
"name", "gview",
"version", "0.9",
"license", license,
"website", "http://www.liralab.it",
"comments", "Program to display images received on a port.",
"authors", authors,
NULL);
#else
printf("Missing functionality on older GTK version, sorry\n");
#endif
return TRUE;
}
static gint menuImageSize_CB(GtkWidget *widget, gpointer data)
{
int targetWidth, targetHeight;
targetWidth = _inputImg.width();
targetHeight = _inputImg.height();
gtk_window_resize(GTK_WINDOW(mainWindow), targetWidth, (targetHeight+_occupiedHeight));
return TRUE;
}
static gint menuImageRatio_CB(GtkWidget *widget, gpointer data)
{
double ratio;
int imgWidth, imgHeight;
int targetWidth, targetHeight;
int daWidth, daHeight;
imgWidth = _inputImg.width();
imgHeight = _inputImg.height();
daWidth = da->allocation.width;
daHeight = da->allocation.height;
ratio = double(imgWidth) / double(imgHeight);
targetWidth = int(double(daHeight) * ratio);
targetHeight = daHeight;
// TO DO : resize DrawingArea Directly
gtk_window_resize(GTK_WINDOW(mainWindow), targetWidth, (targetHeight+_occupiedHeight));
return TRUE;
}
static gint menuImageInterval_CB(GtkWidget *widget, gpointer data)
{
GtkWidget *dialog;
double interval;
interval = _imgRecv.GetEstimatedInterval();
dialog = gtk_message_dialog_new ( GTK_WINDOW (mainWindow),
GTK_DIALOG_MODAL,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"Estimated interval during last cycle:\n");
#if GTK_CHECK_VERSION(2,6,0)
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%.3f seconds.", interval);
#else
printf("Missing functionality on older GTK version, sorry\n");
#endif
gtk_window_set_title (GTK_WINDOW(dialog), "Estimated interval");
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
return TRUE;
}
static gint menuFileSingle_CB(GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
if ( gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM(widget)) )
{
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(fileSetItem), FALSE);
gtk_widget_show_all (saveSingleDialog);
}
else
{
gtk_widget_hide (saveSingleDialog);
}
return TRUE;
}
static gint menuFileSet_CB(GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
#if GTK_CHECK_VERSION(2,6,0)
if ( gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM(widget)) )
{
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(fileSingleItem), FALSE);
gtk_widget_show_all (saveSetDialog);
}
else
{
gtk_widget_hide (saveSetDialog);
}
#endif
return TRUE;
}
static gint menuImageFreeze_CB(GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
if ( gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM(widget)) )
{
_freezed = true;
} else
{
_freezed = false;
}
return TRUE;
}
static gint saveSingleDelete_CB (GtkWidget *widget, gpointer data)
{
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(fileSingleItem), FALSE);
return (TRUE);
}
static gint saveSetDelete_CB (GtkWidget *widget, gpointer data)
{
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(fileSetItem), FALSE);
return (TRUE);
}
static gint saveSingleClicked_CB(GtkWidget *widget, gpointer data)
{
saveCurrentFrame();
return (TRUE);
}
static gint saveSetStartClicked_CB(GtkWidget *widget, gpointer data)
{
_savingSet = true;
return (TRUE);
}
static gint saveSetStopClicked_CB(GtkWidget *widget, gpointer data)
{
_savingSet = false;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?