Skip to main content

Thread: Drawing to a Window in C++


stackoverflow post relating question can found here.

trying alter conway's game of life program wrote object oriented programming class taking. stands, program outputs successive lines of text terminal. instead, have window dynamically displays state of cells. feel i'm on right path, reason line breaks i've coded life's "tostring" method not appear when print life object x11 window. feel problem related way i'm using x11 window, since i'm total n00b @ that. can spot what's going wrong?

code:
#include <stdio.h>  #include <stdlib.h>  #include <string.h>  #include <x11/xlib.h>  #include <sstream>    #include "cell.h"  #include "life.h"    int main (int argc, char *argv[])  {      display                 *display;      visual                  *visual;      int                     depth;      int                     text_x;      int                     text_y;      xsetwindowattributes    frame_attributes;      window                  frame_window;      xfontstruct             *fontinfo;      xgcvalues               gr_values;      gc                      graphical_context;      xevent                  event;      char                    hello_string[] = "hello world";      int                     hello_string_length = strlen(hello_string);        display = xopendisplay(null);      visual = defaultvisual(display, 0);      depth  = defaultdepth(display, 0);            frame_attributes.background_pixel = xwhitepixel(display, 0);      /* create application window */      frame_window = xcreatewindow(display, xrootwindow(display, 0),                                   0, 0, 400, 400, 5, depth,                                   inputoutput, visual, cwbackpixel,                                   &frame_attributes);      xstorename(display, frame_window, "the game of life");      xselectinput(display, frame_window, exposuremask | structurenotifymask);        fontinfo = xloadqueryfont(display, "10x20");      gr_values.font = fontinfo->fid;      gr_values.foreground = xblackpixel(display, 0);      graphical_context = xcreategc(display, frame_window,                                     gcfont+gcforeground, &gr_values);      xmapwindow(display, frame_window);        life <conwaycell> alife (21, 21);        alife.animate (10, 5, '*');      alife.animate (10, 6, '*');      alife.animate (10, 7, '*');      alife.animate (10, 8, '*');      alife.animate (10, 9, '*');      alife.animate (10, 10, '*');      alife.animate (10, 11, '*');      alife.animate (10, 12, '*');      alife.animate (10, 13, '*');      alife.animate (10, 14, '*');        std::ostringstream outstream;      outstream << alife;      string astring = outstream.str ();      const char* achar = astring.c_str ();      int len = outstream.str ().size ();        while ( 1 ) {          xnextevent(display, (xevent *)&event);          switch ( event.type ) {              case expose:              {                  xwindowattributes window_attributes;                  int font_direction, font_ascent, font_descent;                  xcharstruct text_structure;                  xtextextents(fontinfo, achar, len,                                &font_direction, &font_ascent, &font_descent,                                &text_structure);                  xgetwindowattributes(display, frame_window, &window_attributes);                  text_x = (window_attributes.width - text_structure.width)/2;                  text_y = (window_attributes.height -                             (text_structure.ascent+text_structure.descent))/2;                    outstream << alife;                    xdrawstring(display, frame_window, graphical_context,                              text_x, text_y, achar, len);                  break;              }              default:                  break;          }      }      return(0);  }



Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Ubuntu Application Development Drawing to a Window in C++


Ubuntu

Comments

Popular posts from this blog

Some mp4 files not displaying correctly (CS6)

Thread: Samba is not authenticating with LDAP