#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
void GtkMessageBox(const gchar *,GtkMessageType);
void MilApplication(MilWindow* MainWindow)
{
MIL_ID MilApplication,
MilSystem,
MilDisplay,
MilDigitizer,
MilImage;
long BufSizeX;
long BufSizeY;
long BufSizeBand;
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 + MainWindow->HBox->allocation.height);
}
}
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_XWINDOW(MainWindow->Area->window));
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("Welcome to MIL !!! was printed",GTK_MESSAGE_INFO);
if (MilDigitizer)
{
MdigGrabContinuous(MilDigitizer, MilImage);
GtkMessageBox("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(const gchar *msg,GtkMessageType msgtype)
{
GtkWidget *dialog=NULL;
dialog = gtk_message_dialog_new (NULL,
(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)
{
MilWindow *MainWindow=(MilWindow *)data;
gtk_widget_set_sensitive(widget,FALSE);
MilApplication(MainWindow);
gtk_widget_set_sensitive(widget,TRUE);
return TRUE;
}
int main(int argc, char *argv[])
{
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);
gtk_signal_connect (GTK_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_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (MainWindow.Window), vbox);
gtk_widget_show (vbox);
MainWindow.HBox=gtk_hbox_new(FALSE,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 (GTK_OBJECT (button),
"clicked",
G_CALLBACK (gtk_start_callback),
(gpointer) &MainWindow);
gtk_widget_set_double_buffered(MainWindow.Area,False);
gtk_widget_show(MainWindow.Area);
gtk_widget_show (MainWindow.Window);
gtk_main();
return 0;
}