DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2304
Version: 1.3-current


When a scrolled panel is over 32767 pixels high (1310 items in example
code), you get large areas which are greyed out.  This appears to be due
to a 16 bit signed short limit somewhere in the code.

Fails under Linux, works under Windows.


Link: http://www.fltk.org/str.php?L2304
Version: 1.3-current
#include <iostream>

#include <FL/Fl.h>
#include <FL/Fl_Double_Window.h>
#include <FL/Fl_Button.h>
#include <FL/Fl_Return_Button.h>

#include <string>
#include <vector>

#include <FL/Fl_Box.h>
#include <FL/Fl_Double_Window.h>
#include <FL/Fl_Scroll.h>

using namespace std;

string dItoa(int value)
{
        string buf;
        for(; value; value/=10)
      buf= "0123456789"[value % 10] + buf;
   return buf;
}

// -----

class GameTable : public Fl_Scroll
{
   public:
      GameTable(int);
      ~GameTable();

   protected:
      void cursor(int);
      int handle(int ev);

   private:
      vector<Fl_Box *> games;
      vector<string> titles;
      Fl_Group cells;
      int cursor_;
};

// -----

class GameSelect : public Fl_Double_Window
{
   public:
      GameSelect(int);
      virtual ~GameSelect();

      void show_modal();

   private:
      GameTable gtable;
      Fl_Button cancel;
      Fl_Return_Button select;
      static void select_cb(Fl_Widget*, void *);
      static GameSelect *here;
};

// -----

GameTable::GameTable(int size)
:  Fl_Scroll(25, 15, 177, 250),
   cells(25, 15, 160, size * 25)
{
   type(VERTICAL);
   box(FL_BORDER_BOX);

   begin();
   cells.begin();
   cells.color(FL_WHITE);
   cells.box(FL_BORDER_BOX);
   int yy= 15;
   for ( int gamecount=0; gamecount<size; ++gamecount )
   {
      titles.push_back( "game " + dItoa(gamecount) );
      games.push_back( new Fl_Box(25,yy,160,25,titles.back().c_str() ) );
      games.back()->box(FL_BORDER_BOX);
      games.back()->color(FL_WHITE);
      yy+= 25;
   }
   cells.end();
   end();
   cursor_= 0;
   cursor(0);
}

GameTable::~GameTable()
{}

void GameTable::cursor(int newpos)
{
cout << newpos << ": " << games[newpos]->label() << endl;
   games[cursor_]->color(FL_WHITE);
   games[cursor_]->redraw();

   cursor_= newpos;
   games[cursor_]->color(FL_CYAN);
   games[cursor_]->redraw();

   if ( (cursor_ + 1) * 25 - 250 > yposition() )  // cursor after last line
      scroll_to(0, (cursor_ + 1) * 25 - 250);

   if ( (cursor_) * 25 < yposition() )            // cursor before first line
      scroll_to(0, (cursor_) * 25);
}

int GameTable::handle(int ev)
{
   switch ( ev )
   {
      case FL_PUSH:
         if
         (  Fl::event_button() == FL_LEFT_MOUSE
            && Fl::event_inside(25, 15, 160, 250)
         )
         {
            cursor( (Fl::event_y()+yposition()-10 )/25);
            return 1;
         }
      case FL_KEYDOWN:  case FL_SHORTCUT:
         if ( Fl::event_key(FL_Up) )
         {
            if ( cursor_ != 0 )
               cursor(cursor_ - 1 );
            else
               cursor(games.size() - 1);
         }
         else if ( Fl::event_key(FL_Down) )
         {
            if ( cursor_ != (int)games.size() - 1 )
               cursor(cursor_ + 1 );
            else
               cursor(0);
         }
   }
   if
   ( Fl::event_inside(25, 15, 177, 250) )
      return Fl_Scroll::handle(ev);
   else
      return 0;
}

// -----

GameSelect *GameSelect::here;

GameSelect::GameSelect(int size)
:  Fl_Double_Window(227,315,"Select Game"),
   gtable(size),
   cancel(120, 285, 100, 35, "Cancel"),
   select(10, 285, 100, 35, "Select")
{
   here= this;
   cancel.callback(select_cb,0);
   select.callback(select_cb,0);
}

GameSelect::~GameSelect()
{}

void GameSelect::select_cb(Fl_Widget*, void *)
{
   here->hide();
}

void GameSelect::show_modal()
{
   set_modal();
   show();
   do { Fl::wait(1.0); }
   while ( shown() );
};

///////////////////

int main()
{
   GameSelect s(1350);
   s.show_modal();
}
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to