home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
v
/
vista
/
c
/
objects
< prev
next >
Wrap
Text File
|
1996-02-01
|
31KB
|
1,188 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.
//
// *************************************************************************
//
// window objects
//
#include "Vista:task.h"
#include "Vista:window.h"
#include <stdlib.h>
#include <kernel.h>
#include <swis.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <math.h>
Object::Object (Window *w, char *name, int priority, char *menu)
{
window = w ;
if (menu == NULL)
default_menu = NULL ;
else
{
default_menu = w->task->find_menu (menu) ;
if (default_menu == NULL)
throw ("Unknown menu") ;
}
next = NULL ;
prev = NULL ;
this->priority = priority ;
strncpy (this->name, name, 32) ;
w->add_object (this) ;
}
Object::~Object ()
{
window->remove_object (this) ;
}
void Object::redraw (int x0, int y0, int x1, int y1)
{
}
void Object::update (int x0, int y0, int x1, int y1)
{
}
int Object::compare (int x, int y)
{
x = window->xtowindow(x) ; // x in window coords
y = window->ytowindow(y) ; // y in window coords
return x <= this->x1 && x >= this->x0 && y <= this->y1 && y >= this->y0 ;
}
//
// move to alternative window coords
//
void Object::move (int x0, int y0, int x1, int y1)
{
this->x0 = x0 ;
this->y0 = y0 ;
this->x1 = x1 ;
this->y1 = y1 ;
}
void Object::move (int dx, int dy)
{
this->x0 += dx ;
this->y0 += dy ;
this->x1 += dx ;
this->y1 += dy ;
}
void Object::drag (int mx, int my, int buttons)
{
window->task->register_object_drag (this, 1) ;
window->do_drag (5, x0 + window->x0 - window->scx, y0 + window->y1 - window->scy,
x1 + window->x0 - window->scx, y1 + window->y1 - window->scy) ;
}
void Object::click (int mx, int my, int button)
{
}
void Object::double_click (int mx, int my, int button)
{
}
void Object::end_drag (int x0, int y0, int x1, int y1, int id)
{
int oldx0 = this->x0 ;
int oldy0 = this->y0 ;
int oldx1 = this->x1 ;
int oldy1 = this->y1 ;
move (window->xtowindow (x0), window->ytowindow(y0),
window->xtowindow (x1), window->ytowindow(y1)) ;
window->do_redraw (oldx0, oldy0, oldx1, oldy1) ;
window->do_redraw(this->x0, this->y0, this->x1, this->y1) ;
}
void Object::key (int x, int y, int height, int index, int code)
{
}
void Object::select()
{
selected = 1 ;
}
void Object::unselect()
{
selected = 0 ;
}
void Object::pointer (int entering)
{
}
void Object::mode_change()
{
}
Menu *Object::display_menu (int x, int y, int button, int icon)
{
if (default_menu == NULL)
{
char *menu_name = get_menu(x, y, button, icon) ;
if (menu_name == NULL)
return NULL ;
Menu *m = window->task->find_menu (menu_name) ;
if (m != NULL)
{
m->open (x - 40, y) ;
return m ;
}
return NULL ; // no menu
}
else
{
pre_menu (default_menu, x, y, button, icon) ;
default_menu->open (x - 40, y) ;
return default_menu ;
}
}
//
// give user a chance to change the menu before display
//
void Object::pre_menu (Menu *m, int x, int y, int button, int icon)
{
}
//
// this window doesn't have a default menu, ask the user to provide one
//
char *Object::get_menu (int x, int y, int button, int icon)
{
return NULL ;
}
void Object::menu (MenuItem item[])
{
}
char *Object::help (int mx, int my, int buttons)
{
return NULL ;
}
static void move(int x, int y)
{
_kernel_swi_regs r ;
_kernel_oserror *e ;
r.r[0] = 4 ;
r.r[1] = x ;
r.r[2] = y ;
if ((e = _kernel_swi (OS_Plot, &r, &r)) != NULL)
throw (e) ;
}
static void draw_char (char ch)
{
_kernel_swi_regs r ;
_kernel_swi (OS_WriteI+ch, &r, &r) ;
}
static void set_colour (int colour)
{
_kernel_swi_regs r ;
r.r[0] = 18 ;
_kernel_swi (OS_WriteC, &r, &r) ;
r.r[0] = 0 ;
_kernel_swi (OS_WriteC, &r, &r) ;
r.r[0] = colour ;
_kernel_swi (OS_WriteC, &r, &r) ;
}
//
// icon object
//
IconObject::IconObject (Window *w, char *name, Icon *icon, int priority, char *menu)
: Object (w, name, priority, menu)
{
this->icon = icon ;
}
IconObject::~IconObject ()
{
}
void IconObject::redraw (int x0, int y0, int x1, int y1)
{
Box box ;
icon->read_position (box) ;
if (x0 <= box.x1 && x1 >= box.x0 && y0 <= box.y1 && y1 >= box.y0)
icon->plot() ;
}
//
// a sprite object
//
RawSpriteObject::RawSpriteObject (Window *w, char *name, char *sprite, void *area, int x, int y, int priority, char *menu)
: Object (w, name, priority, menu)
{
_kernel_swi_regs r ;
_kernel_oserror *e ;
x0 = x ;
y0 = y ;
this->sprite = sprite ;
this->area = area ;
r.r[0] = 40 + 0x100 ; // read sprite info
r.r[1] = (int)area ;
r.r[2] = (int)sprite ;
if ((e = _kernel_swi (OS_SpriteOp, &r, &r)) != NULL)
throw (e) ;
x1 = x0 + r.r[3] ;
y1 = y0 + r.r[4] ;
}
RawSpriteObject::RawSpriteObject (Window *w, char *name, char *sprite, int x, int y, int priority, char *menu)
: Object (w, name, priority, menu)
{
x0 = x ;
y0 = y ;
this->sprite = sprite ;
this->area = 0 ;
init() ;
}
void RawSpriteObject::init()
{
_kernel_swi_regs r ;
_kernel_oserror *e ;
r.r[0] = 40 + (area == NULL ? 0 : 256) ; // read sprite info
r.r[2] = (int)sprite ;
if ((e = _kernel_swi (area == NULL ? Wimp_SpriteOp : OS_SpriteOp, &r, &r)) != NULL)
throw (e) ;
int xsize = r.r[3] ;
int ysize = r.r[4] ;
mode = r.r[6] ;
xsize <<= window->task->xeigfactor ;
ysize <<= window->task->yeigfactor ;
x1 = x0 + xsize ;
y1 = y0 + ysize ;
// set up scale factors
scale_factors[0] = 1 ;
scale_factors[1] = 1 ;
scale_factors[2] = 1 ;
scale_factors[3] = 1 ;
#if 0
if (area == NULL)
{
if ((e = _kernel_swi (Wimp_BaseOfSprites, &r, &r)) != NULL)
throw (e) ;
r.r[0] = r.r[1] ;
}
else
r.r[0] = (int)area ;
#endif
r.r[0] = mode ;
r.r[1] = 3 ; // NColour (see PRM 1-710)
if ((e = _kernel_swi (OS_ReadModeVariable,&r,&r)) != NULL)
throw (e) ;
pixel_trans = new char [256] ;
if (r.r[2] < 63) // < 256 colours
{
unsigned int palette[20] ;
r.r[1] = (int)palette ;
if ((e = _kernel_swi (Wimp_ReadPalette,&r,&r)) != NULL)
throw (e) ;
unsigned int i,p,col ;
for (i = 0 ; i < 15 ; i++)
{
p = palette[i] ;
col = p ;
col |= (p & 0xf0000000) >> 4 ;
col |= (p & 0x00f00000) >> 4 ;
col |= (p & 0x0000f000) >> 4 ;
palette[i] = p & 0xffffff00 ;
}
r.r[0] = mode ;
r.r[1] = 0 ;
r.r[2] = -1 ;
r.r[3] = (int)palette ;
r.r[4] = (int)pixel_trans ;
r.r[5] = 0 ;
if ((e = _kernel_swi (ColourTrans_GenerateTable, &r, &r)) != NULL)