home *** CD-ROM | disk | FTP | other *** search
- /*
- * Maceditor.c
- */
-
- #include <MacHeaders>
- #include <Windows.h>
- #include <QuickDraw.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Lists.h>
- #include <Types.h>
-
- #include "texture.h"
- #include "geom.h"
- #include "surface.h"
- #include "light.h"
- #include "image.h"
-
- #include "blotch.h"
- #include "bump.h"
- #include "checker.h"
- #include "cloud.h"
- #include "fbm.h"
- #include "fbmbump.h"
- #include "gloss.h"
- #include "imagetext.h"
- #include "marble.h"
- #include "mount.h"
- #include "sky.h"
- #include "stripe.h"
- #include "windy.h"
- #include "wood.h"
-
- #include "macmodify.h"
- #include "maceditor.h"
- #include "macdialog.h"
-
- extern DialogPtr editorDialog ;
- extern Surface *Surfaces ; /* Named surface instances */
- extern Geom *Objects ; /* Named objects */
- extern Geom *World;
- extern Light *Lights;
-
- extern Texture *CreateTexture(short type) ;
- Surface *EditSurface(Geom *obj) ;
-
-
- struct TextureTemplate {
- char *name ;
- char *fieldnames[8] ;
- char surface_enabled ;
- } ;
-
- static Surface tmpsurf ;
- static ListHandle textList ;
- static struct TextureTemplate templates[14] = {
- {"Blotch",{ "Mix",0,0,0,0,0,0,0 },1},
- {"Bump",{ "Size",0,0,0,0,0,0,0 },0},
- {"Checker",{ 0,0,0,0,0,0,0,0 },1},
- {"Cloud",{"Scale","h","Lambda","Octaves","CThresh","LThresh","Transcale",0 },0},
- {"FBm",{ "Offset","Scale","h","Lambda","Octaves","Thresh",0,0 },0},
- {"FBm Bump",{ "Offset","Scale","h","Lambda","Octaves",0,0,0 },0},
- {"Gloss",{ "Glossiness",0,0,0,0,0,0,0 },0},
- {"Image",{ 0,0,0,0,0,0,0,0 },0},
- {"Marble",{ 0,0,0,0,0,0,0,0 },0},
- {"Sky",{ "Scale","h","Lambda","Octaves","cthresh","lthresh",0,0 },0},
- {"Stripe",{ "Width","Bump", 0,0,0,0,0,0 },1},
- {"Wood",{ 0,0,0,0,0,0,0 },0}
- } ;
-
-
- pascal void DrawTextureList(WindowPtr window, short item)
- {
- GrafPtr currPort ;
- PenState saveState;
- short itemType;
- Handle itemHandle;
- Rect itemBox;
-
- GetPort(&currPort) ;
- SetPort(window) ;
- GetPenState(&saveState);
- GetDItem(window, item, &itemType, &itemHandle, &itemBox);
- PenNormal() ;
- InsetRect(&itemBox,-1,-1) ;
- FrameRect(&itemBox);
- LUpdate(window->visRgn, textList) ;
- SetPenState(&saveState);
- SetPort(currPort) ;
- }
-
- void SetTextureText(DialogPtr dlog,int type)
- {
- Str255 name ;
- struct TextureTemplate *temp ;
- short loop ;
-
- temp = &templates[type] ;
- for(loop = textfield1ST ; loop <= textfield7ST ; loop++) {
- if((type != -1) && (temp->fieldnames[loop-textfield1ST] != NULL)) {
- name[0] = strlen(temp->fieldnames[loop-textfield1ST]) ;
- sprintf(&name[1],"%s",temp->fieldnames[loop-textfield1ST]) ;
- SetIText(SnatchHandle(dlog,loop),name) ;
- ShowDItem(dlog,loop);
- ShowDItem(dlog,loop-textfield1ST+textfield1ET);
- }
- else {
- HideDItem(dlog,loop);
- HideDItem(dlog,loop-textfield1ST+textfield1ET);
- }
- }
- if(temp->surface_enabled)
- ShowDItem(dlog,textsurfacepickBU);
- else
- HideDItem(dlog,textsurfacepickBU);
- }
-
-
- Texture *EditTexture(Geom *obj)
- {
- GrafPtr currPort;
- ControlHandle itemHandle ;
- Rect itemRect, bounds ;
- DialogPtr textDialog ;
- short hitItem, itemType, loop, loop2, textsize ;
- char exit = 0, buffer[255], doubleClick, fail ;
- Texture *textarray[50], *chosentexture, *text;
- Surface *surf, *surf2;
- Geom dummyobject;
- Point mousePoint, cellSize ;
- Cell cell = {0,0}, myCell;
- Mapping *mapping;
- Float param[8] ;
- int type ;
-
- textDialog = GetNewDialog(textdialogR, 0L, (WindowPtr)-1) ;
-
- dummyobject.trans = NULL;
-
- /* Turn our user item into a texture list */
- GetDItem(textDialog, textlistUI, &itemType, &itemHandle, &itemRect);
- SetDItem(textDialog, textlistUI, itemType, (ProcPtr) DrawTextureList, &itemRect);
- SetRect(&bounds,0,0,1,0) ;
- itemRect.right -= 15;
- cellSize.v = cellSize.h = 0;
- textList = LNew(&itemRect,&bounds,cellSize,0,textDialog,TRUE,FALSE,FALSE,TRUE) ;
- /* Insert some values */
- textsize = 0 ;
- for(text = obj->texture ; text ; text = text->next) {
- type = TextureType(text) ;
- sprintf(buffer,"%s", templates[type].name) ;
- for(loop = strlen(buffer) ; loop < 255 ; loop++) buffer[loop] = ' ';
- cell.v = textsize ;
- textarray[textsize++] = text ;
- LAddRow(1,cell.v,textList) ;
- LSetCell(buffer,255,cell,textList);
- }
-
- /* Now set up the dialog text fields to correspond to our given template */
- itemHandle = SnatchHandle(textDialog,texttypeCI) ;
- type = GetCtlValue(itemHandle)-1 ;
- SetTextureText(textDialog,type) ;
- chosentexture = NULL;
- surf = SurfaceCreate();
- /* Redraw the dialog and add a thick band round the use button */
- DrawDialog(textDialog) ;
- GetPort(&currPort);
- SetPort(textDialog);
- DrawHilite(textDialog,textdoneBU) ;
- HiliteControl(SnatchHandle(textDialog,textremoveBU),255) ;
- HiliteControl(SnatchHandle(textDialog,texttransformsetBU),255) ;
- do {
- ModalDialog((ModalFilterProcPtr)NULL, &hitItem) ;
- switch(hitItem) {
- case textdoneBU:
- obj->texture = textarray[0];
- for(loop=0;loop < textsize; loop++)
- textarray[loop]->next = textarray[loop+1];
- textarray[textsize-1]->next =NULL;
- exit = 1 ;
- break ;
- case textlistUI:
- GetMouse(&mousePoint);
- doubleClick = LClick(mousePoint,0,textList) ;
- myCell.v = myCell.h = 0;
- if(LGetSelect(TRUE, &myCell, textList)) {
- chosentexture = textarray[myCell.v] ;
- HiliteControl(SnatchHandle(textDialog,textremoveBU),0) ;
- HiliteControl(SnatchHandle(textDialog,texttransformsetBU),0) ;
- }
- else {
- chosentexture = NULL ;
- HiliteControl(SnatchHandle(textDialog,textremoveBU),255) ;
- HiliteControl(SnatchHandle(textDialog,texttransformsetBU),255) ;
- for(loop = 0 ; loop < textsize ; loop++) {
- myCell.v = loop;
- LSetSelect(FALSE,myCell,textList);
- }
- }
- break ;
- case texttypeCI:
- itemHandle = SnatchHandle(textDialog,texttypeCI) ;
- type = GetCtlValue(itemHandle)-1 ;
- SetTextureText(textDialog,type) ;
- break ;
- case textremoveBU:
- if(chosentexture) {
- loop =0;
- while((textarray[loop]!=chosentexture) && (loop < textsize)) loop++;
- LDelRow(1,(short)loop,textList);
-
- for(loop2 = loop; loop2 < textsize ;loop2++)
- textarray[loop2] = textarray[loop2+1];
- textsize--;
-
- obj->texture = textarray[0];
- for(loop=0;loop < textsize; loop++)
- textarray[loop]->next = textarray[loop+1];
- textarray[textsize-1]->next =NULL;
- DeleteTexture(chosentexture) ;
- chosentexture = 0 ;
- HiliteControl(SnatchHandle(textDialog,textremoveBU),255) ;
- HiliteControl(SnatchHandle(textDialog,texttransformsetBU),255) ;
- }
- break ;
- case textcreateBU:
- if(textsize < 50) {
- itemHandle = SnatchHandle(textDialog,texttypeCI) ;
- type = GetCtlValue(itemHandle)-1 ;
- fail = 0 ;
- for(loop = 0 ; loop < 8 ; loop++) {
- if(templates[type].fieldnames[loop])
- if(!GetFloatEditText(textDialog,loop + textfield1ET,¶m[loop]))
- fail = 1 ;
-
- }
- if(fail) break ;
- switch(type) {
- case T_BLOTCH:
- surf2 = SurfaceCreate();
- *surf2 = *surf;
- surf2->next = NULL;
- text = TextBlotchCreate(param[0],surf2) ;
- break ;
- case T_BUMP:
- text = TextBumpCreate(param[0]) ;
- break ;
- case T_CHECKER:
- surf2 = SurfaceCreate();
- *surf2 = *surf;
- surf2->next = NULL;
- text = TextCheckerCreate(surf2) ;
- break ;
- case T_CLOUD:
- text = TextCloudCreate(param[0],param[1],param[2],(int)param[3],param[4],param[5],param[6]) ;
- break ;
- case T_FBM:
- text = TextFBmCreate(param[0],param[1],param[2],param[3],(int)param[4],param[5],NULL) ;
- break ;
- case T_FBMBUMP:
- text = TextFBmBumpCreate(param[0],param[1],param[2],param[3],(int)param[4]) ;
- break ;
- case T_GLOSS:
- text = TextGlossCreate(param[0]) ;
- break ;
- case T_IMAGE:
- break ;
- case T_MARBLE:
- text = TextMarbleCreate(NULL) ;
- break ;
- case T_SKY:
- break ;
- case T_STRIPE:
- surf2 = SurfaceCreate();
- *surf2 = *surf;
- surf2->next = NULL;
- mapping = UVMappingCreate();
- text = TextStripeCreate(surf2,param[0],param[1],mapping) ;
- break ;
- case T_WOOD:
- text = TextWoodCreate() ;
- break ;
- }
- if(text) {
- sprintf(buffer,"%s", templates[type].name) ;
- for(loop = strlen(buffer) ; loop < 255 ; loop++) buffer[loop] = ' ';
- textarray[textsize] = text ;
- text->next = NULL;
- cell.v = textsize;
- textsize++;
- LAddRow(1,cell.v,textList) ;
- LSetCell(buffer, 255, cell, textList);
- }
- }
- else
- SysBeep(1) ; /* Who needs 50 textures on an object anyway ? */
- break ;
- case texttransformsetBU:
- if(chosentexture) {
- if(chosentexture->trans)
- DeleteTrans(chosentexture->trans);
- EditTransforms(&dummyobject);
- chosentexture->trans = dummyobject.trans;
- dummyobject.trans = NULL;
- }
- break;
- case textsurfacepickBU:
- dummyobject.surf = surf;
- EditSurface(&dummyobject) ;
- break ;
- }
- } while (!exit) ;
- LDispose(textList) ;
- SetPort(currPort);
- DisposDialog(textDialog) ;
- }