home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Acorn User 2
/
AUCD2.iso
/
program
/
vista.arc
/
!Vista
/
h
/
objects
< prev
next >
Wrap
Text File
|
1996-01-27
|
10KB
|
267 lines
// **************************************************************************
// Copyright 1996 David Allison
//
// VV VV IIIIII SSSSS TTTTTT AA
// VV VV II SS TT AA AA
// VV VV II SSSS TT AA AA
// VV VV II SS TT AAAAAAAA
// VV IIIIII SSSS TT AA AA
//
// MULTI-THREADED C++ WIMP CLASS LIBRARY
// for RISC OS
// **************************************************************************
//
// P U B L I C D O M A I N L I C E N C E
// -------------------------------------------
//
// This library is copyright. You may not sell the library for
// profit, but you may sell products which use it providing
// those products are presented as executable code and are not
// libraries themselves. The library is supplied without any
// warranty and the copyright owner cannot be held responsible for
// damage resulting from failure of any part of this library.
//
// See the User Manual for details of the licence.
//
// *************************************************************************
//
// objects within a window
//
#ifndef __objects_h
#define __objects_h
#include "Vista:defs.h"
#ifndef __menu_h
#include "Vista:menu.h"
#endif
class Window ;
//
// an object is something within a window. It knows how to redraw
// itself.
//
// The priority of an object determines the order in which it
// is redrawn within the set of all objects in a window. The higher
// the priority, the later it is redrawn with respect to other objects.
// A higher priority object can be viewed as being on top of lower
// priority objects (if they overlap). It is advised to set background
// objects at priority 0 and increase the priority for each "layer"
// in the window.
//
class Object
{
public:
Object (Window *w, char *name, int priority = 0, char *menu = 0) ;
virtual ~Object() ;
virtual void redraw (int x0, int y0, int x1, int y1) ; // redraw with background cleared
virtual void update (int x0, int y0, int x1, int y1) ; // update with no change to background
virtual int compare (int x, int y) ;
virtual void move (int x0, int y0, int x1, int y1) ;
virtual void move (int dx, int dy) ;
virtual void drag (int mx, int my, int buttons) ; // start dragging the object
virtual void end_drag (int x0, int y0, int x1, int y1, int id) ;
virtual void click(int mx, int my, int button) ; // object has been clicked
virtual void key (int x, int y, int height, int index, int code) ;
virtual void double_click (int mx, int my, int buttons) ;
virtual void select() ; // select the object
virtual void unselect() ; // unselect the object
virtual int width() { return x1 - x0 ; } // read width
virtual int height() { return y1 - y0 ; } // ready height
virtual void pointer (int entering) ; // pointer entering or leaving
virtual void mode_change() ; // mode change
Menu *display_menu (int x, int y, int button, int icon) ;
virtual void pre_menu(Menu *m, int x, int y, int button, int icon) ;
virtual char *get_menu (int x, int y, int button, int icon) ;
virtual char *help (int mx, int my, int buttons) ; // give help
virtual void menu (MenuItem items[]) ;
int x0 ; // bounding box min x
int y0 ; // bounding box min y
int x1 ; // bounding box max x
int y1 ; // bounding box max y
Window *window ;
Menu *default_menu ;
Object *next, *prev ;
char name[32] ;
int priority ; // priority for drawing
int selected ;
} ;
//
// an icon object (plotted)
//
class IconObject : public Object
{
public:
IconObject (Window *w, char *name, Icon *icon, int priority = 0, char *menu = 0) ;
~IconObject() ;
void redraw (int x0, int y0, int x1, int y1) ;
private:
Icon *icon ;
} ;
//
// a raw sprite object. This draws the sprite directly to the screen (as opposed to the draw based
// one SpriteObject)
//
class RawSpriteObject : public Object
{
public:
RawSpriteObject (Window *w, char *name, char *sprite, void *area, int x, int y, int priority = 0, char *menu = 0) ;
RawSpriteObject (Window *w, char *name, char *sprite, int x, int y, int priority = 0, char *menu = 0) ;
~RawSpriteObject() ;
void redraw (int x0, int y0, int x1, int y1) ;
protected:
char *sprite ;
void *area ;
int scale_factors[4] ;
char *pixel_trans ;
void init() ;
int mode ;
} ;
//
// a text object
//
// control codes
const int TextObject_Colour = 1 ;
class TextObject : public Object
{
struct line
{
char *text ; // actual text
int length ; // length in bytes
} ;
public:
// TextObject (Window *w, char *name, char *text, int length, int x, int y, int priority = 0, char *menu = 0) ;
TextObject (Window *w, char *name, char *text, int x, int y, int priority = 0, char *menu = 0) ;
TextObject (Window *w, char *name, int x, int y, int priority = 0, char *menu = 0) ;
virtual ~TextObject() ;
void redraw (int x0, int y0, int x1, int y1) ;
void insert_line (char *text, int length) ;
void insert_line (char *text) ;
protected:
char *text ; // text stored in object
line *lines ; // array of lines
int num_lines ; // number of lines
int max_lines ; // mac line space available
int max_length ; // max line length in units
} ;
class LineObject : public Object
{
public:
LineObject (Window *w, char *name, int x1, int y1, int x2, int y2, int thickness = 1, int priority = 0) ;
virtual ~LineObject() ;
void redraw (int x0, int y0, int x1, int y1) ;
protected:
int thickness ;
int dx ; // delta to add to x for thickness
int dy ; // delta to subtract from y for thickness
} ;
const int FONT_BLOCKING_FACTOR = 100 ;
const int FONT_LINE_GAP = 4000 ; // millipoints
const int FONT_BORDER = 1000 ; // millipoints
class FontObject : public Object
{
struct line
{
char *start ; // character at start of line
int y ; // millipoint offset of bottom of text relative to y1
int length ; // line length in bytes
int height ; // line height in millipoints
line *next ;
int width ; // width in millipoints
} ;
public:
FontObject (Window *w, char *name, int fhandle, int x0, int y0, int width, int priority = 0, char *menu = 0) ;
virtual ~FontObject() ;
void redraw (int x0, int y0, int x1, int y1) ;
void set_colour (int r, int g, int b, int R, int G, int B, int max = 14) ;
void begin_underline() ;
void end_underline() ;
void set_font (int handle) ;
void add_text (char *text) ;
void set_indent (int os_units) ;
void finish() ;
int width() ;
int compare (int x, int y) ;
char *text ;
int text_length ;
line *lines ;
line *last_line ;
int max_length ;
void check_buffer(int length) ;
int font_handle ;
int end_width ; // width in OS units to the end of the last line
int indent ; // indent of first line in millipoints
} ;
//
// DrawFile SWI definitions. This is from the Acorn PD module DrawFile
//
#define DrawFile_Render 0x45540
#define DrawFile_BBox 0x45541
#define DrawFile_DeclareFonts 0x45541
const int DRAW_BLOCKING_FACTOR = 100 ; // number of bytes extra added after data extension
class DrawObject : public Object
{
public:
DrawObject(Window *w, char *name, char *data, int length, int x, int y, int priority = 0, char *menu = 0) ;
DrawObject(Window *w, char *name, char *filename, int x, int y, int priority = 0, char *menu = 0) ;
DrawObject(Window *w, char *name, int priority = 0, char *menu = 0) ;
~DrawObject() ;
void redraw (int x0, int y0, int x1, int y1) ;
protected:
char *data ; // draw data (in drawfile format)
int data_length ;
int matrix[6] ; // translation matrix
int xoffset, yoffset ; // draw unit offset to bounding box
bool dealloc_data ; // OK to deallocate data in destructor
int max_length ; // max length for dynamic data array
void init(int x, int y) ; // init for drawing on screen
void make_header (int width, int height) ; // make a file header
void insert_word (int word) ; // insert a word
void insert_string (char *str) ; // insert a string
void insert_byte (char c) ; // insert a byte
void insert_data (void *s, int length) ; // insert a load of data
void align() ; // align to next word
void check_space (int num_bytes) ; // check space and extend if necessary
} ;
//
// This sprite object uses the draw object to place a sprite at the specified coordinates.
//
class SpriteObject : public DrawObject
{
public:
SpriteObject (Window *w, char *name, char *sprite, int x, int y, int priority = 0, char *menu = 0) ;
~SpriteObject() ;
} ;
#endif