open-axiom repository from github
/*1Copyright (C) 1991-2002, The Numerical ALgorithms Group Ltd.2All rights reserved.3Copyright (C) 2007-2008, Gabriel Dos Reis.4All rights reserved.56Redistribution and use in source and binary forms, with or without7modification, are permitted provided that the following conditions are8met:910- Redistributions of source code must retain the above copyright11notice, this list of conditions and the following disclaimer.1213- Redistributions in binary form must reproduce the above copyright14notice, this list of conditions and the following disclaimer in15the documentation and/or other materials provided with the16distribution.1718- Neither the name of The Numerical ALgorithms Group Ltd. nor the19names of its contributors may be used to endorse or promote products20derived from this software without specific prior written permission.2122THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS23IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED24TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A25PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER26OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,27EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,28PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR29PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF30LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING31NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS32SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.33*/343536/* main procedure to test out Gdraw functions in this directory */37#include <stdio.h>38#include "Gdraws0.h"39#include "../view3D/header.h"4041GC gc, gc1;42Display *dsply;43int scrn;44viewPoints *viewport;4546int psInit=no;47GCptr GChead=NULL;48char *PSfilename="OUTPUT.ps";49char *envAXIOM;5051int52main(int argc, char **argv)53{5455XGCValues values;5657XEvent report;58int x0=0, y0=0, width=300, height=200, border=3;5960char *fontname = "6x13";61XFontStruct *dsp_font;6263Window menu;64char *str1 = " Print out the PostScript file? ",65*str0 = "Generate a PostScript file (OUTPUT.ps)?";66int m_width, m_height, flag=yes;6768/* open display */69if ((dsply = XOpenDisplay(NULL)) == NULL) {70printf("Can't open display NULL\n");71exit(-1);72}7374scrn = DefaultScreen(dsply);7576/* access font */77Gdraws_load_font(&dsp_font, fontname);7879values.background = WhitePixel(dsply, scrn);80values.foreground = BlackPixel(dsply, scrn);8182gc = XCreateGC(dsply, RootWindow(dsply, scrn),83(GCForeground | GCBackground), &values);84PSGlobalInit(); /* must initiate before using G/PS functions */85PSCreateContext(gc, "gc", psNormalWidth, psButtCap,86psMiterJoin, psWhite, psBlack);87XSetFont(dsply, gc, dsp_font->fid);88gc1 = XCreateGC(dsply, RootWindow(dsply, scrn),89(GCForeground | GCBackground), &values);90PSCreateContext(gc1, "gc1", psNormalWidth, psButtCap, psMiterJoin,91psWhite, psBlack);92XSetFont(dsply, gc1, dsp_font->fid);9394if (!(viewport = (viewPoints *)malloc(sizeof(viewPoints)))) {95fprintf(stderr,"Ran out of memory (malloc) trying to create a viewport.\n");96exit(-1);97}9899viewport->titleWindow = XCreateSimpleWindow(dsply, RootWindow(dsply,scrn),100x0, y0, width+6,101height+32+height/4, border,102BlackPixel(dsply, scrn),103WhitePixel(dsply, scrn));104105viewport->viewWindow = XCreateSimpleWindow(dsply, viewport->titleWindow,106x0, y0+20, width, height, border,107BlackPixel(dsply, scrn),108WhitePixel(dsply, scrn));109110strcpy(viewport->title, "what is a test title?");111112m_width = width; m_height = height/4;113menu = XCreateSimpleWindow(dsply, viewport->titleWindow, x0, y0+20+height+6,114m_width, m_height, border,115BlackPixel(dsply,scrn), WhitePixel(dsply,scrn));116117XSelectInput(dsply, viewport->viewWindow,118KeyPressMask|ButtonPressMask|ExposureMask);119XSelectInput(dsply, viewport->titleWindow, KeyPressMask|ExposureMask);120XSelectInput(dsply, menu, KeyPressMask|ButtonPressMask|ExposureMask);121122XMapWindow(dsply, viewport->viewWindow);123XMapWindow(dsply, viewport->titleWindow);124XFlush(dsply);125126while (yes) {127XNextEvent(dsply, &report);128switch (report.type) {129130case Expose:131if (report.xexpose.window==viewport->titleWindow) {132if (GDrawImageString(gc, viewport->titleWindow,13320, 15, viewport->title,134strlen(viewport->title),X) == psError)135printf("screen draw image string failed.\n");136if (Gdraws_data(X) == psError)137printf("screen Gdraws_data failed.\n");138}139if (report.xexpose.window==viewport->viewWindow) {140if (Gdraws_data(X) == psError)141printf("screen Gdraws_data failed.\n");142}143else if (report.xexpose.window==menu) {144if (flag)145Gdraws_draw_menu(menu, str0, m_width, m_height);146else147Gdraws_draw_menu(menu, str1, m_width, m_height);148}149break;150151case ButtonPress:152if (report.xbutton.window==viewport->viewWindow) {153XMapWindow(dsply, menu);154XFlush(dsply);155}156else if (report.xbutton.window==menu && flag) {157XUnmapWindow(dsply, menu);158if (Gdraws_pressed_yes(m_width, m_height, report.xbutton.x,159report.xbutton.y)) {160flag=no;161XMapWindow(dsply, menu);162PSInit(viewport->viewWindow, viewport->titleWindow);163if (Gdraws_data(PS) != psError)164PSCreateFile(3,viewport->viewWindow,165viewport->titleWindow,viewport->title);166else printf("PS Gdraws_data failed.\n");167}168}169else if (report.xbutton.window==menu && !flag) {170XUnmapWindow(dsply, menu);171if (Gdraws_pressed_yes(m_width, m_height, report.xbutton.x,172report.xbutton.y))173system("print OUTPUT.ps");174flag = yes;175}176break;177178case KeyPress:179if (report.xkey.window==viewport->viewWindow ||180report.xkey.window==viewport->titleWindow) {181XFreeGC(dsply, gc);182XFreeGC(dsply, gc1);183XCloseDisplay(dsply);184PSClose();185exit(1);186}187else if (report.xkey.window==menu) XUnmapWindow(dsply, menu);188189default:190break;191}192}193return 0;194}195196197