/**************************************************************** Uebungen zur Vorlesung "Graphische Datenverarbeitung" Sommersemester 1997 Programm: loesung_b4.c Autor: Christian Boehm Programm zeichnet Landkarte der EU-Regionen. ****************************************************************/ # include # include # include # include "euro.h" Widget DrawAr; /* Drawing Area */ XtAppContext kontext; /* Applikations-Umgebung */ GC fensterGC, pixmapGC; /* Graphik-Kontext fuer XDrawLine...*/ Display* display; Pixmap GraphikPixmap = 0; static char * fallbackRessourcen [] = { "Drawkarte.geometry: 750x500", "*drawingarea.background: white", "*drawingarea.foreground: black", NULL } ; void initGraphik (Widget widget) { Dimension w, h ; XGCValues werte; /* Struktur zum Setzen von GC-Attributen */ /* Groesse der DrawingArea holen */ XtVaGetValues (widget, XmNheight, &h, XmNwidth, &w, NULL) ; if (GraphikPixmap) { /* Falls schon Pixmap existiert: * alte Pixmap loeschen und mit neuer Groesse erzeugen */ XFreePixmap (display, GraphikPixmap) ; GraphikPixmap = XCreatePixmap (display, XtWindow (widget), w, h, 1) ; } else { /* Falls noch keine Pixmap existiert: * neue Pixmap und dazu passenden Graphik-Kontext erzeugen */ GraphikPixmap = XCreatePixmap (display, XtWindow (widget), w, h, 1) ; pixmapGC = XCreateGC (display, GraphikPixmap, 0, NULL) ; } /* Pixmap muss initialisiert werden ! */ werte.foreground = 0 ; werte.background = 1 ; XChangeGC (display, pixmapGC, GCForeground | GCBackground, &werte) ; XFillRectangle (display, GraphikPixmap, pixmapGC, 0, 0, w, h) ; werte.foreground = 1 ; werte.background = 0 ; XChangeGC (display, pixmapGC, GCForeground | GCBackground, &werte) ; } void DrawLandkarte (int n, struct linesegment *segs, double s, Drawable w, GC g) { int i ; for (i=0 ; ievent->xexpose.x, DAinfos->event->xexpose.y, DAinfos->event->xexpose.width, DAinfos->event->xexpose.height, DAinfos->event->xexpose.x, DAinfos->event->xexpose.y, 1); } void initGraphikWidget (Widget elternWidget) { XGCValues werte; DrawAr = XtVaCreateManagedWidget("drawingarea", xmDrawingAreaWidgetClass, elternWidget, XmNwidth, 500, XmNheight, 500, NULL) ; /* Fuer die Graphik-Ausgabe wird ein Graphik-Kontext (GC) erzeugt und mit den Vorder- und Hintergrundfarben der Drawing-Area-Widget besetzt. */ XtVaGetValues (DrawAr, XmNforeground, &(werte.foreground), XmNbackground, &(werte.background), NULL) ; fensterGC = XCreateGC (display, XtWindow (DrawAr), GCForeground | GCBackground, &werte) ; /* Callbacks registrieren. Der Resize-Callback darf erst nach XtRealizeWidget registriert werden */ XtAddCallback (DrawAr, XmNexposeCallback, exposeCB, (XtPointer)NULL); XtAddCallback (DrawAr, XmNresizeCallback, resizeCB, (XtPointer)NULL); } main (int argc, char ** argv) { Widget applShell; applShell = XtAppInitialize (&kontext, "Drawkarte", (XrmOptionDescRec*)NULL, 0, &argc, argv, fallbackRessourcen, (Arg*)NULL, 0); display = XtDisplay (applShell); XtRealizeWidget (applShell); initGraphikWidget (applShell) ; XtAppMainLoop (kontext); }