Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

g++ ncurses help

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
fpga



Joined: Fri Aug 18, 2006 12:19 pm
Posts: 5

PostPosted: Tue Sep 12, 2006 9:19 am    Post subject: g++ ncurses help Reply with quote

Code:

#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;
}


Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast