g++ ncurses help

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

g++ ncurses help

Postby fpga » Tue Sep 12, 2006 8:19 am

Code: Select all
#include <curses.h>
/*
run this code as is, noting that all 'sets' print out correctly with their right edges aligned at x=15.

Then change PROBLEM's value to 1 and re-run.

Why does changing b2's 'capacity' to 9 cause it to start printing out
at a position other than x=15?

If I make b2's capacity 8 or 10 I don't get a problem.
   
Any help in explaining the right shift and how to stop it would be most
appreciated.
Best regards
*/

#define PROBLEM 0   

//=============================================
class SetupPad {
   public:
      WINDOW * ptr; //ie pPad

      SetupPad();
      ~SetupPad() { delwin(ptr); endwin(); }
      void linesCols();
};

SetupPad::SetupPad()
{
   initscr(); 
   curs_set(0);
};

void SetupPad::linesCols()
{
   ptr = newpad(LINES-1,COLS-1);
}
//=============================================
class Set
{
   public:
   int x,y,cap;
   Set(int nx,int ny, int ncap) : x(nx),y(ny),cap(ncap) {}
   ~Set(){}   
};
//=============================================
void drawQ(Set * pS,WINDOW * pWin)
{
   int x=pS->x;
   int y=pS->y;
   char sym = '.';
   for (int j=0;j<pS->cap;j++)
      mvwaddch(pWin, y, x--, sym);
}

void updtScn(SetupPad * pPad)
{
   prefresh(pPad->ptr,0,0,0,0,LINES-1,COLS-1);
      doupdate();
}

int main()
{
   SetupPad pad;
   pad.linesCols();
   Set b1(15,1,13);
   Set m1(15,2,10);
   Set m2(15,3,10);

#if PROBLEM
   Set b2(15,4,9);
#else
   Set b2(15,4,10);   //works with 8 too!
#endif
                        
   drawQ(&b1,pad.ptr);
   drawQ(&m1,pad.ptr);
   drawQ(&m2,pad.ptr);
   drawQ(&b2,pad.ptr);
   updtScn(&pad);
   for (int i=0;i<1000000000;i++); //delay so you can see it
   return 0;
}


fpga
 
Posts: 5
Joined: Fri Aug 18, 2006 11:19 am

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest