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; }
Vec3q SATSampler::operator()(const Vec2q &uv,const Vec2q &diff) const { f32x4b fullMask=diff.x>=0.5f||diff.x>= 0.5f; if(ForAll(fullMask)) return Vec3q(avg.x,avg.y,avg.z); Vec2q tDiff=diff*floatq(0.5f); Vec2q a=(uv-tDiff),b=(uv+tDiff); a*=Vec2q(floatq(w),floatq(h)); b*=Vec2q(floatq(w),floatq(h)); i32x4 ax(a.x),ay(a.y); i32x4 bx(b.x),by(b.y); ax&=wMask; ay&=hMask; bx&=wMask; by&=hMask; union { __m128 count; float countf[4]; }; TSample sum[4]; i32x4 one(1); if(ForAll(ax<=bx&&ay<=by)) { count = (f32x4(by-ay+one)*f32x4(bx-ax+one)).m; ComputeRect(ax,ay,bx,by,sum); } else for(int k=0;k<4;k++) { if(ax[k]>bx[k]) { if(ay[k]>by[k]) { countf[k]=(bx[k]+1)*(by[k]+1)+(w-ax[k])*(h-ay[k]); sum[k]=ComputeRect(0,0,bx[k],by[k])+ComputeRect(ax[k],ay[k],w-1,h-1); } else { countf[k]=(bx[k]+1+w-ax[k])*(by[k]-ay[k]+1); sum[k]=ComputeRect(0,ay[k],bx[k],by[k])+ComputeRect(ax[k],ay[k],w-1,by[k]); } } else { if(ay[k]>by[k]) { countf[k]=(bx[k]-ax[k]+1)*(by[k]+h+1-ay[k]); sum[k]=ComputeRect(ax[k],0,bx[k],by[k])+ComputeRect(ax[k],ay[k],bx[k],h-1); } else { countf[k]=(by[k]-ay[k]+1)*(bx[k]-ax[k]+1); sum[k]=ComputeRect(ax[k],ay[k],bx[k],by[k]); } } } union { __m128 out[3]; struct { float ox[4]; float oy[4]; float oz[4]; } o; }; o.ox[0]=sum[0].R(); o.oy[0]=sum[0].G(); o.oz[0]=sum[0].B(); o.ox[1]=sum[1].R(); o.oy[1]=sum[1].G(); o.oz[1]=sum[1].B(); o.ox[2]=sum[2].R(); o.oy[2]=sum[2].G(); o.oz[2]=sum[2].B(); o.ox[3]=sum[3].R(); o.oy[3]=sum[3].G(); o.oz[3]=sum[3].B(); return Condition(fullMask,Vec3q(avg.x,avg.y,avg.z), Vec3q(out[0], out[1], out[2]) * Inv(floatq(count) * 255.0f)); }
Vec3f SATSampler::operator()(const Vec2f &uv,const Vec2f &size) const { if(size.x>=0.5f||size.y>=0.5f) return avg; Vec2f a=uv+size*0.5f,b=uv+size*0.5f; a*=Vec2f(w,h); b*=Vec2f(w,h); uint ax=a.x,ay=a.y; uint bx=b.x,by=b.y; ax&=wMask; ay&=hMask; bx&=wMask; by&=hMask; uint count; TSample sum; if(ax>bx) { if(ay>by) { count=(bx+1)*(by+1)+(w-ax)*(h-ay); sum=ComputeRect(0,0,bx,by)+ComputeRect(ax,ay,w-1,h-1); } else { count=(bx+1+w-ax)*(by-ay+1); sum=ComputeRect(0,ay,bx,by)+ComputeRect(ax,ay,w-1,by); } } else { if(ay>by) { count=(bx-ax+1)*(by+h+1-ay); sum=ComputeRect(ax,0,bx,by)+ComputeRect(ax,ay,bx,h-1); } else { count=(by-ay+1)*(bx-ax+1); sum=ComputeRect(ax,ay,bx,by); } } return Vec3f(sum.R(),sum.G(),sum.B())*(1.0f/(255.0f*float(count))); }
//----------------------------------------------------------------------------- // Purpose: // Input : x - // y - // Output : mxExpressionTray::mxETButton //----------------------------------------------------------------------------- mxExpressionTray::mxETButton *mxExpressionTray::GetItemUnderCursor( int x, int y ) { // Convert to cell space int cell = GetCellUnderPosition( x, y ); if ( cell == -1 ) { return NULL; } // Cell is off screen? int cx, cy, cw, ch; if ( !ComputeRect( cell, cx, cy, cw, ch ) ) { return NULL; } mxETButton *p = m_pButtons; while ( p ) { if ( p->m_bActive && x >= cx && x <= cx + cw && y >= cy && y <= cy + ch ) { // In-side cell int cellx = x - cx; int celly = y - cy; if ( cellx >= p->m_rc.left && cellx <= p->m_rc.right && celly >= p->m_rc.top && celly <= p->m_rc.bottom ) { return p; } } p = p->next; } return NULL; }
void mxExpressionTray::DrawButton( CChoreoWidgetDrawHelper& helper, int cell, mxETButton *btn ) { if ( !btn || !btn->m_pImage || !btn->m_pImage->valid ) return; if ( !btn->m_bActive ) return; int x, y, w, h; if ( !ComputeRect( cell, x, y, w, h ) ) return; x += btn->m_rc.left; y += btn->m_rc.top; w = btn->m_rc.right - btn->m_rc.left; h = btn->m_rc.bottom - btn->m_rc.top; HDC dc = helper.GrabDC(); DrawBitmapToDC( dc, x, y, w, h, *btn->m_pImage ); helper.DrawOutlinedRect( RGB( 170, 170, 170 ), PS_SOLID, 1, x, y, x + w, y + h ); }
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; }
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 ); }