paintmap.c

Go to the documentation of this file.
00001 /* --
00002 OpenFX - Modelling, Animation and Rendering Package
00003 -- */
00004 
00005 /*  PAINTMAP.C  DLL to apply mapping coords by unwrapping mesh */
00006 
00007 #include <stdlib.h>
00008 #include <stdio.h>
00009 #include <math.h>
00010 #include <setjmp.h>
00011 #include <windows.h>
00012 #include <commctrl.h>
00013 #include <vfw.h>
00014 
00015 #include "struct.h"
00016 #include "callback.h"
00017 #include "dstruct.h"
00018 
00019 #include "paintmap.h"
00020 
00021 typedef struct tagMENUHELPDATA{
00022   int iCode;
00023   char *str;
00024 } MENUHELPDATA;
00025 
00026 #if __X__MIPS__
00027 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00028 #endif
00029 
00030 #define DESELECTED 0
00031 #define SELECTED   1
00032 
00033 #define MAXTEXT     256
00034 
00035 
00036 static HWND      hParent,hInfo;
00037 static HINSTANCE hThisInstance;
00038 static HDRAWDIB  hDrawDib = NULL;
00039 
00040 #define BOUND(x,min,max) ((x) < (min) ? (min) : ((x) > (max) ? (max) : (x)))
00041 #define SWAP(x,y)   ((x)^=(y)^=(x)^=(y))
00042 #define MIN(x,y) (((x) <= (y)) : x ? y)
00043 #define StartWait() hcurSave = SetCursor(LoadCursor(NULL,IDC_WAIT))
00044 #define EndWait()   SetCursor(hcurSave)
00045 /* macro to determine if resource is a DIB */
00046 
00047 static char *szViewClass="OFX:PaintMapClass";
00048 static SYSTEM_INFO sys_info;
00049 static int ImageWidth, ImageHeight,DisplayWidth,DisplayHeight,DisplayBits,DisplayPlanes,xScreen,yScreen;
00050 static unsigned char  *ImagePixels;
00051 static BITMAPINFOHEADER ImageHeader;
00052 static long xOffset=0,yOffset=0;
00053 static double scale=1.0;
00054 static BOOL bChanged=FALSE;
00055 
00056 static POINT ptSize;
00057 static DWORD fdwStyle = WS_POPUP | WS_CAPTION | ! WS_SYSMENU |
00058                         WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_THICKFRAME;
00059 static HCURSOR hcurSave;
00060 
00061 static int pen=0,stretched=1,tracetool=0;
00062 
00063 static long Nf=0,NvSelect=0;
00064 static struct TFLIST {long fID; BOOL bSelect[3]; float x[3], y[3];} *TFlist=NULL;
00065 
00066 #define NMENUHELPDATA 16
00067 static MENUHELPDATA MenuHelpData[NMENUHELPDATA]={
00068   0xFFFF,             "   ",
00069   IDM_PEN_RED,        "Draw with RED pen",
00070   IDM_PEN_WHITE,      "Draw with WHITE pen",
00071   IDM_PEN_BLACK,      "Draw with BLACK pen",
00072   IDM_PEN_CYAN,       "Draw with CYAN pen",
00073   IDM_SELECT_ALL,     "Select All (ctl+A)",
00074   IDM_SELECT_NONE,    "Select None (ctl+D)",
00075   IDM_SELINVERT,      "Select Invert",
00076   IDM_SCALE,          "Scale (X)<ctl>",
00077   IDM_SELECT,         "Select (S)",
00078   IDM_MOVE,           "Click on vertex to move",
00079   IDM_PAN,            "Pan (P)",
00080   IDM_ZOOM,           "Zoom (Z) ",
00081   IDM_EXIT,           "Finish",
00082   IDM_ABORT,          "Update Mapping ",
00083   IDM_ROTATE,         "Rotate (R)"
00084 };
00085 
00086 static int ErrMsg(char *sz,...);
00087 static void PutMsg(char *s);
00088 static LRESULT CALLBACK MainWndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam);
00089 static BOOL MenuCommand(HWND hWnd, WORD id);
00090 static void AppPaint(HWND hWnd, HDC hDC, int x, int y);
00091 static BOOL Viewer(void);
00092 static void DrawRubberBox(HWND hwnd, int x, int y, int xx, int yy );
00093 static void SelectInBox(BOOL, BOOL, HWND, int x, int y, int xx, int yy );
00094 static void SetMovement(HWND, int, int);
00095 static void SetScale(HWND, float, float, int, int);
00096 static void SetRotation(HWND hwnd, float angle, long rxp, long ryp);
00097 static void DrawList(HWND hwnd, HDC hDC);
00098 static void DrawRubberList(HWND hwnd, int x, int y, float s);
00099 static void DrawRotatedRubberList(HWND hwnd, int xo, int yo, float r);
00100 static void DrawScaledRubberList(HWND hwnd, int xo, int yo, float sx, float sy);
00101 static void DrawFaceList(HWND hwnd, HDC hDC);
00102 static void SetSelection(BOOL);
00103 static void InvertSelection(void);
00104 static void UpdateFaceMapping(void);
00105 
00106 static BOOL Viewer(void){
00107  MSG msg;
00108  HWND hDesktopWnd,hWnd;
00109  HDC hDCcaps;
00110  WNDCLASS wndclass;
00111  HANDLE hAccel;
00112  hDesktopWnd = GetDesktopWindow();
00113  hDCcaps     = GetDC(hDesktopWnd);
00114  DisplayWidth= GetDeviceCaps(hDCcaps,HORZRES);
00115  DisplayHeight= GetDeviceCaps(hDCcaps,VERTRES);
00116  DisplayBits= GetDeviceCaps(hDCcaps,BITSPIXEL);
00117  DisplayPlanes= GetDeviceCaps(hDCcaps,PLANES);
00118  ReleaseDC(hDesktopWnd,hDCcaps);
00119  GetSystemInfo(&sys_info);
00120  wndclass.style         = 0;
00121  wndclass.lpfnWndProc   = (WNDPROC)MainWndProc;
00122  wndclass.cbClsExtra    = 0 ;
00123  wndclass.cbWndExtra    = 0 ;
00124  wndclass.hInstance     = hThisInstance ;
00125  wndclass.hIcon         = NULL;
00126  wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
00127  wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
00128  wndclass.lpszMenuName  = "tracemenu" ;
00129  wndclass.lpszClassName = szViewClass;
00130  if (!RegisterClass (&wndclass))  return FALSE ;
00131  xScreen = GetSystemMetrics (SM_CXSCREEN) ;
00132  yScreen = GetSystemMetrics (SM_CYSCREEN) ;
00133  hWnd = CreateWindow(
00134         szViewClass,
00135         "Texture Coordinate Editor",
00136         fdwStyle,
00137         25,
00138         25,
00139         xScreen-50,
00140         yScreen-50,
00141         hParent,
00142         NULL,
00143         hThisInstance,
00144         NULL) ;
00145  if(hWnd == NULL)return FALSE;
00146  hDrawDib=DrawDibOpen();
00147  ShowWindow (hWnd,SW_SHOWNA);
00148  PostMessage(hWnd,WM_COMMAND,(WPARAM)IDM_DRAWIT,0);
00149  hAccel=LoadAccelerators(hThisInstance,MAKEINTRESOURCE(TRACEACCEL));
00150  while(GetMessage (&msg,NULL,0,0)){
00151    if(!TranslateAccelerator(hWnd,hAccel,&msg)){
00152      TranslateMessage (&msg);
00153      DispatchMessage (&msg);
00154    }
00155  }
00156  DestroyWindow(hWnd);
00157  if(hDrawDib != NULL)DrawDibClose(hDrawDib);
00158  UnregisterClass(wndclass.lpszClassName,wndclass.hInstance);
00159  if(TFlist != NULL)X__Free(TFlist); TFlist=NULL; Nf=0;
00160  return TRUE;
00161 }
00162 
00163 LRESULT CALLBACK MainWndProc(HWND hWnd,UINT iMessage,WPARAM wParam,
00164                              LPARAM lParam){
00165  static BOOL bToolCaptured=FALSE;
00166  static HCURSOR hCursorSave;
00167  static POINT LastPt,FirstPt;
00168  static BOOL bMoved;
00169  static BOOL bSingle;
00170  static float sx,sy,angle;
00171  PAINTSTRUCT ps;
00172  HDC hDC;
00173  int i,dx,dy;
00174  RECT rc;
00175  POINT pt;
00176  double delta;
00177  switch (iMessage) {
00178    case WM_DESTROY:
00179     break;
00180   case WM_COMMAND:
00181     return MenuCommand(hWnd,LOWORD(wParam));
00182     break;
00183   case WM_MENUSELECT: {
00184       HMENU hmenu;
00185       UINT fuFlags,uItem,id;
00186       hmenu=(HMENU)lParam;
00187       fuFlags=(UINT)HIWORD(wParam);
00188       uItem=(UINT)LOWORD(wParam);
00189       id=0;
00190       if(fuFlags == 0xFFFF)id=0;
00191       else if(fuFlags & MF_POPUP){;}
00192       else{
00193         for(i=0;i<NMENUHELPDATA;i++){
00194           if(uItem == MenuHelpData[i].iCode){id=(UINT)i; break;}
00195         }
00196       }
00197       SendMessage(hInfo,SB_SETTEXT,(WPARAM)0,(LPARAM)MenuHelpData[id].str);
00198     }
00199     break;
00200   case WM_LBUTTONDOWN:
00201     bMoved=FALSE;
00202     if(tracetool == 0 || bToolCaptured)break;
00203     else if(tracetool == 1){ // select
00204       bToolCaptured=TRUE;
00205       SetCapture(hWnd);
00206       hCursorSave=SetCursor(LoadCursor(NULL,IDC_SIZE));
00207       LastPt.x=LOWORD(lParam); LastPt.y=HIWORD(lParam);
00208       FirstPt.x=LOWORD(lParam); FirstPt.y=HIWORD(lParam);
00209       DrawRubberBox(hWnd,FirstPt.x,FirstPt.y,LastPt.x,LastPt.y);
00210     }
00211     else if(tracetool == 2){ // move
00212       bToolCaptured=TRUE;
00213       SetCapture(hWnd);
00214       hCursorSave=SetCursor(LoadCursor(NULL,IDC_SIZE));
00215       LastPt.x=LOWORD(lParam); LastPt.y=HIWORD(lParam);
00216       FirstPt.x=LOWORD(lParam); FirstPt.y=HIWORD(lParam);
00217       if(NvSelect == 0){
00218         SelectInBox(FALSE,TRUE,hWnd,FirstPt.x-4,FirstPt.y-4,LastPt.x+4,LastPt.y+4);
00219         bSingle=TRUE;
00220       }
00221       else bSingle=FALSE;
00222       DrawRubberList(hWnd,0,0,1.0);
00223     }
00224     else if(tracetool == 4 || tracetool == 3){ /* zoom  or pan */
00225       if(tracetool == 3 && scale <= 1.0)break; // cant pan if fully zoomed out
00226       bToolCaptured=TRUE;
00227       SetCapture(hWnd);
00228       hCursorSave=SetCursor(LoadCursor(NULL,IDC_HAND));
00229       LastPt.x=LOWORD(lParam); LastPt.y=HIWORD(lParam);
00230 
00231     }
00232     else if(tracetool == 5){ /* scale */
00233       sx=sy=1.0;
00234       bToolCaptured=TRUE;
00235       SetCapture(hWnd);
00236       hCursorSave=SetCursor(LoadCursor(NULL,IDC_SIZE));
00237       LastPt.x=LOWORD(lParam); LastPt.y=HIWORD(lParam);
00238       FirstPt.x=LOWORD(lParam); FirstPt.y=HIWORD(lParam);
00239       DrawScaledRubberList(hWnd,FirstPt.x,FirstPt.y,0.0,0.0);
00240 //      DrawRubberList(hWnd,0,0,1.0);
00241     }
00242     else if(tracetool == 6){ /* rotate */
00243       sx=sy=1.0;
00244       angle=0.0;
00245       bToolCaptured=TRUE;
00246       SetCapture(hWnd);
00247       hCursorSave=SetCursor(LoadCursor(NULL,IDC_SIZE));
00248       LastPt.x=LOWORD(lParam); LastPt.y=HIWORD(lParam);
00249       FirstPt.x=LOWORD(lParam); FirstPt.y=HIWORD(lParam);
00250       DrawRotatedRubberList(hWnd,FirstPt.x,FirstPt.y,angle);
00251     }
00252     GetClientRect(hWnd,&rc);
00253     pt.x=rc.left; pt.y=rc.top;
00254     ClientToScreen(hWnd,&pt);
00255     rc.left=pt.x; rc.top=pt.y;
00256     pt.x=rc.right; pt.y=rc.bottom;
00257     ClientToScreen(hWnd,&pt);
00258     rc.right=pt.x; rc.bottom=pt.y;
00259     ClipCursor(&rc);
00260     break;
00261   case WM_MOUSEMOVE:
00262     if(!bToolCaptured)break;
00263     if(tracetool == 1){ // select
00264       DrawRubberBox(hWnd,FirstPt.x,FirstPt.y,LastPt.x,LastPt.y);
00265       LastPt.x=LOWORD(lParam); LastPt.y=HIWORD(lParam);
00266       DrawRubberBox(hWnd,FirstPt.x,FirstPt.y,LastPt.x,LastPt.y);
00267     }
00268     if(tracetool == 2){ // move
00269       DrawRubberList(hWnd,LastPt.x-FirstPt.x,LastPt.y-FirstPt.y,1.0);
00270       LastPt.x=LOWORD(lParam); LastPt.y=HIWORD(lParam);
00271       DrawRubberList(hWnd,LastPt.x-FirstPt.x,LastPt.y-FirstPt.y,1.0);
00272     }
00273     if(tracetool == 3){ // pan
00274       dx=(int)LOWORD(lParam) - (int)LastPt.x;
00275       dy=(int)HIWORD(lParam) - (int)LastPt.y;
00276       GetClientRect(hWnd,&rc);
00277       delta=(double)ImageWidth/scale*(double)dx/(double)rc.right;   
00278       xOffset = xOffset-(int)delta;
00279       if(xOffset < 0)xOffset=0;
00280       if(xOffset+ImageWidth/scale > ImageWidth)xOffset=ImageWidth-ImageWidth/scale;
00281       delta=(double)ImageHeight/scale*(double)dy/(double)rc.bottom;   
00282       yOffset = yOffset-(int)delta;
00283       if(yOffset < 0)yOffset=0;
00284       if(yOffset+ImageHeight/scale > ImageHeight)yOffset=ImageHeight-ImageHeight/scale;
00285       LastPt.x=LOWORD(lParam); LastPt.y=HIWORD(lParam);
00286       InvalidateRect(hWnd,NULL,FALSE);
00287     }
00288     if(tracetool == 4){ // zoom
00289       dx=(int)LOWORD(lParam) - (int)LastPt.x;
00290       scale += 0.005*(double)dx; if(scale < 1.0)scale=1.0; if(scale > 8.0)scale=8.0;
00291       if(xOffset+ImageWidth/scale > ImageWidth)xOffset=ImageWidth-ImageWidth/scale;
00292       if(xOffset < 0)xOffset=0;
00293       if(yOffset+ImageHeight/scale > ImageHeight)yOffset=ImageHeight-ImageHeight/scale;
00294       if(yOffset < 0)yOffset=0;
00295       LastPt.x=LOWORD(lParam); LastPt.y=HIWORD(lParam);
00296       InvalidateRect(hWnd,NULL,FALSE);
00297     }
00298     if(tracetool == 5){ // scale
00299 //      DrawRubberList(hWnd,0,0,ss);
00300       DrawScaledRubberList(hWnd,FirstPt.x,FirstPt.y,sx,sy);
00301       dx=(int)LOWORD(lParam) - (int)LastPt.x;
00302       sx += 0.005*(double)dx; if(sx < 0.2)sx=0.2; if(sx > 4.0)sx=4.0;
00303       if(!(GetKeyState(VK_CONTROL) & 0x8000))
00304       sy += 0.005*(double)dx; if(sy < 0.2)sy=0.2; if(sy > 4.0)sy=4.0;
00305       LastPt.x=LOWORD(lParam); LastPt.y=HIWORD(lParam);
00306       DrawScaledRubberList(hWnd,FirstPt.x,FirstPt.y,sx,sy);
00307 //      DrawRubberList(hWnd,0,0,ss);
00308     }
00309     if(tracetool == 6){ // rotate
00310       DrawRotatedRubberList(hWnd,FirstPt.x,FirstPt.y,angle);
00311       angle = -(double)((int)LOWORD(lParam)-FirstPt.x)*0.1;
00312       DrawRotatedRubberList(hWnd,FirstPt.x,FirstPt.y,angle);
00313     }
00314     bMoved=TRUE;
00315     break;
00316   case WM_LBUTTONUP:
00317     if(!bToolCaptured)break;
00318     if(tracetool == 1){ /* select */
00319       DrawRubberBox(hWnd,FirstPt.x,FirstPt.y,LastPt.x,LastPt.y);
00320       LastPt.x=LOWORD(lParam); LastPt.y=HIWORD(lParam);
00321       if(!bMoved){
00322         SelectInBox(TRUE,TRUE,hWnd,FirstPt.x-3,FirstPt.y-3,LastPt.x+3,LastPt.y+3);
00323       }
00324       else{
00325         SelectInBox(FALSE,TRUE,hWnd,FirstPt.x,FirstPt.y,LastPt.x,LastPt.y);
00326       }
00327       SetCursor(hCursorSave);
00328       ClipCursor(NULL);
00329       ReleaseCapture();
00330       bToolCaptured=FALSE;
00331       InvalidateRect(hWnd,NULL,FALSE);
00332     }
00333     else if(tracetool == 2){ /* move */
00334       DrawRubberList(hWnd,LastPt.x-FirstPt.x,LastPt.y-FirstPt.y,1.0);
00335       LastPt.x=LOWORD(lParam); LastPt.y=HIWORD(lParam);
00336       SetCursor(hCursorSave);
00337       ClipCursor(NULL);
00338       ReleaseCapture();
00339       SetMovement(hWnd,LastPt.x-FirstPt.x,LastPt.y-FirstPt.y);
00340       if(bSingle)SetSelection(FALSE);
00341       bToolCaptured=FALSE;
00342       InvalidateRect(hWnd,NULL,FALSE);
00343     }
00344     else if(tracetool == 4 || tracetool == 3){ // zoom or pan
00345       SetCursor(hCursorSave);
00346       ClipCursor(NULL);
00347       ReleaseCapture();
00348       bToolCaptured=FALSE;
00349     }
00350     else if(tracetool == 5){ // scale
00351       DrawScaledRubberList(hWnd,FirstPt.x,FirstPt.y,sx,sy);
00352 //      DrawRubberList(hWnd,0,0,ss);
00353       LastPt.x=LOWORD(lParam); LastPt.y=HIWORD(lParam);
00354       SetCursor(hCursorSave);
00355       ClipCursor(NULL);
00356       ReleaseCapture();
00357       SetScale(hWnd,sx, sy, FirstPt.x, FirstPt.y);
00358       bToolCaptured=FALSE;
00359       InvalidateRect(hWnd,NULL,FALSE);
00360     }
00361     else if(tracetool == 6){ // rotate
00362       DrawRotatedRubberList(hWnd,FirstPt.x,FirstPt.y,angle);
00363       LastPt.x=LOWORD(lParam); LastPt.y=HIWORD(lParam);
00364       angle = -(double)(LastPt.x-FirstPt.x)*0.1;
00365       SetCursor(hCursorSave);
00366       ClipCursor(NULL);
00367       ReleaseCapture();
00368       SetRotation(hWnd,angle,FirstPt.x,FirstPt.y);
00369       bToolCaptured=FALSE;
00370       InvalidateRect(hWnd,NULL,FALSE);
00371     }
00372     break;
00373   case WM_PAINT:
00374     hDC = BeginPaint(hWnd, &ps);
00375     AppPaint(hWnd,hDC,0,0);
00376     DrawList(hWnd,hDC);
00377     EndPaint(hWnd,&ps);
00378     break ;
00379   case WM_SIZE:
00380     InvalidateRect(hWnd,NULL,FALSE);
00381     return 0;
00382   default:
00383       return DefWindowProc (hWnd, iMessage, wParam, lParam) ;
00384  }
00385  return 0L ;
00386 }
00387 
00388 BOOL MenuCommand (HWND hWnd, WORD id){
00389  int i;
00390  char lpMessage[MAXTEXT],lpCaption[64];
00391  switch (id) {
00392    case IDM_DRAWIT:
00393      //StartWait();
00394      //EndWait();
00395      InvalidateRect (hWnd, NULL, FALSE);
00396      break;
00397    case IDM_PEN_RED  : pen=0; goto PENID;
00398    case IDM_PEN_WHITE: pen=1; goto PENID;
00399    case IDM_PEN_BLACK: pen=2; goto PENID;
00400    case IDM_PEN_CYAN : pen=3; goto PENID;
00401      PENID:
00402      CheckMenuItem(GetMenu(hWnd),IDM_PEN_RED,MF_UNCHECKED);
00403      CheckMenuItem(GetMenu(hWnd),IDM_PEN_WHITE,MF_UNCHECKED);
00404      CheckMenuItem(GetMenu(hWnd),IDM_PEN_BLACK,MF_UNCHECKED);
00405      CheckMenuItem(GetMenu(hWnd),IDM_PEN_CYAN,MF_UNCHECKED);
00406      if(pen == 0)CheckMenuItem(GetMenu(hWnd),IDM_PEN_RED,MF_CHECKED);
00407      if(pen == 1)CheckMenuItem(GetMenu(hWnd),IDM_PEN_WHITE,MF_CHECKED);
00408      if(pen == 2)CheckMenuItem(GetMenu(hWnd),IDM_PEN_BLACK,MF_CHECKED);
00409      if(pen == 3)CheckMenuItem(GetMenu(hWnd),IDM_PEN_CYAN,MF_CHECKED);
00410      DrawList(hWnd,NULL);
00411      break;
00412    case IDM_SELINVERT:
00413      InvertSelection();
00414      InvalidateRect (hWnd, NULL, FALSE);
00415      break;
00416    case IDM_SELECT_ALL:
00417      SetSelection(TRUE);
00418      InvalidateRect (hWnd, NULL, FALSE);
00419      break;
00420    case IDM_SELECT_NONE:
00421      SetSelection(FALSE);
00422      InvalidateRect (hWnd, NULL, FALSE);
00423      break;
00424    case IDM_ROTATE:
00425      EnableMenuItem(GetMenu(hWnd),IDM_ROTATE,MF_GRAYED);
00426      EnableMenuItem(GetMenu(hWnd),IDM_SCALE,MF_ENABLED);
00427      EnableMenuItem(GetMenu(hWnd),IDM_SELECT,MF_ENABLED);
00428      EnableMenuItem(GetMenu(hWnd),IDM_MOVE,MF_ENABLED);
00429      EnableMenuItem(GetMenu(hWnd),IDM_PAN,MF_ENABLED);
00430      EnableMenuItem(GetMenu(hWnd),IDM_ZOOM,MF_ENABLED);
00431      DrawMenuBar(hWnd);
00432      tracetool=6;
00433      break;
00434    case IDM_SCALE:
00435      EnableMenuItem(GetMenu(hWnd),IDM_SCALE,MF_GRAYED);
00436      EnableMenuItem(GetMenu(hWnd),IDM_SELECT,MF_ENABLED);
00437      EnableMenuItem(GetMenu(hWnd),IDM_MOVE,MF_ENABLED);
00438      EnableMenuItem(GetMenu(hWnd),IDM_PAN,MF_ENABLED);
00439      EnableMenuItem(GetMenu(hWnd),IDM_ZOOM,MF_ENABLED);
00440      EnableMenuItem(GetMenu(hWnd),IDM_ROTATE,MF_ENABLED);
00441      DrawMenuBar(hWnd);
00442      tracetool=5;
00443      break;
00444    case IDM_SELECT:  // Select
00445      EnableMenuItem(GetMenu(hWnd),IDM_SCALE,MF_ENABLED);
00446      EnableMenuItem(GetMenu(hWnd),IDM_SELECT,MF_GRAYED);
00447      EnableMenuItem(GetMenu(hWnd),IDM_MOVE,MF_ENABLED);
00448      EnableMenuItem(GetMenu(hWnd),IDM_PAN,MF_ENABLED);
00449      EnableMenuItem(GetMenu(hWnd),IDM_ZOOM,MF_ENABLED);
00450      EnableMenuItem(GetMenu(hWnd),IDM_ROTATE,MF_ENABLED);
00451      DrawMenuBar(hWnd);
00452      tracetool=1;
00453      break;
00454    case IDM_MOVE:
00455      EnableMenuItem(GetMenu(hWnd),IDM_SCALE,MF_ENABLED);
00456      EnableMenuItem(GetMenu(hWnd),IDM_SELECT,MF_ENABLED);
00457      EnableMenuItem(GetMenu(hWnd),IDM_MOVE,MF_GRAYED);
00458      EnableMenuItem(GetMenu(hWnd),IDM_PAN,MF_ENABLED);
00459      EnableMenuItem(GetMenu(hWnd),IDM_ZOOM,MF_ENABLED);
00460      EnableMenuItem(GetMenu(hWnd),IDM_ROTATE,MF_ENABLED);
00461      DrawMenuBar(hWnd);
00462      tracetool=2;
00463      break;
00464    case IDM_PAN: // pan
00465      EnableMenuItem(GetMenu(hWnd),IDM_SELECT,MF_ENABLED);
00466      EnableMenuItem(GetMenu(hWnd),IDM_SCALE,MF_ENABLED);
00467      EnableMenuItem(GetMenu(hWnd),IDM_MOVE,MF_ENABLED);
00468      EnableMenuItem(GetMenu(hWnd),IDM_PAN,MF_GRAYED);
00469      EnableMenuItem(GetMenu(hWnd),IDM_ZOOM,MF_ENABLED);
00470      EnableMenuItem(GetMenu(hWnd),IDM_ROTATE,MF_ENABLED);
00471      DrawMenuBar(hWnd);
00472      tracetool=3;
00473      break;
00474    case IDM_ZOOM:  // zoom
00475      EnableMenuItem(GetMenu(hWnd),IDM_SCALE,MF_ENABLED);
00476      EnableMenuItem(GetMenu(hWnd),IDM_SELECT,MF_ENABLED);
00477      EnableMenuItem(GetMenu(hWnd),IDM_MOVE,MF_ENABLED);
00478      EnableMenuItem(GetMenu(hWnd),IDM_PAN,MF_ENABLED);
00479      EnableMenuItem(GetMenu(hWnd),IDM_ZOOM,MF_GRAYED);
00480      EnableMenuItem(GetMenu(hWnd),IDM_ROTATE,MF_ENABLED);
00481      DrawMenuBar(hWnd);
00482      tracetool=4;
00483      break;
00484    case IDM_EXIT:
00485      if(bChanged){
00486        int r;
00487        if((r=MessageBox(hWnd,"Keep Changes?","Texture Paint",MB_YESNOCANCEL)) == IDYES){
00488          UpdateFaceMapping();
00489        }
00490        if(r == IDCANCEL)break;
00491      }
00492      PostQuitMessage(0);
00493      break;
00494    case IDM_ABORT:  // Update
00495      UpdateFaceMapping();
00496      break;
00497    default:
00498      break;
00499  }
00500  return TRUE;
00501 }
00502 
00503 static int ErrMsg(char *sz,...){
00504  char ach[128];
00505  va_list arg_ptr;
00506  va_start(arg_ptr,sz);
00507  vsprintf(ach,sz,arg_ptr);   /* Format the string */
00508  va_end(arg_ptr);
00509  MessageBox (NULL, ach, NULL, MB_OK|MB_ICONEXCLAMATION|MB_APPLMODAL);
00510  return FALSE;
00511 }
00512 
00513 static void PutMsg(char *s){
00514  MessageBox (NULL,s, "PaintMap", MB_OK|MB_ICONEXCLAMATION|MB_APPLMODAL);
00515 }
00516 
00517 static void AppPaint(HWND hWnd,HDC hDC,int x,int y){
00518  RECT rc;
00519  GetClientRect(hWnd,&rc);
00520  if(hDrawDib != NULL && ImagePixels != NULL){
00521    DrawDibRealize(hDrawDib,hDC,TRUE);
00522    DrawDibDraw(hDrawDib,hDC,0,0,rc.right,rc.bottom,
00523            (LPBITMAPINFOHEADER)(&ImageHeader),ImagePixels,
00524            xOffset,yOffset,
00525            (int)((double)ImageWidth/scale), 
00526            (int)((double)ImageHeight/scale), 0);
00527  }
00528 }
00529 
00530 static int Xcoord(double c, long l){
00531   c=(c*(double)ImageWidth-xOffset)*scale;
00532   return (int)(c*(double)l/(double)ImageWidth);
00533 }
00534 
00535 static int Ycoord(double c, long l){
00536   c=((1.0-c)*(double)ImageHeight - yOffset)*scale;
00537   return (int)(c*(double)l/(double)ImageHeight);
00538 }
00539 
00540 static double coordX(long c, long l){
00541   return ((double)c*(double)ImageWidth/(double)l/scale+(double)xOffset)/(double)ImageWidth;
00542 }
00543 
00544 static double coordY(long c, long l){
00545   return 1.0-((double)c*(double)ImageHeight/(double)l/scale+(double)yOffset)/(double)ImageHeight;
00546 }
00547 
00548 
00549 static void DrawRubberBox(HWND hwnd, int x, int y, int xx, int yy){
00550  HPEN hOldPen,MyPen;
00551  int oldROP;
00552  HDC hDClocal;
00553  hDClocal=GetDC(hwnd);
00554  if(pen == 0)MyPen=CreatePen(PS_SOLID,0,RGB(255,0,0));
00555  if(pen == 1)MyPen=CreatePen(PS_SOLID,0,RGB(255,255,255));
00556  if(pen == 2)MyPen=CreatePen(PS_SOLID,0,RGB(0,0,0));
00557  if(pen == 3)MyPen=CreatePen(PS_SOLID,0,RGB(0,255,255));
00558  hOldPen=SelectObject(hDClocal,MyPen);
00559  oldROP=SetROP2(hDClocal,R2_NOT);
00560  MoveToEx(hDClocal,x,y,NULL);
00561  LineTo(hDClocal,xx,y);
00562  LineTo(hDClocal,xx,yy);
00563  LineTo(hDClocal,x,yy);
00564  LineTo(hDClocal,x,y);
00565  SetROP2(hDClocal,oldROP);
00566  SelectObject(hDClocal,hOldPen);
00567  DeleteObject(MyPen);
00568  ReleaseDC(hwnd,hDClocal);
00569 }
00570 
00571 static void DrawList(HWND hwnd, HDC hDC){
00572  int i,x,y;
00573  HPEN hOldPen,MyPen;
00574  HBRUSH hOldBrush;
00575  HDC hDClocal;
00576  if(hDC == NULL){
00577    hDClocal=GetDC(hwnd);
00578  }
00579  else hDClocal=hDC;
00580  if(pen == 0)MyPen=CreatePen(PS_SOLID,0,RGB(255,0,0));
00581  if(pen == 1)MyPen=CreatePen(PS_SOLID,0,RGB(255,255,255));
00582  if(pen == 2)MyPen=CreatePen(PS_SOLID,0,RGB(0,0,0));
00583  if(pen == 3)MyPen=CreatePen(PS_SOLID,0,RGB(0,255,255));
00584  hOldPen=SelectObject(hDClocal,MyPen);
00585  hOldBrush=SelectObject(hDClocal,GetStockObject(BLACK_BRUSH));
00586  DrawFaceList(hwnd,hDClocal);
00587  SelectObject(hDClocal,hOldPen);
00588  SelectObject(hDClocal,hOldBrush);
00589  DeleteObject(MyPen);
00590  if(hDC == NULL){
00591    ReleaseDC(hwnd,hDClocal);
00592  }
00593 }
00594 
00595 static void DrawRubberList(HWND hwnd, int xo, int yo, float s){
00596  HPEN hOldPen,MyPen;
00597  int oldROP;
00598  HDC hDClocal;
00599  RECT rc;
00600  int i,x0,y0,x1,y1,x2,y2;
00601  GetClientRect(hwnd,&rc);
00602  hDClocal=GetDC(hwnd);
00603  if(pen == 0)MyPen=CreatePen(PS_SOLID,0,RGB(255,0,0));
00604  if(pen == 1)MyPen=CreatePen(PS_SOLID,0,RGB(255,255,255));
00605  if(pen == 2)MyPen=CreatePen(PS_SOLID,0,RGB(0,0,0));
00606  if(pen == 3)MyPen=CreatePen(PS_SOLID,0,RGB(0,255,255));
00607  hOldPen=SelectObject(hDClocal,MyPen);
00608  oldROP=SetROP2(hDClocal,R2_NOT);
00609  if(Nf > 0 && TFlist != NULL){
00610    for(i=0;i<Nf;i++){
00611      x0=Xcoord(TFlist[i].x[0],rc.right);  y0=Ycoord(TFlist[i].y[0],rc.bottom);
00612      x1=Xcoord(TFlist[i].x[1],rc.right);  y1=Ycoord(TFlist[i].y[1],rc.bottom);
00613      x2=Xcoord(TFlist[i].x[2],rc.right);  y2=Ycoord(TFlist[i].y[2],rc.bottom);
00614      if(TFlist[i].bSelect[0] && TFlist[i].bSelect[1] && TFlist[i].bSelect[2]){
00615        MoveToEx(hDClocal,x0*s+xo,y0*s+yo,NULL);
00616        LineTo(hDClocal,x1*s+xo,y1*s+yo); 
00617        LineTo(hDClocal,x2*s+xo,y2*s+yo); 
00618        LineTo(hDClocal,x0*s+xo,y0*s+yo);
00619      }
00620      else{
00621        x0=Xcoord(TFlist[i].x[0],rc.right);  y0=Ycoord(TFlist[i].y[0],rc.bottom);
00622        x1=Xcoord(TFlist[i].x[1],rc.right);  y1=Ycoord(TFlist[i].y[1],rc.bottom);
00623        x2=Xcoord(TFlist[i].x[2],rc.right);  y2=Ycoord(TFlist[i].y[2],rc.bottom);
00624        if(TFlist[i].bSelect[0] && !TFlist[i].bSelect[1]){MoveToEx(hDClocal,x0*s+xo,y0*s+yo,NULL); LineTo(hDClocal,x1,y1);}
00625        if(TFlist[i].bSelect[0] && !TFlist[i].bSelect[2]){MoveToEx(hDClocal,x0*s+xo,y0*s+yo,NULL); LineTo(hDClocal,x2,y2);}
00626        if(TFlist[i].bSelect[1] && !TFlist[i].bSelect[0]){MoveToEx(hDClocal,x1*s+xo,y1*s+yo,NULL); LineTo(hDClocal,x0,y0);}
00627        if(TFlist[i].bSelect[1] && !TFlist[i].bSelect[2]){MoveToEx(hDClocal,x1*s+xo,y1*s+yo,NULL); LineTo(hDClocal,x2,y2);}
00628        if(TFlist[i].bSelect[2] && !TFlist[i].bSelect[0]){MoveToEx(hDClocal,x2*s+xo,y2*s+yo,NULL); LineTo(hDClocal,x0,y0);}
00629        if(TFlist[i].bSelect[2] && !TFlist[i].bSelect[1]){MoveToEx(hDClocal,x2*s+xo,y2*s+yo,NULL); LineTo(hDClocal,x1,y1);}
00630      }
00631    }
00632  }
00633  SetROP2(hDClocal,oldROP);
00634  SelectObject(hDClocal,hOldPen);
00635  DeleteObject(MyPen);
00636  ReleaseDC(hwnd,hDClocal);
00637 }
00638 
00639 static void DrawScaledRubberList(HWND hwnd, int xo, int yo, float sx, float sy){
00640  HPEN hOldPen,MyPen;
00641  int oldROP;
00642  HDC hDClocal;
00643  RECT rc;
00644  int i,x0,y0,x1,y1,x2,y2;
00645  GetClientRect(hwnd,&rc);
00646  hDClocal=GetDC(hwnd);
00647  if(pen == 0)MyPen=CreatePen(PS_SOLID,0,RGB(255,0,0));
00648  if(pen == 1)MyPen=CreatePen(PS_SOLID,0,RGB(255,255,255));
00649  if(pen == 2)MyPen=CreatePen(PS_SOLID,0,RGB(0,0,0));
00650  if(pen == 3)MyPen=CreatePen(PS_SOLID,0,RGB(0,255,255));
00651  hOldPen=SelectObject(hDClocal,MyPen);
00652  oldROP=SetROP2(hDClocal,R2_NOT);
00653  if(Nf > 0 && TFlist != NULL){
00654    for(i=0;i<Nf;i++){
00655      x0=Xcoord(TFlist[i].x[0],rc.right);  y0=Ycoord(TFlist[i].y[0],rc.bottom);
00656      x1=Xcoord(TFlist[i].x[1],rc.right);  y1=Ycoord(TFlist[i].y[1],rc.bottom);
00657      x2=Xcoord(TFlist[i].x[2],rc.right);  y2=Ycoord(TFlist[i].y[2],rc.bottom);
00658      x0=(x0-xo)*sx+xo; y0=(y0-yo)*sy+yo;
00659      x1=(x1-xo)*sx+xo; y1=(y1-yo)*sy+yo;
00660      x2=(x2-xo)*sx+xo; y2=(y2-yo)*sy+yo;
00661      if(TFlist[i].bSelect[0] && TFlist[i].bSelect[1] && TFlist[i].bSelect[2]){
00662        MoveToEx(hDClocal,x0,y0,NULL);
00663        LineTo(hDClocal,x1,y1); 
00664        LineTo(hDClocal,x2,y2); 
00665        LineTo(hDClocal,x0,y0);
00666      }
00667      else{
00668        if(TFlist[i].bSelect[0] && !TFlist[i].bSelect[1]){MoveToEx(hDClocal,x0,y0,NULL); LineTo(hDClocal,x1,y1);}
00669        if(TFlist[i].bSelect[0] && !TFlist[i].bSelect[2]){MoveToEx(hDClocal,x0,y0,NULL); LineTo(hDClocal,x2,y2);}
00670        if(TFlist[i].bSelect[1] && !TFlist[i].bSelect[0]){MoveToEx(hDClocal,x1,y1,NULL); LineTo(hDClocal,x0,y0);}
00671        if(TFlist[i].bSelect[1] && !TFlist[i].bSelect[2]){MoveToEx(hDClocal,x1,y1,NULL); LineTo(hDClocal,x2,y2);}
00672        if(TFlist[i].bSelect[2] && !TFlist[i].bSelect[0]){MoveToEx(hDClocal,x2,y2,NULL); LineTo(hDClocal,x0,y0);}
00673        if(TFlist[i].bSelect[2] && !TFlist[i].bSelect[1]){MoveToEx(hDClocal,x2,y2,NULL); LineTo(hDClocal,x1,y1);}
00674      }
00675    }
00676  }
00677  SetROP2(hDClocal,oldROP);
00678  SelectObject(hDClocal,hOldPen);
00679  DeleteObject(MyPen);
00680  ReleaseDC(hwnd,hDClocal);
00681 }
00682 
00683 static void DrawRotatedRubberList(HWND hwnd, int xo, int yo, float r){
00684  HPEN hOldPen,MyPen;
00685  int oldROP;
00686  HDC hDClocal;
00687  RECT rc;
00688  int i,x0,y0,x1,y1,x2,y2;
00689  double cosa,sina,tx,ty,ttx,tty;
00690  GetClientRect(hwnd,&rc);
00691  hDClocal=GetDC(hwnd);
00692  if(pen == 0)MyPen=CreatePen(PS_SOLID,0,RGB(255,0,0));
00693  if(pen == 1)MyPen=CreatePen(PS_SOLID,0,RGB(255,255,255));
00694  if(pen == 2)MyPen=CreatePen(PS_SOLID,0,RGB(0,0,0));
00695  if(pen == 3)MyPen=CreatePen(PS_SOLID,0,RGB(0,255,255));
00696  hOldPen=SelectObject(hDClocal,MyPen);
00697  oldROP=SetROP2(hDClocal,R2_NOT);
00698  cosa=cos(r*3.14159/180.0); sina=sin(r*3.14159/180.0);
00699  if(Nf > 0 && TFlist != NULL){
00700    for(i=0;i<Nf;i++){
00701      x0=Xcoord(TFlist[i].x[0],rc.right);  y0=Ycoord(TFlist[i].y[0],rc.bottom);
00702      x1=Xcoord(TFlist[i].x[1],rc.right);  y1=Ycoord(TFlist[i].y[1],rc.bottom);
00703      x2=Xcoord(TFlist[i].x[2],rc.right);  y2=Ycoord(TFlist[i].y[2],rc.bottom);
00704      tx=x0-xo; ty=y0-yo;
00705      ttx = ( tx*cosa+ty*sina); tty = (-tx*sina+ty*cosa);
00706      x0 = xo+ttx; y0 = yo+tty;
00707      tx=x1-xo; ty=y1-yo;
00708      ttx = ( tx*cosa+ty*sina); tty = (-tx*sina+ty*cosa);
00709      x1 = xo+ttx; y1 = yo+tty;
00710      tx=x2-xo; ty=y2-yo;
00711      ttx = ( tx*cosa+ty*sina); tty = (-tx*sina+ty*cosa);
00712      x2 = xo+ttx; y2 = yo+tty;
00713      if(TFlist[i].bSelect[0] && TFlist[i].bSelect[1] && TFlist[i].bSelect[2]){
00714        MoveToEx(hDClocal,x0,y0,NULL);
00715        LineTo(hDClocal,x1,y1); 
00716        LineTo(hDClocal,x2,y2); 
00717        LineTo(hDClocal,x0,y0);
00718      }
00719      else{
00720        if(TFlist[i].bSelect[0] && !TFlist[i].bSelect[1]){MoveToEx(hDClocal,x0,y0,NULL); LineTo(hDClocal,x1,y1);}
00721        if(TFlist[i].bSelect[0] && !TFlist[i].bSelect[2]){MoveToEx(hDClocal,x0,y0,NULL); LineTo(hDClocal,x2,y2);}
00722        if(TFlist[i].bSelect[1] && !TFlist[i].bSelect[0]){MoveToEx(hDClocal,x1,y1,NULL); LineTo(hDClocal,x0,y0);}
00723        if(TFlist[i].bSelect[1] && !TFlist[i].bSelect[2]){MoveToEx(hDClocal,x1,y1,NULL); LineTo(hDClocal,x2,y2);}
00724        if(TFlist[i].bSelect[2] && !TFlist[i].bSelect[0]){MoveToEx(hDClocal,x2,y2,NULL); LineTo(hDClocal,x0,y0);}
00725        if(TFlist[i].bSelect[2] && !TFlist[i].bSelect[1]){MoveToEx(hDClocal,x2,y2,NULL); LineTo(hDClocal,x1,y1);}
00726      }
00727    }
00728  }
00729  SetROP2(hDClocal,oldROP);
00730  SelectObject(hDClocal,hOldPen);
00731  DeleteObject(MyPen);
00732  ReleaseDC(hwnd,hDClocal);
00733 }
00734 
00735 
00736 static void DrawFaceList(HWND hwnd, HDC hDClocal){
00737  RECT rc;
00738  int i,x,y;
00739  GetClientRect(hwnd,&rc);
00740  if(Nf > 0 && TFlist != NULL){
00741    for(i=0;i<Nf;i++){
00742      x=Xcoord(TFlist[i].x[0],rc.right);  y=Ycoord(TFlist[i].y[0],rc.bottom);
00743      MoveToEx(hDClocal,x,y,NULL);
00744      x=Xcoord(TFlist[i].x[1],rc.right);  y=Ycoord(TFlist[i].y[1],rc.bottom);
00745      LineTo(hDClocal,x,y); 
00746      Rectangle(hDClocal,x-2,y-2,x+2,y+2);
00747      if(TFlist[i].bSelect[1])Rectangle(hDClocal,x-4,y-4,x+4,y+4); 
00748      x=Xcoord(TFlist[i].x[2],rc.right);  y=Ycoord(TFlist[i].y[2],rc.bottom);
00749      LineTo(hDClocal,x,y); 
00750      Rectangle(hDClocal,x-2,y-2,x+2,y+2);
00751      if(TFlist[i].bSelect[2])Rectangle(hDClocal,x-4,y-4,x+4,y+4); 
00752      x=Xcoord(TFlist[i].x[0],rc.right);  y=Ycoord(TFlist[i].y[0],rc.bottom);
00753      LineTo(hDClocal,x,y); 
00754      Rectangle(hDClocal,x-2,y-2,x+2,y+2);
00755      if(TFlist[i].bSelect[0])Rectangle(hDClocal,x-4,y-4,x+4,y+4); 
00756    }
00757  }
00758 }
00759 
00760 static void SetSelection(BOOL status){
00761  struct TFLIST *f;
00762  long  i,j;
00763  if(Nf < 1)return;
00764  if(status == TRUE)NvSelect=Nf*3; else NvSelect=0;
00765  for(i=0;i<Nf;i++){
00766    f=(TFlist+i);
00767    for(j=0;j<3;j++)f->bSelect[j]=status;
00768  }
00769 }
00770 
00771 static void InvertSelection(void){
00772  struct TFLIST *f;
00773  long  i,j;
00774  if(Nf < 1)return;
00775  for(i=0;i<Nf;i++){
00776    f=(TFlist+i);
00777    for(j=0;j<3;j++){
00778      if(!f->bSelect[j])NvSelect += 3; else NvSelect -= 3;
00779      f->bSelect[j] ^= 1;
00780    }
00781  }
00782 }
00783 
00784 
00785 static void SelectInBox(BOOL invert, BOOL status, HWND hwnd, int x1, int y1, int x2, int y2 ){
00786  struct TFLIST *f;
00787  RECT rc;
00788  long i,j;
00789  int xp,yp,xb1,xb2,yb1,yb2;
00790  if(Nf < 1)return;
00791  if(x1 > x2){xb1=x2; xb2=x1;} else {xb1=x1; xb2=x2;}
00792  if(y1 > y2){yb1=y2; yb2=y1;} else {yb1=y1; yb2=y2;}
00793  GetClientRect(hwnd,&rc);
00794  for(i=0;i<Nf;i++){
00795    f=(TFlist+i);
00796    for(j=0;j<3;j++){
00797      xp=Xcoord(TFlist[i].x[j],rc.right);  yp=Ycoord(TFlist[i].y[j],rc.bottom);
00798      if(xp >= xb1 && xp <= xb2 && yp >= yb1 && yp <= yb2){
00799        if(invert){
00800          if(!f->bSelect[j])NvSelect += 3; else NvSelect -= 3;
00801          f->bSelect[j] ^= 1;
00802        }
00803        else{
00804          f->bSelect[j]=status;
00805          if(status)NvSelect += 3;  else NvSelect -= 3;
00806        }
00807      }
00808    }
00809  }
00810 }
00811 
00812 static void SetMovement(HWND hwnd, int dx, int dy){
00813  struct TFLIST *f;
00814  RECT rc;
00815  long i,j,xp,yp;
00816  double rdx,rdy;
00817  if(Nf < 1)return;
00818  GetClientRect(hwnd,&rc);
00819  for(i=0;i<Nf;i++){
00820    f=(TFlist+i);
00821    for(j=0;j<3;j++)if(f->bSelect[j]){
00822      xp=Xcoord(f->x[j],rc.right);  yp=Ycoord(f->y[j],rc.bottom);
00823      f->x[j] = coordX(xp+dx,rc.right);
00824      f->y[j] = coordY(yp+dy,rc.bottom);
00825    }
00826  }
00827  bChanged=TRUE;
00828 }
00829 
00830 static void SetScale(HWND hwnd, float sx, float sy, int xc, int yc){
00831  struct TFLIST *f;
00832  RECT rc;
00833  long i,j,xp,yp;
00834  double rdx,rdy;
00835  if(Nf < 1)return;
00836  GetClientRect(hwnd,&rc);
00837  for(i=0;i<Nf;i++){
00838    f=(TFlist+i);
00839    for(j=0;j<3;j++)if(f->bSelect[j]){
00840      xp=Xcoord(f->x[j],rc.right);  yp=Ycoord(f->y[j],rc.bottom);
00841      xp=(xp-xc)*sx+xc;
00842      yp=(yp-yc)*sy+yc;
00843      f->x[j] = coordX(xp,rc.right);
00844      f->y[j] = coordY(yp,rc.bottom);
00845    }
00846  }
00847  bChanged=TRUE;
00848 }
00849 
00850 static void SetRotation(HWND hwnd, float angle, long rxp, long ryp){
00851  struct TFLIST *f;
00852  RECT rc;
00853  long i,j,xp,yp; // xp is in window coord
00854  double rx,ry,cosa,sina;
00855  if(Nf < 1)return;
00856  GetClientRect(hwnd,&rc);
00857  cosa=cos(angle*3.14159/180.0); sina=sin(angle*3.14159/180.0);
00858  for(i=0;i<Nf;i++){
00859    f=(TFlist+i);
00860    for(j=0;j<3;j++)if(f->bSelect[j]){
00861      xp=Xcoord(f->x[j],rc.right);  
00862      yp=Ycoord(f->y[j],rc.bottom);
00863      rx = xp-rxp;
00864      ry = yp-ryp;
00865      xp = (long) (rx*cosa+ry*sina);
00866      yp = (long)(-rx*sina+ry*cosa);
00867      xp = xp+rxp;
00868      yp = yp+ryp;
00869      f->x[j] = coordX(xp,rc.right);
00870      f->y[j] = coordY(yp,rc.bottom);
00871    }
00872  }
00873  bChanged=TRUE;
00874 }
00875 
00876 static void UpdateFaceMapping(void){
00877  struct TFLIST *f;
00878  face *fp;
00879  long i,j;
00880  if(Nf < 1)return;
00881  for(i=0;i<Nf;i++){
00882    f=(TFlist+i);
00883    fp=(MainFp+f->fID); 
00884    for(j=0;j<3;j++){
00885      fp->x[j]=f->x[j];
00886      fp->y[j]=f->y[j];
00887    }
00888  }
00889  bChanged=FALSE;
00890 }
00891 
00892 static void BuildFaceList(long mapID){
00893  face *fp;
00894  struct TFLIST *f;
00895  long  i,j,c;
00896  for(c=0,i=0,fp=MainFp;i<Nface;i++,fp++){
00897    if((MainVp+fp->V[0])->status == SELECTED &&
00898       (MainVp+fp->V[1])->status == SELECTED &&
00899       (MainVp+fp->V[2])->status == SELECTED &&
00900       fp->imagemap == mapID)c++;
00901  }
00902  if(c == 0)return;
00903  if((f=(struct TFLIST *)X__Malloc(c*sizeof(struct TFLIST))) == NULL)return;
00904  TFlist=f;
00905  for(Nf=0,i=0,fp=MainFp;i<Nface;i++,fp++){
00906    if((MainVp+fp->V[0])->status == SELECTED &&
00907       (MainVp+fp->V[1])->status == SELECTED &&
00908       (MainVp+fp->V[2])->status == SELECTED &&
00909       fp->imagemap == mapID){
00910      f=(TFlist+Nf);
00911      f->fID=i;
00912      for(j=0;j<3;j++){f->x[j]=fp->x[j];  f->y[j]=fp->y[j]; f->bSelect[j]=FALSE;}
00913      Nf++;
00914    }
00915  }
00916 }
00917 
00918 #if __WATCOMC__
00919 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00920 #else
00921 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00922 #endif
00923   switch (dwReason) {
00924     case DLL_PROCESS_ATTACH: {
00925 #if __X__MIPS__
00926       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00927 //      MessageBox (GetFocus(),"Trace attaching","Debug",MB_OK);
00928 #endif
00929       hThisInstance=hDLL;
00930       break;
00931     }
00932     case DLL_PROCESS_DETACH:
00933 #if __X__MIPS__
00934       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00935 //      MessageBox (GetFocus(),"Trace detaching","Debug",MB_OK);
00936 #endif
00937       break;
00938   }
00939   return TRUE;
00940 }
00941 
00942 #if __SC__
00943 #pragma startaddress(DllMain)
00944 #endif
00945 
00946 BOOL _PaintMap(
00947  HWND parent_window, HWND info_window,
00948  unsigned char *pix, long w, long h , long mapID, X__STRUCTURE *lpX__in){
00949  LPBITMAPINFOHEADER lpbi;
00950  tracetool=0;
00951  hParent=parent_window;
00952  hInfo=info_window;
00953  lpEVI=lpX__in;
00954  {
00955  IMAGEMAP *map;
00956  map = &(iMap[mapID]);
00957  }
00958  ImageWidth=w;
00959  ImageHeight=h;
00960  ImagePixels=pix;
00961  lpbi=(LPBITMAPINFOHEADER)&ImageHeader;
00962  lpbi->biSize=sizeof(BITMAPINFOHEADER);
00963  lpbi->biWidth=(DWORD)w;
00964  lpbi->biHeight=(DWORD)h;
00965  lpbi->biPlanes=1;
00966  lpbi->biBitCount=24;
00967  lpbi->biCompression=BI_RGB;
00968  lpbi->biSizeImage = w*h*3L;
00969  lpbi->biXPelsPerMeter=0;
00970  lpbi->biYPelsPerMeter=0;
00971  lpbi->biClrUsed=0;
00972  lpbi->biClrImportant=0;
00973  xOffset=0,yOffset=0; scale=1.0;
00974  BuildFaceList(mapID);
00975 #include "keyfile.c"
00976  return Viewer();
00977 }

Generated on Sun Apr 27 14:20:11 2014 for OpenFX by  doxygen 1.5.6