00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #define MODULE_WINDOWS 1
00012
00013 #include "design.h"
00014
00015 static HBITMAP hbmold[3]={NULL,NULL,NULL},hbmoldv=NULL;
00016
00017 BOOL CreateMemoryWindows(void){
00018 int i;
00019 RECT rc;
00020 HDC hdc;
00021 int ifd,ild;
00022 if(View == TRIVIEW){ifd=0;ild=3;}
00023 else {ifd=ActiveView; ild=ifd+1;}
00024 for(i=ifd;i<ild;i++){
00025 hdc=GetDC(ghwnd_triview[i]);
00026 GetClientRect(ghwnd_triview[i],&rc);
00027 if(rc.bottom == 0 || rc.right == 0){
00028 ReleaseDC(ghwnd_triview[i],hdc);
00029 return FALSE;
00030 }
00031 ghdc_triview_Bitmap[i]=CreateCompatibleDC(hdc);
00032 if(ghdc_triview_Bitmap[i] == NULL)return FALSE;
00033 SelectPalette(ghdc_triview_Bitmap[i],ghpaletteScreen,FALSE);
00034 RealizePalette(ghdc_triview_Bitmap[i]);
00035 SelectObject(ghdc_triview_Bitmap[i],ghbrushWindow);
00036 ghbm_triview[i]=CreateCompatibleBitmap(hdc,rc.right,rc.bottom);
00037 if(ghbm_triview[i] == NULL)return FALSE;
00038 ReleaseDC(ghwnd_triview[i],hdc);
00039 hbmold[i]=SelectObject(ghdc_triview_Bitmap[i],ghbm_triview[i]);
00040 PatBlt(ghdc_triview_Bitmap[i],0,0,rc.right,rc.bottom,PATCOPY);
00041 }
00042 hdc=GetDC(ghwnd_view);
00043 GetClientRect(ghwnd_view,&rc);
00044 if(rc.bottom == 0 || rc.right == 0){
00045 ReleaseDC(ghwnd_view,hdc);
00046 return FALSE;
00047 }
00048 ghdc_view_Bitmap=CreateCompatibleDC(hdc);
00049 if(ghdc_view_Bitmap == NULL)return FALSE;
00050 SelectPalette(ghdc_view_Bitmap,ghpaletteScreen,FALSE);
00051 RealizePalette(ghdc_view_Bitmap);
00052 SelectObject(ghdc_view_Bitmap,ghbrushWindow);
00053 ghbm_view=CreateCompatibleBitmap(hdc,rc.right,rc.bottom);
00054 if(ghbm_view == NULL)return FALSE;
00055 ReleaseDC(ghwnd_view,hdc);
00056 hbmoldv=SelectObject(ghdc_view_Bitmap,ghbm_view);
00057 PatBlt(ghdc_view_Bitmap,0,0,rc.right,rc.bottom,PATCOPY);
00058 return TRUE;
00059 }
00060
00061 void DeleteMemoryWindows(void){
00062 int i;
00063 int ifd,ild;
00064 if(View == TRIVIEW){ifd=0;ild=3;}
00065 else {ifd=ActiveView; ild=ifd+1;}
00066 for(i=ifd;i<ild;i++){
00067 if(ghdc_triview_Bitmap[i] != NULL){
00068 if(hbmold[i] != NULL)SelectObject(ghdc_triview_Bitmap[i],hbmold[i]);
00069 DeleteDC(ghdc_triview_Bitmap[i]);
00070 }
00071 hbmold[i]=NULL;
00072 ghdc_triview_Bitmap[i]=NULL;
00073 if(ghbm_triview[i] != NULL)DeleteObject(ghbm_triview[i]);
00074 ghbm_triview[i]=NULL;
00075 }
00076 if(ghdc_view_Bitmap != NULL){
00077 if(hbmoldv != NULL)SelectObject(ghdc_view_Bitmap,hbmoldv);
00078 DeleteDC(ghdc_view_Bitmap);
00079 }
00080 hbmoldv=NULL;
00081 ghdc_view_Bitmap=NULL;
00082 if(ghbm_view != NULL)DeleteObject(ghbm_view);
00083 ghbm_view=NULL;
00084 }
00085
00086 void SetWindowSize(int x, int y, int view, BOOL reset){
00087 static int last_screenXsize,last_screenYsize;
00088 int i,Wsx,Wsy;
00089 x=max(x,20);
00090 y=max(y,20);
00091 if(reset){
00092 last_screenXsize=x;
00093 last_screenYsize=y;
00094 ToolbuttonSize=32;
00095 if(bToolpannelSmall)ToolpannelSpace=32;
00096 else ToolpannelSpace=50;
00097 ToolpannelSpace += 4;
00098 WindowGap=2;
00099 WindowTopOrigin=1;
00100 }
00101 WindowLeftOrigin=WindowGap;
00102 Wsy=y-InfoWindowSize-WindowTopOrigin-WindowGap;
00103 Wsx=x-ToolpannelSpace-WindowLeftOrigin-WindowGap;
00104 TriviewSpaceX=Wsx;
00105 TriviewSpaceY=Wsy;
00106 if(bToolpannelLeft)WindowLeftOrigin += ToolpannelSpace;
00107 if(View == TRIVIEW){
00108 TriviewSpaceX -= 2;
00109 TriviewSpaceY -= 2;
00110 if(reset){
00111 Window0sizeX=TriviewSpaceX/2;
00112 Window0sizeY=TriviewSpaceY/2;
00113 }
00114 Window0sizeX = (long)((double)(Window0sizeX*x)/(double)last_screenXsize);
00115 Window0sizeY = (long)((double)(Window0sizeY*y)/(double)last_screenYsize);
00116 WindowSizeX[0] = Window0sizeX;
00117 WindowSizeY[0] = Window0sizeY;
00118 WindowSizeX[1] = Window0sizeX;
00119 WindowSizeY[1] = TriviewSpaceY-Window0sizeY;
00120 WindowSizeX[2] = TriviewSpaceX-Window0sizeX;
00121 WindowSizeY[2] = TriviewSpaceY-Window0sizeY;
00122 WindowsXmin[0] = WindowLeftOrigin;
00123 WindowsYmin[0] = WindowTopOrigin;
00124 WindowsXmin[1] = WindowsXmin[0];
00125 WindowsYmin[1] = WindowsYmin[0]+WindowSizeY[0]+WindowGap;
00126 WindowsXmin[2] = WindowsXmin[1]+WindowSizeX[1]+WindowGap;
00127 WindowsYmin[2] = WindowsYmin[1];
00128 WindowViewXmin=WindowsXmin[2];
00129 WindowViewYmin=WindowsYmin[0];
00130 WindowViewXsize=WindowSizeX[2];
00131 WindowViewYsize=WindowSizeY[0];
00132 }
00133 else{
00134 for(i=0;i<3;i++){
00135 WindowsXmin[i] = WindowLeftOrigin;
00136 WindowsYmin[i] = WindowTopOrigin;
00137 WindowSizeX[i] = Wsy;
00138 WindowSizeY[i] = Wsy;
00139 }
00140 WindowViewXmin=WindowLeftOrigin+WindowSizeX[0];
00141 WindowViewYmin=WindowsYmin[0];
00142 WindowViewXsize=max(20,x-ToolpannelSpace-2-WindowSizeX[0]);
00143 WindowViewYsize=WindowViewXsize;
00144 }
00145 for(i=0;i<3;i++){
00146 WindowCentreX[i]=WindowSizeX[i]/2;
00147 WindowCentreY[i]=WindowSizeY[i]/2;
00148 }
00149 last_screenXsize=x;
00150 last_screenYsize=y;
00151 }
00152
00153 void SwitchWindow(int button){
00154 char tt[128];
00155 int buttontable[3][2]={{1,2},{0,2},{0,1}};
00156 int i,im;
00157 HDC hdc;
00158 RECT rc;
00159 if(button < 0){
00160 GetClientRect(ghwnd_main,&rc);
00161 if(View == TRIVIEW){
00162 LoadString(ghinst_main,IDX_MISC_QUADVIEW,tt,128);
00163 ModifyMenu(GetMenu(ghwnd_main),IDM_WINDOW_SWITCHWINDOWS,
00164 MF_BYCOMMAND|MF_STRING,IDM_WINDOW_SWITCHWINDOWS,tt);
00165 hdc=GetDC(ghwnd_main);
00166 FocusActiveWindow(hdc,FALSE);
00167 ReleaseDC(ghwnd_main,hdc);
00168 for(i=0;i<3;i++){
00169 if(i != ActiveView)EnableWindow(ghwnd_triview[i],FALSE);
00170 ShowWindow(ghwnd_triview[i],SW_HIDE);
00171 }
00172 if(ghwndOpenGLview == NULL)ShowWindow(ghwnd_view,SW_HIDE);
00173 else ShowWindow(ghwndOpenGLview,SW_HIDE);
00174 DeleteMemoryWindows();
00175 View=ONEVIEW;
00176 SetWindowSize(rc.right,rc.bottom,View,FALSE);
00177 GetTriview(FALSE);
00178 MoveWindow(ghwnd_current,
00179 WindowLeftOrigin,WindowTopOrigin,
00180 WindowSizeX[ActiveView],WindowSizeY[ActiveView],TRUE);
00181 MoveWindow(ghwnd_view,
00182 WindowViewXmin,WindowViewYmin,
00183 WindowViewXsize,WindowViewYsize,TRUE);
00184 if(ghwndOpenGLview != NULL)MoveWindow(ghwndOpenGLview,
00185 WindowViewXmin,WindowViewYmin,
00186 WindowViewXsize,WindowViewYsize,TRUE);
00187 CreateMemoryWindows();
00188 ToolboxSetPosition(1);
00189 ShowWindow(ghwnd_current,SW_SHOWNA);
00190 if(ghwndOpenGLview == NULL)ShowWindow(ghwnd_view,SW_SHOWNA);
00191 else ShowWindow(ghwndOpenGLview,SW_SHOWNA);
00192 DrawModel();
00193 if(ghwndOpenGLview == NULL)Draw3dView(0,0);
00194 else PostMessage(ghwndOpenGLview,(WM_USER+2),0,0);
00195 }
00196 else{
00197 LoadString(ghinst_main,IDX_MISC_SINGLEVIEW,tt,128);
00198 ModifyMenu(GetMenu(ghwnd_main),IDM_WINDOW_SWITCHWINDOWS,
00199 MF_BYCOMMAND|MF_STRING,IDM_WINDOW_SWITCHWINDOWS,tt);
00200 if(ghwndOpenGLview == NULL)ShowWindow(ghwnd_view,SW_HIDE);
00201 else ShowWindow(ghwndOpenGLview,SW_HIDE);
00202 ShowWindow(ghwnd_current,SW_HIDE);
00203 DeleteMemoryWindows();
00204 View=TRIVIEW;
00205 SetWindowSize(rc.right,rc.bottom,View,FALSE);
00206 GetTriview(FALSE);
00207 for(i=0;i<3;i++)
00208 MoveWindow(ghwnd_triview[i],
00209 WindowsXmin[i],WindowsYmin[i],
00210 WindowSizeX[i],WindowSizeY[i],TRUE);
00211 MoveWindow(ghwnd_view,WindowViewXmin,WindowViewYmin,
00212 WindowViewXsize,WindowViewYsize,TRUE);
00213 if(ghwndOpenGLview != NULL)MoveWindow(ghwndOpenGLview,
00214 WindowViewXmin,WindowViewYmin,
00215 WindowViewXsize,WindowViewYsize,TRUE);
00216 CreateMemoryWindows();
00217 for(i=0;i<3;i++){
00218 if(i != ActiveView)EnableWindow(ghwnd_triview[i],TRUE);
00219 ShowWindow(ghwnd_triview[i],SW_SHOWNA);
00220 }
00221 ToolboxSetPosition(0);
00222 if(ghwndOpenGLview == NULL)ShowWindow(ghwnd_view,SW_SHOWNA);
00223 else ShowWindow(ghwndOpenGLview,SW_SHOWNA);
00224 DrawModel();
00225 if(ghwndOpenGLview == NULL)Draw3dView(0,0);
00226 else PostMessage(ghwndOpenGLview,(WM_USER+2),0,0);
00227 hdc=GetDC(ghwnd_main);
00228 FocusActiveWindow(hdc,TRUE);
00229 ReleaseDC(ghwnd_main,hdc);
00230 }
00231 }
00232 else {
00233 int activetable[3][2]={
00234 {TRIFRONT,TRIRIGHT},
00235 {TRITOP, TRIRIGHT},
00236 {TRITOP, TRIFRONT}
00237 };
00238 ShowWindow(ghwnd_current,SW_HIDE);
00239 EnableWindow(ghwnd_triview[ActiveView],FALSE);
00240 DeleteMemoryWindows();
00241 ActiveView=activetable[ActiveView][button];
00242 ghwnd_current=ghwnd_triview[ActiveView];
00243 GetTriview(FALSE);
00244 MoveWindow(ghwnd_current,
00245 WindowLeftOrigin,WindowTopOrigin,
00246 WindowSizeX[ActiveView],WindowSizeY[ActiveView],TRUE);
00247 CreateMemoryWindows();
00248 ToolboxSetPosition(1);
00249 EnableWindow(ghwnd_triview[ActiveView],TRUE);
00250 ShowWindow(ghwnd_triview[ActiveView],SW_SHOWNA);
00251 DrawModel();
00252 }
00253 }
00254
00255 void FormatScreen(void){
00256 HDC hdc;
00257 RECT rc;
00258 int i;
00259 if(View == TRIVIEW){
00260 hdc=GetDC(ghwnd_main);
00261 FocusActiveWindow(hdc,FALSE);
00262 }
00263 DeleteMemoryWindows();
00264 GetClientRect(ghwnd_main,&rc);
00265 SetWindowSize(rc.right,rc.bottom,View,FALSE);
00266 GetTriview(FALSE);
00267 for(i=0;i<3;i++)
00268 MoveWindow(ghwnd_triview[i],
00269 WindowsXmin[i],WindowsYmin[i],
00270 WindowSizeX[i],WindowSizeY[i],TRUE);
00271 MoveWindow(ghwnd_view,WindowViewXmin,WindowViewYmin,
00272 WindowViewXsize,WindowViewYsize,TRUE);
00273 if(ghwndOpenGLview != NULL)MoveWindow(ghwndOpenGLview,
00274 WindowViewXmin,WindowViewYmin,
00275 WindowViewXsize,WindowViewYsize,TRUE);
00276 if(View == TRIVIEW){
00277 FocusActiveWindow(hdc,TRUE);
00278 ReleaseDC(ghwnd_main,hdc);
00279 }
00280 CreateMemoryWindows();
00281 DrawModel();
00282 if(ghwndOpenGLview == NULL)Draw3dView(0,0);
00283 else PostMessage(ghwndOpenGLview,(WM_USER+2),0,0);
00284 }
00285
00286 void UpdateIconPositions(void){
00287 HDC hdc;
00288 RECT rc;
00289 int i;
00290 if(View == TRIVIEW){
00291 hdc=GetDC(ghwnd_main);
00292 FocusActiveWindow(hdc,FALSE);
00293 ReleaseDC(ghwnd_main,hdc);
00294 }
00295 DeleteMemoryWindows();
00296 GetClientRect(ghwnd_main,&rc);
00297 SetWindowSize(rc.right,rc.bottom,View,TRUE);
00298 GetTriview(FALSE);
00299 for(i=0;i<3;i++)
00300 MoveWindow(ghwnd_triview[i],
00301 WindowsXmin[i],WindowsYmin[i],
00302 WindowSizeX[i],WindowSizeY[i],TRUE);
00303 MoveWindow(ghwnd_view,WindowViewXmin,WindowViewYmin,
00304 WindowViewXsize,WindowViewYsize,TRUE);
00305 if(ghwndOpenGLview != NULL)MoveWindow(ghwndOpenGLview,
00306 WindowViewXmin,WindowViewYmin,
00307 WindowViewXsize,WindowViewYsize,TRUE);
00308 MoveToolsWindow();
00309 InvalidateRect(ghwndTools,NULL,FALSE);
00310 UpdateWindow(ghwndTools);
00311 if(View == TRIVIEW){
00312 hdc=GetDC(ghwnd_main);
00313 FocusActiveWindow(hdc,TRUE);
00314 ReleaseDC(ghwnd_main,hdc);
00315 }
00316 CreateMemoryWindows();
00317 DrawModel();
00318 if(ghwndOpenGLview == NULL)Draw3dView(0,0);
00319 else PostMessage(ghwndOpenGLview,(WM_USER+2),0,0);
00320 }
00321
00322 void FocusActiveWindow(HDC hdc, BOOL place){
00323 RECT rc;
00324 POINT pc;
00325 HPEN hOldPen;
00326 if(View == ONEVIEW)return;
00327 GetWindowRect(ghwnd_current,&rc);
00328 pc.x=rc.left; pc.y=rc.top;
00329 ScreenToClient(ghwnd_main,&pc);
00330 rc.left=pc.x-1; rc.top=pc.y-1;
00331 pc.x=rc.right; pc.y=rc.bottom;
00332 ScreenToClient(ghwnd_main,&pc);
00333 rc.right=pc.x+1; rc.bottom=pc.y+1;
00334 if(!place){
00335 RECT rc1;
00336 rc.left -= 1;
00337 rc.right += 1;
00338 CopyRect(&rc1,&rc);
00339 rc1.bottom = rc1.top+1;
00340 InvalidateRect(ghwnd_main,&rc1,TRUE);
00341 CopyRect(&rc1,&rc);
00342 rc1.top = rc1.bottom-1;
00343 InvalidateRect(ghwnd_main,&rc1,TRUE);
00344 CopyRect(&rc1,&rc);
00345 rc1.right = rc1.left+2;
00346 InvalidateRect(ghwnd_main,&rc1,TRUE);
00347 CopyRect(&rc1,&rc);
00348 rc1.left = rc1.right-2;
00349 InvalidateRect(ghwnd_main,&rc1,TRUE);
00350 }
00351 else
00352 { DWORD oldROP;
00353 HPALETTE hpalT;
00354 hpalT = SelectPalette(hdc,ghpaletteScreen,FALSE);
00355 RealizePalette (hdc);
00356
00357 hOldPen=SelectObject(hdc,ghSelectedPen);
00358
00359 MoveToEx(hdc,rc.left,rc.top,NULL);
00360 LineTo(hdc,rc.right,rc.top);
00361 LineTo(hdc,rc.right,rc.bottom-1);
00362 LineTo(hdc,rc.left,rc.bottom-1);
00363 LineTo(hdc,rc.left,rc.top);
00364 MoveToEx(hdc,rc.left-1,rc.top,NULL);
00365 LineTo(hdc,rc.left-1,rc.bottom-1);
00366 MoveToEx(hdc,rc.right-1,rc.top,NULL);
00367 LineTo(hdc,rc.right-1,rc.bottom-1);
00368
00369 SelectObject(hdc,hOldPen);
00370 SelectPalette(hdc,hpalT,FALSE);
00371 }
00372 }
00373
00374 BOOL CursorInTriview(void){
00375 POINT p;
00376 RECT r;
00377 int i;
00378 GetCursorPos(&p);
00379 if(View == TRIVIEW){
00380 for(i=0;i<3;i++){
00381 GetWindowRect(ghwnd_triview[i],&r);
00382 if(PtInRect(&r,p))return TRUE;
00383 }
00384 }
00385 else{
00386 GetWindowRect(ghwnd_current,&r);
00387 if(PtInRect(&r,p))return TRUE;
00388 }
00389 return FALSE;
00390 }
00391