René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

Scroll Bar example [Ming wrapper example]

This example demonstrates Scroll bars.
This flash movie was created with the following program.
ScrollBarExample.cpp
#include "ScrollBar.h"

#include <cmath>
#include <sstream>

void addScrollbar(Movie& movie, double degrees, int width, int length, double start_value, double end_value) {
  static int counter = 0;

  std::stringstream name_txt_var_stream;
  name_txt_var_stream << "txt" << counter++;
  std::string name_txt_var = name_txt_var_stream.str();

  ScrollBar scrollbar(width, length, start_value, end_value);

  scrollbar.ScrollFunction(std::string("_root." + name_txt_var + "=value;"));

  DisplayClip iScrollBar = movie.Add(scrollbar);

  double c=std::sin(degrees/360.0*3.1415*2);
  double s=std::cos(degrees/360.0*3.1415*2);

  const int ir=30;

  iScrollBar.MoveTo(
      250 + c * ir - double(width)/2*s,
      250 + s * ir + double(width)/2*c);

  iScrollBar.Rotate(degrees);

  TextField textField(Font("Verdana.fdb"), 24, 0, 0, "-----", 40, 200, 100) ;
  textField.Variable(name_txt_var);
  DisplayItem iTF = movie.Add(textField);

  iTF.MoveTo(
      250 + c * (ir + length + 30 ) - double(width)/2*s,
      250 + s * (ir + length + 30 ) + double(width)/2*c);
}

int main() {
  Movie movie ("ScrollBarExample.swf", 500, 500);

  double degrees= -45;
  addScrollbar(movie,degrees+=45, 16, 100,     0,     1);
  addScrollbar(movie,degrees+=45, 10, 150,   -10,    10);
  addScrollbar(movie,degrees+=45, 36, 140,     2,   999);
  addScrollbar(movie,degrees+=45,  6,  40,  -100,   110);
  addScrollbar(movie,degrees+=45, 40, 160,    -1,     1);
  addScrollbar(movie,degrees+=45, 20, 100,     0,    10);
  addScrollbar(movie,degrees+=45, 19, 120,     0,    10);
  addScrollbar(movie,degrees+=45, 37, 130,     0,    10);

  movie.NextFrame();

  return 0;
}
This is one of a series of examples that demonstrates the C++ ming wrapper classes. Other examples can be found here.