#include <mil.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#define IMAGE_FILE M_IMAGE_PATH MIL_TEXT("Board.mim")
#define WINDOW_TITLE MIL_TEXT("Custom Title")
void OverlayDraw(MIL_ID Display);
int main(void)
{
MIL_ID MilApplication,
MilSystem,
MilDisplay,
MilDigitizer=0,
MilImage;
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, &MilDisplay, M_NULL, M_NULL);
if (MsysInquire(MilSystem, M_DIGITIZER_NUM, M_NULL))
{
MdigAlloc(MilSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_DEFAULT, &MilDigitizer);
MbufAllocColor(MilSystem,
MdigInquire(MilDigitizer,M_SIZE_BAND,M_NULL),
MdigInquire(MilDigitizer,M_SIZE_X,M_NULL),
MdigInquire(MilDigitizer,M_SIZE_Y,M_NULL),
8+M_UNSIGNED,
M_IMAGE+M_DISP+M_PROC+M_GRAB,
&MilImage);
MbufClear(MilImage, 0);
}
else
{
MbufRestore(IMAGE_FILE, MilSystem, &MilImage);
}
MdispControl(MilDisplay, M_TITLE, M_PTR_TO_DOUBLE(WINDOW_TITLE));
MdispSelect(MilDisplay, MilImage);
OverlayDraw(MilDisplay);
if (MilDigitizer)
MdigGrabContinuous(MilDigitizer, MilImage);
printf("\nOVERLAY ANNOTATIONS:\n");
printf("--------------------\n\n");
printf("Displaying an image with overlay annotations.\n");
printf("Press <Enter> to continue.\n\n");
MosGetchar();
if (MilDigitizer)
{
MdigHalt(MilDigitizer);
MdigFree(MilDigitizer);
printf("Displaying the last grabbed image.\n");
printf("Press <Enter> to end.\n\n");
MosGetchar();
}
MbufFree(MilImage);
MappFreeDefault(MilApplication, MilSystem, MilDisplay, M_NULL, M_NULL);
return 0;
}
void OverlayDraw(MIL_ID MilDisplay)
{
MIL_ID MilOverlayImage;
long ImageWidth, ImageHeight;
long Count;
MIL_TEXT_CHAR chText[80];
Pixmap XPixmap=M_NULL;
MdispControl(MilDisplay, M_OVERLAY, M_ENABLE);
MdispInquire(MilDisplay, M_OVERLAY_ID, &MilOverlayImage);
MdispControl(MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT);
MdispControl(MilDisplay, M_OVERLAY_SHOW, M_DISABLE);
ImageWidth = MbufInquire(MilOverlayImage, M_SIZE_X, M_NULL);
ImageHeight = MbufInquire(MilOverlayImage, M_SIZE_Y, M_NULL);
MgraControl(M_DEFAULT, M_BACKGROUND_MODE, M_TRANSPARENT);
MgraColor(M_DEFAULT, M_COLOR_WHITE);
MgraText(M_DEFAULT, MilOverlayImage, ImageWidth/9, ImageHeight/5, MIL_TEXT(" -------------------- "));
MgraText(M_DEFAULT, MilOverlayImage, ImageWidth/9, ImageHeight/5+25, MIL_TEXT(" - MIL Overlay Text - "));
MgraText(M_DEFAULT, MilOverlayImage, ImageWidth/9, ImageHeight/5+50, MIL_TEXT(" -------------------- "));
MgraColor(M_DEFAULT, M_COLOR_GREEN);
MgraText(M_DEFAULT, MilOverlayImage, ImageWidth*11/18, ImageHeight/5, MIL_TEXT(" ---------------------"));
MgraText(M_DEFAULT, MilOverlayImage, ImageWidth*11/18, ImageHeight/5+25, MIL_TEXT(" - MIL Overlay Text - "));
MgraText(M_DEFAULT, MilOverlayImage, ImageWidth*11/18, ImageHeight/5+50, MIL_TEXT(" ---------------------"));
MdispControl(MilDisplay, M_OVERLAY_SHOW, M_ENABLE);
MappControl(M_DEFAULT, M_ERROR, M_PRINT_DISABLE);
MbufControl(MilOverlayImage, M_XPIXMAP_ALLOC, M_COMPENSATION_ENABLE);
XPixmap=((Pixmap)MbufInquire(MilOverlayImage, M_XPIXMAP_HANDLE, M_NULL));
if(XPixmap)
{
Display *dpy = XOpenDisplay("");
int screen = DefaultScreen(dpy);
GC gc = XCreateGC(dpy,XPixmap,0,0);
XColor xcolors[3],exact;
XPoint Hor[2];
XPoint Ver[2];
int i;
const char *color_names[] = {
"red",
"yellow",
"blue",
};
for(i=0;i<3;i++)
{
if(!XAllocNamedColor(dpy,DefaultColormap(dpy,screen),color_names[i], &xcolors[i],&exact))
{
fprintf(stderr, "cant't alloc color %s\n", color_names[i]);
exit (1);
}
}
XSetForeground(dpy,gc, xcolors[2].pixel);
Hor[0].x = 0;
Hor[0].y = ImageHeight/2;
Hor[1].x = ImageWidth;
Hor[1].y = ImageHeight/2;
XDrawLines(dpy,XPixmap,gc,Hor, 2, CoordModeOrigin);
Ver[0].x = ImageWidth/2;
Ver[0].y = 0;
Ver[1].x = ImageWidth/2;
Ver[1].y = ImageHeight;
XDrawLines(dpy,XPixmap,gc,Ver, 2, CoordModeOrigin);
XSetForeground(dpy,gc, xcolors[0].pixel);
MosStrcpy(chText, 80, MIL_TEXT("X Overlay Text"));
Count = MosStrlen(chText);
XDrawString(dpy,XPixmap,gc,
ImageWidth*3/18, ImageHeight*17/24,
chText,Count);
XSetForeground(dpy,gc, xcolors[1].pixel);
XDrawString(dpy,XPixmap,gc,
ImageWidth*12/18, ImageHeight*17/24,
chText,Count);
XSetForeground(dpy,gc, BlackPixel(dpy,screen));
XFlush(dpy);
XFreeGC(dpy,gc);
XCloseDisplay(dpy);
}
MbufControl(MilOverlayImage, M_XPIXMAP_FREE, M_DEFAULT);
MbufControl(MilOverlayImage, M_MODIFIED, M_DEFAULT);
}