home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Graphics 16,000
/
graphics-16000.iso
/
sgi
/
editors
/
kali.lha
/
kali
/
callbacks.c
next >
Wrap
C/C++ Source or Header
|
1992-10-11
|
7KB
|
310 lines
/*
*** callbacks.c - Tamara Munzner, Sept. 1992
*/
#include <stdio.h>
#include <strings.h>
#include "symmetry.h"
#include "icons.h"
#include "help.h"
#define SAVE 0
#define LOAD 1
#include "panel.c"
void set_linebutton(int new);
void set_symbutton(int new);
void set_angrat();
FL_OBJECT *linelist(int button);
FL_OBJECT *symlist(int button);
void flx_enable(FL_OBJECT *obj);
void flx_disable(FL_OBJECT *obj);
extern WINDOW win;
extern int mode, count, sym_index, pick_for;
extern SYMMETRY *sym;
extern LINE *Lines;
extern RECTANGLE win_rect, sym_rect;
extern float zoom;
extern XFORM xforms[5];
extern POINT *sym_pts;
extern void DrawLine();
extern void PickLine();
extern LINE *DropLine();
extern void (*xformfnc) ();
extern void ChangeRatio();
extern void ChangeScale();
extern void ChangeAngle();
extern void ChangeRotation();
extern LINE *ReadPattern();
extern LINE* ThrowAwayLines(LINE *Lines);
extern void SaveProc();
extern void LoadProc();
extern int lit;
int iostate;
void forms_init()
{
int i;
create_the_forms();
fl_set_bitmap(P6MBitmap, icon_width, icon_height, p6m_bits);
fl_set_bitmap(P6Bitmap, icon_width, icon_height, p6_bits);
fl_set_bitmap(P31MBitmap, icon_width, icon_height, p31m_bits);
fl_set_bitmap(P3M1Bitmap, icon_width, icon_height, p3m1_bits);
fl_set_bitmap(P3Bitmap, icon_width, icon_height, p3_bits);
fl_set_bitmap(P4MBitmap, icon_width, icon_height, p4m_bits);
fl_set_bitmap(P4GBitmap, icon_width, icon_height, p4g_bits);
fl_set_bitmap(P4Bitmap, icon_width, icon_height, p4_bits);
fl_set_bitmap(PMMBitmap, icon_width, icon_height, pmm_bits);
fl_set_bitmap(CMMBitmap, icon_width, icon_height, cmm_bits);
fl_set_bitmap(P2Bitmap, icon_width, icon_height, p2_bits);
fl_set_bitmap(PMGBitmap, icon_width, icon_height, pmg_bits);
fl_set_bitmap(PGGBitmap, icon_width, icon_height, pgg_bits);
fl_set_bitmap(CMBitmap, icon_width, icon_height, cm_bits);
fl_set_bitmap(PGBitmap, icon_width, icon_height, pg_bits);
fl_set_bitmap(PMBitmap, icon_width, icon_height, pm_bits);
fl_set_bitmap(P1Bitmap, icon_width, icon_height, p1_bits);
fl_set_form_position(KaliForm, 8, 8);
SymmetryProc(NULL, sym_index);
fl_show_form(KaliForm, FL_PLACE_POSITION, TRUE, "Symmetry Groups");
for (i=0; help[i][0] != '.'; i++) {
fl_add_browser_line(InfoBrowser, help[i]);
}
}
void SymmetryProc(FL_OBJECT *obj, long val)
{
sym_index = val;
sym = &(SYMTAB[sym_index]);
Lines = ThrowAwayLines(Lines);
set_symbutton(val);
DefineSymWindow(&sym_rect,sym,&win_rect,zoom);
count = SetUpSymmetry(sym,&sym_pts,xforms,&sym_rect);
DrawCurrent(&sym_rect,Lines,sym,
sym_pts,xforms,count,DrawLine);
swapbuffers();
/* we don't set mode to DRAW since we don't want to rubberband yet,
but we will be in draw mode as soon as mouse is used.
*/
set_linebutton(DRAW);
set_linebutton(DRAW);
set_angrat();
mode = 0;
}
void DrawProc(FL_OBJECT *obj, long val)
{
/* 18 19 26*/
DrawCurrent(&sym_rect,Lines,sym,
sym_pts,xforms,count,DrawLine);
swapbuffers();
mode = 0;
set_linebutton(val);
}
void PickProc(FL_OBJECT *obj, long val)
{
if ((mode == DRAW) && (Lines != NULL))
{
Lines = DropLine(Lines);
DrawCurrent(&sym_rect,Lines,sym,
sym_pts,xforms,count,DrawLine);
swapbuffers();
}
mode=PICK;
pick_for = val; /* MOVE or CUT */
set_linebutton(val);
lit = FALSE;
}
void LineProc(FL_OBJECT *obj, long val)
{
mode = TRANSFORM;
switch (val) {
case ZOOM: xformfnc = ChangeScale; break;
case ROTATE: xformfnc = ChangeRotation; break;
}
set_linebutton(val);
}
void AngleProc(FL_OBJECT *obj, long val)
{
mode = TRANSFORM;
xformfnc = ChangeAngle;
set_linebutton(val);
}
void RatioProc(FL_OBJECT *obj, long val)
{
mode = TRANSFORM;
xformfnc = ChangeRatio;
set_linebutton(val);
}
void StartSaveProc(FL_OBJECT *obj, long val)
{
iostate = SAVE;
fl_show_form(IOForm, FL_PLACE_MOUSE, TRUE, "Save");
}
void StartLoadProc(FL_OBJECT *obj, long val)
{
iostate = LOAD;
fl_show_form(IOForm, FL_PLACE_MOUSE, TRUE, "Load");
fl_set_button(DrawButton, 1);
set_linebutton(DRAW);
set_linebutton(DRAW);
mode = 0;
}
void IODoneProc(FL_OBJECT *obj, long val)
{
char *filename, *readwrite;
FILE *pat;
void (*func)();
if (iostate == SAVE) {
func = SaveProc;
readwrite = "w";
} else {
func = LoadProc;
readwrite = "r";
}
filename = strdup(fl_get_input(IOInput));
pat = fopen(filename,readwrite);
if (pat == NULL) {
fl_set_input(IOInput, "Bogus file name!");
return;
} else {
fl_hide_form(IOForm);
}
func(pat);
if (iostate == LOAD) {
set_symbutton(sym_index);
set_symbutton(sym_index);
}
winset(win);
}
void CancelProc(FL_OBJECT *obj, long val)
{
fl_hide_form(IOForm);
winset(win);
}
void QuitProc(FL_OBJECT *obj, long val)
{
fl_hide_form(KaliForm);
exit(0);
}
void InfoProc(FL_OBJECT *obj, long val)
{
static int winid = 0;
winid = fl_show_form(InfoForm, FL_PLACE_SIZE, TRUE, "Kali Help");
winset(winid);
winpop();
}
void CloseThisPanel(FL_OBJECT *obj, long val)
{
fl_hide_form(obj->form);
winset(win);
}
FL_OBJECT *linelist(int button)
{
switch (button) {
case DRAW: return DrawButton; break;
case CUT: return DeleteButton; break;
case MOVE: return MoveButton; break;
case ZOOM: return ZoomButton; break;
case ROTATE: return RotateButton; break;
case ANGLE: return AngleButton; break;
case RATIO: return RatioButton; break;
}
}
FL_OBJECT *symlist(int button)
{
switch (button) {
case P1: return P1Bitmap; break;
case P2: return P2Bitmap; break;
case P3: return P3Bitmap; break;
case PG: return PGBitmap; break;
case PGG: return PGGBitmap; break;
case PMG: return PMGBitmap; break;
case PM: return PMBitmap; break;
case CM: return CMBitmap; break;
case PMM: return PMMBitmap; break;
case CMM: return CMMBitmap; break;
case P31M: return P31MBitmap; break;
case P3M1: return P3M1Bitmap; break;
case P4: return P4Bitmap; break;
case P4G: return P4GBitmap; break;
case P4M: return P4MBitmap; break;
case P6: return P6Bitmap; break;
case P6M: return P6MBitmap; break;
}
}
void set_linebutton(int new)
{
static int old = DRAW;
fl_set_button(linelist(old), 0);
fl_set_button(linelist(new), 1);
old = new;
}
#define WHITEINDEX 7
#define BLUEINDEX 4
#define BLACKINDEX 0
void set_symbutton(int new)
{
static int old = P3;
fl_set_object_color(symlist(old), BLUEINDEX, WHITEINDEX);
fl_set_object_color(symlist(new), WHITEINDEX, BLUEINDEX);
old = new;
}
void flx_enable(FL_OBJECT *obj) {
obj->active = 1;
fl_set_object_lcol(obj, BLACKINDEX);
}
void flx_disable(FL_OBJECT *obj) {
obj->active = 0;
fl_set_object_lcol(obj, WHITEINDEX);
}
void set_angrat()
{
if (sym->dof & ANG)
flx_enable(AngleButton);
else
flx_disable(AngleButton);
if (sym->dof & RAT)
flx_enable(RatioButton);
else
flx_disable(RatioButton);
}