|
From: <sch...@us...> - 2008-11-27 20:08:26
|
Revision: 56
http://deraciel.svn.sourceforge.net/deraciel/?rev=56&view=rev
Author: schnippi001
Date: 2008-11-27 20:08:16 +0000 (Thu, 27 Nov 2008)
Log Message:
-----------
First C++ version checkin
Modified Paths:
--------------
trunk/main.c
trunk/map_window.c
trunk/map_window.h
trunk/text_window.c
trunk/text_window.h
Added Paths:
-----------
trunk/cpp/
trunk/cpp/CMakeLists.txt
trunk/cpp/KeyboardReader.cpp
trunk/cpp/KeyboardReader.h
trunk/cpp/MapWindow.cpp
trunk/cpp/MapWindow.h
trunk/cpp/StatusWindow.cpp
trunk/cpp/StatusWindow.h
trunk/cpp/TextWindow.cpp
trunk/cpp/TextWindow.h
trunk/cpp/_cmake-distclean.bash
trunk/cpp/main.cpp
Copied: trunk/cpp/CMakeLists.txt (from rev 54, trunk/CMakeLists.txt)
===================================================================
--- trunk/cpp/CMakeLists.txt (rev 0)
+++ trunk/cpp/CMakeLists.txt 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,27 @@
+cmake_minimum_required(VERSION 2.6)
+
+project(deraciel)
+SET(CMAKE_CXX_FLAGS "-Wall -Werror")
+
+# requirements
+find_library( NCURSES_LIBRARY ncurses )
+if( NCURSES_LIBRARY )
+ message( STATUS "ncurses library found: ${NCURSES_LIBRARY}" )
+else( NCURSES_LIBRARY )
+ message( FATAL_ERROR "ncurses library not found". )
+endif( NCURSES_LIBRARY )
+
+include_directories(
+ ${NCURSES_INCLUDE_DIRS}
+)
+link_directories(
+ ${NCURSES_LIBRARY_DIRS}
+)
+
+# build
+file(GLOB DERACIEL_SOURCES *.cpp)
+add_executable(deraciel ${DERACIEL_SOURCES})
+target_link_libraries(deraciel
+ ${NCURSES_LIBRARY}
+ pthread
+)
Property changes on: trunk/cpp/CMakeLists.txt
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Added: trunk/cpp/KeyboardReader.cpp
===================================================================
--- trunk/cpp/KeyboardReader.cpp (rev 0)
+++ trunk/cpp/KeyboardReader.cpp 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,48 @@
+#include "KeyboardReader.h"
+
+#include <iostream>
+#include <ncurses.h>
+
+
+using namespace std;
+
+
+
+bool KeyboardReader::keyboardReaderActive = true;
+
+
+void KeyboardReader::setKeyboardHandler(void (*handler)(const int key)) {
+ /* If the specified keyboard handler is not NULL set it as active keyboard handling function */
+ if (handler) {
+ keyboardHandler = handler;
+ } else {
+ cerr << "ERROR: Specified keyboard handler was NULL!" << endl;
+ }
+}
+
+
+
+void KeyboardReader::startLoop() {
+ /* This variable will hold the keycode of pressed key */
+ int key;
+
+ /* Run an infinite loop */
+ while(keyboardReaderActive) {
+ /* Fetch a key from keyboard buffer */
+ key = getch();
+
+ /* If handler callback is specified, delegate the previously
+ fetched key to it, else throw an error message */
+ if (keyboardHandler) {
+ keyboardHandler(key);
+ } else {
+ cerr << "ERROR: Handler callback was NULL!" << endl;
+ }
+ }
+}
+
+
+
+void KeyboardReader::stop() {
+ keyboardReaderActive = false;
+}
Property changes on: trunk/cpp/KeyboardReader.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/cpp/KeyboardReader.h
===================================================================
--- trunk/cpp/KeyboardReader.h (rev 0)
+++ trunk/cpp/KeyboardReader.h 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,11 @@
+
+class KeyboardReader {
+ public:
+ static void setKeyboardHandler(void (*handler)(const int key));
+ static void startLoop();
+ static void stop();
+
+ private:
+ static void (*keyboardHandler)(const int key);
+ static bool keyboardReaderActive;
+};
\ No newline at end of file
Property changes on: trunk/cpp/KeyboardReader.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/cpp/MapWindow.cpp
===================================================================
--- trunk/cpp/MapWindow.cpp (rev 0)
+++ trunk/cpp/MapWindow.cpp 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,49 @@
+#include "MapWindow.h"
+
+#include <iostream>
+#include <string>
+#include <ncurses.h>
+
+using namespace std;
+
+MapWindow::MapWindow() {
+ window = newwin(maxHeight, maxWidth, 2, 0);
+
+ if (!window) {
+ cerr << "Error: Map window creation failed!" << endl;
+ return;
+ }
+
+ wattron(window, COLOR_PAIR(4));
+ wbkgd(window, COLOR_PAIR(4));
+
+ wrefresh(window);
+}
+
+
+
+MapWindow::~MapWindow() {
+ /* Free resources consumed by windows */
+ delwin(window);
+}
+
+
+
+void MapWindow::resize() {
+ /* Reallocate storage for resized text window */
+ wresize(window, maxHeight, maxWidth);
+}
+
+
+
+void MapWindow::displayMap(const chtype *map) {
+ /* Set cursor to first position (upper left) in map window */
+ wmove(window, 0, 0);
+
+ /* Copy map to local map */
+ for (unsigned int s = 0; s < screensize; s++) {
+ waddch(window, map[s]);
+ }
+
+ wnoutrefresh(window);
+}
Property changes on: trunk/cpp/MapWindow.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/cpp/MapWindow.h
===================================================================
--- trunk/cpp/MapWindow.h (rev 0)
+++ trunk/cpp/MapWindow.h 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,17 @@
+#include <string>
+#include <ncurses.h>
+
+class MapWindow {
+ public:
+ MapWindow();
+ ~MapWindow();
+ void draw();
+ void resize();
+ void displayMap(const chtype *map);
+
+ private:
+ WINDOW *window; // Window handle
+ static const unsigned int maxWidth = 80; // Maximum window width
+ static const unsigned int maxHeight = 20; // Maximum window height
+ static const unsigned int screensize = maxWidth * maxHeight;
+};
\ No newline at end of file
Property changes on: trunk/cpp/MapWindow.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/cpp/StatusWindow.cpp
===================================================================
--- trunk/cpp/StatusWindow.cpp (rev 0)
+++ trunk/cpp/StatusWindow.cpp 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,62 @@
+#include "StatusWindow.h"
+
+#include <iostream>
+#include <string>
+#include <ncurses.h>
+
+using namespace std;
+
+StatusWindow::StatusWindow() {
+ window = newwin(maxHeight, maxWidth, 25-maxHeight, 0);
+
+ if (!window) {
+ cerr << "Error: Status window creation failed!" << endl;
+ return;
+ }
+
+ wattron(window, COLOR_PAIR(3));
+ wbkgd(window, COLOR_PAIR(3));
+
+ wrefresh(window);
+}
+
+
+
+StatusWindow::~StatusWindow() {
+ /* Free resources consumed by window */
+ delwin(window);
+}
+
+
+
+void StatusWindow::resize() {
+ /* Reallocate storage for resized text window */
+ wresize(window, maxHeight, maxWidth);
+}
+
+
+
+void StatusWindow::displayStatus() {
+ if (borderIsDrawn) {
+ /* Redraw border */
+ drawBorder();
+ }
+
+ mvwprintw(window, 1, 2, "$:%d HP:%d(%d) MP:%d(%d) St:%2d Dx:%2d Co:%2d Wi:%2d Wp:%2d Ch:%2d",
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+
+ mvwprintw(window, 2, 2, "%s Xp:%2d/%d T:%d S:%d",
+ "Deraciel", 0, 1, 2, 3);
+
+ wnoutrefresh(window);
+}
+
+
+
+/*
+ Private member function declarations
+*/
+
+void StatusWindow::drawBorder() {
+ wborder(window, 0, 0, 0, ' ', '/', '\\', ACS_VLINE, ACS_VLINE);
+}
Property changes on: trunk/cpp/StatusWindow.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/cpp/StatusWindow.h
===================================================================
--- trunk/cpp/StatusWindow.h (rev 0)
+++ trunk/cpp/StatusWindow.h 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,17 @@
+#include <string>
+#include <ncurses.h>
+
+class StatusWindow {
+ public:
+ StatusWindow();
+ ~StatusWindow();
+ void resize();
+ void displayStatus(void);
+
+ private:
+ WINDOW *window; // Window handle
+ static const unsigned int maxWidth = 80; // Maximum window width
+ static const unsigned int maxHeight = 3; // Maximum window height
+ static const bool borderIsDrawn = true; // Draw window borders by default
+ void drawBorder();
+};
\ No newline at end of file
Property changes on: trunk/cpp/StatusWindow.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/cpp/TextWindow.cpp
===================================================================
--- trunk/cpp/TextWindow.cpp (rev 0)
+++ trunk/cpp/TextWindow.cpp 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,68 @@
+#include "TextWindow.h"
+
+#include <iostream>
+#include <string>
+#include <ncurses.h>
+
+using namespace std;
+
+TextWindow::TextWindow() {
+ borderWindow = newwin(maxHeight, maxWidth, 0, 0);
+ textWindow = newwin(maxHeight-1, maxWidth-2, 0, 1);
+
+ if (!borderWindow || !textWindow) {
+ cerr << "Error: Text window creation failed!" << endl;
+ return;
+ }
+
+ wattron(borderWindow, COLOR_PAIR(1));
+ wbkgd(textWindow, COLOR_PAIR(1));
+
+ if (borderIsDrawn) {
+ /* Redraw border with new dimensions */
+ drawBorder();
+ }
+
+ wrefresh(borderWindow);
+ wrefresh(textWindow);
+}
+
+
+
+TextWindow::~TextWindow() {
+ /* Free resources consumed by windows */
+ delwin(borderWindow);
+ delwin(textWindow);
+}
+
+
+
+void TextWindow::resize() {
+ /* Reallocate storage for resized text window */
+ wresize(borderWindow, maxHeight, maxWidth);
+ wresize(textWindow, maxHeight-1, maxWidth);
+}
+
+
+
+void TextWindow::displayString(const string string) {
+ if (borderIsDrawn) {
+ /* Redraw border*/
+ drawBorder();
+ }
+
+ wmove(textWindow, 0, 0);
+ wprintw(textWindow, string.c_str());
+
+ wnoutrefresh(borderWindow);
+ wnoutrefresh(textWindow);
+}
+
+
+/*
+ Private member function declarations
+*/
+
+void TextWindow::drawBorder() {
+ wborder(borderWindow, 0, 0, ' ', 0, ACS_VLINE, ACS_VLINE, '\\', '/');
+}
\ No newline at end of file
Property changes on: trunk/cpp/TextWindow.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/cpp/TextWindow.h
===================================================================
--- trunk/cpp/TextWindow.h (rev 0)
+++ trunk/cpp/TextWindow.h 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,19 @@
+#include <string>
+#include <ncurses.h>
+
+class TextWindow {
+ public:
+ TextWindow();
+ ~TextWindow();
+ void resize();
+ void clear();
+ void displayString(const std::string string);
+
+ private:
+ WINDOW *borderWindow; // Window handle
+ WINDOW *textWindow; // Window handle
+ static const unsigned int maxWidth = 80; // Maximum window width
+ static const unsigned int maxHeight = 2; // Maximum window height
+ static const bool borderIsDrawn = true; // Draw window borders by default
+ void drawBorder();
+};
\ No newline at end of file
Property changes on: trunk/cpp/TextWindow.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Copied: trunk/cpp/_cmake-distclean.bash (from rev 54, trunk/_cmake-distclean.bash)
===================================================================
--- trunk/cpp/_cmake-distclean.bash (rev 0)
+++ trunk/cpp/_cmake-distclean.bash 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,27 @@
+#!/bin/bash
+find . -name "*.cmake" |while read f; do
+ echo "rm ${f}"
+ rm "${f}"
+done
+
+find . -name "CMakeCache.txt" |while read f; do
+ echo "rm ${f}"
+ rm "${f}"
+done
+
+find . -name "Makefile" |while read f; do
+ echo "rm ${f}"
+ rm "${f}"
+done
+
+find . -type d -name CMakeFiles |while read d; do
+ echo "rm -r ${d}"
+ rm -r "${d}"
+done
+
+find . -type d -name CMakeTmp |while read d; do
+ echo "rm -r ${d}"
+ rm -r "${d}"
+done
+
+
Property changes on: trunk/cpp/_cmake-distclean.bash
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ text/plain
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Added: trunk/cpp/main.cpp
===================================================================
--- trunk/cpp/main.cpp (rev 0)
+++ trunk/cpp/main.cpp 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,99 @@
+#include <iostream>
+#include <signal.h>
+#include <ncurses.h>
+
+#include "TextWindow.h"
+#include "MapWindow.h"
+#include "StatusWindow.h"
+#include "KeyboardReader.h"
+
+using namespace std;
+
+#define KEY_ESCAPE 27
+
+static void finish(const int signum);
+static void keyhandler(const int key);
+
+int main(int argc, char **argv) {
+ signal(SIGINT, finish); /* arrange interrupts to terminate */
+ initscr(); /* initialize the curses library */
+ keypad(stdscr, TRUE); /* enable keyboard mapping */
+ nonl(); /* tell curses not to do NL->CR/NL on output */
+ //cbreak(); /* take input chars one at a time, no wait for \n */
+ noecho(); /* don't echo input */
+
+ curs_set(0); /* Hide the cursor */
+
+ start_color();
+ init_pair(1, COLOR_WHITE, COLOR_BLUE);
+ init_pair(2, COLOR_BLACK, COLOR_YELLOW);
+ init_pair(3, COLOR_WHITE, COLOR_RED);
+ init_pair(4, COLOR_WHITE, COLOR_GREEN);
+
+ clear();
+ refresh();
+
+ TextWindow textWindow;
+ MapWindow mapWindow;
+ StatusWindow statusWindow;
+
+ statusWindow.displayStatus();
+
+ //invt_init(&main_char.inventory);
+
+ /* Assign key handler callback */
+ KeyboardReader::setKeyboardHandler(keyhandler);
+
+ /* Start keyboard handler loop */
+ KeyboardReader::startLoop();
+
+ doupdate();
+ sleep(2);
+
+ finish(0);
+ return 0;
+}
+
+
+
+void finish(const int signum)
+{
+ /* If text window is still existing, destroy it */
+
+ /* End ncurses library */
+ endwin();
+
+ /* Do your non-curses wrapup here */
+
+}
+
+
+
+static void keyhandler(const int key)
+{
+ if (key == KEY_ESCAPE) {
+ // Stop keyboard handler loop
+ KeyboardReader::stop();
+ finish(0);
+ }
+
+ if (key == KEY_RESIZE) {
+ endwin();
+ curs_set(0); /* Hide the cursor */
+
+ clear();
+ refresh();
+ }
+
+ if (key == KEY_DOWN) {
+ cout << "KEY_DOWN" << endl;
+ }
+
+ if (key == KEY_LEFT) {
+ cout << "KEY_LEFT" << endl;
+ }
+
+ if (key == KEY_RIGHT) {
+ cout << "KEY_RIGHT" << endl;
+ }
+}
Property changes on: trunk/cpp/main.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: trunk/main.c
===================================================================
--- trunk/main.c 2008-11-24 05:32:17 UTC (rev 55)
+++ trunk/main.c 2008-11-27 20:08:16 UTC (rev 56)
@@ -113,15 +113,15 @@
if (key == KEY_DOWN) {
counter++;
if (counter == 1) {
- text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
+ text_window_display_string("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
}
if (counter == 2) {
- text_window_out("Ein etwas laengerer Text 2");
+ text_window_display_string("Ein etwas laengerer Text 2");
}
if (counter == 3) {
- text_window_out("Und Text 3");
+ text_window_display_string("Und Text 3");
counter = 0;
}
}
@@ -130,14 +130,14 @@
for (int i = 0; i < 80*20; i++) {
map[i] = 'o';
}
- map_window_update(map);
+ map_window_display_map(map);
}
if (key == KEY_RIGHT) {
for (int i = 0; i < 80*20; i++) {
map[i] = '*';
}
- map_window_update(map);
+ map_window_display_map(map);
}
status_window_update(&main_char);
Modified: trunk/map_window.c
===================================================================
--- trunk/map_window.c 2008-11-24 05:32:17 UTC (rev 55)
+++ trunk/map_window.c 2008-11-27 20:08:16 UTC (rev 56)
@@ -47,7 +47,7 @@
-void map_window_update(const chtype *map)
+void map_window_display_map(const chtype *map)
{
/* Set cursor to first position (upper left) in map window */
wmove(map_wnd, 0, 0);
Modified: trunk/map_window.h
===================================================================
--- trunk/map_window.h 2008-11-24 05:32:17 UTC (rev 55)
+++ trunk/map_window.h 2008-11-27 20:08:16 UTC (rev 56)
@@ -6,6 +6,6 @@
void map_window_create(void);
void map_window_destroy(void);
void map_window_resize(void);
-void map_window_update(const chtype *m);
+void map_window_display_map(const chtype *m);
#endif // !DERACIEL_MAP_WINDOW_H
Modified: trunk/text_window.c
===================================================================
--- trunk/text_window.c 2008-11-24 05:32:17 UTC (rev 55)
+++ trunk/text_window.c 2008-11-27 20:08:16 UTC (rev 56)
@@ -60,7 +60,7 @@
-void text_window_out(const char *string)
+void text_window_display_string(const char *string)
{
#ifdef TEXTWINDOW_BORDER
/* Redraw border with new dimensions */
Modified: trunk/text_window.h
===================================================================
--- trunk/text_window.h 2008-11-24 05:32:17 UTC (rev 55)
+++ trunk/text_window.h 2008-11-27 20:08:16 UTC (rev 56)
@@ -4,7 +4,7 @@
void text_window_create(void);
void text_window_destroy(void);
void text_window_resize(void);
-void text_window_out(const char *string);
+void text_window_display_string(const char *string);
void text_window_clear(void);
#endif // !DERACIEL_TEXT_WINDOW_H
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|