📄 _sunview.c
字号:
/*******************************************************************************
+
+ LEDA 3.0
+
+
+ _sunview.c
+
+
+ Copyright (c) 1992 by Max-Planck-Institut fuer Informatik
+ Im Stadtwald, 6600 Saarbruecken, FRG
+ All rights reserved.
+
*******************************************************************************/
#include <suntool/sunview.h>
#include <suntool/canvas.h>
#include <suntool/panel.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
#define NOCLIP 0x1
#define XCOL(c) PIX_SRC ^ PIX_DST | PIX_COLOR(c)
#define COL(c) PIX_SRC|PIX_COLOR(c)
#define pix_mode(c) (pix_mode_op | PIX_COLOR(c))
#define XPIX(coord) (int)(xorigin + (coord)*x_draw_scale)
#define YPIX(coord) (int)(yorigin - (coord)*x_draw_scale)
#define XREAL(pix) ((double)(pix-xorigin)/x_draw_scale)
#define YREAL(pix) ((double)(yorigin-pix)/x_draw_scale)
extern Notify_error notify_dispatch();
static short icon_image[] = {
#include "leda.icon"
};
static mpr_static(leda_icon_pixrect,64,64,1,icon_image);
static char default_frame_label[128];
static char frame_label[80];
static char read_frame_format[] = "%8.2f %8.2f %s";
static Frame frame;
static Canvas canvas;
static Pixwin *pw = 0;
static Icon icon;
static Frame panel_frame;
static Panel panel;
typedef void (*PRD)();
typedef void (*PMA)();
static void x_draw_default_redraw() { /* do nothing */ }
static void x_draw_mouse_default_action(x,y)
double x,y;
{ /* do nothing */}
PRD x_draw_redraw = x_draw_default_redraw;
PMA x_draw_mouse_action = x_draw_mouse_default_action;
static int x_draw_done;
static Pixfont *font;
static int pix_mode_op;
static int xdots,ydots, xorigin,yorigin; /* pixels */
static int mouse_key,mouse_xpix, mouse_ypix;
static int mouse_last_xpix, mouse_last_ypix;
static int mouse_start_xpix, mouse_start_ypix; /* start for segments ... */
static int mouse_read_kind;
static double mouse_xreal,mouse_yreal;
static double mouse_last_xreal,mouse_last_yreal;
static double mouse_start_xreal,mouse_start_yreal;
static char* mesg_list[32];
static int mesg_count;
/* external variables */
/*
SCREEN_WIDTH = 1152;
SCREEN_HEIGHT = 900;
*/
int x_draw_window_xpos = 0;
int x_draw_window_ypos = 0;
int x_draw_window_width = 0;
int x_draw_window_height = 0;
double x_draw_xmax,x_draw_xmin,x_draw_ymax,x_draw_ymin,x_draw_scale;
int x_draw_grid_mode;
int x_draw_depth;
int x_draw_line_width,
x_draw_node_width,
x_draw_line_style,
x_draw_text_mode,
x_draw_drawing_mode,
x_draw_screen_flush;
static unsigned char RED[256],GREEN[256],BLUE[256];
static char* x_draw_default_font = "screen.r.12";
static Pr_texture *Line_style = 0;
static Pr_texture *solid;
static Pr_texture *dashed;
static Pr_texture *dotted;
/*
x_draw_new_color(r,g,b)
int r,g,b;
{ int col = col_count;
col_count++;
RED[col] = r;
GREEN[col] = g;
BLUE[col] = b;
pw_setcmsname(pw,"new_color");
pw_putcolormap(pw,0,col_count,RED,GREEN,BLUE);
return col;
}
*/
x_draw_init_colors()
{ RED[0] = 255; GREEN[0] = 255; BLUE[0] = 255; /* white */
RED[1] = 0; GREEN[1] = 0; BLUE[1] = 0; /* black */
RED[2] = 255; GREEN[2] = 0; BLUE[2] = 0; /* red */
RED[3] = 0; GREEN[3] = 255; BLUE[3] = 0; /* green */
RED[4] = 0; GREEN[4] = 100; BLUE[4] = 255; /* blue */
RED[5] = 128; GREEN[5] = 128; BLUE[5] = 0; /* yellow */
RED[6] = 128; GREEN[6] = 0; BLUE[6] = 178; /* violet */
RED[7] = 192; GREEN[7] = 64; BLUE[7] = 0; /* orange */
/*
indigo: RED[] = 64; GREEN[] = 0; BLUE[] = 76;
*/
pw_setcmsname(pw,"new_color");
pw_putcolormap(pw,0,8,RED,GREEN,BLUE);
}
x_draw_set_redraw(f)
PRD f;
{ x_draw_redraw = f; }
x_draw_set_frame_label(message)
char* message;
{ strcpy(frame_label,message); }
x_draw_reset_frame_label()
{ strcpy(frame_label,default_frame_label); }
void x_draw_mouse_segment_action(x,y)
double x,y;
{ pw_vector(pw, mouse_start_xpix,mouse_start_ypix,
XPIX(x), YPIX(y),PIX_SRC^PIX_DST,1);
}
void x_draw_mouse_rect_action(x,y)
double x,y;
{ int save_pix_mode = pix_mode_op;
pix_mode_op = PIX_SRC ^ PIX_DST;
x_draw_rectangle(mouse_start_xreal,mouse_start_yreal,x,y,1,1);
pix_mode_op = save_pix_mode;
}
void x_draw_mouse_circle_action(x,y)
double x,y;
{ double r = hypot(x - mouse_start_xreal, y - mouse_start_yreal);
int save_pix_mode = pix_mode_op;
pix_mode_op = PIX_SRC ^ PIX_DST;
x_draw_circle(mouse_start_xreal, mouse_start_yreal, r, 1, 1);
pix_mode_op = save_pix_mode;
}
x_draw_set_font(fname)
char* fname;
{ char buf[256];
Pixfont *f;
sprintf(buf,"/usr/lib/fonts/fixedwidthfonts/%s",fname);
if ( f=pf_open(buf) )
{ font =f ;
return 1;
}
else return 0;
}
x_draw_set_line_style(s)
int s;
{ int save = x_draw_line_style;
x_draw_line_style = s;
switch (x_draw_line_style) {
case 0 : Line_style = solid;
break;
case 1 : Line_style = dashed;
break;
case 2 : Line_style = dotted;
break;
default: break;
}
return save;
}
int x_draw_set_mode(m)
int m;
{ int save = x_draw_drawing_mode;
x_draw_drawing_mode = m;
switch (x_draw_drawing_mode) {
case 0 : pix_mode_op = PIX_SRC;
break;
case 1 : pix_mode_op = PIX_SRC ^ PIX_DST;
break;
default: break;
}
return save;
}
int x_draw_set_line_width(w)
int w;
{ int save = x_draw_line_width;
x_draw_line_width = w;
return save;
}
int x_draw_set_node_width(w)
int w;
{ int save = x_draw_node_width;
x_draw_node_width = w;
return save;
}
int x_draw_set_text_mode(m)
int m;
{ int save = x_draw_text_mode;
x_draw_text_mode = m;
return save;
}
static void my_event_proc(canvas,event)
Canvas canvas;
Event* event;
{
char s[256];
/*int k = event_action(event); does not work for SUN3 */
int k = event_id(event);
switch (k) {
case WIN_RESIZE: x_draw_init(x_draw_xmin,x_draw_xmax,x_draw_ymin,x_draw_grid_mode);
break;
case MS_LEFT: mouse_key = 1;
if (event_ctrl_is_down(event)) mouse_key +=3;
if (event_shift_is_down(event)) mouse_key = -mouse_key;
break;
case MS_MIDDLE: mouse_key = 2;
if (event_ctrl_is_down(event)) mouse_key +=3;
if (event_shift_is_down(event)) mouse_key = -mouse_key;
break;
case MS_RIGHT: mouse_key = 3;
if (event_ctrl_is_down(event)) mouse_key +=3;
if (event_shift_is_down(event)) mouse_key = -mouse_key;
break;
case KEY_RIGHT(7): /* left arrow */
mouse_xpix -= (int)x_draw_scale*x_draw_grid_mode;
window_set(canvas,WIN_MOUSE_XY,mouse_xpix,mouse_ypix,0);
break;
case KEY_RIGHT(9): /* right arrow */
mouse_xpix += (int)x_draw_scale*x_draw_grid_mode;
window_set(canvas,WIN_MOUSE_XY,mouse_xpix,mouse_ypix,0);
break;
case KEY_RIGHT(11): /* down arrow */
mouse_ypix += (int)x_draw_scale*x_draw_grid_mode;
window_set(canvas,WIN_MOUSE_XY,mouse_xpix,mouse_ypix,0);
break;
case KEY_RIGHT(5): /* up arrow */
mouse_ypix -= (int)x_draw_scale*x_draw_grid_mode;
window_set(canvas,WIN_MOUSE_XY,mouse_xpix,mouse_ypix,0);
break;
case KEY_RIGHT(1): /* center */
mouse_xpix = XPIX(0);
mouse_ypix = YPIX(0);
window_set(canvas,WIN_MOUSE_XY,mouse_xpix,mouse_ypix,0);
break;
default: mouse_xpix = event_x(event);
mouse_ypix = event_y(event);
break;
}
if (x_draw_grid_mode) x_draw_cursor();
mouse_xreal = x_draw_xmin+((double)mouse_xpix)/x_draw_scale;
mouse_yreal = x_draw_ymax-((double)mouse_ypix)/x_draw_scale;
if (x_draw_grid_mode)
{
mouse_xreal = x_draw_grid_mode * (int)(mouse_xreal/x_draw_grid_mode + ((mouse_xreal > 0) ? 0.5 : -0.5));
mouse_yreal = x_draw_grid_mode * (int)(mouse_yreal/x_draw_grid_mode + ((mouse_yreal > 0) ? 0.5 : -0.5));
mouse_xpix = XPIX(mouse_xreal);
mouse_ypix = YPIX(mouse_yreal);
x_draw_cursor();
}
sprintf(s,read_frame_format, mouse_xreal,mouse_yreal,frame_label);
window_set(frame,FRAME_LABEL,s,0);
if (x_draw_mouse_action) /* user defined action */
{ x_draw_mouse_action(mouse_last_xreal,mouse_last_yreal);
x_draw_mouse_action(mouse_xreal,mouse_yreal);
}
mouse_last_xpix = mouse_xpix;
mouse_last_ypix = mouse_ypix;
mouse_last_xreal = mouse_xreal;
mouse_last_yreal = mouse_yreal;
}
int x_read_mouse(kind, xstart,ystart,x,y)
int kind; /* 0: point, 1: segment, 2:rectangle, 3: circle */
double xstart;
double ystart;
double *x;
double *y;
{
PMA f;
switch(kind) {
case 0 : f = x_draw_mouse_default_action;
break;
case 1: f = x_draw_mouse_segment_action;
break;
case 2: f = x_draw_mouse_rect_action;
break;
case 3: f = x_draw_mouse_circle_action;
break;
default: f = x_draw_mouse_default_action;
break;
}
return x_read_mouse_action(f,xstart,ystart,x,y);
}
int x_draw_get_button()
{ x_draw_mouse_action = x_draw_mouse_default_action;
mouse_key = 0;
notify_dispatch();
return mouse_key;
}
int x_read_mouse_action(action, xstart,ystart,x,y)
PMA action;
double xstart;
double ystart;
double *x;
double *y;
{
x_draw_mouse_action = action;
mouse_key = 0;
mouse_start_xreal = xstart;
mouse_start_yreal = ystart;
mouse_start_xpix = XPIX(xstart);
mouse_start_ypix = YPIX(ystart);
if (x_draw_grid_mode) x_draw_cursor();
if (x_draw_mouse_action) /* user defined action */
{ x_draw_mouse_action(mouse_last_xreal,mouse_last_yreal);
}
while (!mouse_key && !x_draw_done) notify_dispatch();
if (x_draw_done) return 0;
if (x_draw_mouse_action) /* user defined action */
{ x_draw_mouse_action(mouse_xreal,mouse_yreal);
}
if (x_draw_grid_mode) x_draw_cursor();
*x = mouse_xreal;
*y = mouse_yreal;
return mouse_key;
}
Notify_value my_notice_destroy(frame, status)
Frame frame;
Destroy_status status;
{
if (status !=DESTROY_CHECKING)
{
x_draw_done = 1;
(void) notify_stop();
}
return (notify_next_destroy_func(frame,status));
}
x_draw_init_window(w_width,w_height,w_xpos,w_ypos,label)
int w_width,
w_height,
w_xpos,
w_ypos;
char* label;
{
if (pw!=0)
{ fprintf(stderr,"warning: second initialization of window ignored.\n");
return;
}
strcpy(default_frame_label,label);
icon = icon_create(ICON_IMAGE, &leda_icon_pixrect, 0);
frame = window_create(0, FRAME,
WIN_WIDTH, w_width,
WIN_HEIGHT, w_height,
WIN_X, w_xpos,
WIN_Y, w_ypos,
FRAME_ICON, icon,
FRAME_NO_CONFIRM, TRUE,
FRAME_LABEL, default_frame_label, 0);
canvas = window_create(frame, CANVAS,
WIN_CONSUME_KBD_EVENT, WIN_RIGHT_KEYS,
WIN_IGNORE_PICK_EVENT, WIN_UP_EVENTS,
WIN_EVENT_PROC, my_event_proc,
0);
pw = canvas_pixwin(canvas);
notify_interpose_destroy_func(frame,my_notice_destroy);
window_set(frame,WIN_SHOW,TRUE,0);
/* init panel */
panel_frame = window_create(0, FRAME,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -