steve@cad0.arch.unsw.oz.au (Stephen Peter) (04/04/91)
G'Day all, I'm having some problems trying to write an Xview based program that creates and then alters a dynamic colour-map-segment. If the colour map has two entries (0=back, 1=fore) everytime is fine, BUT if I try to have more colours it doesnot seem to work. Included below is a small program that demonstrates the problem. If anyone has any comments or suggestions, I would really appreciate hearing them (post or mail)! Thanks, Stephen. --------------included program starts here ------------------ /* * XView based program: * testing creation of a dynamic colour-map-segment. * * The program should change the RGB of the displayed line pattern * every time a Canvas Event occurs (mouse button presses). * * The program works fine if COLOUR_NUM (defined below) is 2, * but does NOT work if COLOUR_NUM is greater than 2. * * If anybody can shed some light on this, I would appreciate it! * * My compile line is as follows ("col.c" is the source filename): * cc -I/usr/openwin/include col.c -L/usr/openwin/lib -lxview -lX * *------------------------------------------------------------ * Stephen Peter, internet: steve@cad0.arch.unsw.oz.au * April 1991. *------------------------------------------------------------ */ #include <stdio.h> #include <X11/Xlib.h> #include <X11/X.h> #include <X11/Xutil.h> #include <xview/xview.h> #include <xview/notify.h> #include <xview/canvas.h> #include <xview/cms.h> #include <xview/xv_xrect.h> #define COLOUR_NUM 2 /* <------- if this number is changed (eg: to 4) then nothing is drawn */ Frame frame; Canvas canvas; Cms cms; void canvas_repaint_proc(); void set_colour(); void event_proc (); static Xv_singlecolor colour_map_seg[COLOUR_NUM]; unsigned char red, green, blue; /**************************************************************************/ main(argc, argv) int argc; char *argv[]; { extern void exit(); int a; xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL); /*----- initialise the colours (to white) */ for (a = 0; a < COLOUR_NUM; a++) { colour_map_seg[a].red = 255; colour_map_seg[a].green = 255; colour_map_seg[a].blue = 255; } cms = (Cms)xv_create(NULL, CMS, CMS_TYPE, XV_DYNAMIC_CMS, CMS_SIZE, 2, CMS_COLORS, colour_map_seg, NULL); frame = (Frame)xv_create(XV_NULL, FRAME, FRAME_LABEL, argv[0], FRAME_SHOW_FOOTER, TRUE, NULL); canvas = (Canvas)xv_create(frame, CANVAS, CANVAS_REPAINT_PROC, canvas_repaint_proc, /*XV_WIDTH, 250, XV_HEIGHT, 260,*/ WIN_CMS, cms, CANVAS_X_PAINT_WINDOW, TRUE, CANVAS_RETAINED, FALSE, NULL); xv_set (canvas_paint_window(canvas), WIN_EVENT_PROC, set_colour, NULL); red = 120; green = 120; blue = 120; xv_main_loop(frame); } /**************************************************************************/ /* this routine gets called after the app-window is resized/covered etc, the size of the window is requested and then the line pattern is drawn.*/ /**************************************************************************/ void canvas_repaint_proc(canvas, paint_window, dpy, xwin, xrects) Canvas canvas; /* unused */ Xv_Window paint_window; Display *dpy; Window xwin; Xv_xrectlist *xrects; /* unused */ { GC gc; int width, height, x,y, space; set_colour(); gc = DefaultGC(dpy, DefaultScreen(dpy)); XSetForeground (dpy, gc, xv_get(cms, CMS_FOREGROUND_PIXEL)); width = (int)xv_get(paint_window, XV_WIDTH); height = (int)xv_get(paint_window, XV_HEIGHT); space = 3; for (x = 0; x <= (width/space); x++) { XDrawLine(dpy, xwin, gc, x*space,0, width-(x*space),height); } for (y = 0; y <= (height/space); y++) { XDrawLine(dpy, xwin, gc, width,y*space, 0,height-(y*space)); } } /**************************************************************************/ /* event-proc (I'm not using the arguements) */ void set_colour () { int i; red = (red + 10) % 255; blue = (blue + 20) % 255; green = (green + 30) % 255; colour_map_seg[COLOUR_NUM-1].red = red; colour_map_seg[COLOUR_NUM-1].green = green; colour_map_seg[COLOUR_NUM-1].blue = blue; (void) xv_set (cms, CMS, CMS_SIZE, COLOUR_NUM, CMS_INDEX, 0, CMS_COLORS, colour_map_seg, NULL); } -------------- end included program ------------------ -- _--_|\ steve@cad0.arch.unsw.oz.au / \ Stephen Peter or steve@keystone.arch.unsw.oz.au \_.--._/<------------------------------------------------------------------- v School of Architecture, University of New South Wales, Australia
pamela@tandem.Camex.COM (Pamela Wybieracki) (04/06/91)
In article <1330@usage.csd.unsw.oz.au> steve@cad0.arch.unsw.oz.au (Stephen Peter) writes: > >G'Day all, > >I'm having some problems trying to write an Xview based program >that creates and then alters a dynamic colour-map-segment. If the >colour map has two entries (0=back, 1=fore) everytime is fine, BUT >if I try to have more colours it doesnot seem to work. The CMS_SIZE is a create and get-only attribute. See Chapter 20.2 of xview manual. Set it to the max you expect when creating the colormap. Pamela Blalock Wybieracki pamela@camex.com Camex, Inc. 75 Kneeland St., Boston, MA 02111 Tel: (617) 426-3577