summaryrefslogtreecommitdiff
path: root/ycurses/src/examples
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2010-11-21 17:01:59 +0000
committerPaul Buetow <paul@buetow.org>2010-11-21 17:01:59 +0000
commitb891420946d5269cc326d67555c6aab3db41a01a (patch)
treef6c5e7d6dbf18ec8c0ea9ec0b037251df46b4cbb /ycurses/src/examples
parenta537e8323d932125232c305f9573daef89aef0df (diff)
added yhttpd and ycurses trunk versions
Diffstat (limited to 'ycurses/src/examples')
-rw-r--r--ycurses/src/examples/example1.cpp80
-rw-r--r--ycurses/src/examples/example1.h8
-rw-r--r--ycurses/src/examples/example2.cpp52
-rw-r--r--ycurses/src/examples/example2.h8
-rw-r--r--ycurses/src/examples/example3.cpp45
-rw-r--r--ycurses/src/examples/example3.h8
-rw-r--r--ycurses/src/examples/example4.cpp22
-rw-r--r--ycurses/src/examples/example4.h8
8 files changed, 231 insertions, 0 deletions
diff --git a/ycurses/src/examples/example1.cpp b/ycurses/src/examples/example1.cpp
new file mode 100644
index 0000000..239e476
--- /dev/null
+++ b/ycurses/src/examples/example1.cpp
@@ -0,0 +1,80 @@
+#include "example1.h"
+
+int example1()
+{
+ /* Initialize the ycurses object at first! You MUST also delete this as the last! */
+ curses cur;
+
+ /* Make the cursor invisible.
+ * All available options are:
+ * Invisible
+ * Visible
+ * VeryVisible
+ */
+ cursor::set_invisible();
+
+ /* Get the root-window */
+ window win_root(root);
+
+ /*
+ * There are standard colors defined which can be mixed together to
+ * get foreground/background color pairs:
+ * Red, Green, Yellow, Blue, Cyan, Magenta and White
+ */
+ color col1(Cyan, Blue); // 1. With implicit Name.
+ // color col1("col1", Cyan, Blue); // 2. With explicit Name.
+
+ /* Now we define attributes, and pass them the color */
+ attributes attr1(col1);
+ win_root.set_attributes(attr1);
+
+ /* Print out some text on the cursor location, with line break */
+ win_root.println(0, 0, "Hello, welcome to ncurses in cyan-blue");
+
+ win_root.unset_attributes(attr1);
+
+ /* Create a new centeralized window with the specified height and width */
+ window win1(20, 78);
+
+ color col2(Yellow, Black);
+ attributes attr2(col2);
+ attr1.set_bold(true);
+
+ win1.set_attributes(attr2);
+ win1.print(2, 2, "Print into window at pos 2-2 w/out newline in yellow-black-bold!");
+
+ /* Create yet another window */
+ window win2(10, 20);
+
+ /* Print out the y and the x component of the absolute coordinates of win1 */
+ coordinate coord_win(Absolutecoord,win1);
+ coordinate coord_text(10,11);
+
+ /* Other available coordinates
+ *
+ * coordinate(Absolutecoord,win1); // Gets window's absolute position.
+ * coordinate(Relativecoord,win1); // Gets window's relative position.
+ * coordinate(Beginningcoord,win1); // Gets window's beginning coords.
+ * coordinate(windowSize,win1); // Gets window's size.
+ * coordinate(TerminalSize); // Gets the total terminal size.
+ * coordinate(TerminalCenter); // Gets the center of the terminal
+ */
+
+ attributes attr_bold(Bold);
+ // Hint: you can use Normal instead of Bold to set all attributes to default.
+
+ win_root.print(coord_text, "Demonstration output", attr_bold);
+ win_root.print(coord_text.down(), "coordinate y:");
+ win_root.print(coord_text.displace(1,1), coord_win.y, attr_bold);
+ win_root.print(coord_text.displace(1,-1), "coordinate x:");
+ win_root.print(coord_text.displace(1,1), coord_win.x, attr_bold);
+
+ /* Wait for user key stroke */
+ cur.pause();
+
+ /* Deletes all curses elements from memory, also all pointers
+ Because the ycurses Objekt will get out of scope now.
+ */
+ return 0;
+}
+
diff --git a/ycurses/src/examples/example1.h b/ycurses/src/examples/example1.h
new file mode 100644
index 0000000..dc5e753
--- /dev/null
+++ b/ycurses/src/examples/example1.h
@@ -0,0 +1,8 @@
+#ifndef EXAMPLE1_H
+#define EXAMPLE1_H
+
+#include "../curses/ycurses.h"
+
+int example1();
+
+#endif
diff --git a/ycurses/src/examples/example2.cpp b/ycurses/src/examples/example2.cpp
new file mode 100644
index 0000000..c93d79c
--- /dev/null
+++ b/ycurses/src/examples/example2.cpp
@@ -0,0 +1,52 @@
+#include "example2.h"
+
+int example2()
+{
+ curses cur;
+ cursor::set_invisible();
+
+ window win_root(root);
+ win_root.print(1, 1, "Press any key to continue...");
+
+ coordinate coord(2, 0);;
+
+ window win1(10, 40, coord);
+ window win2(10, 40, coord.displace(3, 6));
+ window win3(10, 40, coord.displace(3, 6));
+
+ win1.print(1, 1, "window 1");
+ win2.print(1, 1, "window 2");
+ win3.print(1, 1, "window 3");
+
+ /* Initialize pwindows. */
+ pwindow pwindow1(win1);
+ pwindow pwindow2(win2);
+ pwindow pwindow3(win3);
+
+
+ /* Remove pwindow3, pwindow3 doesnt contain a valid pwindow any more!
+ * DONT USE THIS OBJECT AGAIN until re-init!!!
+ */
+ pwindow3.remove();
+
+ /* Re-init a new pwindow, using the old variable. Now the object
+ * can be used again.
+ */
+ pwindow3.reinit(win3);
+ cur.pause();
+
+ /* Remove the center pwindow. */
+ pwindow2.remove();
+ win3.print(2, 1, "pwindow 2 removed!");
+ cur.pause();
+
+ win1.print(2, 1, "Some text!");
+ cur.pause();
+
+ pwindow3.remove();
+ win1.print(3, 1, "pwindow 3 removed!");
+ cur.pause();
+
+ return 0;
+}
+
diff --git a/ycurses/src/examples/example2.h b/ycurses/src/examples/example2.h
new file mode 100644
index 0000000..fbdc6c7
--- /dev/null
+++ b/ycurses/src/examples/example2.h
@@ -0,0 +1,8 @@
+#ifndef EXAMPLE2_H
+#define EXAMPLE2_H
+
+#include "../curses/ycurses.h"
+
+int example2();
+
+#endif
diff --git a/ycurses/src/examples/example3.cpp b/ycurses/src/examples/example3.cpp
new file mode 100644
index 0000000..5fee1f8
--- /dev/null
+++ b/ycurses/src/examples/example3.cpp
@@ -0,0 +1,45 @@
+#include "example3.h"
+
+int example3()
+{
+ curses cur;
+ cursor::set_invisible();
+
+ window win_root(root);
+ win_root.print(1, 1, "Press any key to continue...");
+
+ coordinate coord(2, 0);;
+ window win1(10, 30, coord);
+ window win2(10, 30, coord.displace(3, 6));
+
+ win1.print(1, 1, "pwindow 1");
+ win2.print(1, 1, "pwindow 2");
+
+ pwindow pwindow1(win1);
+ pwindow pwindow2(win2);
+
+ cur.pause();
+
+ pwindow1.hide();
+ win2.print(2, 1, "pwindow 1 hidden");
+ cur.pause();
+
+ pwindow1.show();
+ pwindow1.on_bottom();
+ win2.print(3, 1, "pwindow 1 back");
+ cur.pause();
+
+ win1.print(2, 1, "Some pwindow 1 text");
+ cur.pause();
+
+ pwindow1.on_top();
+ win1.print(3, 1, "pwindow 2 is on bottom");
+ cur.pause();
+
+ win1.print(4, 1, "Moved pwindow 2 to 10-10");
+ pwindow2.move(10,10);
+ cur.pause();
+
+ return 0;
+}
+
diff --git a/ycurses/src/examples/example3.h b/ycurses/src/examples/example3.h
new file mode 100644
index 0000000..80f1575
--- /dev/null
+++ b/ycurses/src/examples/example3.h
@@ -0,0 +1,8 @@
+#ifndef EXAMPLE3_H
+#define EXAMPLE3_H
+
+#include "../curses/ycurses.h"
+
+int example3();
+
+#endif
diff --git a/ycurses/src/examples/example4.cpp b/ycurses/src/examples/example4.cpp
new file mode 100644
index 0000000..7e0e317
--- /dev/null
+++ b/ycurses/src/examples/example4.cpp
@@ -0,0 +1,22 @@
+#include "example4.h"
+
+int example4()
+{
+ curses cur;
+ cursor::set_invisible();
+
+ window win_root(root);
+ win_root.print(1, 1, "Class menu example...");
+
+ vector<string> vec_choices;
+ vec_choices.push_back("Hallo das ist asd asdas d asd asda sd asd asd a");
+ vec_choices.push_back("Bdsfsdsa das d asd asd asd as das djf");
+ vec_choices.push_back("s das d asd saa sdCsdfsdf");
+ menu menu1(vec_choices);
+
+ menu1.run();
+
+ return 0;
+}
+
+
diff --git a/ycurses/src/examples/example4.h b/ycurses/src/examples/example4.h
new file mode 100644
index 0000000..1bf0cbb
--- /dev/null
+++ b/ycurses/src/examples/example4.h
@@ -0,0 +1,8 @@
+#ifndef EXAMPLE4_H
+#define EXAMPLE4_H
+
+#include "../curses/ycurses.h"
+
+int example4();
+
+#endif