35 PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_ntk = 
"ntk:New tk driver:1:ntk:43:ntk\n";
    41 void plD_line_ntk( 
PLStream *, 
short, 
short, 
short, 
short );
    51 #ifndef ENABLE_DYNDRIVERS    71 static PLFLT      scale = 10.0;   
    74 static Tcl_Interp *
interp = NULL; 
    75 static Tk_Window  mainw;          
    77 static char       curcolor[80];   
    81 #define PLPLOT_NTK_CMD_SIZE    48000    82 static char cmd[PLPLOT_NTK_CMD_SIZE]; 
    89 static short xold = -1, yold = -1; 
    91 static int   curpts = 0;           
    94 static char  rem_interp[80];       
    97 static PLINT xmin = 0;
    98 static PLINT xmax = XPIXELS;
    99 static PLINT ymin = 0;
   100 static PLINT ymax = YPIXELS;
   106 tk_cmd( 
const char *gcmd )
   108     static char scmd[PLPLOT_NTK_CMD_SIZE];
   118         sprintf( scmd, 
"send %s {%s}", rem_interp, gcmd ); 
   119         if ( Tcl_Eval( 
interp, scmd ) != TCL_OK )
   120             fprintf( stderr, 
"%s\n", Tcl_GetStringResult( 
interp ) );
   130     columnbreak = ( ccanv % 30 == 0 );
   133     sprintf( cmd, 
"set ccanv %d; canvas $plf.f2.c$ccanv -width $xmax -height $ymax -background #%02x%02x%02x -xscrollcommand \"$hs set\" -yscrollcommand \"$vs set\" -scrollregion \"0 0 $xmax $ymax\"", ccanv, pls->
cmap0[0].
r, pls->
cmap0[0].
g, pls->
cmap0[0].
b );
   137     sprintf( cmd, 
"$plf.f1.mb.menu add command -label \"Page $ccanv\" -columnbreak %d -command {\n"   138         "set w $plf.f2.c%d;\n"   139         "$hs configure -command \"$w xview\";\n"   140         "$vs configure -command \"$w yview\";\n"   141         "set dname \"Page %d\";\n"   142         "pack forget $ocanvas;\n"   143         "set ocanvas $plf.f2.c%d;\n"   144         "pack $ocanvas -fill both -expand 1;\n"   145         "scan [$w xview] \"%%f %%f\" i j;\n"   147         "scan [$w yview] \"%%f %%f\" i j;\n"   149         columnbreak, ccanv, ccanv, ccanv );
   152     sprintf( cmd, 
"set item(%d) 0", ccanv );
   158     sprintf( cmd, 
"bind $plf.f2.c$ccanv <Shift-Button-1> {\n"   160         "incr item($cc); set tt $item($cc);\n"   163         "pack $hs -side bottom -fill x;\n"   164         "pack $vs -side right -fill y;\n"   165         "pack forget %%W; pack %%W -fill both -expand 1}\n"   166         "set zx($cc,$tt) %%x;\n"   167         "set zy($cc,$tt) %%y;\n"   168         "%%W scale all %%x %%y 1.6 1.6;\n"   169         "%%W configure -scrollregion [%%W bbox all];\n"   175     sprintf( cmd, 
"bind $plf.f2.c$ccanv <Shift-Button-3> {\n"   176         "set cc %d; set tt $item($cc);\n"   178         "%%W scale all $zx($cc,$tt) $zy($cc,$tt) 0.625 0.625\n"   179         "%%W configure -scrollregion [%%W bbox all];\n"   180         "set item($cc) [expr $tt - 1]}\n"   181         "if { $item($cc) == 0} {\n"   182         "set scroll_use [expr $scroll_use - 1];\n"   183         "if {$scroll_use == 0} {\n"   184         "pack forget $plf.f2.hscroll $plf.f2.vscroll}\n"   185         "%%W configure -scrollregion \"0 0 $xmax $ymax\"}}", ccanv );
   189     sprintf( cmd, 
"bind $plf.f2.c$ccanv <Shift-Button-2> {\n"   190         "set cc %d; set tt $item($cc); \n"   191         "while {$tt != 0} {\n"   192         "%%W scale all $zx($cc,$tt) $zy($cc,$tt) 0.625 0.625\n"   193         "set tt [expr $tt - 1]};\n"   195         "%%W configure -scrollregion \"0 0 $xmax $ymax\";\n"   196         "set scroll_use [expr $scroll_use - 1];\n"   197         "if {$scroll_use == 0} {\n"   198         "pack forget $plf.f2.hscroll $plf.f2.vscroll}}", ccanv );
   202     sprintf( cmd, 
"bind $plf.f2.c$ccanv <Control-Button-1> \"$plf.f2.c%d scan mark %%x %%y\"", ccanv );
   205     sprintf( cmd, 
"bind $plf.f2.c$ccanv <Control-Button1-Motion> \"$plf.f2.c%d scan dragto %%x %%y\"", ccanv );
   209     tk_cmd( 
"bind $plf.f2.c$ccanv <Control-Button-2> {\n"   210         "set xx [ expr [winfo pointerx .] - [winfo rootx %W]];\n"   211         "set yy [ expr [winfo pointery .] - [winfo rooty %W]];\n"   212         "set near [%W find closest $xx $yy];\n"   213         "%W move $near 20 20;\n"   214         "after 500 \"%W move $near -20 -20\"}" );
   217     sprintf( cmd, 
"$plf.f1.mb.menu invoke %d", ccanv - 1 );
   236     strcpy( curcolor, 
"black" ); 
   245         sscanf( pls->
geometry, 
"%dx%d", &xmax, &ymax );
   250     strcpy( base, 
".plf" );     
   252     interp = Tcl_CreateInterp();
   254     if ( Tcl_Init( 
interp ) != TCL_OK )
   255         plexit( 
"Unable to initialize Tcl." );
   258         plexit( 
"Unable to initialize Tk." );
   260     mainw = Tk_MainWindow( 
interp );
   261     Tcl_Eval( 
interp, 
"rename exec {}" );
   263     Tcl_Eval( 
interp, 
"tk appname PLplot_ntk" ); 
   267         Tcl_Eval( 
interp, 
"wm withdraw ." );
   269         sprintf( cmd, 
"send %s \"set client [tk appname]; wm deiconify .\"", rem_interp );
   270         if ( Tcl_Eval( 
interp, cmd ) != TCL_OK )
   272             fprintf( stderr, 
"%s\n", Tcl_GetStringResult( 
interp ) );
   273             plexit( 
"No such tk server." );
   277     sprintf( cmd, 
"set scroll_use 0; set plf %s; set vs $plf.f2.vscroll; set hs $plf.f2.hscroll; set xmax %d; set ymax %d; set ocanvas .;", base, xmax, ymax );
   280     tk_cmd( 
"catch \"frame $plf\"; pack $plf -fill both -expand 1" );
   282     sprintf( cmd, 
"frame $plf.f1;\n"   283         "frame $plf.f2 -width %d -height %d;\n"   284         "pack $plf.f1 -fill x;\n"   285         "pack $plf.f2 -fill both -expand 1", xmax, ymax );
   288     tk_cmd( 
"scrollbar $plf.f2.hscroll -orient horiz;\n"   289         "scrollbar $plf.f2.vscroll" );
   291     tk_cmd( 
"menubutton $plf.f1.mb -text \"Page 1\" -textvariable dname -relief raised -indicatoron 1 -menu $plf.f1.mb.menu;\n"   292         "menu $plf.f1.mb.menu -tearoff 0;\n"   293         "pack $plf.f1.mb -side left" );
   296         tk_cmd( 
"button $plf.f1.quit -text Quit -command exit;\n"   297             "pack $plf.f1.quit -side right" );
   299         tk_cmd( 
"button $plf.f1.quit -text Quit -command {send -async $client exit;\n"   302             "pack $plf.f1.quit -side right" );
   308     Tcl_Eval( 
interp, 
"tk scaling" ); 
   309     ppm = (
PLFLT) atof( Tcl_GetStringResult( 
interp ) ) / ( 25.4 / 72. );
   321         plD_polyline_ntk( pls, xb, yb, curpts );
   323         xold = yold = -1; curpts = 0;
   328 plD_line_ntk( 
PLStream *pls, 
short x1a, 
short y1a, 
short x2a, 
short y2a )
   330     if ( xold == x1a && yold == y1a )
   332         xold = xb[curpts] = x2a; yold = yb[curpts] = y2a; curpts++;
   337         xb[curpts] = x1a; yb[curpts] = y1a; curpts++;
   338         xold       = xb[curpts] = x2a; yold = yb[curpts] = y2a; curpts++;
   341     if ( curpts == 
NPTS )
   354     j = sprintf( cmd, 
"$plf.f2.c%d create line ", ccanv );
   355     for ( i = 0; i < npts; i++ )
   360         if ( ( j + 16 ) > PLPLOT_NTK_CMD_SIZE )
   361             plexit( 
"plD_polyline_ntk: too many x, y values to hold in static cmd array" );
   362         j += sprintf( &cmd[j], 
"%.1f %.1f ", xa[i] / scale, ymax - ya[i] / scale );
   364     j += sprintf( &cmd[j], 
" -fill %s", curcolor );
   365     if ( dash[0] == 
'-' )
   366         j += sprintf( &cmd[j], 
" %s", dash );
   379     tk_cmd( 
"bind . <KeyPress> {set keypress %N}" );
   386             tk_cmd( 
"info exists keypress" );
   387             sscanf( Tcl_GetStringResult( 
interp ), 
"%d", &st );
   390         tk_cmd( 
"set keypress" );
   391         sscanf( Tcl_GetStringResult( 
interp ), 
"%d", &key );
   393         tk_cmd( 
"unset keypress" );
   397     tk_cmd( 
"bind . <Key> {};" );
   410     create_canvas( pls );
   419     tk_cmd( 
"destroy $plf; wm withdraw ." );
   430         sprintf( curcolor, 
"#%02x%02x%02x",
   448             tk_cmd( 
"winfo exists $plf.f2.c$ccanv" );
   449             sscanf( Tcl_GetStringResult( 
interp ), 
"%d", &st );
   453         tk_cmd( 
"set ocursor [lindex [$plf.f2.c$ccanv configure -cursor] 4]" );
   456     tk_cmd( 
"$plf.f2.c$ccanv configure -cursor cross;\n"   457         "bind $plf.f2.c$ccanv <Button> {set xloc %x; set yloc %y; set bloc %b; set sloc %s};\n"   458         "bind $plf.f2.c$ccanv <B1-Motion> {set xloc %x; set yloc %y; set bloc %b; set sloc %s};\n"   459         "bind $plf.f2.c$ccanv <B2-Motion> {set xloc %x; set yloc %y; set bloc %b; set sloc %s};\n"   460         "bind $plf.f2.c$ccanv <B3-Motion> {set xloc %x; set yloc %y; set bloc %b; set sloc %s};" );
   465         tk_cmd( 
"info exists xloc" );
   466         sscanf( Tcl_GetStringResult( 
interp ), 
"%d", &st );
   468     tk_cmd( 
"set xloc" );
   469     sscanf( Tcl_GetStringResult( 
interp ), 
"%d", &gin.
pX );
   470     tk_cmd( 
"set yloc" );
   471     sscanf( Tcl_GetStringResult( 
interp ), 
"%d", &gin.
pY );
   472     tk_cmd( 
"set bloc" );
   473     sscanf( Tcl_GetStringResult( 
interp ), 
"%ud", &gin.
button );
   474     tk_cmd( 
"set sloc" );
   475     sscanf( Tcl_GetStringResult( 
interp ), 
"%ud", &gin.
state );
   480     tk_cmd( 
"bind $plf.f2.c$ccanv <ButtonPress> {};\n"   481         "bind $plf.f2.c$ccanv <ButtonMotion> {};\n"   482         "bind $plf.f2.c$ccanv <B2-Motion> {};\n"   483         "bind $plf.f2.c$ccanv <B3-Motion> {};\n"   487     tk_cmd( 
"$plf.f2.c$ccanv configure -cursor {}" );
   498     static const unsigned char bit_pat[] = {
   499         0x24, 0x01, 0x92, 0x00, 0x49, 0x00, 0x24, 0x00, 0x12, 0x00, 0x09, 0x00,
   500         0x04, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   501         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff
   507         xa = (
short *) malloc( 
sizeof ( 
short ) * (size_t) pls->
dev_npts );
   508         ya = (
short *) malloc( 
sizeof ( 
short ) * (size_t) pls->
dev_npts );
   509         for ( i = 0; i < pls->
dev_npts; i++ )
   511             xa[i] = pls->
dev_x[i];
   512             ya[i] = pls->
dev_y[i];
   515         j = sprintf( dash, 
"-dash {" );
   516         for ( i = 0; i < pls->
nms; i++ )
   517             j += sprintf( &dash[j], 
" %d %d",
   518                 (
int) ceil( pls->
mark[i] / 1e3 * ppm ),
   519                 (
int) ceil( pls->
space[i] / 1e3 * ppm ) );
   520         sprintf( &dash[j], 
"}" );
   521         plD_polyline_ntk( pls, xa, ya, pls->
dev_npts );
   522         free( xa ); free( ya );
   535         if ( pls->
patt != 0 )
   546             j = sprintf( cmd, 
"$plf.f2.c%d create polygon ", ccanv );
   547             for ( i = 0; i < pls->
dev_npts; i++ )
   548                 j += sprintf( &cmd[j], 
"%.1f %.1f ", pls->
dev_x[i] / scale,
   549                     ymax - pls->
dev_y[i] / scale );
   550             j += sprintf( &cmd[j], 
" -fill %s", curcolor );
   556             if ( pls->
patt != 0 )
   558                 Tk_DefineBitmap( 
interp, Tk_GetUid( 
"foo" ), (
const char *) bit_pat, 16, 16 );
   561             j = sprintf( cmd, 
"$plf.f2.c%d create polygon ", ccanv );
   562             for ( i = 0; i < pls->
dev_npts; i++ )
   563                 j += sprintf( &cmd[j], 
"%.1f %.1f ", pls->
dev_x[i] / scale,
   564                     ymax - pls->
dev_y[i] / scale );
   565             j += sprintf( &cmd[j], 
" -fill %s", curcolor );
   566             if ( pls->
patt != 0 )
   567                 sprintf( &cmd[j], 
" -stipple patt -outline black" );
 
void plexit(PLCHAR_VECTOR errormsg)
void(* plD_tidy_fp)(struct PLStream_struct *)
void plGinInit(PLGraphicsIn *gin)
void(* plD_init_fp)(struct PLStream_struct *)
void(* plD_eop_fp)(struct PLStream_struct *)
void(* plD_line_fp)(struct PLStream_struct *, short, short, short, short)
void(* plD_esc_fp)(struct PLStream_struct *, PLINT, void *)
void(* plD_polyline_fp)(struct PLStream_struct *, short *, short *, PLINT)
void plP_setpxl(PLFLT xpmm, PLFLT ypmm)
PLDLLIMPEXP_DRIVER void plD_dispatch_init_ntk(PLDispatchTable *pdt)
#define PLDLLIMPEXP_DRIVER
static PLStream * pls[PL_NSTREAMS]
void plP_setphy(PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax)
void plfill_soft(short *x, short *y, PLINT n)
void(* plD_bop_fp)(struct PLStream_struct *)
static Tcl_Interp * interp
plD_polyline_fp pl_polyline
void(* plD_state_fp)(struct PLStream_struct *, PLINT)