WINDOWS.C

Go to the documentation of this file.
00001 /* file WINDOWS.C  Draw the main screen windows                   */
00002 
00003 #define MODULE_WINDOWS 1
00004 
00005 #include "animate.h"
00006 
00007 static HBITMAP hbmold[3]={NULL,NULL,NULL},hbmoldv=NULL;
00008 
00009 // Drawing of lines and shapes takes place in MEMORY windows
00010 // it is only after these windows are drawn that they are
00011 // copied to the display so that they become visible.
00012 // This function creates the memory windows.
00013 
00014 BOOL CreateMemoryWindows(void){
00015  int i;
00016  RECT rc;
00017  HDC hdc;
00018  int ifd,ild;
00019  if(View == TRIVIEW){ifd=0;ild=3;}
00020  else               {ifd=ActiveView; ild=ifd+1;}
00021  for(i=ifd;i<ild;i++){
00022    hdc=GetDC(ghwnd_triview[i]);
00023    GetClientRect(ghwnd_triview[i],&rc);
00024    if(rc.bottom == 0 || rc.right == 0){
00025      ReleaseDC(ghwnd_triview[i],hdc);
00026      return FALSE;
00027    }
00028    ghdc_triview_Bitmap[i]=CreateCompatibleDC(hdc);
00029    if(ghdc_triview_Bitmap[i] == NULL)return FALSE;
00030 //   SelectPalette(ghdc_triview_Bitmap[i],ghpaletteScreen,FALSE);
00031 //   RealizePalette(ghdc_triview_Bitmap[i]);
00032    SelectObject(ghdc_triview_Bitmap[i],ghbrushWindow);
00033    ghbm_triview[i]=CreateCompatibleBitmap(hdc,rc.right,rc.bottom);
00034    if(ghbm_triview[i] == NULL)return FALSE;
00035    ReleaseDC(ghwnd_triview[i],hdc);
00036    hbmold[i]=SelectObject(ghdc_triview_Bitmap[i],ghbm_triview[i]);
00037    PatBlt(ghdc_triview_Bitmap[i],0,0,rc.right,rc.bottom,PATCOPY);
00038  }
00039  hdc=GetDC(ghwnd_view);
00040  GetClientRect(ghwnd_view,&rc);
00041  if(rc.bottom == 0 || rc.right == 0){
00042    ReleaseDC(ghwnd_view,hdc);
00043    return FALSE;
00044  }
00045  ghdc_view_Bitmap=CreateCompatibleDC(hdc);
00046  if(ghdc_view_Bitmap == NULL)return FALSE;
00047 // SelectPalette(ghdc_view_Bitmap,ghpaletteScreen,FALSE);
00048 // RealizePalette(ghdc_view_Bitmap);
00049  SelectObject(ghdc_view_Bitmap,ghbrushWindow);
00050  ghbm_view=CreateCompatibleBitmap(hdc,rc.right,rc.bottom);
00051  if(ghbm_view == NULL)return FALSE;
00052  ReleaseDC(ghwnd_view,hdc);
00053  hbmoldv=SelectObject(ghdc_view_Bitmap,ghbm_view);
00054  PatBlt(ghdc_view_Bitmap,0,0,rc.right,rc.bottom,PATCOPY);
00055  return TRUE;
00056 }
00057 
00058 // Delete the off-screen memory windows.
00059 
00060 void DeleteMemoryWindows(void){
00061  int i;
00062  int ifd,ild;
00063  if(View == TRIVIEW){ifd=0;ild=3;}
00064  else               {ifd=ActiveView; ild=ifd+1;}
00065  for(i=ifd;i<ild;i++){
00066    if(ghdc_triview_Bitmap[i] != NULL){
00067      if(hbmold[i] != NULL)SelectObject(ghdc_triview_Bitmap[i],hbmold[i]);
00068      DeleteDC(ghdc_triview_Bitmap[i]);
00069    }
00070    hbmold[i]=NULL;
00071    ghdc_triview_Bitmap[i]=NULL;
00072    if(ghbm_triview[i] != NULL)DeleteObject(ghbm_triview[i]);
00073    ghbm_triview[i]=NULL;
00074  }
00075  if(ghdc_view_Bitmap != NULL){
00076    if(hbmoldv != NULL)SelectObject(ghdc_view_Bitmap,hbmoldv);
00077    DeleteDC(ghdc_view_Bitmap);
00078  }
00079  hbmoldv=NULL;
00080  ghdc_view_Bitmap=NULL;
00081  if(ghbm_view != NULL)DeleteObject(ghbm_view);
00082  ghbm_view=NULL;
00083 }
00084 
00085 // Draw a YELLOW coloured box around the active window when the 4 view
00086 // windows are in use.
00087 
00088 void FocusActiveWindow(HDC hdc, BOOL place){
00089  RECT rc;
00090  POINT pc;
00091  HPEN  hOldPen;
00092  if(View == ONEVIEW)return;
00093  GetWindowRect(ghwnd_current,&rc);
00094  pc.x=rc.left; pc.y=rc.top;
00095  ScreenToClient(ghwnd_main,&pc);
00096  rc.left=pc.x-1; rc.top=pc.y-1;
00097  pc.x=rc.right; pc.y=rc.bottom;
00098  ScreenToClient(ghwnd_main,&pc);
00099  rc.right=pc.x+1; rc.bottom=pc.y+1;
00100  if(!place){
00101    RECT rc1;
00102    rc.left  -= 1;
00103    rc.right += 1;
00104    CopyRect(&rc1,&rc);
00105    rc1.bottom = rc1.top+1;
00106    InvalidateRect(ghwnd_main,&rc1,TRUE);
00107    CopyRect(&rc1,&rc);
00108    rc1.top = rc1.bottom-1;
00109    InvalidateRect(ghwnd_main,&rc1,TRUE);
00110    CopyRect(&rc1,&rc);
00111    rc1.right = rc1.left+2;
00112    InvalidateRect(ghwnd_main,&rc1,TRUE);
00113    CopyRect(&rc1,&rc);
00114    rc1.left = rc1.right-2;
00115    InvalidateRect(ghwnd_main,&rc1,TRUE);
00116  }
00117  else
00118  { //DWORD oldROP;
00119    HPALETTE hpalT;
00120 //   hpalT = SelectPalette(hdc,ghpaletteScreen,FALSE);
00121 //   RealizePalette (hdc);
00122 
00123 //   oldROP=SetROP2(hdc,R2_NOT);
00124 //   hOldPen=SelectObject(hdc,GetStockObject(WHITE_PEN));
00125    hOldPen=SelectObject(hdc,ghSelectedPen);
00126    MoveToEx(hdc,rc.left,rc.top,NULL);
00127    LineTo(hdc,rc.right,rc.top);
00128    LineTo(hdc,rc.right,rc.bottom-1);
00129    LineTo(hdc,rc.left,rc.bottom-1);
00130    LineTo(hdc,rc.left,rc.top);
00131    MoveToEx(hdc,rc.left-1,rc.top,NULL);
00132    LineTo(hdc,rc.left-1,rc.bottom-1);
00133    MoveToEx(hdc,rc.right-1,rc.top,NULL);
00134    LineTo(hdc,rc.right-1,rc.bottom-1);
00135 //   SetROP2(hdc,oldROP);
00136    SelectObject(hdc,hOldPen);
00137 //   SelectPalette(hdc,hpalT,FALSE);
00138  }
00139 }
00140 
00141 void SetWindowSize(int x, int y, int view, BOOL reset){
00142  static int last_screenXsize,last_screenYsize;
00143  int i,Wsx,Wsy,KeySpace;
00144  x=max(x,20);
00145  y=max(y,20);
00146  if(reset){
00147    last_screenXsize=x;
00148    last_screenYsize=y;
00149    ToolbuttonSize=32;
00150    if(bToolpannelSmall)ToolpannelSpace=32;  // small size toolbar 
00151    else                ToolpannelSpace=50;
00152    ToolpannelSpace += 4;
00153    WindowGap=2;
00154    WindowTopOrigin=1;
00155    WindowViewSliderYsize=GetSystemMetrics(SM_CXHTHUMB);
00156    // To effect bigger scroll bar expecially at higher resoluton
00157    if(Xres > 800)WindowViewSliderYsize = (3*WindowViewSliderYsize)/2; // RSF
00158    else          WindowViewSliderYsize = (6*WindowViewSliderYsize)/5; // RSF
00159    KeyframerSize=GetSystemMetrics(SM_CXHTHUMB)/*+InfoWindowSize*/+60;
00160  }
00161  if(keyframer_docked_and_visible)KeySpace=KeyframerSize;
00162  else                            KeySpace=0;
00163  WindowLeftOrigin=WindowGap;
00164  Wsy=y-InfoWindowSize-WindowTopOrigin-WindowGap-KeySpace;
00165  Wsx=x-ToolpannelSpace-WindowLeftOrigin-WindowGap;
00166  TriviewSpaceX=Wsx;
00167  TriviewSpaceY=Wsy;
00168  KeyframerYpos=WindowTopOrigin+TriviewSpaceY+2;
00169  if(bToolpannelLeft)WindowLeftOrigin += ToolpannelSpace;
00170  if(View == TRIVIEW){
00171    TriviewSpaceX -= 2; /* borders */
00172    TriviewSpaceY -= 2;
00173    if(reset){
00174      Window0sizeX=TriviewSpaceX/2;
00175      Window0sizeY=TriviewSpaceY/2;
00176    }
00177    Window0sizeX = (long)((double)(Window0sizeX*x)/(double)last_screenXsize);
00178    Window0sizeY = (long)((double)(Window0sizeY*y)/(double)last_screenYsize);
00179    WindowSizeX[0] = Window0sizeX;
00180    WindowSizeY[0] = Window0sizeY;
00181    WindowSizeX[1] = Window0sizeX;
00182    WindowSizeY[1] = TriviewSpaceY-Window0sizeY;
00183    WindowSizeX[2] = TriviewSpaceX-Window0sizeX;
00184    WindowSizeY[2] = TriviewSpaceY-Window0sizeY;
00185    WindowsXmin[0] = WindowLeftOrigin;
00186    WindowsYmin[0] = WindowTopOrigin;
00187    WindowsXmin[1] = WindowsXmin[0];
00188    WindowsYmin[1] = WindowsYmin[0]+WindowSizeY[0]+WindowGap;
00189    WindowsXmin[2] = WindowsXmin[1]+WindowSizeX[1]+WindowGap;
00190    WindowsYmin[2] = WindowsYmin[1];
00191    WindowViewXmin=WindowsXmin[2];
00192    WindowViewYmin=WindowsYmin[0];
00193    WindowViewXsize=WindowSizeX[2];
00194    WindowViewYsize=WindowSizeY[0]-WindowViewSliderYsize-1;
00195    WindowViewSliderXpos=WindowViewXmin;
00196    WindowViewSliderYpos=WindowViewYmin+WindowViewYsize,
00197    WindowViewSliderXsize=WindowViewXsize;
00198  }
00199  else{
00200    if(BigCameraView){
00201      WindowViewXmin=WindowLeftOrigin;
00202      WindowViewYmin=WindowTopOrigin;
00203      WindowViewXsize=Wsy+KeySpace;
00204      WindowViewYsize=Wsy-WindowViewSliderYsize-1;
00205      WindowViewSliderYpos=WindowTopOrigin+WindowViewYsize+2;
00206      WindowViewSliderXpos=WindowViewXmin;
00207      WindowViewSliderXsize=WindowViewXsize;
00208      for(i=0;i<3;i++){
00209        WindowsXmin[i]=WindowLeftOrigin+WindowViewXsize+WindowGap;
00210        WindowsYmin[i]=WindowViewYmin;
00211        WindowSizeX[i]=max(20,x-ToolpannelSpace-WindowViewXsize-3*WindowGap);
00212        WindowSizeY[i]=WindowSizeX[i];
00213      }
00214    }
00215    else {
00216      for(i=0;i<3;i++){
00217        WindowsXmin[i] = WindowLeftOrigin;
00218        WindowsYmin[i] = WindowTopOrigin;
00219        WindowSizeX[i] = Wsy+KeySpace;
00220        WindowSizeY[i] = Wsy;
00221      }
00222      WindowViewXmin=WindowLeftOrigin+WindowSizeX[0]+WindowGap;
00223      WindowViewYmin=WindowsYmin[0];
00224      WindowViewXsize=max(20,x-ToolpannelSpace-WindowSizeX[0]-3*WindowGap);
00225      WindowViewYsize=(WindowViewXsize*3)/4;
00226      WindowViewSliderYpos=WindowViewYmin+WindowViewYsize+1;
00227      WindowViewSliderXpos=WindowViewXmin;
00228      WindowViewSliderXsize=WindowViewXsize;
00229    }
00230  }
00231  for(i=0;i<3;i++){
00232    WindowCentreX[i]=WindowSizeX[i]/2;
00233    WindowCentreY[i]=WindowSizeY[i]/2;
00234  }
00235  last_screenXsize=x;
00236  last_screenYsize=y;
00237 }
00238 
00239 void SwitchWindow(int button){
00240  char tt[128];
00241  int  buttontable[3][2]={{1,2},{0,2},{0,1}};
00242  int i,im;
00243  HDC hdc;
00244  RECT rc;
00245  if(button < 0){ /* switch between 3 / 1 view */
00246    GetClientRect(ghwnd_main,&rc);
00247    if(View == TRIVIEW){
00248      LoadString(ghinst_main,IDX_MISC_QUADVIEW,tt,128);
00249      ModifyMenu(GetMenu(ghwnd_main),IDM_WINDOW_SWITCHWINDOWS,
00250            MF_BYCOMMAND|MF_STRING,IDM_WINDOW_SWITCHWINDOWS,tt);
00251      hdc=GetDC(ghwnd_main);
00252      FocusActiveWindow(hdc,FALSE);
00253      ReleaseDC(ghwnd_main,hdc);
00254      for(i=0;i<3;i++){
00255        if(i != ActiveView)EnableWindow(ghwnd_triview[i],FALSE);
00256        ShowWindow(ghwnd_triview[i],SW_HIDE);
00257      }
00258      if(ghwndOpenGLview == NULL)ShowWindow(ghwnd_view,SW_HIDE);
00259      else                       ShowWindow(ghwndOpenGLview,SW_HIDE);
00260      ShowWindow(ghwndQuicktime,SW_HIDE);
00261      DeleteMemoryWindows();
00262      View=ONEVIEW;
00263      SetWindowSize(rc.right,rc.bottom,View,FALSE);
00264      GetTriview(FALSE);
00265      MoveWindow(ghwnd_current,
00266                 WindowsXmin[ActiveView],WindowsYmin[ActiveView],
00267                 WindowSizeX[ActiveView],WindowSizeY[ActiveView],TRUE);
00268      MoveWindow(ghwndQuicktime,WindowViewSliderXpos,WindowViewSliderYpos,
00269                 WindowViewSliderXsize,WindowViewSliderYsize,TRUE);
00270      MoveWindow(ghwnd_view,WindowViewXmin,WindowViewYmin,
00271                 WindowViewXsize,WindowViewYsize,TRUE);
00272      if(ghwndOpenGLview != NULL)MoveWindow(ghwndOpenGLview,
00273                 WindowViewXmin,WindowViewYmin,
00274                 WindowViewXsize,WindowViewYsize,TRUE);
00275      CreateMemoryWindows();
00276      if(BigCameraView)ToolboxSetPosition(2);
00277      else             ToolboxSetPosition(1);
00278      ShowWindow(ghwndQuicktime,SW_SHOWNA);
00279      ShowWindow(ghwnd_current,SW_SHOWNA);
00280      if(ghwndOpenGLview == NULL)ShowWindow(ghwnd_view,SW_SHOWNA);
00281      else                       ShowWindow(ghwndOpenGLview,SW_SHOWNA);
00282      ReDrawStageDisplay(TRUE);
00283      PerspectiveView(0,0);
00284    }
00285    else{
00286      LoadString(ghinst_main,IDX_MISC_SINGLEVIEW,tt,128);
00287      ModifyMenu(GetMenu(ghwnd_main),IDM_WINDOW_SWITCHWINDOWS,
00288            MF_BYCOMMAND|MF_STRING,IDM_WINDOW_SWITCHWINDOWS,tt);
00289      ShowWindow(ghwnd_current,SW_HIDE);
00290      if(ghwndOpenGLview == NULL)ShowWindow(ghwnd_view,SW_HIDE);
00291      else                       ShowWindow(ghwndOpenGLview,SW_HIDE);
00292      ShowWindow(ghwndQuicktime,SW_HIDE);
00293      DeleteMemoryWindows();
00294      View=TRIVIEW;
00295      SetWindowSize(rc.right,rc.bottom,View,FALSE);
00296      GetTriview(FALSE);
00297      for(i=0;i<3;i++)MoveWindow(ghwnd_triview[i],
00298                           WindowsXmin[i],WindowsYmin[i],
00299                           WindowSizeX[i],WindowSizeY[i],TRUE);
00300      MoveWindow(ghwndQuicktime,WindowViewSliderXpos,WindowViewSliderYpos,
00301                 WindowViewSliderXsize,WindowViewSliderYsize,TRUE);
00302      MoveWindow(ghwnd_view,WindowViewXmin,WindowViewYmin,
00303                 WindowViewXsize,WindowViewYsize,TRUE);
00304      if(ghwndOpenGLview != NULL)MoveWindow(ghwndOpenGLview,
00305                 WindowViewXmin,WindowViewYmin,
00306                 WindowViewXsize,WindowViewYsize,TRUE);
00307      CreateMemoryWindows();
00308      for(i=0;i<3;i++){
00309        if(i != ActiveView)EnableWindow(ghwnd_triview[i],TRUE);
00310        ShowWindow(ghwnd_triview[i],SW_SHOWNA);
00311      }
00312      ToolboxSetPosition(0);
00313      if(ghwndOpenGLview == NULL)ShowWindow(ghwnd_view,SW_SHOWNA);
00314      else                       ShowWindow(ghwndOpenGLview,SW_SHOWNA);
00315      ShowWindow(ghwndQuicktime,SW_SHOWNA);
00316      ReDrawStageDisplay(TRUE);
00317      PerspectiveView(0,0);
00318      hdc=GetDC(ghwnd_main);
00319      FocusActiveWindow(hdc,TRUE);
00320      ReleaseDC(ghwnd_main,hdc);
00321    }
00322  }
00323  else { /* one single view to another */
00324   int activetable[3][2]={
00325     {TRIFRONT,TRIRIGHT},
00326     {TRITOP,  TRIRIGHT},
00327     {TRITOP,  TRIFRONT}
00328    };
00329    ShowWindow(ghwnd_current,SW_HIDE);
00330    EnableWindow(ghwnd_triview[ActiveView],FALSE);
00331    DeleteMemoryWindows();
00332    ActiveView=activetable[ActiveView][button];
00333    ghwnd_current=ghwnd_triview[ActiveView];
00334    MoveWindow(ghwnd_current,
00335               WindowsXmin[ActiveView],WindowsYmin[ActiveView],
00336               WindowSizeX[ActiveView],WindowSizeY[ActiveView],TRUE);
00337    CreateMemoryWindows();
00338    EnableWindow(ghwnd_triview[ActiveView],TRUE);
00339    if(BigCameraView)ToolboxSetPosition(2);
00340    else             ToolboxSetPosition(1);
00341    ShowWindow(ghwnd_triview[ActiveView],SW_SHOWNA);
00342    ReDrawStageDisplay(TRUE);
00343  }
00344 }
00345 
00346 void FormatScreen(void){ /* called after windows have been reset */
00347  HDC hdc;
00348  RECT rc;
00349  int i;
00350  if(View == TRIVIEW){
00351    hdc=GetDC(ghwnd_main);
00352    FocusActiveWindow(hdc,FALSE);
00353  }
00354  DeleteMemoryWindows();
00355  GetClientRect(ghwnd_main,&rc);
00356  SetWindowSize(rc.right,rc.bottom,View,FALSE);
00357  GetTriview(FALSE);
00358  for(i=0;i<3;i++)
00359    MoveWindow(ghwnd_triview[i],
00360               WindowsXmin[i],WindowsYmin[i],
00361               WindowSizeX[i],WindowSizeY[i],TRUE);
00362  MoveWindow(ghwndQuicktime,WindowViewSliderXpos,WindowViewSliderYpos,
00363               WindowViewSliderXsize,WindowViewSliderYsize,TRUE);
00364  MoveWindow(ghwnd_view,WindowViewXmin,WindowViewYmin,
00365               WindowViewXsize,WindowViewYsize,TRUE);
00366  if(ghwndOpenGLview != NULL)MoveWindow(ghwndOpenGLview,
00367               WindowViewXmin,WindowViewYmin,
00368               WindowViewXsize,WindowViewYsize,TRUE);
00369  if(View == TRIVIEW){
00370    FocusActiveWindow(hdc,TRUE);
00371    ReleaseDC(ghwnd_main,hdc);
00372  }
00373  CreateMemoryWindows();
00374  InvalidateRect(ghwndQuicktime,NULL,TRUE);
00375  UpdateWindow(ghwndQuicktime);
00376  ReDrawStageDisplay(TRUE);
00377  if(ghwndOpenGLview == NULL)PerspectiveView(0,1);
00378  else UpdateGLview(TRUE);
00379 }
00380 
00381 void UpdateIconPositions(void){
00382  HDC hdc;
00383  RECT rc;
00384  int i;
00385  if(View == TRIVIEW){
00386    hdc=GetDC(ghwnd_main);
00387    FocusActiveWindow(hdc,FALSE);
00388    ReleaseDC(ghwnd_main,hdc);
00389  }
00390  DeleteMemoryWindows();
00391  GetClientRect(ghwnd_main,&rc);
00392  SetWindowSize(rc.right,rc.bottom,View,TRUE);
00393  GetTriview(FALSE);
00394  for(i=0;i<3;i++)
00395    MoveWindow(ghwnd_triview[i],
00396               WindowsXmin[i],WindowsYmin[i],
00397               WindowSizeX[i],WindowSizeY[i],TRUE);
00398  MoveWindow(ghwndQuicktime,WindowViewSliderXpos,WindowViewSliderYpos,
00399               WindowViewSliderXsize,WindowViewSliderYsize,TRUE);
00400  MoveWindow(ghwnd_view,WindowViewXmin,WindowViewYmin,
00401               WindowViewXsize,WindowViewYsize,TRUE);
00402  if(ghwndOpenGLview != NULL)MoveWindow(ghwndOpenGLview,
00403               WindowViewXmin,WindowViewYmin,
00404               WindowViewXsize,WindowViewYsize,TRUE);
00405  MoveToolsWindow();
00406  InvalidateRect(ghwndTools,NULL,FALSE);
00407  UpdateWindow(ghwndTools);
00408  if(View == TRIVIEW){
00409    hdc=GetDC(ghwnd_main);
00410    FocusActiveWindow(hdc,TRUE);
00411    ReleaseDC(ghwnd_main,hdc);
00412  }
00413  CreateMemoryWindows();
00414  InvalidateRect(ghwndQuicktime,NULL,TRUE);
00415  UpdateWindow(ghwndQuicktime);
00416  ReDrawStageDisplay(TRUE);
00417  if(ghwndOpenGLview == NULL)PerspectiveView(0,1);
00418  else UpdateGLview(TRUE);
00419 }
00420 
00421 // Check to see in which of the view windows the mouse cursor
00422 // lies in.
00423 
00424 BOOL CursorInTriview(void){
00425  POINT p;
00426  RECT  r;
00427  int   i;
00428  GetCursorPos(&p);
00429  if(View == TRIVIEW){
00430    for(i=0;i<3;i++){
00431      GetWindowRect(ghwnd_triview[i],&r);
00432      if(PtInRect(&r,p))return TRUE;
00433    }
00434  }
00435  else{
00436    GetWindowRect(ghwnd_current,&r);
00437    if(PtInRect(&r,p))return TRUE;
00438  }
00439  return FALSE;
00440 }
00441 

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