I am trying to figure out which parts of the following code are represented by 
each of the following steps. The code works, but I am confused as to why and 
what makes each of the following steps it work
  I think 'attach' puts it on the screen and 'next' just goes from the present 
button to the next button
  1. define the button: 
  2. get it displayed
  3. define a function for the GUI to call
  4. tell the GUI about that button and about that function
  5. wait for the GUI to call our function
   
   
   
  void show_scores() {
              Simple_window score(Point(200,200), 300, 300, "scores");
              string name = "scores.txt";
              ifstream ist(name.c_str());
              if (!ist) error("cannot open the file", name);
              string username;
              vector<Text> names;
              vector<Text> scores;
              int s;
              for (int i=0; i<4; i++) {
                          ist>>username>>s;
                          Text t_text(Point(100, 50+30*(i+1)), username);
                          names.push_back(t_text);
                          stringstream ss;
                          ss << s;
                          Text s_text(Point(180, 50+30*(i+1)), ss.str());
                          scores.push_back(s_text);
              }
   
              for (int i=0; i<4; i++) {
                          score.attach(names[i]);
                          score.attach(scores[i]);
              }
      Text t_text(Point(100, 50), "Name");
              Text s_text(Point(180, 50), "Score");
              score.attach(t_text);
              score.attach(s_text);
              score.wait_for_button();
  }
   
  struct Lines_window: Window {
  Lines_window(Point xy, int w, int h, const string& title);
  //Open_polyline lines;
  private:
  // add (next_x.next_y) to lines
  Button next_button;
  Button quit_button;
  Button highscore_button;
  In_box next_x;
  //In_box next_y;
  Out_box xy_out;
  // callback for next button
  static void cb_next(Address, Address);
  void next();
  // callback for quit button
  static void cb_quit(Address, Address);
  static void button_next(Address, Address);
  void quit();
  void button();
   
  };
   
  Lines_window::Lines_window(Point xy, int w, int h, const string& title) 
  :Window(xy, w, h, title),
  next_button(Point(x_max()-150, 0), 70, 20, "Enter word", cb_next),
  quit_button(Point(x_max()-70, 0), 70, 20, "Quit", cb_quit),
  next_x(Point(x_max()-310, 0), 70, 20, "word "),
  //next_y(Point(x_max()-210, 0), 50, 20, "next y: "),
  xy_out(Point(100, 0), 100, 20, "score "),
  highscore_button(Point(x_max()-100, 30), 100, 20, "High scores", button_next)
  {
  attach(next_button);
  attach(quit_button);
  attach(highscore_button);
  attach(next_x);
  //attach(next_y);
  attach(xy_out);
  //attach(lines);
  }
   
   
  void Lines_window::cb_quit(Address, Address pw) // the usual
  {
  reference_to<Lines_window>(pw).quit();
  }
  void Lines_window::quit()
  {
  hide(); // curious FLTK idiom delete window
  }
  void Lines_window::cb_next(Address, Address pw) // the usual
  {
  reference_to<Lines_window>(pw).next();
  }
   
  void Lines_window::next() {
              string x = next_x.get_string();
  //int y = next_y.get_int();
  //lines.add(Point(x, y));
  // update current position readout:
  //stringstream ss;
  //ss << '(' << x << ',' << y << ')';
  //ss << '(' << x <<')';
  //xy_out.put(ss.str());
  redraw();
  }
   
  void Lines_window::button_next(Address, Address pw) // the usual
  {
  reference_to<Lines_window>(pw).button();
  }
   
  void Lines_window::button()
  {
  // curious FLTK idiom delete window
              show_scores();
  }
   
  int main() 
  try {
  Lines_window win(Point(100, 100), 600, 400, "lines");
  return gui_main();
  }
  catch(exception& e) {
  cerr << "exception: " << e.what() << '\n';
  return 1;
  }
  catch(...) {
  cerr << "Some exceptionn\n: ";
  return 2; 
  }
   

       
---------------------------------
Ahhh...imagining that irresistible "new car" smell?
 Check outnew cars at Yahoo! Autos.

[Non-text portions of this message have been removed]

Reply via email to