C - X11 API: Graphics not Working in a While Loop -


i trying draw background dynamically. graphics work great normally...but:

int width, height; gc gc_backcolor; xgcvalues gcv_backcolor;  width = c_values.width; height = c_values.height;  gcv_backcolor.background = c_values.backcolor; gcv_backcolor.foreground = c_values.backcolor; gc_backcolor = xcreategc(display, canvas, gcbackground | gcforeground, &gcv_backcolor);  int x = 0; int y = 0;  while (y < height) {     x = 0;      while (x < width) {         xdrawpoint(display, canvas, gc_backcolor, x, y);         x++;     }     y++; }  x = 0; y = 0; 

...for reason, when run in loop, not work. if explain me why behaving way, grateful.

could calling function on canvas expose event?

  while(1) {       xnextevent(display, &event);        if (event.xany.window == canvas) {           if (event.type == expose) {               canvas_draw(display, canvas, c_values);           }         }    } 

here main code:

#include <stdio.h> #include <stdlib.h> #include <x11/xlib.h> #include "canvas.h" #include "extensions.h"  int main(int argc, char* argv[]) {    display* display;    int screen;    window window;    window canvas;    xevent event;    gc gc_canvas;     //canvas* canvas;     display = xopendisplay(null);     if (display == null) {       fprintf(stderr, "error trying open display\n");       exit(1);    }     screen = defaultscreen(display);    window = xcreatesimplewindow(display, rootwindow(display, screen), 0, 0, 640, 480, 1, blackpixel(display, screen), whitepixel(display, screen));     xselectinput(display, window, exposuremask | keypressmask);    xmapwindow(display, window);     /*   create canvas   */     xgcvalues gcv_canvas;    canvasvalues c_values;     gcv_canvas.foreground = 0xff00ff;    gcv_canvas.background = 0xff00ff;     canvas = xcreatesimplewindow(display, window, 0, 0, 256, 256, 1, blackpixel(display, screen), whitepixel(display, screen));     gc_canvas = xcreategc(display, canvas, gcforeground | gcbackground, &gcv_canvas);     xselectinput(display, canvas, exposuremask | keypressmask);    xmapwindow(display, canvas);     canvas_create_content_field(display, canvas, c_values);     c_values.backcolor = 0x00ff00;     //canvas_draw(display, canvas, c_values); code appears work in expose event     /*   create canvas   */     while(1) {       xnextevent(display, &event);        if (event.xany.window == canvas) {       if (event.type == expose) {           canvas_draw(display, canvas, c_values);       }         }    }     return 0; } 

you have not reset x within outer y loop. try this

while (y < height) {     x = 0;                  // <<--- insert here     while (x < width) {         xdrawpoint(display, canvas, gc_backcolor, x, y);         x++;     }     y++; } 

update

you setting foreground , background same colour

gcv_backcolor.background = c_values.backcolor; gcv_backcolor.foreground = c_values.backcolor; 

and background colour returned being used draw

gc_backcolor = xcreategc(display, canvas, gcbackground | gcforeground, &gcv_backcolor); ... xdrawpoint(display, canvas, gc_backcolor, x, y); 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -