home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 55
/
Amiga_Dream_55.iso
/
RISCOS
/
APPS
/
SCI
/
ELECTRON
/
AUTOPC.ZIP
/
!AutoPCB
/
Source
/
c
/
Draw
< prev
next >
Wrap
Text File
|
1991-04-05
|
5KB
|
290 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "win.h"
#include "wimp.h"
#include "wimpt.h"
#include "res.h"
#include "resspr.h"
#include "template.h"
#include "event.h"
#include "menu.h"
#include "baricon.h"
#include "flex.h"
#include "heap.h"
#include "werr.h"
#include "drawfdiag.h"
#include "drawftypes.h"
#include "draw.h"
#define MAIN_WINDOW 0
#define ICON_MENU 0
#define MIL (180*256/1000)
#define TRANSPARENT 0xffffffff
#define BLUE 0xff000000
#define GREEN 0x00ff0000
#define RED 0x0000ff00
int *diag, diagp;
static wimp_w main_window;
static int diagm;
static double scale;
static draw_diag diagram;
static void draw_report_error(draw_error *error);
static wimp_w create_window(char *name)
{
wimp_wind *window;
wimp_w handle;
handle = 0;
window = template_syshandle(name);
if (window)
wimpt_complain(wimp_create_wind(window, &handle));
return handle;
}
static void open_window(wimp_w handle)
{
wimp_wstate state;
if (wimpt_complain(wimp_get_wind_state(handle, &state)) == 0)
{
state.o.behind = -1;
wimpt_noerr(wimp_open_wind(&state.o));
}
}
static void redraw_window(wimp_w handle)
{
BOOL flag;
wimp_redrawstr r;
draw_error error;
r.w = handle;
wimpt_noerr(wimp_redraw_wind(&r, &flag));
while(flag)
{
if (!draw_render_diag(&diagram,
(draw_redrawstr *)&r,
scale,
&error))
draw_report_error(&error);
wimpt_noerr(wimp_get_rectangle(&r, &flag));
}
}
static void window_event(wimp_eventstr *e, void *handle)
{
int id;
id = (int)handle;
switch(e->e)
{
case wimp_EREDRAW:
redraw_window(e->data.o.w);
break;
case wimp_EOPEN:
wimpt_noerr(wimp_open_wind(&e->data.o));
break;
case wimp_ECLOSE:
wimpt_noerr(wimp_close_wind(e->data.o.w));
break;
default:
break;
}
}
static void draw_report_error(draw_error *error)
{
switch(error->type)
{
case DrawOSError:
werr(0, "OS error: %s (%d)", error->err.os.errmess, error->err.os.errnum);
break;
case DrawOwnError:
werr(0, "Draw error: %ld at location %lx",
error->err.draw.code,
error->err.draw.location);
break;
case None:
werr(0, "Unknown error");
break;
}
}
void draw_file_header(char *app)
{
struct
{
char name[4];
int major, minor;
char title[12];
int x0, y0, x1, y1;
} header;
diagp = 0;
memcpy(header.name, "Draw", 4);
header.major = 201;
header.minor = 0;
memcpy(header.title, app, 12);
header.x0 = 0;
header.y0 = 0;
header.x1 = 8000 * MIL;
header.y1 = 11000 * MIL;
memcpy(&diag[diagp], &header, sizeof(header));
diagp += (sizeof(header) / sizeof(int));
}
void draw_object_header(int type, int x1, int y1)
{
struct
{
int type;
int size;
int x0, y0, x1, y1;
} header;
header.type = type;
header.size = 0;
header.x0 = 0;
header.y0 = 0;
header.x1 = x1 * MIL;
header.y1 = y1 * MIL;
diagm = diagp;
memcpy(&diag[diagp], &header, sizeof(header));
diagp += (sizeof(header) / sizeof(int));
}
void draw_path_header(int fill, int colour)
{
struct
{
int fill, outline, width, style;
} header;
header.fill = fill;
header.outline = colour;
header.width = 15 * MIL;
header.style = 1 << packshft_join |
1 << packshft_endcap |
1 << packshft_startcap;
memcpy(&diag[diagp], &header, sizeof(header));
diagp += (sizeof(header) / sizeof(int));
}
void draw_path_move(int x, int y)
{
struct
{
int tag;
int x, y;
} header;
header.tag = 2;
header.x = x;
header.y = y;
memcpy(&diag[diagp], &header, sizeof(header));
diagp += (sizeof(header) / sizeof(int));
}
void draw_path_line(int x, int y)
{
struct
{
int tag;
int x, y;
} header;
header.tag = 8;
header.x = x;
header.y = y;
memcpy(&diag[diagp], &header, sizeof(header));
diagp += (sizeof(header) / sizeof(int));
}
void draw_path_circle(int x, int y, int r)
{
int c;
struct
{
int tag;
int x0, y0;
int x1, y1;
int i, j;
} path1, path2;
c = r * 14 / 10;
draw_path_move(x, y - r);
path1.tag = 6;
path1.x0 = x - c;
path1.y0 = y - r;
path1.x1 = x - c;
path1.y1 = y + r;
path1.i = x;
path1.j = y + r;
path2.tag = 6;
path2.x0 = x + c;
path2.y0 = y + r;
path2.x1 = x + c;
path2.y1 = y - r;
path2.i = x;
path2.j = y - r;
memcpy(&diag[diagp], &path1, sizeof(path1));
diagp += (sizeof(path1) / sizeof(int));
memcpy(&diag[diagp], &path2, sizeof(path2));
diagp += (sizeof(path2) / sizeof(int));
}
void draw_path_end(void)
{
diag[diagp++] = 0;
diag[diagm + 1] = (diagp - diagm) * 4;
}
void draw_init(void)
{
main_window = create_window("main");
win_register_event_handler(main_window, window_event, MAIN_WINDOW);
diag = (int *)heap_alloc(50000);
}
void draw_display(double setscale)
{
draw_error error;
scale = setscale;
diagram.data = (char *)&diag[0];
diagram.length = (diagp) * 4;
if (draw_verify_diag(&diagram, &error))
open_window(main_window);
else
draw_report_error(&error);
}