int mxExpressionTray::GetCellUnderPosition( int x, int y )
{
	CExpClass *active = expressions->GetActiveClass();
	if ( !active )
		return -1;

	int rcx, rcy, rcw, rch;
	int c = 0;
	while ( c < active->GetNumExpressions() )
	{
		if ( !ComputeRect( c, rcx, rcy, rcw, rch ) )
		{
			c++;
			continue;
		}

		if ( x >= rcx && x <= rcx + rcw &&
			 y >= rcy && y <= rcy + rch )
		{
			return c;
		}

		c++;
	}
	return -1;
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : exp - 
//-----------------------------------------------------------------------------
void mxExpressionTray::Select( int exp, bool deselect /*=true*/ )
{
	int oldcell = m_nCurCell;

	if ( deselect )
	{
		Deselect();
	}

	m_nPrevCell = oldcell;
	m_nCurCell = exp;

	if ( m_nCurCell >= 0 )
	{
		CExpClass *active = expressions->GetActiveClass();
		if ( active )
		{
			CExpression *exp = active->GetExpression( m_nCurCell );
			if ( exp )
			{
				exp->SetSelected( true );
			}
		}
	}

	redraw();
}
void mxExpressionTray::ShowRightClickMenu( int mx, int my )
{
	CExpClass *active = expressions->GetActiveClass();
	if ( !active )
		return;

	mxPopupMenu *pop = new mxPopupMenu();
	Assert( pop );

	CExpression *exp = NULL;
	if ( m_nClickedCell != -1 )
	{
		exp = active->GetExpression( m_nClickedCell );
	}

	pop->add( "New Expression...", IDC_CONTEXT_NEWEXP );
	if ( exp )
	{
		pop->addSeparator();
		pop->add( va( "Edit '%s'...", exp->name ), IDC_CONTEXT_EDITEXP );
		pop->add( va( "Save '%s'", exp->name ), IDC_CONTEXT_SAVEEXP );

		if ( exp->CanUndo() || exp->CanRedo() )
		{
			pop->add( va( "Revert '%s'", exp->name ), IDC_CONTEXT_REVERT );
		}
		pop->addSeparator();
		pop->add( va( "Delete '%s'", exp->name ), IDC_CONTEXT_DELETEXP );
		pop->addSeparator();
		pop->add( va( "Re-create thumbnail for '%s'", exp->name ), IDC_CONTEXT_CREATEBITMAP );
	}

	pop->popup( this, mx, my );
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void ControlPanel::Redo( void )
{
	CExpClass *active = expressions->GetActiveClass();
	if ( !active )
		return;
	int index = active->GetSelectedExpression();
	if ( index != -1 )
	{
		RedoExpression( index );
	}
}
void mxExpressionTray::ReloadBitmaps( void )
{
	CExpClass *cl;
	int c = expressions->GetNumClasses();
	for ( int i = 0 ; i < c; i++ )
	{
		cl = expressions->GetClass( i );
		if ( !cl )
			continue;

		cl->ReloadBitmaps();
	}
	redraw();
}
void mxExpressionTray::AB( void )
{
	if ( m_nPrevCell == -1 && m_nCurCell == -1 )
		return;

	CExpClass *active = expressions->GetActiveClass();
	if ( !active )
		return;

	if ( m_nPrevCell >= 0 && m_nPrevCell < active->GetNumExpressions() )
	{
		active->SelectExpression( m_nPrevCell );
	}
}
bool ControlPanel::CanClose( void )
{
	workspacefiles->StartStoringFiles( IWorkspaceFiles::EXPRESSION );
	for ( int i = 0 ; i < expressions->GetNumClasses(); i++ )
	{
		CExpClass *cl = expressions->GetClass( i );
		if ( cl )
		{
			workspacefiles->StoreFile( IWorkspaceFiles::EXPRESSION, cl->GetFileName() );
		}
	}
	workspacefiles->FinishStoringFiles( IWorkspaceFiles::EXPRESSION );
	// Now close them all, or abort exit if user doesn't want to close any that have changed
	return Closeall();
}
void ControlPanel::DeleteExpression( int index )
{
	CExpClass *active = expressions->GetActiveClass();
	if ( !active )
		return;

	CExpression *exp = active->GetExpression( index );
	if ( exp )
	{
		Con_Printf( "Deleting expression %s : %s\n", exp->name, exp->description );
			
		g_pFlexPanel->DeleteExpression( index );

		active->SelectExpression( max( 0, index - 1 ) );
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void ControlPanel::RedoExpression( int index )
{
	if ( index == -1 )
		return;
	
	CExpClass *active = expressions->GetActiveClass();
	if ( !active )
		return;

	CExpression *exp = active->GetExpression( index );
	if ( exp )
	{
		exp->Redo();
		// Show the updated data
		active->SelectExpression( index );
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
// Output : int
//-----------------------------------------------------------------------------
int mxExpressionTray::ComputePixelsNeeded( void )
{
	CExpClass *active = expressions->GetActiveClass();
	if ( !active )
		return 100;

	// Remove scroll bar
	int w = this->w2() - 16;

	int colsperrow;

	colsperrow = ( w - m_nGap ) / ( m_nSnapshotWidth + m_nGap );
	// At least one
	colsperrow = max( 1, colsperrow );

	int rowsneeded = ( ( active->GetNumExpressions() + colsperrow - 1 ) / colsperrow  );
	return rowsneeded * ( m_nSnapshotHeight + m_nGap ) + m_nGap + TOP_GAP + GetCaptionHeight();
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void mxExpressionTray::Deselect( void )
{
	CExpClass *active = expressions->GetActiveClass();
	if ( active )
	{
		for ( int i = 0 ; i < active->GetNumExpressions(); i++ )
		{
			CExpression *exp = active->GetExpression( i );
			if ( exp )
			{
				exp->SetSelected( false );
			}
		}
	}

	m_nCurCell = m_nPrevCell = -1;
	redraw();
}
Exemplo n.º 12
0
//-----------------------------------------------------------------------------
// Purpose: 
// Output : const char
//-----------------------------------------------------------------------------
const char *CExpression::GetBitmapFilename( int modelindex )
{
	static char filename[ 256 ] = { 0 };
	
	char const *classname = "error";
	CExpClass *cl = GetExpressionClass();
	if ( cl )
	{
		classname = cl->GetBaseName();
	}
	
	char modelName[512], modelNameTemp[512];
	Q_strncpy( modelNameTemp, models->GetModelName( modelindex ), sizeof( modelNameTemp ) );

	char const *in = modelNameTemp;
	char *out = modelName;

	while ( *in )
	{
		if ( isalnum( *in ) ||
			*in == '_' || 
			*in == '\\' || 
			*in == '/' ||
			*in == '.' ||
			*in == ':' )
		{
			*out++ = *in;
		}
		in++;
	}
	*out = 0;


	sprintf( filename, "expressions/%s/%s/%s.bmp", modelName, classname, GetBitmapCheckSum() );

	Q_FixSlashes( filename );
	strlwr( filename );

	CreatePath( filename );
	
	return filename;
}
int mxExpressionTray::CountSelected( void )
{
	CExpClass *active = expressions->GetActiveClass();
	if ( !active )
		return 0;

	int c = 0;
	for ( int i = 0; i < active->GetNumExpressions(); i++ )
	{
		CExpression *exp = active->GetExpression( i );
		if ( !exp )
			continue;

		if ( exp->GetSelected() )
		{
			c++;
		}
	}

	return c;
}
Exemplo n.º 14
0
void ControlPanel::ChangeModel( const char *filename )
{
	// init all the selection tabs based on the current model
	initSequenceChoices();
	initBodypartChoices();
	initBoneControllerChoices();
	initSkinChoices();

	setModelInfo();

	SetCloseCaptionLanguageId( g_viewerSettings.cclanguageid, true );

	g_viewerSettings.m_iEditAttachment = -1;

	g_viewerSettings.enableIK = true;
	g_viewerSettings.enableTargetIK = false;

	setSequence( models->GetActiveStudioModel()->GetSequence() );
	setSpeed( g_viewerSettings.speedScale );

	mx_setcwd (mx_getpath (filename));

	g_pFlexPanel->initFlexes();
	
	//	centerView();
	//	CenterOnFace();

	IFacePoserToolWindow::ModelChanged();
	
	CExpClass *cl = expressions->GetActiveClass();
	if ( cl )
	{
		cl->SelectExpression( cl->GetSelectedExpression() );
	}

	SetSuffix( va( " - %s.mdl", models->GetActiveModelName() ) );
	redraw();
}
Exemplo n.º 15
0
int MDLViewer::handleEvent (mxEvent *event)
{
	int iret = 0;

	switch (event->event)
	{
	case mxEvent::Size:
		{
			int width = w2();
			int height = h2();

			workspace->setBounds( 0, 0, width, height - WINDOW_TAB_OFFSET );
			int gridsettingswide = 100;
			int gridstart = width - gridsettingswide - 5;
			int windowwide = gridstart * 0.6f;
			int modelwide = gridstart * 0.4f;

			gridsettings->setBounds( gridstart, height - WINDOW_TAB_OFFSET + 1, gridsettingswide, WINDOW_TAB_OFFSET - 2 );

			windowtab->setBounds( 0, height - WINDOW_TAB_OFFSET, windowwide, WINDOW_TAB_OFFSET );
			modeltab->setBounds( windowwide, height - WINDOW_TAB_OFFSET, modelwide, WINDOW_TAB_OFFSET );

			iret = 1;
		}
		break;
	case mxEvent::Action:
		{
			iret = 1;
			switch (event->action)
			{
			case IDC_WINDOW_TAB:
				{
					windowtab->HandleWindowSelect();
				}
				break;
			case IDC_MODEL_TAB:
				{
					modeltab->HandleModelSelect();
				}
				break;
			case IDC_EDIT_COPY:
				{
					Copy();
				}
				break;
				
			case IDC_EDIT_PASTE:
				{
					Paste();
				}
				break;
				
			case IDC_EDIT_UNDO:
				{
					Undo();
				}
				break;
				
			case IDC_EDIT_REDO:
				{
					Redo();
				}
				break;
				
			case IDC_FILE_LOADMODEL:
				{
					const char *ptr = mxGetOpenFileName(
						this, 
						FacePoser_MakeWindowsSlashes( va( "%s/models/", GetGameDirectory() ) ),
						"*.mdl");
					if (ptr)
					{
						LoadModelFile( ptr );
					}
				}
				break;
				
			case IDC_FILE_REFRESH:
				{
					Refresh();
					break;
				}
				
			case IDC_FILE_LOADBACKGROUNDTEX:
			case IDC_FILE_LOADGROUNDTEX:
				{
					const char *ptr = mxGetOpenFileName (this, 0, "*.*");
					if (ptr)
					{
						if (0 /* g_pMatSysWindow->loadTexture (ptr, event->action - IDC_FILE_LOADBACKGROUNDTEX) */)
						{
							if (event->action == IDC_FILE_LOADBACKGROUNDTEX)
								g_pControlPanel->setShowBackground (true);
							else
								g_pControlPanel->setShowGround (true);
							
						}
						else
							mxMessageBox (this, "Error loading texture.", g_appTitle, MX_MB_OK | MX_MB_ERROR);
					}
				}
				break;
				
			case IDC_FILE_UNLOADGROUNDTEX:
				{
					// g_pMatSysWindow->loadTexture (0, 1);
					g_pControlPanel->setShowGround (false);
				}
				break;
				
			case IDC_FILE_RECENTMODELS1:
			case IDC_FILE_RECENTMODELS2:
			case IDC_FILE_RECENTMODELS3:
			case IDC_FILE_RECENTMODELS4:
				{
					int i = event->action - IDC_FILE_RECENTMODELS1;
					
					LoadModelFile( recentFiles[ i ] );
					
					char tmp[256];			
					strcpy (tmp, recentFiles[0]);
					strcpy (recentFiles[0], recentFiles[i]);
					strcpy (recentFiles[i], tmp);
					
					initRecentFiles ();
					
					redraw ();
				}
				break;
				
			case IDC_FILE_EXIT:
				{
					redraw ();
					mx::quit ();
				}
				break;
				
			case IDC_OPTIONS_COLORBACKGROUND:
			case IDC_OPTIONS_COLORGROUND:
			case IDC_OPTIONS_COLORLIGHT:
				{
					float *cols[3] = { g_viewerSettings.bgColor, g_viewerSettings.gColor, g_viewerSettings.lColor };
					float *col = cols[event->action - IDC_OPTIONS_COLORBACKGROUND];
					int r = (int) (col[0] * 255.0f);
					int g = (int) (col[1] * 255.0f);
					int b = (int) (col[2] * 255.0f);
					if (mxChooseColor (this, &r, &g, &b))
					{
						col[0] = (float) r / 255.0f;
						col[1] = (float) g / 255.0f;
						col[2] = (float) b / 255.0f;
					}
				}
				break;
				
			case IDC_OPTIONS_CENTERVIEW:
				g_pControlPanel->centerView ();
				break;
				
			case IDC_OPTIONS_CENTERONFACE:
				g_pControlPanel->CenterOnFace();
				break;
				
			case IDC_OPTIONS_MAKESCREENSHOT:
				{
					char *ptr = (char *) mxGetSaveFileName (this, "", "*.tga");
					if (ptr)
					{
						if (!strstr (ptr, ".tga"))
							strcat (ptr, ".tga");
						// g_pMatSysWindow->dumpViewport (ptr);
					}
				}
				break;
				
			case IDC_OPTIONS_DUMP:
				g_pControlPanel->dumpModelInfo ();
				break;
				
#ifdef WIN32
			case IDC_HELP_GOTOHOMEPAGE:
				ShellExecute (0, "open", "http://www.swissquake.ch/chumbalum-soft/index.html", 0, 0, SW_SHOW);
				break;
#endif
				
			case IDC_HELP_ABOUT:
				mxMessageBox (this,
					"v0.1 (c) 2001, Valve, LLC.  All rights reserved.\r\nBuild Date: "__DATE__"",
					"Valve Face Poser", 
					MX_MB_OK | MX_MB_INFORMATION);
				break;
				
			case IDC_EXPRESSIONS_REDOBITMAPS:
				{
					bool saveOverrides = g_pExpressionTrayTool->GetOverridesShowing();
					g_pExpressionTrayTool->SetOverridesShowing( false );
					CExpClass *active = expressions->GetActiveClass();
					if ( active )
					{
						for ( int i = 0; i < active->GetNumExpressions() ; i++ )
						{
							CExpression *exp = active->GetExpression( i );
							if ( !exp )
								continue;
							
							active->SelectExpression( i );
							exp->CreateNewBitmap( models->GetActiveModelIndex() );
							
							if ( ! ( i % 5 ) )
							{
								g_pExpressionTrayTool->redraw();
							}
						}
						
						if ( active->HasOverrideClass() )
						{
							
							g_pExpressionTrayTool->SetOverridesShowing( true );
							
							CExpClass *oc = active->GetOverrideClass();
							for ( int i = 0; i < oc->GetNumExpressions() ; i++ )
							{
								CExpression *exp = oc->GetExpression( i );
								if ( !exp )
									continue;
								
								oc->SelectExpression( i );
								exp->CreateNewBitmap( models->GetActiveModelIndex() );
								
								if ( ! ( i % 5 ) )
								{
									g_pExpressionTrayTool->redraw();
								}
							}
						}
						active->SelectExpression( 0 );
					}
					
					g_pExpressionTrayTool->SetOverridesShowing( saveOverrides );
				}
				break;
			case IDC_EXPRESSIONS_NEW:
				{
					const char *filename = mxGetSaveFileName( 
						this, 
						FacePoser_MakeWindowsSlashes( va( "%s/expressions/", GetGameDirectory() ) ), 
						"*.txt" );
					if ( filename && filename[ 0 ] )
					{
						char classfile[ 512 ];
						strcpy( classfile, filename );
						StripExtension( classfile );
						DefaultExtension( classfile, ".txt" );
						
						expressions->CreateNewClass( classfile );
					}
				}
				break;
			case IDC_EXPRESSIONS_LOAD:
				{
					const char *filename = NULL;
					
					filename = mxGetOpenFileName( 
						this, 
						FacePoser_MakeWindowsSlashes( va( "%s/expressions/", GetGameDirectory() ) ), 
						"*.txt" );
					if ( filename && filename[ 0 ] )
					{
						expressions->LoadClass( filename );
					}
				}
				break;
				
			case IDC_EXPRESSIONS_SAVE:
				{
					CExpClass *active = expressions->GetActiveClass();
					if ( active )
					{
						active->Save();
						active->Export();
					}
				}
				break;
			case IDC_EXPRESSIONS_EXPORT:
				{
					CExpClass *active = expressions->GetActiveClass();
					if ( active )
					{
						active->Export();
					}
				}
				break;
			case IDC_EXPRESSIONS_CLOSE:
				g_pControlPanel->Close();
				break;
			case IDC_EXPRESSIONS_CLOSEALL:
				g_pControlPanel->Closeall();
				break;
			case IDC_CHOREOSCENE_NEW:
				g_pChoreoView->New();
				break;
			case IDC_CHOREOSCENE_LOAD:
				g_pChoreoView->Load();
				break;
			case IDC_CHOREOSCENE_SAVE:
				g_pChoreoView->Save();
				break;
			case IDC_CHOREOSCENE_SAVEAS:
				g_pChoreoView->SaveAs();
				break;
			case IDC_CHOREOSCENE_CLOSE:
				g_pChoreoView->Close();
				break;
			case IDC_CHOREOSCENE_ADDACTOR:
				g_pChoreoView->NewActor();
				break;
			case IDC_WINDOW_TILE:
				{
					OnTile();
				}
				break;
			case IDC_WINDOW_TILE_HORIZ:
				{
					OnTileHorizontally();
				}
				break;
			case IDC_WINDOW_TILE_VERT:
				{
					OnTileVertically();
				}
				break;
			case IDC_WINDOW_CASCADE:
				{
					OnCascade();
				}
				break;
			case IDC_WINDOW_HIDEALL:
				{
					OnHideAll();
				}
				break;
			case IDC_WINDOW_SHOWALL:
				{
					OnShowAll();
				}
				break;
			default:
				{
					iret = 0;
					int tool_number = event->action - IDC_WINDOW_FIRSTTOOL;
					int max_tools = IDC_WINDOW_LASTTOOL - IDC_WINDOW_FIRSTTOOL;
					
					if ( tool_number >= 0 && 
						tool_number <= max_tools && 
						tool_number < IFacePoserToolWindow::GetToolCount() )
					{
						iret = 1;
						IFacePoserToolWindow *tool = IFacePoserToolWindow::GetTool( tool_number );
						if ( tool )
						{
							mxWindow *toolw = tool->GetMxWindow();
							
							bool wasvisible = toolw->isVisible();
							toolw->setVisible( !wasvisible );
							
							g_MDLViewer->UpdateWindowMenu();

						}
					}
				}
				break;
			} //switch (event->action)
		} // mxEvent::Action
		break;
	case KeyDown:
		{
			g_pMatSysWindow->handleEvent(event);
			iret = 1;
		}
		break;
	case mxEvent::Activate:
		{
			if (event->action)
			{
				mx::setIdleWindow( g_pMatSysWindow );
			}
			else
			{
				mx::setIdleWindow( 0 );
			}
			iret = 1;
		}
		break;
	} // event->event
	
	return iret;
}
void mxExpressionTray::redraw()
{
	if ( !ToolCanDraw() )
		return;

	bool updateSelection = false;

	CExpClass *active = expressions->GetActiveClass();
	if ( active && active->GetNumExpressions() != m_nPreviousExpressionCount )
	{
		m_nTopOffset = 0;

		RepositionSlider();
		m_nPreviousExpressionCount = active->GetNumExpressions();
	}

	CChoreoWidgetDrawHelper helper( this, GetSysColor( COLOR_BTNFACE ) );
	HandleToolRedraw( helper );

	int w, h;
	w = w2();
	h = h2();

	if ( active )
	{
		RECT clipRect;
		helper.GetClientRect( clipRect );
		
		clipRect.top += TOP_GAP + GetCaptionHeight();

		helper.StartClipping( clipRect );

		if ( m_nLastNumExpressions != active->GetNumExpressions() )
		{
			m_nTopOffset = 0;
			m_nLastNumExpressions = active->GetNumExpressions();
			RepositionSlider();
			updateSelection = true;
		}

		int selected = active->GetSelectedExpression();

		int rcx, rcy, rcw, rch;

		int c = 0;
		while ( c < active->GetNumExpressions() )
		{
			if ( !ComputeRect( c, rcx, rcy, rcw, rch ) )
			{
				c++;
				continue;
			}

			CExpression *current = active->GetExpression( c );
			if ( !current )
				break;

			DrawThumbNail( active, current, helper, rcx, rcy, rcw, rch, c, selected, updateSelection );

			c++;
		}

		helper.StopClipping();

	}
	else
	{

		RECT rc;
		helper.GetClientRect( rc );

		// Arial 36 normal
		char sz[ 256 ];
		sprintf( sz, "No expression file loaded" );

		int pointsize = 18;

		int textlen = helper.CalcTextWidth( "Arial", pointsize, FW_NORMAL, sz );

		RECT rcText;
		rcText.top = ( rc.bottom - rc.top ) / 2 - pointsize / 2;
		rcText.bottom = rcText.top + pointsize + 10;
		int fullw = rc.right - rc.left;

		rcText.left = rc.left + ( fullw - textlen ) / 2;
		rcText.right = rcText.left + textlen;

		helper.DrawColoredText( "Arial", pointsize, FW_NORMAL,  RGB( 80, 80, 80 ), rcText, sz );
	}


// 	ValidateRect( (HWND)getHandle(), &rc );
}
int mxExpressionTray::handleEvent (mxEvent *event)
{
	MDLCACHE_CRITICAL_SECTION_( g_pMDLCache );

	int iret = 0;

	if ( HandleToolEvent( event ) )
	{
		return iret;
	}

	switch ( event->event )
	{
	case mxEvent::Action:
		{
			iret = 1;
			switch ( event->action )
			{
			default:
				iret = 0;
				break;
			case IDC_EXPRESSIONCLASS:
				{
					int index = g_pExpressionClass->getSelectedIndex();
					if ( index >= 0 )
					{
						CExpClass *current = expressions->GetClass( index );
						if ( current )
						{
							// Switch classname
							expressions->ActivateExpressionClass( current );
							current->SelectExpression( 0 );
						}
					}
				}
				break;
			case IDC_CONTEXT_NEWEXP:
				g_pFlexPanel->NewExpression();
				break;
			case IDC_CONTEXT_EDITEXP:
				if ( m_nClickedCell != -1 )
				{
					g_pFlexPanel->EditExpression();
				}
				break;
			case IDC_CONTEXT_REVERT:
				if ( m_nClickedCell != -1 )
				{
					g_pFlexPanel->RevertExpression( m_nClickedCell );
				}
				break;
			case IDC_CONTEXT_SAVEEXP:
				if ( m_nClickedCell != -1 )
				{
					g_pFlexPanel->SaveExpression( m_nClickedCell );
				}
				break;
			case IDC_CONTEXT_DELETEXP:
				if ( m_nClickedCell != -1 )
				{
					g_pControlPanel->DeleteExpression( m_nClickedCell );
				}
				break;
			case IDC_TRAYSCROLL:
				{
					if (event->modifiers == SB_THUMBTRACK)
					{
						int offset = event->height;
						
						slScrollbar->setValue( offset );
						
						m_nTopOffset = offset;
						
						redraw();
					}
					else if ( event->modifiers == SB_PAGEUP )
					{
						int offset = slScrollbar->getValue();
						
						offset -= m_nGranularity;
						offset = max( offset, slScrollbar->getMinValue() );
						
						slScrollbar->setValue( offset );
						InvalidateRect( (HWND)slScrollbar->getHandle(), NULL, TRUE );
						
						m_nTopOffset = offset;
						
						redraw();
					}
					else if ( event->modifiers == SB_PAGEDOWN )
					{
						int offset = slScrollbar->getValue();
						
						offset += m_nGranularity;
						offset = min( offset, slScrollbar->getMaxValue() );
						
						slScrollbar->setValue( offset );
						InvalidateRect( (HWND)slScrollbar->getHandle(), NULL, TRUE );
						
						m_nTopOffset = offset;
						
						redraw();
					}
				}
				break;
			case IDC_AB:
				{
					AB();	
				}
				break;
			case IDC_THUMBNAIL_INCREASE:
				{
					ThumbnailIncrease();
				}
				break;
			case IDC_THUMBNAIL_DECREASE:
				{
					ThumbnailDecrease();
				}
				break;
			case IDC_CONTEXT_CREATEBITMAP:
				{
					if ( m_nClickedCell >= 0 )
					{
						CExpClass *active = expressions->GetActiveClass();
						if ( active )
						{
							CExpression *exp = active->GetExpression( m_nClickedCell );
							if ( exp )
							{
								active->SelectExpression( m_nClickedCell );
								exp->CreateNewBitmap( models->GetActiveModelIndex() );
								redraw();
							}
						}
					}
				}
				break;
			}
			break;
		}
	case mxEvent::MouseDown:
		{
			if ( !( event->buttons & mxEvent::MouseRightButton ) )
			{
				// Figure out cell #
				int cell = GetCellUnderPosition( event->x, event->y );
				CExpClass *active = expressions->GetActiveClass();
				if ( active )
				{

					if ( cell == m_nCurCell && cell >= 0 && cell < active->GetNumExpressions() )
					{
						mxETButton *btn = GetItemUnderCursor( event->x, event->y );
						if ( btn && btn->m_fnCallback )
						{	
							(this->*(btn->m_fnCallback))( cell );
							return iret;
						}
					}
					
					if ( cell >= 0 && cell < active->GetNumExpressions() )
					{
						active->SelectExpression( cell, event->modifiers & mxEvent::KeyShift ? false : true );

						int cx, cy, cw, ch;
						if ( ComputeRect( cell, cx, cy, cw, ch ) )
						{
							m_bDragging = true;
							m_nDragCell = cell;
							
							m_nXStart = (short)event->x;
							m_nYStart = (short)event->y;

							m_rcFocus.left = cx;
							m_rcFocus.top = cy;
							m_rcFocus.right = cx + cw;
							m_rcFocus.bottom = cy + ch - m_nDescriptionHeight;

							POINT pt;
							pt.x = pt.y = 0;
							ClientToScreen( (HWND)getHandle(), &pt );

							OffsetRect( &m_rcFocus, pt.x, pt.y );

							m_rcOrig = m_rcFocus;

							DrawFocusRect();
						}
					}
					else
					{
						Deselect();
						active->DeselectExpression();
						redraw();
					}
				}
			}
			iret = 1;
		}
		break;
	case mxEvent::MouseDrag:
		{
			if ( m_bDragging )
			{
				// Draw drag line of some kind
				DrawFocusRect();
	
				// update pos
				m_rcFocus = m_rcOrig;
				OffsetRect( &m_rcFocus, ( (short)event->x - m_nXStart ), 
					( (short)event->y - m_nYStart ) );
				
				DrawFocusRect();
			}
			iret = 1;
		}
		break;
	case mxEvent::MouseUp:
		{
			iret = 1;

			if ( event->buttons & mxEvent::MouseRightButton )
			{
				SetClickedCell( GetCellUnderPosition( (short)event->x, (short)event->y ) );
				ShowRightClickMenu( (short)event->x, (short)event->y );
				return iret;
			}

			int cell = GetCellUnderPosition( event->x, event->y );
			CExpClass *active = expressions->GetActiveClass();

			if ( m_bDragging )
			{
				DrawFocusRect();
				m_bDragging = false;
				// See if we let go on top of the choreo view

				if ( active )
				{
					// Convert x, y to screen space
					POINT pt;
					pt.x = (short)event->x;
					pt.y = (short)event->y;
					ClientToScreen( (HWND)getHandle(), &pt );

					HWND maybeTool = WindowFromPoint( pt );

					// Now tell choreo view
					CExpression *exp = active->GetExpression( m_nDragCell );
					if ( exp && maybeTool )
					{
						if ( IsWindowOrChild( g_pChoreoView, maybeTool ) )
						{
							if ( g_pChoreoView->CreateExpressionEvent( pt.x, pt.y, active, exp ) )
							{
								return iret;
							}
						}
					
						if ( IsWindowOrChild( g_pExpressionTool, maybeTool ) )
						{
							if ( g_pExpressionTool->SetFlexAnimationTrackFromExpression( pt.x, pt.y, active, exp ) )
							{
								return iret;
							}
						}
					}
				}
			}

			if ( active )
			{
				// Over a new cell
				if ( cell >= 0 && 
					cell < active->GetNumExpressions() && 
					cell != m_nCurCell &&
					m_nCurCell != -1 )
				{
					// Swap cells
					CExpression *exp = active->GetExpression( m_nCurCell );
					if ( exp )
					{
						active->SwapExpressionOrder( m_nCurCell, cell );
						active->SetDirty( true );
						active->SelectExpression( cell );
					}
				}
			}
		}
		break;
	case mxEvent::Size:
		{
			int width = w2();

			int ch = GetCaptionHeight();

			g_pExpressionClass->setBounds( 5, 5 + ch, width - 120, 20 );

			m_pABButton->setBounds( width - 60, 4 + ch, 60, 16 );
			m_pThumbnailIncreaseButton->setBounds( width - 60 - 40, 4 + ch, 16, 16 );
			m_pThumbnailDecreaseButton->setBounds( width - 60 - 20, 4 + ch, 16, 16 );

			m_nTopOffset = 0;
			RepositionSlider();

			redraw();
			iret = 1;
		}
		break;
	case mxEvent::MouseWheeled:
		{
			// Figure out cell #
			POINT pt;

			pt.x = event->x;
			pt.y = event->y;

			ScreenToClient( (HWND)getHandle(), &pt );

			if ( event->height < 0 )
			{
				m_nTopOffset = min( m_nTopOffset + 10, slScrollbar->getMaxValue() );
			}
			else
			{
				m_nTopOffset = max( m_nTopOffset - 10, 0 );
			}
			RepositionSlider();
			redraw();
			iret = 1;
		}
		break;
	};

	if ( iret )
	{
		SetActiveTool( this );
	}
	return iret;
}