Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members  

cursive source code

The project is hosted on SourceForge.net Logo
Welcome to the cursive source documentation and project homepage, generated with doxygen.

What is cursive?

cursive is an object oriented TUI (Text User Interface) layer on top the ncurses library with enhanced features and a great widget system. But the widgets are called "controls" in cursive and they are much l33ter. It uses only a couple of ncurses functions and implements an own drawing mechanism, so it should be easily portable to other screen handling library.

Who made cursive?

It was me. Daniel Albuschat, a bored trainee fighting against gui, stupid software and stupid users. :) My goal is to provide an easy way to write portable console-based programs, instead of writing os-dependent programs using huge GUI libraries.

What does cursive mean?

The project was initially named oocurses (as it is an object oriented curses wrapper), but a voting in one of my favourite irc channels resulted in cursive... there's nothing special in the name, except that it sounds nice. ;)

Where can I get cursive?

You can find a simple demo-project with the whole cursive sourcecode included here. Just untar the tarball and make the project. Type ./main to run the program... There are some ugly effects when highlighting special characters I used for the borders of the group_box and list_box... I'm working on it. There are still many things to do (e.g. the edit_ctrl and list_box do not scroll, and the handling is far from perfect), so I'm looking for contributor (especially in programming).

How do I use cursive?

Cursive is quite easy to use. You just create the controls and apply a self-created event class to it. First you have to know that every control needs a parent. If you want it to be a top-level control, you need to assign the whole screen as the parent. That's simply made by assigning crs::crsv.getScreen() to it's parent property. Every control is unvisible when it is created, so you need to set the visible property to true, when you want to control to be shown. That should be all to create a simple control... here's some example code:
    include "crs/cursive.h"
    include "crs/group_box.h"
    include "crs/edit_ctrl.h"
    include <string>

    int main() {
      crs::group_box grpbox( "I'm a groupbox", crs::crsv.getScreen(), 1, 1, 20, 20 );
      grpbox.visible = true;
      std::string edit_text;
      crs::edit_ctrl<std::string> edit( &grpbox, 0, 2, 4, 13, &edit_text, 0, crs::style::bubble );
      edit.visible = true;
      crs::crsv.mainloop();
    }
  

How do I add new Controls?

I tried to make it very easy to code own controls, so I hope it won't be a problem to get started. Here is an easy example how to create a Control (the code is the original code taken from crs::group_box):
Header:
    include "base_control.h"

    class group_box: public base_control {
      private:
        std::string caption;
      public:
        group_box( const std::string &caption, base_control *Parent, 
            const unsigned int Left=0, const unsigned int Top=0, const unsigned int Width=3, const unsigned int Height=3 );
        virtual void draw();
    };
  
Implementation:
    group_box::group_box( const std::string &Caption, base_control *Parent, 
        const unsigned int Left, const unsigned int Top, const unsigned int Width, const unsigned int Height ):
    base_control( Parent, 0, Left, Top, Width, Height ), caption( Caption ) { 
    }

    void group_box::draw() {
      base_control::draw();
      buffer.drawHLine( 1, 0, mWidth - 2, sc::HorizontalLine );           // upper border
      buffer.drawHLine( 1, mHeight - 1, mWidth - 2, sc::HorizontalLine ); // lower border
      buffer[ 0 ] = sc::UpperLeftCorner;                                  // upper left corner
      buffer[ mWidth - 1 ] = sc::UpperRightCorner;                        // upper right corner
      buffer[ ( mHeight - 1 ) * mWidth ] = sc::LowerLeftCorner;           // lower left corner
      buffer[ mHeight * mWidth - 1 ] = sc::LowerRightCorner;              // lower right corner
      buffer.drawVLine( 0, 1, mHeight - 2, sc::VerticalLine );            // left border
      buffer.drawVLine( mWidth - 1, 1, mHeight - 2, sc::VerticalLine );   // right border
      buffer.setText( caption, 1, 0 );
    }
  
If you need control over keyboard input (what will be the case most of the time), you need to override the keyPress virtual function. If the control shall be focusable, derive the class from crs::focused_ctrl instead of crs::base_control. Thats all.


Generated on Mon May 19 20:36:03 2003 for cursive by doxygen1.2.18