version 1.1, 2000/11/22 06:20:13 |
version 1.6, 2015/08/20 17:47:53 |
Line 14 static char THIS_FILE[] = __FILE__; |
|
Line 14 static char THIS_FILE[] = __FILE__; |
|
#include <math.h> |
#include <math.h> |
|
|
extern "C" { |
extern "C" { |
#include "ca.h" |
#include "if_canvas.h" |
#include "ifplot.h" |
|
|
|
#if defined(sun) && !defined(__svr4__) |
struct pa { |
#define EXP10(a) exp10(a) |
int length; |
#else |
POINT *pos; |
|
}; |
|
|
|
typedef struct RealVect { |
|
int len; |
|
int body[1]; |
|
} RealVect; |
|
|
#define EXP10(a) pow(10.0,a) |
#define EXP10(a) pow(10.0,a) |
#endif |
|
|
|
|
extern struct canvas *current_can; |
|
extern POINT start_point,end_point; |
|
|
HANDLE hResizeNotify,hResizeNotify_Ack; |
HANDLE hResizeNotify,hResizeNotify_Ack; |
void destroy_canvas(struct canvas *); |
void destroy_canvas(struct canvas *); |
void pline(int *,struct canvas *, HDC); |
void pline(int *,struct canvas *, HDC); |
Line 80 void CChildView::OnPaint() |
|
Line 88 void CChildView::OnPaint() |
|
// TODO: メッセージ ハンドラのコードをここに追加してください。 |
// TODO: メッセージ ハンドラのコードをここに追加してください。 |
|
|
// 描画のために CWnd::OnPaint を呼び出してはいけません。 |
// 描画のために CWnd::OnPaint を呼び出してはいけません。 |
if ( can->mode == MODE_INTERACTIVE ) { |
if ( canvas_is_interactive(can) ) { |
::BitBlt(dc.m_hDC,0,0,can->width,can->height,can->pix,0,0,SRCCOPY); |
canvas_bitblt(can,dc.m_hDC,0,0); |
} else { |
} else { |
if ( !can->wide ) { |
if ( !canvas_wide(can) ) { |
::BitBlt(dc.m_hDC,0,0,can->width,can->height,can->pix,0,0,SRCCOPY); |
canvas_bitblt(can,dc.m_hDC,0,0); |
pline(0,can,dc.m_hDC); |
pline(0,can,dc.m_hDC); |
} else |
} else |
draw_wideframe(can,dc.m_hDC); |
draw_wideframe(can,dc.m_hDC); |
Line 95 void CChildView::OnPaint() |
|
Line 103 void CChildView::OnPaint() |
|
void CChildView::OnPrint(CDC &dc) |
void CChildView::OnPrint(CDC &dc) |
{ |
{ |
DOCINFO docinfo; |
DOCINFO docinfo; |
NODE n; |
// NODE n; |
int width,height,ratio,x,y; |
int width,height,ratio,x,y,step; |
|
int ch,cw,len,i; |
|
|
memset(&docinfo,0,sizeof(DOCINFO)); |
memset(&docinfo,0,sizeof(DOCINFO)); |
docinfo.cbSize = sizeof(DOCINFO); |
docinfo.cbSize = sizeof(DOCINFO); |
Line 122 void CChildView::OnPrint(CDC &dc) |
|
Line 131 void CChildView::OnPrint(CDC &dc) |
|
dc.StartDoc(&docinfo); |
dc.StartDoc(&docinfo); |
dc.StartPage(); |
dc.StartPage(); |
|
|
if ( can->mode == MODE_INTERACTIVE ) { |
cw = canvas_width(can); |
// We want to associate precisely one printer pixel to |
ch = canvas_height(can); |
|
|
|
if ( canvas_is_interactive(can) ) { |
|
|
|
// We want to associate a rectangle of a fixed size to |
// one bitmap pixel |
// one bitmap pixel |
// if can->width/can->height > width/height |
// if cw/ch > width/height |
// then match the widths, else match the height |
// then match the widths, else match the height |
if ( can->width*height > can->height*width ) |
if ( cw*height > ch*width ) |
ratio = width/can->width; |
ratio = width/cw; |
else |
else |
ratio = height/can->height; |
ratio = height/ch; |
|
|
// set the logical src bitmap size |
// set the logical src bitmap size |
dc.SetWindowExt(can->width*ratio,can->height*ratio); |
dc.SetWindowExt(cw*ratio,ch*ratio); |
|
|
// set the viewport size and the origine in printer pixel |
// set the viewport size and the origine in printer pixel |
dc.SetViewportOrg(width/18,height/18); |
dc.SetViewportOrg(width/18,height/18); |
dc.SetViewportExt(width,height); |
dc.SetViewportExt(width,height); |
|
|
for ( n = can->history; n; n = NEXT(n) ) { |
step = (ratio+4)/5; |
RealVect *rv = (RealVect *)n->body; |
RealVect **p = (RealVect **)canvas_history(can, &len); |
|
for(i=0; i<len; i++) { |
|
RealVect *rv = p[i]; |
if ( rv->len == 2 ) { |
if ( rv->len == 2 ) { |
// dc.SetPixel(rv->body[0],rv->body[1],0); |
// dc.SetPixel(rv->body[0],rv->body[1],0); |
x = rv->body[0]*ratio; |
x = rv->body[0]*ratio; |
y = rv->body[1]*ratio; |
y = rv->body[1]*ratio; |
// dc.FillRect(CRect(x,y,x+1,y+1),&brush); |
// dc.FillRect(CRect(x,y,x+1,y+1),&brush); |
dc.FillRect(CRect(x-1,y-1,x+1,y+1),&brush); |
// dc.FillRect(CRect(x-1,y-1,x+1,y+1),&brush); |
|
dc.FillRect(CRect(x,y,x+step,y+step),&brush); |
} else if ( rv->len == 4 ) { |
} else if ( rv->len == 4 ) { |
dc.MoveTo(rv->body[0]*ratio,rv->body[1]*ratio); |
dc.MoveTo(rv->body[0]*ratio,rv->body[1]*ratio); |
dc.LineTo(rv->body[2]*ratio,rv->body[3]*ratio); |
dc.LineTo(rv->body[2]*ratio,rv->body[3]*ratio); |
Line 154 void CChildView::OnPrint(CDC &dc) |
|
Line 170 void CChildView::OnPrint(CDC &dc) |
|
} |
} |
} else { |
} else { |
// set the logical src bitmap size |
// set the logical src bitmap size |
dc.SetWindowExt(can->width,can->height); |
dc.SetWindowExt(cw,ch); |
|
|
// set the viewport size and the origine in printer pixel |
// set the viewport size and the origine in printer pixel |
dc.SetViewportOrg(width/18,height/18); |
dc.SetViewportOrg(width/18,height/18); |
dc.SetViewportExt(width,height); |
dc.SetViewportExt(width,height); |
|
|
if ( can->mode == MODE_PLOT ) |
if ( canvas_is_plot(can) ) |
dc.Polyline(can->pa[0].pos,can->pa[0].length); |
dc.Polyline(canvas_pa(can)->pos,canvas_pa(can)->length); |
else |
else |
::StretchBlt(dc.m_hDC,0,0,can->width,can->height,can->pix, |
::StretchBlt(dc.m_hDC,0,0,cw,ch,canvas_pix(can),0,0,cw,ch,SRCCOPY); |
0,0,can->width,can->height,SRCCOPY); |
|
PrintAxis(dc); |
PrintAxis(dc); |
} |
} |
dc.EndPage(); |
dc.EndPage(); |
Line 174 void CChildView::OnPrint(CDC &dc) |
|
Line 189 void CChildView::OnPrint(CDC &dc) |
|
void CChildView::PrintAxis(CDC &dc) |
void CChildView::PrintAxis(CDC &dc) |
{ |
{ |
#define D 5 |
#define D 5 |
|
#define DEFAULTWIDTH 400 |
|
#define DEFAULTHEIGHT 400 |
|
|
double w,w1,k,e,n; |
double w,w1,e,n; |
int x0,y0,x,y,xadj,yadj; |
int x0,y0,x,y,xadj,yadj; |
char buf[BUFSIZ]; |
char buf[BUFSIZ]; |
|
double cxmin,cxmax,cymin,cymax; |
|
int cw,ch; |
|
|
|
cxmin = canvas_xmin(can); |
|
cxmax = canvas_xmax(can); |
|
cymin = canvas_ymin(can); |
|
cymax = canvas_ymax(can); |
|
cw = canvas_width(can); |
|
ch = canvas_height(can); |
|
|
/* XXX : should be cleaned up */ |
/* XXX : should be cleaned up */ |
if ( can->noaxis || (can->mode == MODE_PLOT && !can->pa) ) |
if ( canvas_noaxis(can) || (canvas_is_plot(can) && !canvas_pa(can)) |
|
|| canvas_is_interactive(can) ) |
return; |
return; |
if ( can->mode == MODE_INTERACTIVE ) |
|
return; |
|
|
|
xadj = yadj = 0; |
xadj = yadj = 0; |
if ( (can->xmin < 0) && (can->xmax > 0) ) { |
if ( (cxmin < 0) && (cxmax > 0) ) { |
x0 = (int)((can->width)*(-can->xmin/(can->xmax-can->xmin))); |
x0 = (int)((cw)*(-cxmin/(cxmax-cxmin))); |
dc.MoveTo(x0,0); dc.LineTo(x0,can->height); |
dc.MoveTo(x0,0); dc.LineTo(x0,ch); |
} else if ( can->xmin >= 0 ) |
} else if ( cxmin >= 0 ) |
x0 = 0; |
x0 = 0; |
else |
else |
x0 = can->width-D; |
x0 = cw-D; |
if ( (can->ymin < 0) && (can->ymax > 0) ) { |
if ( (cymin < 0) && (cymax > 0) ) { |
y0 = (int)((can->height)*(can->ymax/(can->ymax-can->ymin))); |
y0 = (int)((ch)*(cymax/(cymax-cymin))); |
dc.MoveTo(0,y0); dc.LineTo(can->width,y0); |
dc.MoveTo(0,y0); dc.LineTo(cw,y0); |
} else if ( can->ymin >= 0 ) |
} else if ( cymin >= 0 ) |
y0 = can->height; |
y0 = ch; |
else |
else |
y0 = D; |
y0 = D; |
w = can->xmax-can->xmin; |
w = cxmax-cxmin; |
w1 = w * DEFAULTWIDTH/can->width; |
w1 = w * DEFAULTWIDTH/cw; |
e = adjust_scale(EXP10(floor(log10(w1))),w1); |
e = adjust_scale(EXP10(floor(log10(w1))),w1); |
for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) { |
for ( n = ceil(cxmin/e); n*e<= cxmax; n++ ) { |
x = (int)can->width*(n*e-can->xmin)/w; |
x = (int)(cw*(n*e-cxmin)/w); |
dc.MoveTo(x,y0); dc.LineTo(x,y0-D); |
dc.MoveTo(x,y0); dc.LineTo(x,y0-D); |
sprintf(buf,"%g",n*e); |
sprintf(buf,"%g",n*e); |
dc.TextOut(x+2,y0+2,buf,strlen(buf)); |
dc.TextOut(x+2,y0+2,buf,strlen(buf)); |
} |
} |
w = can->ymax-can->ymin; |
w = cymax-cymin; |
w1 = w * DEFAULTHEIGHT/can->height; |
w1 = w * DEFAULTHEIGHT/ch; |
e = adjust_scale(EXP10(floor(log10(w1))),w1); |
e = adjust_scale(EXP10(floor(log10(w1))),w1); |
for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) { |
for ( n = ceil(cymin/e); n*e<= cymax; n++ ) { |
y = (int)can->height*(1-(n*e-can->ymin)/w); |
y = (int)(ch*(1-(n*e-cymin)/w)); |
dc.MoveTo(x0,y); dc.LineTo(x0+D,y); |
dc.MoveTo(x0,y); dc.LineTo(x0+D,y); |
sprintf(buf,"%g",n*e); |
sprintf(buf,"%g",n*e); |
if ( can->xmax <= 0 ) { |
if ( cxmax <= 0 ) { |
xadj = dc.GetOutputTextExtent(buf,strlen(buf)).cx; |
xadj = dc.GetOutputTextExtent(buf,strlen(buf)).cx; |
} |
} |
dc.TextOut(x0+2-xadj,y+2,buf,strlen(buf)); |
dc.TextOut(x0+2-xadj,y+2,buf,strlen(buf)); |
Line 268 void CChildView::DestroyCanvas() { |
|
Line 293 void CChildView::DestroyCanvas() { |
|
void CChildView::OnOptNoaxis() |
void CChildView::OnOptNoaxis() |
{ |
{ |
// TODO: この位置にコマンド ハンドラ用のコードを追加してください |
// TODO: この位置にコマンド ハンドラ用のコードを追加してください |
can->noaxis = !can->noaxis; |
canvas_toggle_noaxis(can); |
RedrawWindow(); |
RedrawWindow(); |
} |
} |
|
|
void CChildView::OnUpdateOptNoaxis(CCmdUI* pCmdUI) |
void CChildView::OnUpdateOptNoaxis(CCmdUI* pCmdUI) |
{ |
{ |
// TODO: この位置に command update UI ハンドラ用のコードを追加してください |
// TODO: この位置に command update UI ハンドラ用のコードを追加してください |
pCmdUI->SetCheck(can->noaxis); |
pCmdUI->SetCheck(canvas_noaxis(can)); |
} |
} |
|
|
void CChildView::OnOptPrecise() |
void CChildView::OnOptPrecise() |
{ |
{ |
// TODO: この位置にコマンド ハンドラ用のコードを追加してください |
// TODO: この位置にコマンド ハンドラ用のコードを追加してください |
can->precise = !can->precise; |
canvas_toggle_precise(can); |
} |
} |
|
|
void CChildView::OnUpdateOptPrecise(CCmdUI* pCmdUI) |
void CChildView::OnUpdateOptPrecise(CCmdUI* pCmdUI) |
{ |
{ |
// TODO: この位置に command update UI ハンドラ用のコードを追加してください |
// TODO: この位置に command update UI ハンドラ用のコードを追加してください |
pCmdUI->SetCheck(can->precise); |
pCmdUI->SetCheck(canvas_precise(can)); |
} |
} |
|
|
void CChildView::OnOptWide() |
void CChildView::OnOptWide() |
{ |
{ |
// TODO: この位置にコマンド ハンドラ用のコードを追加してください |
// TODO: この位置にコマンド ハンドラ用のコードを追加してください |
can->wide = !can->wide; |
canvas_toggle_wide(can); |
RedrawWindow(); |
RedrawWindow(); |
} |
} |
|
|
void CChildView::OnUpdateOptWide(CCmdUI* pCmdUI) |
void CChildView::OnUpdateOptWide(CCmdUI* pCmdUI) |
{ |
{ |
// TODO: この位置に command update UI ハンドラ用のコードを追加してください |
// TODO: この位置に command update UI ハンドラ用のコードを追加してください |
pCmdUI->SetCheck(can->wide); |
pCmdUI->SetCheck(canvas_wide(can)); |
} |
} |