#include "MdispWindowGtk.h"
#define MIL_APPLICATION_NAME "MIL Application"
#define MIL_APPLICATION_NAME_SIZE 128
#define DEFAULT_IMAGE_SIZE_X 640
#define DEFAULT_IMAGE_SIZE_Y 480
#define DEFAULT_IMAGE_SIZE_BAND 1
static void GtkMessageBox(MilWindow* MainWindow, const gchar *,GtkMessageType);
void MilApplication(MilWindow* MainWindow)
{
MIL_ID MilApplication,
MilSystem,
MilDisplay,
MilDigitizer,
MilImage;
long BufSizeX = 0;
long BufSizeY = 0;
long BufSizeBand = 0;
MappAlloc(M_NULL, M_DEFAULT, &MilApplication);
MsysAlloc(M_DEFAULT, "M_DEFAULT", M_DEFAULT, M_DEFAULT, &MilSystem);
MdispAlloc(MilSystem, M_DEFAULT, "M_DEFAULT", M_WINDOWED, &MilDisplay);
if (MsysInquire(MilSystem, M_DIGITIZER_NUM, M_NULL) > 0)
{
MdigAlloc(MilSystem, M_DEFAULT, "M_DEFAULT", M_DEFAULT, &MilDigitizer);
MdigInquire(MilDigitizer, M_SIZE_X, &BufSizeX);
MdigInquire(MilDigitizer, M_SIZE_Y, &BufSizeY);
MdigInquire(MilDigitizer, M_SIZE_BAND, &BufSizeBand);
if((BufSizeX > DEFAULT_IMAGE_SIZE_X) || (BufSizeY > DEFAULT_IMAGE_SIZE_Y))
{
gtk_window_resize(GTK_WINDOW(MainWindow->Window),
BufSizeX,
BufSizeY + gtk_widget_get_allocated_height(MainWindow->HBox));
}
}
else
{
MilDigitizer = M_NULL;
BufSizeX = DEFAULT_IMAGE_SIZE_X;
BufSizeY = DEFAULT_IMAGE_SIZE_Y;
BufSizeBand = DEFAULT_IMAGE_SIZE_BAND;
}
MbufAllocColor(MilSystem, BufSizeBand, BufSizeX, BufSizeY, 8+M_UNSIGNED,
(MilDigitizer ? M_IMAGE+M_DISP+M_GRAB : M_IMAGE+M_DISP), &MilImage);
MbufClear(MilImage,0);
MdispSelectWindow(MilDisplay, MilImage, GDK_WINDOW_XID(gtk_widget_get_window(MainWindow->Area)));
MgraFont(M_DEFAULT, M_FONT_DEFAULT_LARGE);
MgraText(M_DEFAULT, MilImage, (BufSizeX/8)*2, BufSizeY/2,
MIL_TEXT(" Welcome to MIL !!! "));
MgraRect(M_DEFAULT, MilImage, ((BufSizeX/8)*2)-60, (BufSizeY/2)-80,
((BufSizeX/8)*2)+370, (BufSizeY/2)+100);
MgraRect(M_DEFAULT, MilImage, ((BufSizeX/8)*2)-40, (BufSizeY/2)-60,
((BufSizeX/8)*2)+350, (BufSizeY/2)+80);
MgraRect(M_DEFAULT, MilImage, ((BufSizeX/8)*2)-20, (BufSizeY/2)-40,
((BufSizeX/8)*2)+330, (BufSizeY/2)+60);
GtkMessageBox(MainWindow, "Welcome to MIL !!! was printed",GTK_MESSAGE_INFO);
if (MilDigitizer)
{
MdigGrabContinuous(MilDigitizer, MilImage);
GtkMessageBox(MainWindow, "Continuous grab in progress",GTK_MESSAGE_INFO);
MdigHalt(MilDigitizer);
}
MdispSelect(MilDisplay, M_NULL);
MbufFree(MilImage);
if (MilDigitizer)
MdigFree(MilDigitizer);
MdispFree(MilDisplay);
MsysFree(MilSystem);
MappFree(MilApplication);
}
void GtkMessageBox(MilWindow* MainWindow, const gchar *msg,GtkMessageType msgtype)
{
GtkWidget *dialog=NULL;
dialog = gtk_message_dialog_new (GTK_WINDOW(MainWindow->Window),
(GtkDialogFlags)(GTK_DIALOG_MODAL| GTK_DIALOG_DESTROY_WITH_PARENT),
msgtype,
(GTK_BUTTONS_CLOSE),
"%s",
msg);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
gboolean gtk_start_callback(GtkWidget *widget,
gpointer data)
{
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
MilWindow *MainWindow=(MilWindow *)data;
GdkColor color;
GtkStyle *style = gtk_widget_get_style (MainWindow->Area);
if (style != NULL)
{
color = style->bg[GTK_STATE_NORMAL];
gtk_widget_modify_bg ( GTK_WIDGET(MainWindow->Area), GTK_STATE_NORMAL, &color);
}
gtk_widget_set_sensitive(widget,FALSE);
gtk_widget_set_double_buffered(MainWindow->Area, False);
MilApplication(MainWindow);
gtk_widget_set_sensitive(widget,TRUE);
G_GNUC_END_IGNORE_DEPRECATIONS
return TRUE;
}
int main(int argc, char *argv[])
{
setenv("GDK_BACKEND","x11", 1);
XInitThreads();
GtkWidget *button=NULL;
GtkWidget *vbox=NULL;
MilWindow MainWindow;
gtk_init(&argc, &argv);
MainWindow.Window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(MainWindow.Window), MIL_APPLICATION_NAME);
g_signal_connect (G_OBJECT (MainWindow.Window), "destroy", gtk_main_quit,NULL);
gtk_window_set_default_size(GTK_WINDOW(MainWindow.Window),
DEFAULT_IMAGE_SIZE_X,
DEFAULT_IMAGE_SIZE_Y);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (MainWindow.Window), vbox);
gtk_widget_show (vbox);
MainWindow.HBox=gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0);
gtk_box_pack_start (GTK_BOX (vbox), MainWindow.HBox, FALSE, FALSE, 0);
gtk_widget_show (MainWindow.HBox);
button=gtk_button_new_with_label ("Start");
gtk_box_pack_start (GTK_BOX (MainWindow.HBox), button, FALSE, FALSE, 0);
gtk_widget_show(button);
MainWindow.Area = gtk_drawing_area_new ();
gtk_widget_set_size_request (MainWindow.Area,
DEFAULT_IMAGE_SIZE_X,
DEFAULT_IMAGE_SIZE_Y);
gtk_box_pack_start (GTK_BOX (vbox), MainWindow.Area, TRUE, TRUE, 0);
g_signal_connect (G_OBJECT (button),
"clicked",
G_CALLBACK (gtk_start_callback),
(gpointer) &MainWindow);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_widget_set_double_buffered(MainWindow.Area,False);
G_GNUC_END_IGNORE_DEPRECATIONS
gtk_widget_show(MainWindow.Area);
gtk_widget_show (MainWindow.Window);
gtk_main();
return 0;
}