home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2004 March / PCWELT_3_2004.ISO / pcwsoft / flaskmpeg_078_39_src.z.exe / flaskmpeg / flletterboxpad.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-28  |  3.8 KB  |  175 lines

  1. /* 
  2.  *  flletterboxpad.cpp
  3.  *
  4.  *    Copyright (C) Alberto Vigata - January 2000
  5.  *
  6.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  7.  *    
  8.  *  FlasKMPEG is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2, or (at your option)
  11.  *  any later version.
  12.  *   
  13.  *  FlasKMPEG is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *   
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with GNU Make; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  21.  *
  22.  */
  23.  
  24. #include "flletterboxpad.h"
  25. #include "debug.h"
  26.  
  27.  
  28. #define AREA_SIDE 20
  29.  
  30.  
  31. FlLetterboxPad::FlLetterboxPad()
  32. {
  33.   m_clx = m_cly = 0;
  34.   m_bLocked = false;
  35.   m_nLockedType = 0;
  36. }
  37.  
  38. bool FlLetterboxPad::SetConfig( int nWidth, int nHeight, TLetterboxConfig *cfg )
  39. {
  40.   m_nWidth = nWidth;
  41.   m_nHeight = nHeight;
  42.   m_cfg = *cfg;
  43.   BuildAreas();
  44.   return true;
  45. }
  46.  
  47.  
  48. bool FlLetterboxPad::OnDrag( int x, int y )
  49. {
  50.   bool res = false;
  51.   
  52.   if( m_bLocked )
  53.     res = Notify( x, y, m_nLockedType );
  54.  
  55.   return res;
  56. }
  57.  
  58. bool FlLetterboxPad::OnHover( int x, int y, LPCTSTR &mousetype)
  59. {
  60.   for( int i=0; i<4; i++ ) {
  61.     if( m_vAreas[i].Poll( x, y ) ) {
  62.       int type = m_bLocked ? m_nLockedType : m_vAreas[i].GetType();
  63.       switch( type )
  64.       {
  65.         case top:
  66.         case bottom:
  67.           mousetype = IDC_SIZENS;
  68.           break;
  69.         case left:
  70.         case right:
  71.           mousetype = IDC_SIZEWE;
  72.           break;
  73.       }
  74.       return true;
  75.     }
  76.   }
  77.   return false;
  78. }
  79.  
  80.  
  81. bool FlLetterboxPad::BuildAreas()
  82.   int w = m_nWidth;
  83.   int h = m_nHeight;
  84.  
  85.   int b = m_cfg.bottom;
  86.   int l = m_cfg.left;
  87.   int r = m_cfg.right;
  88.   int t = m_cfg.top;
  89.  
  90.   // left, right, top, bottom
  91.   m_vAreas[0].Set( l, h/2, AREA_SIDE, h, left );
  92.   m_vAreas[1].Set( w - r, h/2, AREA_SIDE, h, right );
  93.   m_vAreas[2].Set( w/2, t, w, AREA_SIDE, top );
  94.   m_vAreas[3].Set( w/2, h - b, w, AREA_SIDE, bottom );
  95.  
  96.   return true;
  97. }
  98.  
  99. int FlLetterboxPad::SnapCoordinate( int c, int oldc )
  100. {
  101.   return c/2*2;
  102. }
  103.  
  104. bool FlLetterboxPad::OnClick( int x, int y )
  105. {
  106.   bool bSuccess = false;
  107.   m_clx = x;
  108.   m_cly = y;
  109.   for( int i=0; i<4; i++ ) {
  110.     if( m_vAreas[i].Poll( x, y ) ) {
  111.       m_bLocked = true;
  112.       m_nLockedType = m_vAreas[i].GetType();
  113.       bSuccess = true;
  114.     }
  115.   }
  116.   return bSuccess;
  117. }
  118.  
  119. bool FlLetterboxPad::OnRelease()
  120. {
  121.   m_bLocked = false;
  122.   return true;
  123. }
  124.  
  125. bool FlLetterboxPad::Notify( int x, int y, int nType )
  126. {
  127.   int w = m_nWidth;
  128.   int h = m_nHeight;
  129.  
  130.   TLetterboxConfig cfg;
  131.  
  132.   // clip x, y first
  133.   //x = x<0 ? 0 : x>w ? w : x;
  134.   //y = y<0 ? 0 : y>h ? h : y;
  135.  
  136.   cfg = m_cfg;
  137.   switch( nType )
  138.   {
  139.     case top:
  140.       cfg.top = SnapCoordinate(y, cfg.top);
  141.       break;
  142.     case left:
  143.       cfg.left = SnapCoordinate(x, cfg.left);
  144.       break;
  145.     case right:
  146.       cfg.right = SnapCoordinate(w - x, cfg.right);
  147.       break;
  148.     case bottom:
  149.       cfg.bottom = SnapCoordinate(h - y, cfg.bottom);
  150.       break;
  151.   }
  152.  
  153.   FlLetterbox oLetterbox;
  154.  
  155.   oLetterbox.Configure( &cfg, sizeof (TLetterboxConfig) );
  156.  
  157.   flfilter_conf fc;
  158.   memset( &fc, 0, sizeof flfilter_conf );
  159.   fc.iw = w;
  160.   fc.ih = h;
  161.  
  162.   // Validate configuration
  163.   if( oLetterbox.ValFilterConf(&fc) ) 
  164.   {
  165.     // if nothing to do
  166.     if( memcmp(&cfg, &m_cfg, sizeof TLetterboxConfig)==0 )
  167.       return false;
  168.  
  169.     m_cfg = cfg;
  170.     BuildAreas();
  171.     return true;
  172.   }
  173.   return false;
  174. }