00001
00002 #include <basis/chaos.h>
00003 #include <opsystem/application_shell.h>
00004 #include <loggers/console_logger.h>
00005 #include <data_struct/static_memory_gremlin.h>
00006 #include <wp_active/button.h>
00007 #include <wp_active/quit_button.h>
00008 #include <wp_passive/manager.h>
00009 #include <wp_passive/wp_implementation.h>
00010
00011 class my_button : public button
00012 {
00013 public:
00014 my_button(manager &root, const c_point &origin, char *message,
00015 color &foreground, color &background,
00016 my_button *button_list[], int numbuts)
00017 : button(root, origin, message, foreground, background),
00018 buttons(button_list), numbuttons(numbuts) {}
00019 ~my_button() {}
00020 virtual void button_event() {
00021 FUNCDEF("button_event");
00022 LOG("my button event");
00023 chaos ran;
00024 for (int i = 0; i < numbuttons; i++) {
00025 buttons[i]->set_origin(c_point(ran.inclusive(0, 1000),
00026 ran.inclusive(0, 1000)));
00027 }
00028 }
00029 my_button **buttons;
00030 int numbuttons;
00031 };
00032
00034
00035 class test_tender_buttons : public application_shell
00036 {
00037 public:
00038 test_tender_buttons() : application_shell(class_name()) {}
00039 IMPLEMENT_CLASS_NAME("test_buttons");
00040 virtual int execute();
00041 };
00042
00044
00045 int test_tender_buttons::execute()
00046 {
00047 FUNCDEF("execute");
00048 manager root("fred");
00049 color purple(root.lookup("purple"));
00050 root.foreground(purple);
00051 color red(root.lookup("red"));
00052 color green(root.lookup("green"));
00053 quit_button to_die(root, c_point(0, 0), green, red);
00054 to_die.draw();
00055
00056 istring my_message("Enter arguments on the command line to see them on "
00057 "the button.");
00058 if (__argc - 1 > 0) {
00059
00060 my_message = "";
00061 for (int i = 1; i < __argc; i++)
00062 my_message += istring(" ") + istring(__argv[i]);
00063 }
00064 color blue(root.lookup("blue"));
00065 color wheat(root.lookup("wheat"));
00066 chaos ran;
00067 my_button *button_list[100];
00068 int numbuts = ran.inclusive(30, 90);
00069 {
00070 for (int i = 0; i < numbuts; i++) {
00071 my_button *to_show = new my_button(root,
00072 c_point(ran.inclusive(0, 1000), ran.inclusive(0, 1000)),
00073 my_message.s(), wheat, blue, button_list, numbuts);
00074 button_list[i] = to_show;
00075 to_show->draw();
00076 }
00077 }
00078 root.poll();
00079 for (int i = 0; i < numbuts; i++) delete button_list[i];
00081 LOG("main program exiting");
00082 return 0;
00083 }
00084
00086
00087 HOOPLE_MAIN(test_tender_buttons, )
00088