00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 #ifndef _MY_TEXTURE_EDITOR_
00059 #define _MY_TEXTURE_EDITOR_
00060
00061 #include <X11/Intrinsic.h>
00062 #include <Xm/Xm.h>
00063 #include <GL/glx.h>
00064 #include <Inventor/Xt/SoXtComponent.h>
00065 #include <Inventor/misc/SoCallbackList.h>
00066 #include <Inventor/SbPList.h>
00067
00068 class SoPath;
00069 class SoSensor;
00070 class SoNodeSensor;
00071 class SoTexture2;
00072 class SoTexture2Transform;
00073 class SoTextureCoordinateFunction;
00074 class SoNode;
00075 class SoSeparator;
00076 class SoXtExaminerViewer;
00077 class MyColorWheel;
00078 class MyColorSlider;
00079 class MyThumbWheel;
00080
00081 struct TextureNameStruct;
00082 class MyTextureEditor;
00083
00084
00085 typedef void MyTextureEditorCB(void *userData, MyTextureEditor *editor);
00086
00087
00089
00090
00091
00092
00093
00094
00095
00096
00098
00099 class MyTextureEditor : public SoXtComponent {
00100 public:
00101
00102
00103
00104
00105
00106 MyTextureEditor(
00107 Widget parent = NULL,
00108 const char *name = NULL,
00109 SbBool buildInsideParent = TRUE,
00110 const char *dir = NULL);
00111 ~MyTextureEditor();
00112
00113
00114
00115
00116
00117 void setObjectGeometry(SoNode *geomRoot);
00118
00119
00120
00121
00122
00123
00124 void setTextureNode(const SoTexture2 *txtNode);
00125 const SoTexture2 *getTextureNode() const { return texNode; }
00126
00127 void setTransformNode(const SoTexture2Transform *xf);
00128 const SoTexture2Transform *getTransformNode() const
00129 { return texXfNode; }
00130
00131 void setFunctionNode(const SoTextureCoordinateFunction *func);
00132 const SoTextureCoordinateFunction *getFunctionNode() const
00133 { return texFuncNode; }
00134
00135
00136
00137
00138
00139
00140
00141
00142 void addCallback(
00143 MyTextureEditorCB *f,
00144 void *userData = NULL)
00145 { callbackList.addCallback((SoCallbackListCB *) f, userData);}
00146
00147 void removeCallback(
00148 MyTextureEditorCB *f,
00149 void *userData = NULL)
00150 { callbackList.removeCallback((SoCallbackListCB *) f, userData); }
00151
00152 protected:
00153
00154
00155 virtual const char * getDefaultWidgetName() const;
00156 virtual const char * getDefaultTitle() const;
00157 virtual const char * getDefaultIconTitle() const;
00158
00159 private:
00160
00161 SoSeparator *sceneRoot;
00162 SoTexture2 *texNode;
00163 SoTexture2Transform *texXfNode;
00164 SoTextureCoordinateFunction *texFuncNode;
00165 SoNode *userGeometry;
00166 SbBool repeatState;
00167
00168 SoCallbackList callbackList;
00169
00170 void updateTexture2UI();
00171 void updateTextureXfUI();
00172 void updateTextureFuncUI();
00173 void updateTextureFieldAndSlider(int fieldID);
00174 SbBool setRepeatState(SbBool flag);
00175
00176 void deselectCurrentItem(SbBool drawHighlight = TRUE);
00177 void updateTextureName();
00178 void updateTextureNode();
00179 void getPaletteNames();
00180 void loadPaletteItems();
00181 void savePalette();
00182 void deleteTextureEntry(int id);
00183 SbBool addTextureEntry(int id, char *fullName);
00184 SbBool readScaledImage(char *fileName, int xsize, int ysize,
00185 char *buf, int &zsize);
00186 char *readImage(char *file, int &xsize, int &ysize, int &zsize);
00187 void switchPalette(int id);
00188 void updateWindowTitle();
00189 void createNewPalette(char *palName);
00190
00191
00192 SbBool ignoreCallback;
00193 MyColorWheel *colWheel;
00194 MyColorSlider *colSlider;
00195 SoXtExaminerViewer *viewer;
00196 MyThumbWheel *scaleXThumb, *scaleYThumb;
00197 float oldXThumbVal, oldYThumbVal;
00198 static void colWheelCB(void *, const float hsv[3]);
00199 static void colSliderCB(void *, float);
00200 static void scaleXThumbCB(void *, float);
00201 static void scaleYThumbCB(void *, float);
00202
00203
00204 Widget buildWidget(Widget parent);
00205 Widget buildMenu(Widget parent);
00206 void buildPaletteSubMenu();
00207 Widget buildPaletteMenuEntry(int id);
00208 Widget buildSliders(Widget parent);
00209 Widget buildButtons(Widget parent);
00210 Widget buildTexturePaletteWidget(Widget parent);
00211
00212
00213 Widget *widgetList;
00214 SbBool fieldChanged;
00215 static void fieldChangedCB(Widget, MyTextureEditor *, void *);
00216 static void fieldsCB(Widget, int, void *);
00217 static void slidersCB(Widget, int, void *);
00218 static void mappingMenuCB(Widget, int, void *);
00219 static void optionMenuCB(Widget, int, void *);
00220 static void acceptCB(Widget, MyTextureEditor *, void *);
00221
00222
00223 void createNewDialog();
00224 void createDeleteDialog(char *title, char *str1, char *str2);
00225 void updateFileMenu();
00226 static void fileMenuCB(Widget, int id, void *);
00227 static void paletteMenuCB(Widget w, int num, void *);
00228 static void newDialogCB(Widget, MyTextureEditor *, XmAnyCallbackStruct *);
00229 static void deleteDialogCB(Widget, MyTextureEditor *, XmAnyCallbackStruct *);
00230
00231
00232 GLXContext paletteCtx;
00233 SbBool loadedPalette;
00234 char *paletteDir;
00235 Time prevTime;
00236 int selectedItem, currentItem;
00237 int curPalette;
00238 TextureNameStruct *textureNames;
00239 SbPList paletteList;
00240 void redrawPalette();
00241 void drawTextureTile(int id, int style);
00242 void handleEvent(XAnyEvent *xe);
00243 static void glxExposeCB(Widget, MyTextureEditor *, void *);
00244 static void glxInitCB(Widget, MyTextureEditor *, void *);
00245 static void glxEventCB(Widget, MyTextureEditor *, XAnyEvent *, Boolean *);
00246
00247
00248 GLXContext imageDialogCtx;
00249 char *dialogImage;
00250 char *dialogImageName, *dialogImageInfo;
00251 int dialogImageSize[3];
00252 short buttonsTotalWidth;
00253 void openImageDialog();
00254 void redrawImageDialog();
00255 void setNewDialogImage(char *fileName = NULL);
00256 static void imageDialogDestroyCB(Widget, MyTextureEditor *, void *);
00257 static void imageDialogExposeCB(Widget, MyTextureEditor *, void *);
00258 static void imageDialogInitCB(Widget, MyTextureEditor *, void *);
00259 static void imageDialogOpenCB(Widget, MyTextureEditor *, void *);
00260 static void imageDialogClearCB(Widget, MyTextureEditor *, void *);
00261 static void imageDialogApplyCB(Widget, MyTextureEditor *, void *);
00262 static void imageDialogCloseCB(Widget, MyTextureEditor *, void *);
00263 static void fileDialogOkCB(Widget, MyTextureEditor *, XmFileSelectionBoxCallbackStruct *);
00264 };
00265
00266 #endif // _MY_TEXTURE_EDITOR_