I came across sconsole which is a great little snippet to print console-like text. So I decided it to make a wrapper class for it that makes it actually work like a console (you can set the line wrap width and the maximum number of lines).
Here's an example homebrew with source that uses my class --> Download
*Note: i slightly modified sconsole to make it work with c++ (changed the .c file to .cpp and made the struct extern in the .h)
Using CConsole is pretty simple:
- Put sconsole.h, Vector2f.hpp, and CConsole.hpp in your include folder
- Put sconsole.cpp, Vectro2f.cpp and CConsole.cpp in your source folder
Now you can just include it and use it right away:
- Code: Select all
#include "CConsole.hpp"
...
// (after initializing video)
sconsoleInit(FONT_COLOR_NONE, FONT_COLOR_BLACK, res.width, res.height); // Initialize sConsole
...
// (inside the main loop)
unsigned long max_lines = 20;
unsigned long max_width = 30;
CVector2f position(10.0, 10.0);
CConsole myconsole(position, max_lines, max_width);
myconsole.write("Hello World!");
console.draw(buffer[currentBuffer]);
Check out CConsole.hpp for a list of all the available methods:
- Code: Select all
#ifndef _CCONSOLE_HPP_
#define _CCONSOLE_HPP_
#include "CVector2f.hpp"
#include "sconsole.h"
#include <vector>
#include <string>
using namespace std;
class CConsole {
public:
CConsole(const CVector2f &pos, unsigned long max_rows, unsigned long width);
~CConsole();
void write(const char *text);
void clear();
void draw(s32 *buffer);
void setMaxRows(unsigned long max_rows);
void setWidth(unsigned long width);
void setPosition(const CVector2f &pos);
unsigned long getMaxRows();
unsigned long getWidth();
CVector2f &getPosition();
private:
CVector2f pos;
unsigned long max_rows, width;
vector<string> rows;
};
#endif
