Impressionist Setup

If you unpack the distribution onto your Z: drive, you should only need to do this once, no matter which machine you use.
  1. The lab machines already have Tcl/Tk installed, but if you are working from home, or somewhere that doesn't have Tcl installed, you can download it from www.scriptics.com. You want version 8.2.
  2. Download the project distribution off the web and unzip it. I will assume that I've unzipped the distribution in the "Z:\FOO" directory; you'll have to change these instructions to correspond to where you unzip it.

  3. Now you need to set up an environment variable. You only need to do this once; it should persist when you log out and log back in. In NT, you go to the System control panel, and click the Environment tab. In the Variable: box, type in the name of the variable, and in the Value: put value you want. Click Set, and then the new variable should be listed in "User Variables".

    Create a variable "TCL" with the path where Tcl was installed (on the lab machines this is "D:\Program Files\Tcl").

  4. Now build the project. To enter MSVC, click on the Impressionist.dsw file, and to compile, click on the "Build/Compile" menu. Once compiled, you'll have a .dll that Tcl is able to load.

  5. Now you should be able to start the program. Go to your distribution directory and click on the file "impressionist.tcl". This is a Tcl/Tk script that will load your .dll and run it.
  6. A much better way of running your program is to tell MSVC to run the script for you. The method I'm about to prescribe will also let you send debug information to the MSVC debug window, thus it's a pretty important step!
    1. Choose Project > Settings... to bring up the configuration dialog.

      1. At the upper left there is a dropdown labeled Settings For:. Select "All configurations."
      2. Click the Debug tab.
      3. In "Executable for debug session:", put the value of your TCL environment variable, plus the string "\bin\wish82.exe". Note that you can't use "$(TCL)", you have to type in the path yourself (thank you, Microsoft). For the lab machines, you'll put in:
        d:\program files\tcl\bin\wish82.exe
        
      4. In "Program arguments:", put "Impressionist.tcl".

      Now when you debug from within MSVC (Build > Start Debug > Go, or press F5), it will start the program for you. When you run the program this way, you're also able to print messages to the MFC debug window. If you look in Impressionist.cpp you'll see a function called Debug -- this function works just like printf, but will output to MSVC. You must run your project in debug mode Build/Debug/Go (or F5) to see any output.

    Adding interactive controls

    The skeleton code has a few widgets that let you change the size and select the dot brush. You will be adding several more controls, and to do so you will use pre-written widget functions. Let's step through how to make a slider to control line width. Each control widget that you want must have a unique integer ID. To keep these straight, we recommend using #define'd constants. Stick
    #define LINE_WIDTH  1
    
    somewhere at the top of your impressionist.h. Note that this doesn't mean the thickness of the line is 1, it means that control #1 is going to control the thickness. We can use any number as the ID, as long as it is unique in the model.

    CreateControlMenu in impressionist.cpp is where we create the widgets. The available commands to create widgets are listed below. The first argument to each one should be the interp argument passed to CreateControlMenu; just pass it straight through.

    scale( interp, id, name, min, max, res, start )
    Create a slider widget. res is the resolution of the slider (the smallest amount you can move it). start is the initial value. name, as in all these calls, is a string that labels the widget.

    checkbox( interp, id, name, start )
    Create a checkbox. start is the initial setting.

    radiobutton( interp, id, name, start, ... )
    menu( interp, id, name, start, ... )
    Create a selection widget - either a set of radio buttons or a menu of choices. The "..." arguments are one or more strings, terminated with NULL - these are the available choices. They are numbered choice 0, 1, 2, and so on. start is the initial selection.

    Let's create a slider for the line. In CreateControlMenu, add these lines:
    scale( interp, LINE_WIDTH, "Line width", 1.0, 5.0, 1.0, 1.0 );
    
    Now, in the brush functions, we need to read the current value of the slider. Widget settings can be read with the get_control_* functions, where "*" is one of "d" (to read a double), "i" (to read an int), or "b" (to read a boolean). You pass the function the ID of the control whose value you want. Widget settings can also be changed with the set_control_* functions

    For example, we would get the current position of our slider with the following call:

    double width = get_control_d( LINE_WIDTH);
    
    Now when you start the program, there will be a slider added to the main window.