request sample code for jpeg display and aa text

This forum is read only. No new submissions are accepted.

Questions about motif? Contact us

3 posts / 0 new
Last post
request sample code for jpeg display and aa text

Submitted by motifn00b on Mon, 02/19/2007 - 06:47.

Greetings I am new to motif altho the coming months I will undertake a project to update some old existing code. The newest features of 2.3 are of interest to me because I have multiple jpeg images displayed in my existing code and in the code I am planning on writing. Anti-Aliased text is also of interest for obvious reasons. Where can I locate simple sample code implementing the process of loading, displaying and changing jpeg images in a motif 2.3 applications? Much thanks to you all!

Mon, 03/05/2007 - 10:06#1

Mon, 03/05/2007 - 10:06#1

Yuriy Syrota

request sample code for jpeg display and aa text

motifn00b,

here is a simple example you requested:

#include <Xm/XmAll.h></p>
<p>int<br />
main(int argc, char *argv[]) {<br />
Widget toplevel, label;<br />
XtAppContext app;<br />
Arg al[10];<br />
Cardinal ac = 0;<br />
Pixmap pixmap;</p>
<p> XtSetLanguageProc(NULL, NULL, NULL);<br />
toplevel = XtVaAppInitialize(&app, "test", NULL, 0, &argc, argv, NULL,<br />
NULL);</p>
<p> pixmap = XmGetPixmap(XtScreen(toplevel), "toucan.jpg",<br />
XmUNSPECIFIED_PIXEL, XmUNSPECIFIED_PIXEL);<br />
XtSetArg(al[ac], XmNlabelType, XmPIXMAP); ac++;<br />
XtSetArg(al[ac], XmNlabelPixmap, pixmap); ac++;<br />
label = XmCreateLabel(toplevel, "label", al, ac);<br />
XtManageChild(label);</p>
<p> XtRealizeWidget(toplevel);</p>
<p> XtAppMainLoop(app);<br />
}<br />

 

Sat, 12/12/2009 - 13:05#2

Sat, 12/12/2009 - 13:05#2

squeen

On CentOS 5, this version

On CentOS 5, this version (sans HTML) worked great.

/* TO BUILD: cc xmjpg.c -o xmjpg -lXm -lXt -lX11*/
#include
#include
#include

int main(int argc, char *argv[])
{
Widget toplevel, label;
XtAppContext app;
Arg al[10];
Cardinal ac = 0;
Pixmap pixmap;

if (argc<2 || strstr(argv[1],".jpg")==NULL) {
printf("usage: xmjpg image.jpg\n");
return;
}

XtSetLanguageProc(NULL, NULL, NULL);
toplevel = XtVaAppInitialize(&app, "test", NULL, 0, &argc, argv, NULL, NULL);
pixmap = XmGetPixmap(XtScreen(toplevel), argv[1], XmUNSPECIFIED_PIXEL, XmUNSPECIFIED_PIXEL);
XtSetArg(al[ac], XmNlabelType, XmPIXMAP); ac++;
XtSetArg(al[ac], XmNlabelPixmap, pixmap); ac++;
label = XmCreateLabel(toplevel, "label", al, ac);
XtManageChild(label);
XtRealizeWidget(toplevel);
XtAppMainLoop(app);
return;
}

I would upload an image to the forum, but that capability appears to be broken for me.

This is a really nice feature! It would also be great if there was an Xm utility function (or this function was extended) to just as effortlessly include and cache an Xpm image. I have my own functions wrapping XpmCreatePixmapFromData, but it is not nearly as convenient as this. Xpm's are still nice (compared to jpeg's) since they compile right into the executable from source.

Does XmGetPixmap work with PNG's as well? If so, does it handle the alpha compositing?