DrawPalette.cpp

Go to the documentation of this file.
00001 //DrawPalette.cpp
00002 
00003 /*************************************************************/
00004 //
00005 // DrawPaletteDialog
00006 //
00007 // Object drawing palette
00008 //
00009 //-------------------------------------------------------------
00010 //
00011 // v 1.3 - 2007/02/17 - Added distance display
00012 // v 1.2 - 2007/02/08 - Save draw directory
00013 // v 1.1 - 2007/02/07 - Fixed positioning of elements
00014 // v 1.0 - 2007/01/06 - Initial release
00015 //
00016 // See LICENSE.txt for distribution and usage restrictions
00017 // Copyright (c) 2006-2007 Simon Chorley
00018 // www.mylaboratory.co.uk - greylab@mylaboratory.co.uk
00019 //
00020 /*************************************************************/
00021 
00022 
00023 ///Drawing palette (Implementation)
00024 /**
00025  * Provides implementation of DrawPaletteDialog window class to manage creation of drawing primatives on the colourscale and linescan graphs.
00026  * @file DrawPalette.cpp
00027  * @version 1.3 - 2007/02/17
00028  */
00029 
00030 
00031 #include "DrawPalette.h"
00032 
00033 
00034 #include "GreyLab.h"
00035 
00036 
00037 #include <fstream>
00038 
00039 
00040 FXDEFMAP(DrawPaletteDialog) DrawPaletteDialogMap[]={
00041         FXMAPFUNC(SEL_COMMAND,                  DrawPaletteDialog::ID_DRAW_CHANGED,                     DrawPaletteDialog::cmdUpdateData),
00042         FXMAPFUNC(SEL_CHANGED,                  DrawPaletteDialog::ID_DRAW_CHANGED,                     DrawPaletteDialog::cmdUpdateData),
00043 
00044         FXMAPFUNC(SEL_COMMAND,                  DrawPaletteDialog::ID_DRAW_NEWLINE,                     DrawPaletteDialog::cmdNewLine),
00045         FXMAPFUNC(SEL_COMMAND,                  DrawPaletteDialog::ID_DRAW_NEWTEXT,                     DrawPaletteDialog::cmdNewText),
00046         FXMAPFUNC(SEL_COMMAND,                  DrawPaletteDialog::ID_DRAW_NEWRECT,                     DrawPaletteDialog::cmdNewRect),
00047         FXMAPFUNC(SEL_COMMAND,                  DrawPaletteDialog::ID_DRAW_NEWELLIPSE,          DrawPaletteDialog::cmdNewEllipse),
00048         FXMAPFUNC(SEL_COMMAND,                  DrawPaletteDialog::ID_DRAW_NEWIMAGE,            DrawPaletteDialog::cmdNewImage),
00049         FXMAPFUNC(SEL_COMMAND,                  DrawPaletteDialog::ID_DRAW_NEWFUNCTION,         DrawPaletteDialog::cmdNewFunction),
00050 
00051         FXMAPFUNC(SEL_COMMAND,                  DrawPaletteDialog::ID_DRAW_ITEMDN,                      DrawPaletteDialog::cmdItemUp),
00052         FXMAPFUNC(SEL_COMMAND,                  DrawPaletteDialog::ID_DRAW_ITEMUP,                      DrawPaletteDialog::cmdItemDown),
00053 
00054         FXMAPFUNC(SEL_SELECTED,                 DrawPaletteDialog::ID_DRAW_ITEMSEL,                     DrawPaletteDialog::cmdItemSelect),
00055         FXMAPFUNC(SEL_DOUBLECLICKED,    DrawPaletteDialog::ID_DRAW_ITEMSEL,                     DrawPaletteDialog::cmdItemDelete),
00056 
00057         FXMAPFUNC(SEL_COMMAND,                  DrawPaletteDialog::ID_DRAW_IMAGEBROWSE,         DrawPaletteDialog::cmdImageBrowse),
00058 
00059         FXMAPFUNC(SEL_COMMAND,                  DrawPaletteDialog::ID_DRAW_NEW,                         DrawPaletteDialog::cmdNew),
00060         FXMAPFUNC(SEL_COMMAND,                  DrawPaletteDialog::ID_DRAW_LOAD,                        DrawPaletteDialog::cmdLoad),
00061         FXMAPFUNC(SEL_COMMAND,                  DrawPaletteDialog::ID_DRAW_APPEND,                      DrawPaletteDialog::cmdAppend),
00062         FXMAPFUNC(SEL_COMMAND,                  DrawPaletteDialog::ID_DRAW_SAVE,                        DrawPaletteDialog::cmdSave),
00063         FXMAPFUNC(SEL_COMMAND,                  DrawPaletteDialog::ID_DRAW_SAVEAS,                      DrawPaletteDialog::cmdSaveAs)
00064 
00065 };
00066 
00067 
00068 FXIMPLEMENT(DrawPaletteDialog, FXDialogBox, DrawPaletteDialogMap, ARRAYNUMBER(DrawPaletteDialogMap))
00069 
00070 
00071 DrawPaletteDialog::~DrawPaletteDialog()
00072 {
00073 }
00074 
00075 
00076 ///Palette window class constructor
00077 /**
00078  * @param owner Parent window object.
00079  * @param target Graph to draw primatives onto.
00080  */
00081 DrawPaletteDialog::DrawPaletteDialog(FXWindow* owner, int target) : FXDialogBox(owner, "Drawing Palette", DECOR_TITLE|DECOR_CLOSE)
00082 {
00083         FXVerticalFrame *frame = new FXVerticalFrame(this, LAYOUT_FILL_X|LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0);
00084 
00085         FXHorizontalFrame *penFrame = new FXHorizontalFrame(frame, LAYOUT_TOP|LAYOUT_FILL_X|FRAME_NONE, 0, 0, 0, 0, 0, 0, 0, 0);
00086         new FXLabel(penFrame, "FG:", NULL, LAYOUT_SIDE_TOP|LAYOUT_LEFT|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00087         drawfgColourwell = new FXColorWell(penFrame, FXRGBA(0,0,0, 255), this, ID_DRAW_CHANGED, LAYOUT_SIDE_TOP|LAYOUT_FIX_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y, 0, 0, 50, 0);
00088         new FXLabel(penFrame, " BG:", NULL, LAYOUT_SIDE_TOP|LAYOUT_LEFT|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00089         drawbgColourwell = new FXColorWell(penFrame, FXRGBA(255,255,255, 0), this, ID_DRAW_CHANGED, LAYOUT_SIDE_TOP|LAYOUT_FIX_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y, 0, 0, 50, 0);
00090         new FXLabel(penFrame, " Stroke:", NULL, LAYOUT_SIDE_TOP|LAYOUT_LEFT|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00091         drawstrokeTextfield = new FXTextField(penFrame, 2, this, ID_DRAW_CHANGED, TEXTFIELD_INTEGER|FRAME_SUNKEN|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00092 
00093         FXHorizontalFrame *posFrame = new FXHorizontalFrame(frame, LAYOUT_TOP|LAYOUT_FILL_X|FRAME_NONE, 0, 0, 0, 0, 0, 0, 0, 0);
00094         new FXLabel(posFrame, "Position:", NULL, LAYOUT_SIDE_TOP|LAYOUT_LEFT|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00095         drawxposTextfield = new FXTextField(posFrame, 8, this, ID_DRAW_CHANGED, TEXTFIELD_REAL|FRAME_SUNKEN|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00096         drawyposTextfield = new FXTextField(posFrame, 8, this, ID_DRAW_CHANGED, TEXTFIELD_REAL|FRAME_SUNKEN|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00097         drawbasisPopup = new FXPopup(this);
00098         drawaxisOption = new FXOption(drawbasisPopup, "Axes space\tCo-ordinates based on axes values\tCo-ordinates based on axes values", NULL, this, ID_DRAW_CHANGED, JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00099         drawfractionalOption = new FXOption(drawbasisPopup, "Image fractional\tCo-ordinates are a percentage of the whole image\tCo-ordinates are a percentage of the whole image", NULL, this, ID_DRAW_CHANGED, JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00100         drawabsoluteOption = new FXOption(drawbasisPopup, "Absolute\tCo-ordinates are absolute\tCo-ordinates are absolute", NULL, this, ID_DRAW_CHANGED, JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00101         drawaxisfractionalOption = new FXOption(drawbasisPopup, "Axes fractional\tCo-ordinates are a percentage of the axes\tCo-ordinates are a percentage of the axes", NULL, this, ID_DRAW_CHANGED, JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00102         drawborderOption = new FXOption(drawbasisPopup, "Border fractional\tCo-ordinates are positioned in the image borders\tCo-ordinates are positioned in the image borders", NULL, this, ID_DRAW_CHANGED, JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00103         drawbasisOptionmenu = new FXOptionMenu(posFrame, drawbasisPopup, LAYOUT_CENTER_Y|FRAME_RAISED|JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00104 
00105         FXHorizontalFrame *dimsFrame = new FXHorizontalFrame(frame, LAYOUT_TOP|LAYOUT_FILL_X|FRAME_NONE, 0, 0, 0, 0, 0, 0, 0, 0);
00106         new FXLabel(dimsFrame, "Dimensions:", NULL, LAYOUT_SIDE_TOP|LAYOUT_LEFT|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00107         drawxsizeTextfield = new FXTextField(dimsFrame, 8, this, ID_DRAW_CHANGED, TEXTFIELD_REAL|FRAME_SUNKEN|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00108         drawysizeTextfield = new FXTextField(dimsFrame, 8, this, ID_DRAW_CHANGED, TEXTFIELD_REAL|FRAME_SUNKEN|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00109         drawsizebasisPopup = new FXPopup(this);
00110         drawsizeaxisOption = new FXOption(drawsizebasisPopup, "Axes space\tCo-ordinates based on axes values\tCo-ordinates based on axes values", NULL, this, ID_DRAW_CHANGED, JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00111         drawsizefractionalOption = new FXOption(drawsizebasisPopup, "Image fractional\tCo-ordinates are a percentage of the whole image\tCo-ordinates are a percentage of the whole image", NULL, this, ID_DRAW_CHANGED, JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00112         drawsizeabsoluteOption = new FXOption(drawsizebasisPopup, "Absolute\tCo-ordinates are absolute\tCo-ordinates are absolute", NULL, this, ID_DRAW_CHANGED, JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00113         drawsizeaxisfractionalOption = new FXOption(drawsizebasisPopup, "Axes fractional\tCo-ordinates are a percentage of the axes\tCo-ordinates are a percentage of the axes", NULL, this, ID_DRAW_CHANGED, JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00114         drawsizeborderOption = new FXOption(drawsizebasisPopup, "Border fractional\tCo-ordinates are positioned in the image borders\tCo-ordinates are positioned in the image borders", NULL, this, ID_DRAW_CHANGED, JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00115         drawsizebasisOptionmenu = new FXOptionMenu(dimsFrame, drawsizebasisPopup, LAYOUT_CENTER_Y|FRAME_RAISED|JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00116 
00117         drawobjectSwitcher = new FXSwitcher(frame, LAYOUT_FILL_X, 0, 0, 0, 0, 0, 0, 0, 0);
00118 
00119         FXHorizontalFrame *arrowFrame = new FXHorizontalFrame(drawobjectSwitcher, LAYOUT_TOP|LAYOUT_FILL_X|FRAME_NONE, 0, 0, 0, 0, 0, 0, 0, 0);
00120         drawstartarrowCheckbutton = new FXCheckButton(arrowFrame, "Start arrow", this, ID_DRAW_CHANGED, CHECKBUTTON_NORMAL|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00121         drawendarrowCheckbutton = new FXCheckButton(arrowFrame, "End arrow", this, ID_DRAW_CHANGED, CHECKBUTTON_NORMAL|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00122         new FXLabel(arrowFrame, "Size:", NULL, LAYOUT_SIDE_TOP|LAYOUT_LEFT|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00123         drawarrowlengthTextfield = new FXTextField(arrowFrame, 5, this, ID_DRAW_CHANGED, TEXTFIELD_REAL|FRAME_SUNKEN|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00124         drawarrowwidthTextfield = new FXTextField(arrowFrame, 5, this, ID_DRAW_CHANGED, TEXTFIELD_REAL|FRAME_SUNKEN|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00125 
00126         FXHorizontalFrame *textFrame = new FXHorizontalFrame(drawobjectSwitcher, LAYOUT_TOP|LAYOUT_FILL_X|FRAME_NONE, 0, 0, 0, 0, 0, 0, 0, 0);
00127         new FXLabel(textFrame, "Text:", NULL, LAYOUT_SIDE_TOP|LAYOUT_LEFT|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00128         drawtextTextfield = new FXTextField(textFrame, 37, this, ID_DRAW_CHANGED, FRAME_SUNKEN|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00129         drawjustifyPopup = new FXPopup(this);
00130         drawtljustifyOption = new FXOption(drawjustifyPopup, "TL\tTop-left justified\tTop-left justified", NULL, this, ID_DRAW_CHANGED, JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00131         drawtrjustifyOption = new FXOption(drawjustifyPopup, "TR\tTop-right justified\tTop-right justified", NULL, this, ID_DRAW_CHANGED, JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00132         drawbljustifyOption = new FXOption(drawjustifyPopup, "BL\tBottom-left justified\tBottom-left justified", NULL, this, ID_DRAW_CHANGED, JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00133         drawbrjustifyOption = new FXOption(drawjustifyPopup, "BR\tBottom-right justified\tBottom-right justified", NULL, this, ID_DRAW_CHANGED, JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00134         drawcjustifyOption = new FXOption(drawjustifyPopup, "C\tCentre justified\tCentre justified", NULL, this, ID_DRAW_CHANGED, JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00135         drawjustifyOptionmenu = new FXOptionMenu(textFrame, drawjustifyPopup, LAYOUT_CENTER_Y|FRAME_RAISED|JUSTIFY_HZ_APART|ICON_AFTER_TEXT);
00136 
00137         FXHorizontalFrame *rectangleFrame = new FXHorizontalFrame(drawobjectSwitcher, LAYOUT_TOP|LAYOUT_FILL_X|FRAME_NONE, 0, 0, 0, 0, 0, 0, 0, 0);
00138         FXHorizontalFrame *ellipseFrame = new FXHorizontalFrame(drawobjectSwitcher, LAYOUT_TOP|LAYOUT_FILL_X|FRAME_NONE, 0, 0, 0, 0, 0, 0, 0, 0);
00139 
00140         FXHorizontalFrame *imageFrame = new FXHorizontalFrame(drawobjectSwitcher, LAYOUT_TOP|LAYOUT_FILL_X|FRAME_NONE, 0, 0, 0, 0, 0, 0, 0, 0);
00141         new FXLabel(imageFrame, "Image:", NULL, LAYOUT_SIDE_TOP|LAYOUT_LEFT|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00142         drawimageTextfield = new FXTextField(imageFrame, 30, this, ID_DRAW_CHANGED, FRAME_SUNKEN|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00143         new FXButton(imageFrame, "...", NULL, this, ID_DRAW_IMAGEBROWSE, FRAME_RAISED|LAYOUT_LEFT|ICON_BEFORE_TEXT);
00144 
00145         FXHorizontalFrame *functionFrame = new FXHorizontalFrame(drawobjectSwitcher, LAYOUT_TOP|LAYOUT_FILL_X|FRAME_NONE, 0, 0, 0, 0, 0, 0, 0, 0);
00146         new FXLabel(functionFrame, "Function:", NULL, LAYOUT_SIDE_TOP|LAYOUT_LEFT|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00147         drawfunctionTextfield = new FXTextField(functionFrame, 25, this, ID_DRAW_CHANGED, FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00148         draw2dCheckbutton = new FXCheckButton(functionFrame, "2D", this, ID_DRAW_CHANGED, CHECKBUTTON_NORMAL|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00149 /*      new FXLabel(functionFrame, "Scale:", NULL, LAYOUT_SIDE_TOP|LAYOUT_LEFT|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00150         drawscaleTextfield = new FXTextField(functionFrame, 4, this, ID_DRAW_CHANGED, TEXTFIELD_REAL|FRAME_SUNKEN|PACK_UNIFORM_WIDTH|LAYOUT_LEFT|LAYOUT_CENTER_Y);*/
00151 
00152         FXHorizontalFrame *labelsFrame = new FXHorizontalFrame(frame, LAYOUT_TOP|LAYOUT_FILL_X|FRAME_NONE, 0, 0, 0, 0, 0, 0, 0, 0);
00153         drawstartlCheckbutton = new FXCheckButton(labelsFrame, "Start coords", this, ID_DRAW_CHANGED, CHECKBUTTON_NORMAL|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00154         drawendlCheckbutton = new FXCheckButton(labelsFrame, "End coords", this, ID_DRAW_CHANGED, CHECKBUTTON_NORMAL|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00155         drawgradlCheckbutton = new FXCheckButton(labelsFrame, "Gradient", this, ID_DRAW_CHANGED, CHECKBUTTON_NORMAL|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00156         drawdistlCheckbutton = new FXCheckButton(labelsFrame, "Distance", this, ID_DRAW_CHANGED, CHECKBUTTON_NORMAL|LAYOUT_LEFT|LAYOUT_CENTER_Y);
00157 
00158         FXHorizontalFrame *newFrame = new FXHorizontalFrame(frame, LAYOUT_TOP|LAYOUT_FILL_X|FRAME_NONE, 0, 0, 0, 0, 0, 0, 0, 0);
00159         new FXButton(newFrame, "  /  ", NULL, this, ID_DRAW_NEWLINE, FRAME_RAISED|LAYOUT_LEFT|ICON_BEFORE_TEXT);
00160         new FXButton(newFrame, "  T  ", NULL, this, ID_DRAW_NEWTEXT, FRAME_RAISED|LAYOUT_LEFT|ICON_BEFORE_TEXT);
00161         new FXButton(newFrame, "  []  ", NULL, this, ID_DRAW_NEWRECT, FRAME_RAISED|LAYOUT_LEFT|ICON_BEFORE_TEXT);
00162         new FXButton(newFrame, "  o  ", NULL, this, ID_DRAW_NEWELLIPSE, FRAME_RAISED|LAYOUT_LEFT|ICON_BEFORE_TEXT);
00163         new FXButton(newFrame, "  i  ", NULL, this, ID_DRAW_NEWIMAGE, FRAME_RAISED|LAYOUT_LEFT|ICON_BEFORE_TEXT);
00164         new FXButton(newFrame, "  ~  ", NULL, this, ID_DRAW_NEWFUNCTION, FRAME_RAISED|LAYOUT_LEFT|ICON_BEFORE_TEXT);
00165         new FXButton(newFrame, " Dn ", NULL, this, ID_DRAW_ITEMDN, FRAME_RAISED|LAYOUT_RIGHT|ICON_BEFORE_TEXT);
00166         new FXButton(newFrame, " Up ", NULL, this, ID_DRAW_ITEMUP, FRAME_RAISED|LAYOUT_RIGHT|ICON_BEFORE_TEXT);
00167 
00168         drawitemsColourlist = new FXColorList(frame, this, ID_DRAW_ITEMSEL, LIST_BROWSESELECT|LAYOUT_FILL_X|LAYOUT_FIX_HEIGHT, 0, 0, 0, 300);
00169 
00170         FXHorizontalFrame *filesFrame = new FXHorizontalFrame(frame, LAYOUT_TOP|LAYOUT_FILL_X|FRAME_NONE, 0, 0, 0, 0, 0, 0, 0, 0);
00171         new FXButton(filesFrame, "Save As", NULL, this, ID_DRAW_SAVEAS, FRAME_RAISED|LAYOUT_RIGHT|ICON_BEFORE_TEXT);
00172         new FXButton(filesFrame, "Save", NULL, this, ID_DRAW_SAVE, FRAME_RAISED|LAYOUT_RIGHT|ICON_BEFORE_TEXT);
00173         new FXButton(filesFrame, "Append", NULL, this, ID_DRAW_APPEND, FRAME_RAISED|LAYOUT_RIGHT|ICON_BEFORE_TEXT);
00174         new FXButton(filesFrame, "Load", NULL, this, ID_DRAW_LOAD, FRAME_RAISED|LAYOUT_RIGHT|ICON_BEFORE_TEXT);
00175         new FXButton(filesFrame, "New", NULL, this, ID_DRAW_NEW, FRAME_RAISED|LAYOUT_RIGHT|ICON_BEFORE_TEXT);
00176 
00177         nPrimatives = 0;
00178         primatives = NULL;
00179 
00180         startpx = 0;
00181         startpy = 0;
00182         startax = 0.0;
00183         startay = 0.0;
00184         currentpx = 0;
00185         currentpy = 0;
00186         
00187         drawing = false;
00188 
00189         updatetarget = target;
00190 }
00191 
00192 
00193 ///Hide palette
00194 void DrawPaletteDialog::hide()
00195 {
00196         this->getOwner()->handle(this, FXSEL(SEL_COMMAND, GreyLabWindow::ID_DRAWMODEOFF), NULL);
00197         FXDialogBox::hide();
00198 }
00199 
00200 
00201 ///Create new primative
00202 /**
00203  * Creates a new primative and initialises it.
00204  * @param p New primative type.
00205  */
00206 void DrawPaletteDialog::createPrimative(primative::typemode p)
00207 {
00208         primative *temp;
00209         if (nPrimatives > 0)
00210         {
00211                 temp = new primative[nPrimatives];
00212                 memcpy(temp, primatives, nPrimatives*sizeof(primative));
00213                 delete[] primatives;
00214                 primatives = new primative[nPrimatives+1];
00215                 memcpy(primatives, temp, nPrimatives*sizeof(primative));
00216                 delete[] temp;
00217         }
00218         else
00219         {
00220                 primatives = new primative[1];
00221         }
00222         primatives[nPrimatives].type = p;
00223         primatives[nPrimatives].text = new FXString;
00224         primatives[nPrimatives].file = new FXString;
00225         primatives[nPrimatives].func = new FXString;
00226         if (p == primative::FUNCTION)
00227                 primatives[nPrimatives].datafunc = new CDataFunc;
00228         if (p == primative::IMAGE)
00229         {
00230                 ilGenImages(1, &primatives[nPrimatives].imageid);
00231                 primatives[nPrimatives].validimage = false;
00232         }
00233         ++nPrimatives;
00234 }
00235 
00236 
00237 ///Creates new primative and updates the display
00238 /**
00239  * @param p New primative type.
00240  */
00241 void DrawPaletteDialog::newPrimative(primative::typemode p)
00242 {
00243         createPrimative(p);
00244         drawitemsColourlist->setCurrentItem(nPrimatives-1);
00245         cmdUpdateAllData(NULL, 0, NULL);
00246         drawobjectSwitcher->setCurrent((int)p);
00247         return;
00248 }
00249 
00250 
00251 ///New line button handler
00252 long DrawPaletteDialog::cmdNewLine(FXObject*, FXSelector, void*)
00253 {
00254         drawitemsColourlist->appendItem("LINE", drawfgColourwell->getRGBA());
00255         newPrimative(primative::LINE);
00256         return(1);
00257 }
00258 
00259 
00260 ///New text button handler
00261 long DrawPaletteDialog::cmdNewText(FXObject*, FXSelector, void*)
00262 {
00263         drawitemsColourlist->appendItem("TEXT", drawfgColourwell->getRGBA());
00264         newPrimative(primative::TEXT);
00265         return(1);
00266 }
00267 
00268 
00269 ///New rectangle button handler
00270 long DrawPaletteDialog::cmdNewRect(FXObject*, FXSelector, void*)
00271 {
00272         drawitemsColourlist->appendItem("RECT", drawfgColourwell->getRGBA());
00273         newPrimative(primative::RECT);
00274         return(1);
00275 }
00276 
00277 
00278 ///New ellipse button handler
00279 long DrawPaletteDialog::cmdNewEllipse(FXObject*, FXSelector, void*)
00280 {
00281         drawitemsColourlist->appendItem("ELLIPSE", drawfgColourwell->getRGBA());
00282         newPrimative(primative::ELLIPSE);
00283         return(1);
00284 }
00285 
00286 
00287 ///New image button handler
00288 long DrawPaletteDialog::cmdNewImage(FXObject*, FXSelector, void*)
00289 {
00290         drawitemsColourlist->appendItem("IMAGE", drawfgColourwell->getRGBA());
00291         newPrimative(primative::IMAGE);
00292         return(1);
00293 }
00294 
00295 
00296 ///New function button handler
00297 long DrawPaletteDialog::cmdNewFunction(FXObject*, FXSelector, void*)
00298 {
00299         drawitemsColourlist->appendItem("FUNC", drawfgColourwell->getRGBA());
00300         newPrimative(primative::FUNCTION);
00301         return(1);
00302 }
00303 
00304 
00305 ///Move current item down the draw order list
00306 long DrawPaletteDialog::cmdItemDown(FXObject*, FXSelector, void*)
00307 {
00308         int i = drawitemsColourlist->getCurrentItem();
00309         if (i > 0)
00310         {
00311                 drawitemsColourlist->moveItem(i-1, i);
00312                 primative temp;
00313                 memcpy(&temp, &primatives[i], sizeof(primative));
00314                 memcpy(&primatives[i], &primatives[i-1], sizeof(primative));
00315                 memcpy(&primatives[i-1], &temp, sizeof(primative));
00316 
00317                 this->getOwner()->handle(this, FXSEL(SEL_COMMAND, updatetarget), NULL);
00318         }
00319         return(1);
00320 }
00321 
00322 
00323 ///Move current item up the draw order list
00324 long DrawPaletteDialog::cmdItemUp(FXObject*, FXSelector, void*)
00325 {
00326         int i = drawitemsColourlist->getCurrentItem();
00327         if ((i >= 0) && (i < drawitemsColourlist->getNumItems()-1))
00328         {
00329                 drawitemsColourlist->moveItem(i+1, i);
00330 
00331                 primative temp;
00332                 memcpy(&temp, &primatives[i], sizeof(primative));
00333                 memcpy(&primatives[i], &primatives[i+1], sizeof(primative));
00334                 memcpy(&primatives[i+1], &temp, sizeof(primative));
00335 
00336                 this->getOwner()->handle(this, FXSEL(SEL_COMMAND, updatetarget), NULL);
00337         }
00338 
00339         return(1);
00340 }
00341 
00342 
00343 ///Loads an image to draw
00344 void DrawPaletteDialog::ImageLoad(void)
00345 {
00346         int idx = drawitemsColourlist->getCurrentItem();
00347         if (idx > -1)
00348         {
00349                 ilBindImage(primatives[idx].imageid);
00350                 if (ilLoadImage((char*)primatives[idx].file->text()) == IL_FALSE)
00351                 {
00352                         FXMessageBox::error(this, FX::MBOX_OK, "Error!", "Could not load image (image library error).");
00353                 }
00354                 primatives[idx].validimage = true;
00355                 this->getOwner()->handle(this, FXSEL(SEL_COMMAND, updatetarget), NULL);
00356         }
00357 }
00358 
00359 
00360 ///Browse for an image to draw
00361 long DrawPaletteDialog::cmdImageBrowse(FXObject*, FXSelector, void*)
00362 {
00363         FXFileDialog openFiledialog(this, "Image file", PLACEMENT_OWNER);
00364         openFiledialog.setSelectMode(SELECTFILE_EXISTING);
00365         openFiledialog.setPatternList("All Files (*)");
00366         openFiledialog.setCurrentPattern(0);
00367 //      openFiledialog.setDirectory(graddirectory);
00368 
00369         if(openFiledialog.execute())
00370         {
00371                 FXString imagefile = openFiledialog.getFilename();
00372                 drawimageTextfield->setText(imagefile);
00373 //              graddirectory = openFiledialog.getDirectory();
00374                 int idx = drawitemsColourlist->getCurrentItem();
00375                 if (idx > -1)
00376                 {
00377                         primatives[idx].file->assign(imagefile);
00378                         ImageLoad();
00379                 }
00380         }
00381         return(1);
00382 }
00383 
00384 
00385 #ifndef WIN32
00386 ///Sort coordinate into order
00387 /**
00388  * @remark Required for Linux X drawing of the objects
00389  * @param[out] xmin Smallest x.
00390  * @param[out] xmax Largest x.
00391  * @param[out] ymin Smallest y.
00392  * @param[out] ymax Largest y.
00393  * @param spx X1.
00394  * @param epx X2.
00395  * @param spy Y1.
00396  * @param epy Y2.
00397  */
00398 void DrawPaletteDialog::coordSort(int &xmin, int &xmax, int &ymin, int &ymax, int spx, int epx, int spy, int epy)
00399 {
00400         if (spx < epx)
00401         {
00402                 xmin = spx;
00403                 xmax = epx;
00404         }
00405         else
00406         {
00407                 xmin = epx;
00408                 xmax = spx;
00409         }
00410         if (spy < epy)
00411         {
00412                 ymin = spy;
00413                 ymax = epy;
00414         }
00415         else
00416         {
00417                 ymin = epy;
00418                 ymax = spy;
00419         }
00420 }
00421 #endif
00422 
00423 
00424 ///Set image sizes
00425 /**
00426  * Initialises the size of the image so the palette knows where to draw objects.
00427  * @param tw Image width.
00428  * @param th Image height.
00429  * @param xp Data width.
00430  * @param yp Data height.
00431  * @param bl Left border width.
00432  * @param bb Bottom border height.
00433  */
00434 void DrawPaletteDialog::setImageCoords(int tw, int th, int xp, int yp, int bl, int bb)
00435 {
00436         totalwidth = tw;
00437         totalheight = th;
00438         xpixels = xp;
00439         ypixels = yp;
00440         borderleft = bl;
00441         borderbottom = bb;
00442         borderright = totalwidth-xpixels-borderleft;
00443         bordertop = totalheight-ypixels-borderbottom;
00444 }
00445 
00446 
00447 ///Draw outline of current primative
00448 /**
00449  * Draws the current primative as it is dragged out with the mouse.
00450  * @param dcw Window to draw to.
00451  * @param x Axis space x coordinate.
00452  * @param y Axis space y coordinate.
00453  * @param mx Mouse x.
00454  * @param my Mouse y.
00455  * @param xpx Image space x coordinate.
00456  * @param ypx Image space y coordinate.
00457  */
00458 void DrawPaletteDialog::drawPrimative(FXDCWindow *dcw, double x, double y, int mx, int my, int xpx, int ypx)
00459 {
00460         if (drawing == false)
00461                 return;
00462         int idx = drawitemsColourlist->getCurrentItem();
00463         if (idx > -1)
00464         {
00465 #ifndef WIN32
00466                 FXFunction func = dcw->getFunction();
00467 #endif
00468                 dcw->setFunction(FX::BLT_NOT_DST);
00469                 switch (primatives[idx].type)
00470                 {
00471                 case primative::LINE:
00472                         {
00473                                 if ((startpx != currentpx) || (startpy != currentpy))
00474                                         dcw->drawLine(startpx, startpy, currentpx, currentpy);
00475                                 dcw->drawLine(startpx, startpy, mx, my);
00476                         }
00477                         break;
00478                 case primative::RECT:
00479                 case primative::IMAGE:
00480                 case primative::FUNCTION:
00481                         {
00482 #ifdef WIN32
00483                                 if ((startpx != currentpx) || (startpy != currentpy))
00484                                         dcw->drawRectangle(startpx, startpy, currentpx-startpx, currentpy-startpy);
00485                                 dcw->drawRectangle(startpx, startpy, mx-startpx, my-startpy);
00486 #else
00487                                 int xmin, xmax, ymin, ymax;
00488                                 if ((startpx != currentpx) || (startpy != currentpy))
00489                                 {
00490                                         coordSort(xmin, xmax, ymin, ymax, startpx, currentpx, startpy, currentpy);
00491                                         dcw->drawRectangle(xmin, ymin, xmax-xmin, ymax-ymin);
00492                                 }
00493                                 coordSort(xmin, xmax, ymin, ymax, startpx, mx, startpy, my);
00494                                 dcw->drawRectangle(xmin, ymin, xmax-xmin, ymax-ymin);
00495 #endif
00496                         }
00497                         break;
00498                 case primative::ELLIPSE:
00499                         {
00500 #ifdef WIN32
00501                                 if ((startpx != currentpx) || (startpy != currentpy))
00502                                         dcw->drawEllipse(startpx-(currentpx-startpx), startpy-(currentpy-startpy), 2*(currentpx-startpx), 2*(currentpy-startpy));
00503                                 dcw->drawEllipse(startpx-(mx-startpx), startpy-(my-startpy), 2*(mx-startpx), 2*(my-startpy));
00504 #else
00505                                 int xmin, xmax, ymin, ymax;
00506                                 if ((startpx != currentpx) || (startpy != currentpy))
00507                                 {
00508                                         coordSort(xmin, xmax, ymin, ymax, startpx, currentpx, startpy, currentpy);
00509                                         dcw->drawEllipse(startpx-abs(currentpx-startpx), startpy-abs(currentpy-startpy), 2*(xmax-xmin), 2*(ymax-ymin));
00510                                 }
00511                                 coordSort(xmin, xmax, ymin, ymax, startpx, mx, startpy, my);
00512                                 dcw->drawEllipse(startpx-abs(mx-startpx), startpy-abs(my-startpy), 2*(xmax-xmin), 2*(ymax-ymin));
00513 #endif
00514                         }
00515                         break;
00516                 default:
00517                         break;
00518                 }
00519 #ifndef WIN32
00520                 dcw->setFunction(func);
00521 #endif
00522                 currentpx = mx;
00523                 currentpy = my;
00524         }
00525         switch (drawsizebasisOptionmenu->getCurrentNo())
00526         {
00527         case 0:         //Axes space
00528                 {
00529                         drawxsizeTextfield->setText(FXStringVal(x, 4));
00530                         drawysizeTextfield->setText(FXStringVal(y, 4));
00531                 }
00532                 break;
00533         case 1:         //Image fractional
00534                 {
00535                         drawxsizeTextfield->setText(FXStringVal((float)xpx/totalwidth));
00536                         drawysizeTextfield->setText(FXStringVal((float)ypx/totalheight));
00537                 }
00538                 break;
00539         case 2:         //Absolute
00540                 {
00541                         drawxsizeTextfield->setText(FXStringVal(xpx));
00542                         drawysizeTextfield->setText(FXStringVal(ypx));
00543                 }
00544                 break;
00545         case 3:         //Axes fractional
00546                 {
00547                         drawxsizeTextfield->setText(FXStringVal((float)(xpx-borderleft)/(float)xpixels));
00548                         drawysizeTextfield->setText(FXStringVal((float)(ypx-borderbottom)/(float)ypixels));
00549                 }
00550                 break;
00551         case 4:         //Border fractional
00552                 {
00553                         if (xpx < borderleft)
00554                                 drawxsizeTextfield->setText(FXStringVal((float)xpx/(float)borderleft));
00555                         else if (xpx < borderleft+xpixels)
00556                                 drawxsizeTextfield->setText(FXStringVal(1.0+(float)(xpx-borderleft)/(float)xpixels));
00557                         else
00558                                 drawxsizeTextfield->setText(FXStringVal(2.0+(float)(xpx-borderleft-xpixels)/(float)borderright));
00559                         if (ypx < borderbottom)
00560                                 drawysizeTextfield->setText(FXStringVal((float)ypx/(float)borderbottom));
00561                         else if (ypx < borderbottom+ypixels)
00562                                 drawysizeTextfield->setText(FXStringVal(1.0+(float)(ypx-borderbottom)/(float)ypixels));
00563                         else
00564                                 drawysizeTextfield->setText(FXStringVal(2.0+(float)(ypx-borderbottom-ypixels)/(float)bordertop));
00565                 }
00566                 break;
00567         default:
00568                 break;
00569         }
00570         return;
00571 }
00572 
00573 
00574 ///Start drawing a new primative
00575 /**
00576  * Sets initial coordinate of the primative.
00577  * @param dcw Window to draw to.
00578  * @param x Axis space x coordinate.
00579  * @param y Axis space y coordinate.
00580  * @param mx Mouse x.
00581  * @param my Mouse y.
00582  * @param xpx Image space x coordinate.
00583  * @param ypx Image space y coordinate.
00584  */
00585 void DrawPaletteDialog::startDraw(double x, double y, int mx, int my, int xpx, int ypx)
00586 {
00587         drawing = true;
00588         
00589         startpx = mx;
00590         startax = x;
00591         currentpx = mx;
00592         startpy = my;
00593         startay = y;
00594         currentpy = my;
00595         switch (drawbasisOptionmenu->getCurrentNo())
00596         {
00597         case 0:         //Axes space
00598                 {
00599                         drawxposTextfield->setText(FXStringVal(x, 4));
00600                         drawyposTextfield->setText(FXStringVal(y, 4));
00601                 }
00602                 break;
00603         case 1:         //Image fractional
00604                 {
00605                         drawxposTextfield->setText(FXStringVal((float)xpx/totalwidth));
00606                         drawyposTextfield->setText(FXStringVal((float)ypx/totalheight));
00607                 }
00608                 break;
00609         case 2:         //Absolute
00610                 {
00611                         drawxposTextfield->setText(FXStringVal(xpx));
00612                         drawyposTextfield->setText(FXStringVal(ypx));
00613                 }
00614                 break;
00615         case 3:         //Axes fractional
00616                 {
00617                         drawxposTextfield->setText(FXStringVal((float)(xpx-borderleft)/(float)xpixels));
00618                         drawyposTextfield->setText(FXStringVal((float)(ypx-borderbottom)/(float)ypixels));
00619                 }
00620                 break;
00621         case 4:         //Border fractional
00622                 {
00623                         if (xpx < borderleft)
00624                                 drawxposTextfield->setText(FXStringVal((float)xpx/(float)borderleft));
00625                         else if (xpx < borderleft+xpixels)
00626                                 drawxposTextfield->setText(FXStringVal(1.0+(float)(xpx-borderleft)/(float)xpixels));
00627                         else
00628                                 drawxposTextfield->setText(FXStringVal(2.0+(float)(xpx-borderleft-xpixels)/(float)borderright));
00629                         if (ypx < borderbottom)
00630                                 drawyposTextfield->setText(FXStringVal((float)ypx/(float)borderbottom));
00631                         else if (ypx < borderbottom+ypixels)
00632                                 drawyposTextfield->setText(FXStringVal(1.0+(float)(ypx-borderbottom)/(float)ypixels));
00633                         else
00634                                 drawyposTextfield->setText(FXStringVal(2.0+(float)(ypx-borderbottom-ypixels)/(float)bordertop));
00635                 }
00636                 break;
00637         default:
00638                 break;
00639         }
00640         return;
00641 }
00642 
00643 
00644 ///End drawing a new primative
00645 /**
00646  * Sets final position/dimension coordinate of the primative.
00647  * @param dcw Window to draw to.
00648  * @param x Axis space x coordinate.
00649  * @param y Axis space y coordinate.
00650  * @param mx Mouse x.
00651  * @param my Mouse y.
00652  * @param xpx Image space x coordinate.
00653  * @param ypx Image space y coordinate.
00654  */
00655 void DrawPaletteDialog::endDraw(FXDCWindow *dcw, double x, double y, int mx, int my, int xpx, int ypx)
00656 {
00657         drawing = false;
00658         
00659         int idx = drawitemsColourlist->getCurrentItem();
00660         if (idx > -1)
00661         {
00662 #ifndef WIN32
00663                 FXFunction func = dcw->getFunction();
00664 #endif
00665                 dcw->setFunction(FX::BLT_NOT_DST);
00666                 switch (primatives[idx].type)
00667                 {
00668                 case primative::LINE:
00669                         {
00670                                 dcw->drawLine(startpx, startpy, currentpx, currentpy);
00671                         }
00672                         break;
00673                 case primative::RECT:
00674                 case primative::IMAGE:
00675                 case primative::FUNCTION:
00676                         {
00677 #ifdef WIN32
00678                                 dcw->drawRectangle(startpx, startpy, currentpx-startpx, currentpy-startpy);
00679 #else
00680                                 int xmin, xmax, ymin, ymax;
00681                                 coordSort(xmin, xmax, ymin, ymax, startpx, currentpx, startpy, currentpy);
00682                                 dcw->drawRectangle(xmin, ymin, xmax-xmin, ymax-ymin);
00683 #endif
00684                         }
00685                         break;
00686                 case primative::ELLIPSE:
00687                         {
00688 #ifdef WIN32
00689                                 dcw->drawEllipse(startpx-(currentpx-startpx), startpy-(currentpy-startpy), 2*(currentpx-startpx), 2*(currentpy-sta