void wxGridCtrl::DrawRowLabel(wxDC& dc, int row) { if (GetRowHeight(row) <= 0 || m_rowLabelWidth <= 0) return; wxRect rect; #ifdef __WXGTK20__ rect.SetX(1); rect.SetY(GetRowTop(row) + 1); rect.SetWidth(m_rowLabelWidth - 2); rect.SetHeight(GetRowHeight(row) - 2); CalcScrolledPosition(0, rect.y, NULL, &rect.y); wxWindowDC *win_dc = (wxWindowDC*)&dc; wxRendererNative::Get().DrawHeaderButton(win_dc->m_owner, dc, rect, 0); #else int rowTop = GetRowTop(row), rowBottom = GetRowBottom(row) - 1; dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW), 1, wxSOLID)); dc.DrawLine(m_rowLabelWidth - 1, rowTop, m_rowLabelWidth - 1, rowBottom); dc.DrawLine(0, rowTop, 0, rowBottom); dc.DrawLine(0, rowBottom, m_rowLabelWidth, rowBottom); dc.SetPen(*wxWHITE_PEN); dc.DrawLine(1, rowTop, 1, rowBottom); dc.DrawLine(1, rowTop, m_rowLabelWidth - 1, rowTop); #endif if (row == GetGridCursorRow()) { dc.DrawBitmap(m_pImageList->GetBitmap(4), 0, GetRowTop(row), true); } }
int TestAIDestination( int player, int testX, int testR ) { int x, y, height, chains, rensa = 50, result = 0; for( x=0; x<kGridAcross; x++ ) { for( y=0; y<kGridDown; y++ ) { tempGrid[x][y] = grid[player][x][y]; } } height = GetRowHeight(player, testX); switch( testR ) { case upRotate: tempGrid[testX][height--] = colorA[player]; if( height >= 0 ) tempGrid[testX][height] = colorB[player]; break; case downRotate: tempGrid[testX][height--] = colorB[player]; if( height >= 0 ) tempGrid[testX][height] = colorA[player]; break; case leftRotate: tempGrid[testX][height] = colorA[player]; tempGrid[testX-1][GetRowHeight(player,testX-1)] = colorB[player]; break; case rightRotate: tempGrid[testX][height] = colorA[player]; tempGrid[testX+1][GetRowHeight(player,testX+1)] = colorB[player]; break; } chains = TestTemporaryGrid( ); result = ScoreTemporaryGrid( ); if( (chains < 2) && (character[player].intellect > (24 * 2/3)) ) { rensa = 0; } else { while( chains-- ) rensa *= 10; } result += rensa; return result; }
void PlaneListWidget::Prepare(ContainerWindow &parent, const PixelRect &rc) { const DialogLook &look = UIGlobals::GetDialogLook(); CreateList(parent, look, rc, GetRowHeight(look)); UpdateList(); }
void TableListedItems::PaintClients( const WidgetPainter &painter ) { Pos p; Dim2i d( GetWidth(), 0); Rect client_area = GetParent()->GetClientRect(this)-GetPosition(); Rect visibile = TableWidget::GetCrossing( client_area ); p.y = RowRect( visibile.GetY1() ).GetY(); for ( int i=visibile.GetY1(); i<visibile.GetY2(); ++i ) { d.y = GetRowHeight(i); int last_col = GetNumColumns() -1; Rect fa = RowRect( i ); if ( _skins.Select( GetState(i) ) ) { _skins.SetSize( Dim2i(fa.GetW(),fa.GetH()) ); } _skins.Paint( painter, fa.GetPos(), fa ); p.y += d.y; } }
void QuoteTableCtrlGeneralSort::OnDraw(CDC* pDC) { CHSGridCtrl::OnDraw(pDC); CRect rect, itemrect, rccvlient; GetClientRect(rccvlient); ClientToScreen(rccvlient); GetClientRect(rect); itemrect = rect; if (GetRowCount() <=0) return; int rowheight = GetRowHeight(0); itemrect.bottom = rowheight-1; COLORREF bkcolor = GetBkColor(); COLORREF textcolor = RGB(155,155,155); if (m_iColorFontProt) textcolor = m_iColorFontProt->GetQuoteTabTextColor(); CFont* pFont; CFont* pOldFont; BOOL bCreat = FALSE; if (m_iFont) pFont = (CFont*)m_iFont->GetQuoteColHeadFont(); else { pFont = new CFont(); VERIFY(pFont->CreateFont(16,0, 0,0,FW_NORMAL,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_SWISS, _T("宋体"))); bCreat = TRUE; } pOldFont = pDC->SelectObject(pFont); pDC->SetBkColor( GetSysColor(COLOR_HIGHLIGHT) ); pDC->SetBkColor(bkcolor); pDC->SetTextColor(textcolor); pDC->SetBkColor(bkcolor); pDC->DrawText(m_pTableFlag->strTitle, &itemrect, DT_CENTER | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER); pDC->SelectObject(pOldFont); if (bCreat) pFont->DeleteObject(); CPen hPen; hPen.CreatePen(PS_SOLID ,1,RGB(200,0,0)); CPen* hOldPen = pDC->SelectObject(&hPen); pDC->MoveTo(CPoint(itemrect.left,itemrect.bottom)); pDC->LineTo(CPoint(itemrect.right, itemrect.bottom)); pDC->SelectObject(hOldPen); hPen.DeleteObject(); }
int CXTPCalendarDayViewTimeScale::CalcWidth(CDC* pDC) { // calculate actual correct width int nWidth1 = m_nWidth, nWidth2 = m_nWidth; // calculate width for midnight COleDateTime dtMid(0, 0); CString strHour, strMin; Format(dtMid, TRUE, &strHour, &strMin); COleDateTimeSpan spScaleInterval = GetScaleInterval(); int nRowHeight = XTP_SAFE_GET1(m_pDayView, GetRowHeight(), 1); int nHourHeight = nRowHeight * (CXTPCalendarUtils::GetTotalMinutes(spScaleInterval) < 60 ? 2 : 1); XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleCellPart(), CalcWidth(pDC, strHour, strMin, nHourHeight, nWidth1)); // calculate width for midday dtMid += COleDateTimeSpan(0, 12, 0, 0); Format(dtMid, TRUE, &strHour, &strMin); XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleCellPart(), CalcWidth(pDC, strHour, strMin, nHourHeight, nWidth2)); // choose the widest one m_nWidth = max(nWidth1, nWidth2); return m_nWidth; }
void CGridDocs::SelectItem(int iRow, BOOL bSetFocus) { if(iSelRow != iRow) { CCellID cell; cell.col = 0; cell.row = iRow; if (!IsCellVisible(cell)) { CCellID idTopLeft = GetTopleftNonFixedCell(); int iPos; iPos = 0; for(int i = 1;i<iRow;i++) { iPos = iPos + GetRowHeight(i); } SetScrollPos(SB_VERT, iPos, TRUE); GetTopleftNonFixedCell(TRUE); Invalidate(); } iSelRow = iRow; SetSelectedRange(iRow,GetFixedColumnCount(),iRow,GetColumnCount()-1,TRUE,TRUE); SendMessageToParent(iRow,GetFixedColumnCount(), GVN_SELCHANGED); if(bSetFocus) SetFocus(); } }
void CustomGrid::DrawRowLabel( wxDC& dc, int row ) { //init dc font and colours dc.SetFont( m_labelFont ); dc.SetPen(GetDefaultGridLinePen()); dc.SetBrush( wxBrush( m_labelBackgroundColour, wxBRUSHSTYLE_SOLID ) ); int w = dc.GetTextExtent(_T("Speed")).x; wxString label1,label2; label1 = GetRowLabelValue(row).BeforeFirst(',', &label2); bool pline = true; //row is the first of 3 for the same parameter (wind ... waves ...) if(GetNumberRows() > row + 2 && label1 == GetRowLabelValue(row + 2).BeforeFirst(',')){ pline = false; if(IsRowVisible(row + 2)) label1 = _T(" "); } //row is the second of 3 or the first of 2 else if(GetNumberRows() > row + 1 && label1 == GetRowLabelValue(row + 1).BeforeFirst(',')){ pline = false; if(row > 0 && label1 == GetRowLabelValue(row - 1).BeforeFirst(',')){ //second of 3 if(!IsRowVisible(row + 1)) label1 = _T(" "); } } //row is the last of 3 else if(row > 1 && label1 == GetRowLabelValue(row - 2).BeforeFirst(',')){ if(IsRowVisible(row - 1)) label1 = _T(" "); } //row is the last of 2 else if(row > 0 && label1 == GetRowLabelValue(row - 1).BeforeFirst(',')){ if(IsRowVisible(row - 1)) label1 = _T(" "); } //draw first part of the label wxRect aRect(5, GetRowTop(row), m_rowLabelWidth - w, GetRowHeight(row)); dc.DrawLabel(label1, aRect, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL); //draw second part of the label wxRect bRect(m_rowLabelWidth - w, GetRowTop(row), w, GetRowHeight(row)); dc.SetFont( wxFont(m_labelFont).Scale(0.85) ); dc.DrawLabel(label2 , bRect, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL); //draw row lines around labels if(pline) dc.DrawLine(0, GetRowBottom(row) - 1, m_rowLabelWidth, GetRowBottom(row) - 1); dc.DrawLine(0, GetRowTop(row), 0, GetRowBottom(row) ); dc.DrawLine(m_rowLabelWidth - 1, GetRowTop(row), m_rowLabelWidth - 1, GetRowBottom(row) ); }
void OOPLyric::CorrectViewStart(wxDC *pDC) { wxASSERT(m_parser); // TODO: 添加 m_currIndex 吧 int rowHeight = GetRowHeight(); int yStart = rowHeight * double (m_parser->IndexOf(m_currLine) + GetLineProgress()); SetViewStart(0, yStart, pDC); }
FlarmId dlgFlarmDetailsListShowModal(SingleWindow &parent, const TCHAR *title, FlarmId _array[], unsigned count) { assert(count > 0); array = _array; UPixelScalar line_height = GetRowHeight(UIGlobals::GetDialogLook()); unsigned index = ListPicker(parent, title, count, 0, line_height, PaintListItem, true); return index < count ? array[index] : FlarmId::Undefined(); }
void OOPLyric::UpdateVirtualHeight() { wxASSERT(m_parser); int rowHeight = GetRowHeight(); int topBlankLinesHeight = m_blankLinesTop * rowHeight; int bottomBlankLinesHeight = m_Rect.height - topBlankLinesHeight; int actualHeight = m_parser->GetLinesCount() * rowHeight; int ySize = topBlankLinesHeight + actualHeight + bottomBlankLinesHeight; // -1 是为了得到一个总是不超出有效作用域的大小 SetVirtualSize(0, ySize - 1); }
void TrafficListWidget::Prepare(ContainerWindow &parent, const PixelRect &rc) { const DialogLook &look = UIGlobals::GetDialogLook(); ListControl &list = CreateList(parent, look, rc, GetRowHeight(look)); if (filter_widget != nullptr) UpdateList(); else list.SetLength(items.size()); }
void CLogSpreadSheet::InitSheet() { SetMaxCols(colMax); SetMaxRows(rowMax); SetBackColorStyle(SS_BACKCOLORSTYLE_UNDERGRID); SetTypeEditMultiLine(true); m_nDefaultRowHeight = GetRowHeight(0); InitColumnName(); InitColumnWidth(); SetBlockMode(true); SetGridColor(m_cGridNotComplete); SetBlockMode(false); m_nCurLastLogID = m_daoLogContent.GetLastLogID(); }
CRect CXTPCalendarWeekViewDay::GetDayEventsRect() const { int nColHeaderHeight = XTP_SAFE_GET1(GetView(), GetRowHeight(), 0); CRect rcDayEvents = m_Layout.m_rcDay; //rcDayEvents.bottom -= min(2, rcDayEvents.Height()); rcDayEvents.top += min(nColHeaderHeight + 0, rcDayEvents.Height()); int nBotSpace = XTP_SAFE_GET5(GetView(), GetCalendarControl(), GetTheme(), GetWeekViewPart(), GetDayPart(), GetExpandButtonHeight(), 0); rcDayEvents.bottom -= min(nBotSpace + 2, rcDayEvents.Height()); return rcDayEvents; }
void wxGridCtrl::DrawRowLabel(wxDC& dc, int row) { if (GetRowHeight(row) <= 0 || m_rowLabelWidth <= 0) return; wxRect rect; int rowTop = GetRowTop(row), rowBottom = GetRowBottom(row) - 1; dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW), 1, wxSOLID)); dc.DrawLine(m_rowLabelWidth - 1, rowTop, m_rowLabelWidth - 1, rowBottom); dc.DrawLine(0, rowTop, 0, rowBottom); dc.DrawLine(0, rowBottom, m_rowLabelWidth, rowBottom); dc.SetPen(*wxWHITE_PEN); dc.DrawLine(1, rowTop, 1, rowBottom); dc.DrawLine(1, rowTop, m_rowLabelWidth - 1, rowTop); if (row == GetGridCursorRow()) { dc.DrawBitmap(wxBitmap(small_arrow_xpm), 0, GetRowTop(row), true); } }
void wxMacDataBrowserListControl::ListScrollTo( unsigned int n ) { UInt32 top , left ; GetScrollPosition( &top , &left ) ; wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n ); // there is a bug in RevealItem that leads to situations // in large lists, where the item does not get scrolled // into sight, so we do a pre-scroll if necessary UInt16 height ; GetRowHeight( (DataBrowserItemID) item , &height ) ; UInt32 linetop = n * ((UInt32) height ); UInt32 linebottom = linetop + height; Rect rect ; GetControlBounds( m_controlRef, &rect ); if ( linetop < top || linebottom > (top + rect.bottom - rect.top ) ) SetScrollPosition( wxMax( n-2, 0 ) * ((UInt32)height) , left ) ; RevealItem( item , kDataBrowserRevealWithoutSelecting ); }
void EGridCtrl::AddRow( IGridRow* pRowHost ) { // // collect properties (columns) for the row // Row* pRow = new Row( pRowHost ); pRowHost->GetGridColumns( *pRow ); pRowHost->m_pGridCtrl = this; // // prepare the dc for size calculations // CDC* pDC = GetDC(); pDC->SelectObject( &m_Font ); // // // pRow->m_nHeight = GetRowHeight( pRow , pDC ); m_vRows.push_back( pRow ); // // update column list // std::list<Row*>::iterator iter = m_vRows.begin(); std::list<Row*>::iterator iend = m_vRows.end(); while( iter != iend ) //for all rows... { Row* pRow = *iter; ASSERT( pRow->GetTabCount()==1 ); ASSERT( pRow->GetActiveTab()==0 ); int n = pRow->Size(); for( int i=0 ; i<n ; i++ ) { EProperty* pProperty = pRow->Get(i); int m = EIconTextButtonProperty::s_nMargin; CString sName = pProperty->GetName(); Column* pColumn = GetColumn( sName , true , m + pDC->GetTextExtent(sName).cx + m ); pColumn->EnsureWidth( pProperty->GetPreferedWidth(pDC) ); } iter++; } ReleaseDC(pDC); // // calculate left of each column // RefreshColumnLefts( m_ViewportOrg.x ); RefreshRowTops( m_ViewportOrg.y ); // // // BuildPropertyMap(); // // // Invalidate(); }
void OOPLyric::OnMouseEvent(VdkMouseEvent &e) { switch (e.evtCode) { case RIGHT_UP: { // 拖动歌词时不要响应右键事件 if (TestState(OLST_DRAGGING)) { return; } wxPoint menuPos(AbsoluteRect().GetPosition()); menuPos.x += e.mousePos.x; menuPos.y += e.mousePos.y; m_Window->ShowContextMenu(this, menuPos); break; } case LEFT_DOWN: { m_draggDistance = e.mousePos.y; SetAddinState(OLST_DRAGGING_STARTED); break; } case DRAGGING: { // 不接受先在一首歌的会话中拖动歌词,然后在未释放鼠标的情况下 // 另一首歌开始播放,继续前面的拖动事件 if (!TestState(OLST_DRAGGING_STARTED)) { break; } if (!IsOk()) { break; } if (m_timer.IsRunning()) { Pause(); SetAddinState(OLST_RUNNING_BEFORE_DRAGGING); } SetAddinState(OLST_DRAGGING); //====================================================== int ystart; GetViewStartCoord(NULL, &ystart); int dY = e.mousePos.y - m_draggDistance; m_draggDistance = e.mousePos.y; // 这是一行我们手工加上去的空行 int rowHeight = GetRowHeight(); int upperBound = (*(m_parser->begin()))->GetLyric().empty() ? rowHeight : 0; // 无法继续将帘布向上卷(再拖下去就到下一首了) // 我们将拖到尽头的事件视为无效 bool lastLine = false; // 情景:将虚拟画布像窗帘一样向下拖 // 拖动尽头了,不能再把窗帘哪怕拖下一寸 if (ystart - dY < upperBound) { dY = ystart - upperBound; // 加加减减的原因参照(*) } else { int maxy; GetMaxViewStartCoord(NULL, &maxy); // 将帘布向上卷,卷到尽头了,再卷下去就会导致 // 无法完整遮住窗口 if (ystart - dY > maxy) { dY = ystart - maxy; // 加加减减的原因参照(*) // 无效拖动事件 lastLine = true; } } if (dY) { SetViewStart(0, ystart - dY, &e.dc); //………………(*) } // 无效拖动事件 if (lastLine) { m_draggHit = m_parser->end(); } //=================================================== // 绘制中间线段 wxRect rc(GetAbsoluteRect()); int y = rc.y + m_blankLinesTop * GetRowHeight(); m_Window->ResetDcOrigin(e.dc); e.dc.SetPen(wxPen(m_TextColor)); e.dc.DrawLine(rc.x, y, rc.GetRight(), y); break; } case NORMAL: case LEFT_UP: { if (!TestState(OLST_DRAGGING) || !TestState(OLST_DRAGGING_STARTED)) { break; } wxASSERT(IsOk()); //----------------------------------------------------- RemoveState(OLST_DRAGGING | OLST_DRAGGING_STARTED); // 拖到最下面了,尽头 if (m_draggHit == m_parser->end()) { RefreshState(&e.dc); } else { int ystart; // 起始绘图坐标 GetViewStartCoord(NULL, &ystart); LineInfo *lineDraggHit = *m_draggHit; size_t timeToGo = lineDraggHit->GetStartTime(); int rowHeight = GetRowHeight(); double linePercentage = double(ystart % rowHeight) / rowHeight ; timeToGo += lineDraggHit->GetMilSeconds() * linePercentage; // 歌词可能并不匹配正在播放的歌曲 if (timeToGo < m_parser->GetTimeSum()) { m_currLine = m_draggHit; if (IsReadyForEvent()) { FireEvent(&e.dc, (void *) timeToGo); } } } bool resume = TestState(OLST_RUNNING_BEFORE_DRAGGING); if (resume) { RemoveState(OLST_RUNNING_BEFORE_DRAGGING); Resume(); } break; } default: break; } }
void ctlSQLGrid::OnLabelDoubleClick(wxGridEvent &event) { int maxHeight, maxWidth; GetClientSize(&maxWidth, &maxHeight); int row = event.GetRow(); int col = event.GetCol(); int extent, extentWant = 0; if (row >= 0) { for (col = 0 ; col < GetNumberCols() ; col++) { extent = GetBestSize(row, col).GetHeight(); if (extent > extentWant) extentWant = extent; } extentWant += EXTRAEXTENT_HEIGHT; extentWant = wxMax(extentWant, GetRowMinimalAcceptableHeight()); extentWant = wxMin(extentWant, maxHeight * 3 / 4); int currentHeight = GetRowHeight(row); if (currentHeight >= maxHeight * 3 / 4 || currentHeight == extentWant) extentWant = GetRowMinimalAcceptableHeight(); else if (currentHeight < maxHeight / 4) extentWant = wxMin(maxHeight / 4, extentWant); else if (currentHeight < maxHeight / 2) extentWant = wxMin(maxHeight / 2, extentWant); else if (currentHeight < maxHeight * 3 / 4) extentWant = wxMin(maxHeight * 3 / 4, extentWant); if (extentWant != currentHeight) { BeginBatch(); if(IsCellEditControlShown()) { HideCellEditControl(); SaveEditControlValue(); } SetRowHeight(row, extentWant); EndBatch(); } } else if (col >= 0) { // Holding Ctrl or Meta switches back to automatic column's sizing if (event.ControlDown() || event.CmdDown()) { colSizes.erase(GetColKeyValue(col)); BeginBatch(); if(IsCellEditControlShown()) { HideCellEditControl(); SaveEditControlValue(); } AutoSizeColumn(col, false); EndBatch(); } else // toggle between some predefined sizes { if (col < (int)colMaxSizes.GetCount() && colMaxSizes[col] >= 0) extentWant = colMaxSizes[col]; else { for (row = 0 ; row < GetNumberRows() ; row++) { if (CheckRowPresent(row)) { extent = GetBestSize(row, col).GetWidth(); if (extent > extentWant) extentWant = extent; } } } extentWant += EXTRAEXTENT_WIDTH; extentWant = wxMax(extentWant, GetColMinimalAcceptableWidth()); extentWant = wxMin(extentWant, maxWidth * 3 / 4); int currentWidth = GetColumnWidth(col); if (currentWidth >= maxWidth * 3 / 4 || currentWidth == extentWant) extentWant = GetColMinimalAcceptableWidth(); else if (currentWidth < maxWidth / 4) extentWant = wxMin(maxWidth / 4, extentWant); else if (currentWidth < maxWidth / 2) extentWant = wxMin(maxWidth / 2, extentWant); else if (currentWidth < maxWidth * 3 / 4) extentWant = wxMin(maxWidth * 3 / 4, extentWant); if (extentWant != currentWidth) { BeginBatch(); if(IsCellEditControlShown()) { HideCellEditControl(); SaveEditControlValue(); } SetColumnWidth(col, extentWant); EndBatch(); colSizes[GetColKeyValue(col)] = extentWant; } } } }
BOOL COwnerDrawnListControl::OnEraseBkgnd(CDC* pDC) { int i = 0; ASSERT(GetHeaderCtrl()->GetItemCount() > 0); // We should recalculate m_yFirstItem here (could have changed e.g. when // the XP-Theme changed). if(GetItemCount() > 0) { CRect rc; GetItemRect(GetTopIndex(), rc, LVIR_BOUNDS); m_yFirstItem = rc.top; } // else: if we did the same thing as in OnColumnsCreated(), we get // repaint problems. const COLORREF gridColor = RGB(212,208,200); CRect rcClient; GetClientRect(rcClient); CRect rcHeader; GetHeaderCtrl()->GetWindowRect(rcHeader); ScreenToClient(rcHeader); CRect rcBetween = rcClient; // between header and first item rcBetween.top = rcHeader.bottom; rcBetween.bottom = m_yFirstItem; pDC->FillSolidRect(rcBetween, gridColor); CArray<int, int> columnOrder; columnOrder.SetSize(GetHeaderCtrl()->GetItemCount()); GetColumnOrderArray(columnOrder.GetData(), int(columnOrder.GetSize())); CArray<int, int> vertical; vertical.SetSize(GetHeaderCtrl()->GetItemCount()); int x = - GetScrollPos(SB_HORZ); HDITEM hdi; ZeroMemory(&hdi, sizeof(hdi)); hdi.mask = HDI_WIDTH; for(i = 0; i < GetHeaderCtrl()->GetItemCount(); i++) { GetHeaderCtrl()->GetItem(columnOrder[i], &hdi); x += hdi.cxy; vertical[i]= x; } if(m_showGrid) { CPen pen(PS_SOLID, 1, gridColor); CSelectObject sopen(pDC, &pen); for(int y = m_yFirstItem + GetRowHeight() - 1; y < rcClient.bottom; y += GetRowHeight()) { pDC->MoveTo(rcClient.left, y); pDC->LineTo(rcClient.right, y); } // BUGBUG: re-using i could be a potential bug! for(i = 0; i < vertical.GetSize(); i++) { pDC->MoveTo(vertical[i] - 1, rcClient.top); pDC->LineTo(vertical[i] - 1, rcClient.bottom); } } const int gridWidth = m_showGrid ? 1 : 0; const COLORREF bgcolor = ::GetSysColor(COLOR_WINDOW); const int lineCount = GetCountPerPage() + 1; const int firstItem = GetTopIndex(); const int lastItem = min(firstItem + lineCount, GetItemCount()) - 1; ASSERT(GetItemCount() == 0 || firstItem < GetItemCount()); ASSERT(GetItemCount() == 0 || lastItem < GetItemCount()); ASSERT(GetItemCount() == 0 || lastItem >= firstItem); const int itemCount = lastItem - firstItem + 1; CRect fill; fill.left = vertical[vertical.GetSize() - 1]; fill.right = rcClient.right; fill.top = m_yFirstItem; fill.bottom = fill.top + GetRowHeight() - gridWidth; for(i = 0; i < itemCount; i++) { pDC->FillSolidRect(fill, bgcolor); fill.OffsetRect(0, GetRowHeight()); } int top = fill.top; while(top < rcClient.bottom) { fill.top = top; fill.bottom = top + GetRowHeight() - gridWidth; int left = 0; for(int i = 0; i < vertical.GetSize(); i++) { fill.left = left; fill.right = vertical[i] - gridWidth; pDC->FillSolidRect(fill, bgcolor); left = vertical[i]; } fill.left = left; fill.right = rcClient.right; pDC->FillSolidRect(fill, bgcolor); top += GetRowHeight(); } return true; }
void CDrivesList::MeasureItem(LPMEASUREITEMSTRUCT mis) { mis->itemHeight= GetRowHeight(); }
void ctlSQLGrid::OnLabelDoubleClick(wxGridEvent &event) { int maxHeight, maxWidth; GetClientSize(&maxWidth, &maxHeight); int row = event.GetRow(); int col = event.GetCol(); int extent, extentWant = 0; if (row >= 0) { for (col = 0 ; col < GetNumberCols() ; col++) { extent = GetBestSize(row, col).GetHeight(); if (extent > extentWant) extentWant = extent; } extentWant += EXTRAEXTENT_HEIGHT; extentWant = wxMax(extentWant, GetRowMinimalAcceptableHeight()); extentWant = wxMin(extentWant, maxHeight * 3 / 4); int currentHeight = GetRowHeight(row); if (currentHeight >= maxHeight * 3 / 4 || currentHeight == extentWant) extentWant = GetRowMinimalAcceptableHeight(); else if (currentHeight < maxHeight / 4) extentWant = wxMin(maxHeight / 4, extentWant); else if (currentHeight < maxHeight / 2) extentWant = wxMin(maxHeight / 2, extentWant); else if (currentHeight < maxHeight * 3 / 4) extentWant = wxMin(maxHeight * 3 / 4, extentWant); if (extentWant != currentHeight) { BeginBatch(); if(IsCellEditControlShown()) { HideCellEditControl(); SaveEditControlValue(); } SetRowHeight(row, extentWant); EndBatch(); } } else if (col >= 0) { for (row = 0 ; row < GetNumberRows() ; row++) { if (CheckRowPresent(row)) { extent = GetBestSize(row, col).GetWidth(); if (extent > extentWant) extentWant = extent; } } extentWant += EXTRAEXTENT_WIDTH; extentWant = wxMax(extentWant, GetColMinimalAcceptableWidth()); extentWant = wxMin(extentWant, maxWidth * 3 / 4); int currentWidth = GetColumnWidth(col); if (currentWidth >= maxWidth * 3 / 4 || currentWidth == extentWant) extentWant = GetColMinimalAcceptableWidth(); else if (currentWidth < maxWidth / 4) extentWant = wxMin(maxWidth / 4, extentWant); else if (currentWidth < maxWidth / 2) extentWant = wxMin(maxWidth / 2, extentWant); else if (currentWidth < maxWidth * 3 / 4) extentWant = wxMin(maxWidth * 3 / 4, extentWant); if (extentWant != currentWidth) { BeginBatch(); if(IsCellEditControlShown()) { HideCellEditControl(); SaveEditControlValue(); } SetColumnWidth(col, extentWant); EndBatch(); } } }
VdkCusdrawReturnFlag OOPLyric::DoDrawCellText (const VdkLcCell *cell, int col_index, int index0, wxDC &dc, VdkLcHilightState state) { wxASSERT(m_parser); // 注意:index 是不计算加入的空行的 int index = (int) (cell->GetClientData()) - 1; if (index == -1) { // 此时 ClientData == NULL,是我们添加的空行 return VCCDRF_DODEFAULT; } dc.SetTextForeground(m_TextColor); // 暂停时高亮当前行,情景见于用户正在拖动歌词。 // 另外先暂停,然后拖动歌词完毕,此时假如歌词秀是以卡拉OK // 方式进行显示时,那么不会保持半高亮的状态,而是全高亮。 if (TestState(OLST_PAUSED)) { int yStart; GetViewStartCoord(NULL, &yStart); int rowHeight = GetRowHeight(); int dragRegion = yStart + rowHeight * m_blankLinesTop; int index2 = index + m_blankLinesTop; // 检测拖动歌词时中间线下面的一行 if (rowHeight * index2 <= dragRegion && rowHeight * (index2 + 1) > dragRegion) { m_draggHit = m_parser->GetLine(index); dc.SetTextForeground(m_HilightColor); } return VCCDRF_DODEFAULT; } LineInfo *currLine = *m_currLine; // TODO: 是否考虑优化? size_t currLineIndex = m_parser->IndexOf(m_currLine); int lineHasGone = m_stopWatch->Time() - currLine->GetStartTime(); if ((index == currLineIndex - 1) && !cell->GetLabel().empty()) { // 使用渐变色还原上一句歌词 if (lineHasGone < ALPHA_SHOW_LAST_LINE_MS) { unsigned char r, g, b; double alpha2 = double(lineHasGone) / ALPHA_SHOW_LAST_LINE_MS; double alpha1 = 1 - alpha2; r = m_HilightColor.Red() * alpha1 + m_TextColor.Red() * alpha2; g = m_HilightColor.Green() * alpha1 + m_TextColor.Green() * alpha2; b = m_HilightColor.Blue() * alpha1 + m_TextColor.Blue() * alpha2; dc.SetTextForeground(wxColour(r, g, b)); } } else if (index == currLineIndex) { // 高亮当前文本行 // 尽管这是一种很罕见的情况,但一旦出现了就会导致下面 (*) 表达式 // 的除数为 0 if (currLine->GetMilSeconds() == 0) { return VCCDRF_DODEFAULT; } if (!cell->IsEmpty()) { /* 经验教训: 1. SetClippingRegiion 有叠加效应,因此在执行新的 SetClippingRegiion 前别忘了销毁原来的 ClippingRegiion 。 2. 关于表达式中整数与浮点数混用:注意中间运算结果会 被强制转换成 int 然后参加下一步的运算,并不是对 最终结果进行转换,使之成为一个浮点数。 */ const int rowHeight = GetRowHeight(); int y = (currLineIndex + m_blankLinesTop) * rowHeight; cell->DrawLabel(dc, 0, y); // (*) double lineProgress = double(lineHasGone) / currLine->GetMilSeconds(); // 要实现 KALA-OK 效果的文本宽度 int w = (m_Rect.width - cell->GetX_Padding() * 2) * lineProgress; wxRect rc(GetAbsoluteRect()); const int bottom = rc.y + rc.height; int yStart; VdkScrolledWindow::GetViewStartCoord(NULL, &yStart); rc.y += y - yStart; rc.width = cell->GetX_Padding() + w; rc.height = rowHeight; // 不能使 KALA-OK 效果的 ClippingRegion 超出列表窗口 if ((rc.y + rc.height) > bottom) { rc.height = bottom - rc.y; } VdkDcDeviceOriginSaver saver(dc); dc.SetDeviceOrigin(0, 0); VdkDcClippingRegionDestroyer destroyer(dc, rc); # ifdef __WXGTK__ dc.SetBrush(m_crossBrush1); dc.DrawRectangle(rc); # endif dc.SetTextForeground(m_HilightColor); cell->DrawLabel(dc, rc.x, rc.y); } return VCCDRF_SKIPDEFAULT; } return VCCDRF_DODEFAULT; }
void CXTPCalendarDayViewTimeScale::Draw(CDC* pDC) { ASSERT(pDC && m_pDayView); if (!pDC || !m_pDayView) { return; } pDC->FillSolidRect(m_Layout.m_rcHeader, GetSysColor(COLOR_3DFACE)); pDC->SetBkMode(TRANSPARENT); int nRowHeight = XTP_SAFE_GET1(m_pDayView, GetRowHeight(), 0); if (nRowHeight <= 0) return; const int nRowCount = m_pDayView->GetVisibleRowCount(); const int nTopRow = m_pDayView->GetTopRow(); COleDateTimeSpan spScaleInterval = GetScaleInterval(); if (CXTPCalendarUtils::GetTotalMinutes(spScaleInterval) < 1) { ASSERT(FALSE); spScaleInterval.SetDateTimeSpan(0, 0, 5, 0); } //=== Calculate 'now' line. Draw it's BK ================================ int nNowLineY = 0; if (m_bDrawNowLineDyn) { int nBottomRow = nTopRow + m_pDayView->GetVisibleRowCount(); COleDateTime dtTopTime = m_pDayView->GetCellTime(nTopRow); COleDateTime dtBottomTime = m_pDayView->GetCellTime(nBottomRow); COleDateTimeSpan spView = dtBottomTime - dtTopTime; COleDateTime dtNow = CXTPCalendarUtils::GetCurrentTime(); dtNow = CXTPCalendarUtils::ResetDate(dtNow); COleDateTimeSpan spNow = dtNow - dtTopTime; double dPixelPerSecond = m_Layout.m_rcTimeZone.Height() / (double)CXTPCalendarUtils::GetTotalSeconds(spView); int nDlta = int(CXTPCalendarUtils::GetTotalSeconds(spNow) * dPixelPerSecond); nNowLineY = m_Layout.m_rcTimeZone.top + nDlta; XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleHeaderPart(), DrawNowLine(pDC, m_pDayView, m_Layout.m_rcTimeZone, nNowLineY, TRUE) ); } //================================================================ int nTimeShiftCorrectorY = 0; COleDateTimeSpan spShiftCorrector(0); int nScaleInterval_min = max(1, (int)CXTPCalendarUtils::GetTotalMinutes(spScaleInterval)); double dPixelPerMin = (double)nRowHeight / (double)nScaleInterval_min; if (CXTPCalendarUtils::GetTotalHours(spScaleInterval) < 1) { int nMul = m_nTimeshift_min / 60; int nMod = m_nTimeshift_min % 60; int nShiftCorrector_min = (nMul + (nMod ? 1 :0))*60 - m_nTimeshift_min; //------------------------------------------------------------------- int nMul2 = nShiftCorrector_min / nScaleInterval_min; int nMod2 = nShiftCorrector_min % nScaleInterval_min; int nShiftCorrector2_min = (nMul2 + (nMod2 ? 1 :0)) * nScaleInterval_min; nTimeShiftCorrectorY = (int)(dPixelPerMin * nShiftCorrector2_min); spShiftCorrector = CXTPCalendarUtils::Minutes2Span(nShiftCorrector_min); } // draw time scale header COleDateTimeSpan spShift = CXTPCalendarUtils::Minutes2Span(m_nTimeshift_min); // draw time scale rows if (CXTPCalendarUtils::GetTotalHours(spScaleInterval) >= 1) { // draw time scale cells one by one for (int i = 0; i < nRowCount; i++) { CRect rcCell(m_Layout.m_rcTimeZone.left, m_Layout.m_rcTimeZone.top + nRowHeight * i, m_Layout.m_rcTimeZone.right, m_Layout.m_rcTimeZone.top + nRowHeight * (i + 1)); COleDateTime dtTime = m_pDayView->GetCellTime(nTopRow + i); dtTime += spShift; CString str = Format(dtTime, FALSE); XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleCellPart(), DrawHourCell(pDC, rcCell, str, FALSE)); } } else { COleDateTimeSpan spHour(0, 1, 0, 0); spShift += spShiftCorrector; int nRowPerHour = (int)((double)spHour / (double)spScaleInterval + XTP_HALF_SECOND); ASSERT(nRowPerHour > 0); nRowPerHour = max(1, nRowPerHour); const int nHourCellHeight = nRowHeight*nRowPerHour; // Adjust time font size CRect rcStartCell(m_Layout.m_rcTimeZone); rcStartCell.top += nTimeShiftCorrectorY; rcStartCell.bottom = rcStartCell.top + nHourCellHeight; //XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleCellPart(), // AdjustTimeFont(pDC, rcStartCell)); //------------------------------------------------------------------- int nHrCellDiv = m_Layout.m_rcTimeZone.Height() / rcStartCell.Height(); int nHrCellMod = m_Layout.m_rcTimeZone.Height() / rcStartCell.Height(); int nDrawCellCount = nHrCellDiv + (nHrCellMod ? 1 :0); COleDateTime dtStartCell = m_pDayView->GetCellTime(nTopRow); dtStartCell += spShift; int nSCMinute = dtStartCell.GetMinute(); if (nSCMinute != 0) { int nMinutesShiftY = (int)(dPixelPerMin * nSCMinute); rcStartCell.top -= nMinutesShiftY; rcStartCell.bottom -= nMinutesShiftY; dtStartCell.SetTime(dtStartCell.GetHour(), 0, 0); nDrawCellCount++; } //while (rcStartCell.top > m_rcTimeZone.top) for (int n = 0; rcStartCell.top > m_Layout.m_rcTimeZone.top && n < 100; n++) { dtStartCell -= spHour; rcStartCell.top -= nHourCellHeight; rcStartCell.bottom -= nHourCellHeight; nDrawCellCount++; } // draw time scale cells with only one big hour number BOOL bTopCell = TRUE; CRect rcCell = rcStartCell; for (int i = 0; i < nDrawCellCount; i++) { COleDateTime dtCell = dtStartCell + COleDateTimeSpan(i * (double)spHour); ASSERT(dtCell.GetMinute() == 0); CString strHour, strMin; Format(dtCell, bTopCell, &strHour, &strMin); if (rcCell.top >= m_Layout.m_rcTimeZone.top) { bTopCell = FALSE; } // draw text XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleCellPart(), DrawBigHourCell(pDC, rcCell, strHour, strMin, nRowPerHour, FALSE)); rcCell.top += nHourCellHeight; rcCell.bottom += nHourCellHeight; } } //*** draw 'now' line if (m_bDrawNowLineDyn) { XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleHeaderPart(), DrawNowLine(pDC, m_pDayView, m_Layout.m_rcTimeZone, nNowLineY, FALSE) ); } //*** Draw Expand Signs XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleHeaderPart(), DrawExpandSigns(pDC, m_pDayView, m_Layout.m_rcTimeZone) ); //*** Draw header CRect rcHeader(m_Layout.m_rcHeader.left, m_Layout.m_rcHeader.top, m_Layout.m_rcHeader.right, m_Layout.m_rcTimeZone.top); XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleHeaderPart(), OnDraw(pDC, m_pDayView, rcHeader, m_strCaption)); }
CSize CToolPalette::CalcButtonLocations(int nColumns, bool bCalcOnly) { if (nColumns < 1) { nColumns = 1; } bool bHorizontal = (GetCurrentAlignment () & CBRS_ORIENT_HORZ) != 0; // Toolbar layout mode CRect rectClient; GetClientRect (rectClient); EDisplayOptions edo = GetToolbarDisplayOptions (); if ((edo & eDisplayTitle) != 0) { if (!bHorizontal) { rectClient.top += m_nCaptionHeight + 4; } } int xBorders = 0; int yBorders = 0; if ((edo & eDisplayBorder) != 0) { const CRect& rectCorners = m_imgCaption.GetParams ().m_rectCorners; rectClient.left += rectCorners.left + 3; rectClient.top += rectCorners.top; xBorders = rectCorners.left + rectCorners.right; yBorders = rectCorners.top + rectCorners.bottom; } else { rectClient.left += 1; } if ((edo & eDisplaySizeControl) != 0 && bHorizontal) { const int sizeControlHeight = m_imgCaption.GetParams ().m_rectImage.Height (); yBorders += sizeControlHeight; rectClient.top += sizeControlHeight; } // Consider border area CPoint xyPos = rectClient.TopLeft (); // Current position bool bPrevSeparator = true; // Indicates that previous button was a separator. // Initial 'true' value prevents separator to appear first. CClientDC dc (this); CSize szButtonDefault (GetColumnWidth (), GetRowHeight ()); // Default button size to pass to button's OnCalculateSize method int nMaxSize = nColumns * (bHorizontal ? szButtonDefault.cy : szButtonDefault.cx) * 11 / 10; // (11/10) adds +10% space here // The toolbar height (for horizontal layout) or width (for vertical) of toolbar. CList<ButtonStripe, const ButtonStripe&> listStripes; ButtonStripe stripe; // Current stripe CBCGPToolbarButton* pButton = NULL; // Current button for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;) { pButton = (CBCGPToolbarButton*)m_Buttons.GetNext (pos); if (pButton == NULL) { break; } if (!pButton->IsVisible ()) { continue; } bool bSep = (pButton->m_nStyle & TBBS_SEPARATOR) != 0; if (bSep && bPrevSeparator) { continue; } // Layout algorithm: // ------------------- // if (separator) AddPreviousStripe, AddSeparatorStripe, BeginNewStripe // else { // AddButton // if (stripe.breadth > default_stripe_breadth) // AddPreviousStripe, BeginNewStripe, AddButton // } CSize szButton = pButton->OnCalculateSize (&dc, szButtonDefault, bHorizontal); if (bHorizontal) { } else // vertical layout { if (bSep) { if (stripe.buttonCount > 0) { listStripes.AddTail (stripe); } stripe.buttonCount = 1; stripe.breadth = 0; // separator length is set automatically stripe.size = szButton.cy; // cx for horz. listStripes.AddTail (stripe); stripe = ButtonStripe (); } else if (szButton.cx > nMaxSize) // this button is larger than current toolbar width { if (stripe.buttonCount > 0) { listStripes.AddTail (stripe); } stripe.buttonCount = 1; stripe.breadth = szButton.cx; // cy for horz. stripe.size = szButton.cy; // cx for horz. listStripes.AddTail (stripe); // stripe with a single large button stripe = ButtonStripe (); } else // usual button { if (stripe.breadth + szButton.cx <= nMaxSize) { stripe.breadth += szButton.cx; stripe.buttonCount ++; if (szButton.cy > stripe.size) stripe.size = szButton.cy; } else { if (stripe.buttonCount > 0) { listStripes.AddTail (stripe); } stripe.buttonCount = 1; stripe.breadth = szButton.cx; // cy for horz. stripe.size = szButton.cy; // cx for horz. } } } bPrevSeparator = bSep; } if (stripe.buttonCount > 0) { listStripes.AddTail (stripe); } if (listStripes.IsEmpty ()) { return CSize (0, 0); } if (listStripes.GetTail ().breadth == 0) // last item is separator { listStripes.RemoveTail (); } // Now calculate total size int totalLength = m_nCaptionHeight + 4; int maxBreadth = nMaxSize; POSITION posStripes = listStripes.GetHeadPosition (); while (posStripes != NULL) { stripe = listStripes.GetNext (posStripes); ASSERT (stripe.buttonCount > 0); totalLength += stripe.size; if (stripe.breadth > maxBreadth) { maxBreadth = stripe.breadth; } } if (!bCalcOnly) { CPoint ptButtonPos = rectClient.TopLeft (); posStripes = listStripes.GetHeadPosition (); stripe = ButtonStripe(); for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;) { pButton = (CBCGPToolbarButton*)m_Buttons.GetNext (pos); if (pButton == NULL) { break; } if (!pButton->IsVisible ()) { continue; } bool bSep = (pButton->m_nStyle & TBBS_SEPARATOR) != 0; if (bSep && bPrevSeparator) { continue; } CSize szButton = pButton->OnCalculateSize (&dc, szButtonDefault, bHorizontal); CRect rcButton (0, 0, 0, 0); if (stripe.buttonCount == 0) // this member is decremented below { ptButtonPos.y += stripe.size; if (posStripes == NULL) { break; } stripe = listStripes.GetNext (posStripes); ptButtonPos.x = rectClient.left + (maxBreadth - stripe.breadth) / 2; // center-alignment } if (bSep) { ASSERT (stripe.breadth == 0); ASSERT (stripe.buttonCount == 1); rcButton.left = rectClient.left; rcButton.top = ptButtonPos.y; rcButton.right = rcButton.left + maxBreadth; rcButton.bottom = rcButton.top + szButton.cy; } else { rcButton.left = ptButtonPos.x; rcButton.top = ptButtonPos.y + (stripe.size - szButton.cy) / 2; // center-alignment rcButton.right = rcButton.left + szButton.cx; rcButton.bottom = rcButton.top + szButton.cy; ptButtonPos.x += szButton.cx; } pButton->SetRect (rcButton); stripe.buttonCount --; } } if (m_bAdditionalPixel) { ++maxBreadth; } return bHorizontal ? CSize (totalLength + xBorders, maxBreadth + yBorders) : CSize (maxBreadth + xBorders, totalLength + yBorders); }
void CExtensionListControl::MeasureItem(LPMEASUREITEMSTRUCT mis) { mis->itemHeight = GetRowHeight(); }
int CXTPSyntaxEditDrawTextProcessor::PrintRowPart(CDC* pDC, int nRow, int nPosY, UINT nFlags, LPCTSTR pcszText, int nchCount, int *pnPrintedTextLen) { if (pnPrintedTextLen) *pnPrintedTextLen = 0; if (m_nPrintingRow != nRow) { m_nPrintingRow = nRow; m_ptNextPrintPos = CPoint(0, 0); } if (nRow == -1) return 0; //-------------------------------------------------------- int nTextLen = 0; if (nchCount < 0) { nchCount = (int)_tcsclen(pcszText); nTextLen = (int)_tcslen(pcszText); } else { nTextLen = (int)_tcsnbcnt(pcszText, nchCount); } ASSERT(nchCount <= (int)_tcsclen(pcszText)); //-------------------------------------------------------- if (m_arBuf_aDx.GetSize() < nTextLen) m_arBuf_aDx.SetSize(nTextLen + 100); LPINT alpDx = (int*)m_arBuf_aDx.GetData(); //-------------------------------------------------------- CRect rcText = m_rcTextRect; int nTextLen_rest = nTextLen; LPCTSTR pTxt = NULL; for (pTxt = pcszText; nTextLen_rest;) { int nY = m_rcTextRect.top + nPosY + m_ptNextPrintPos.y; int nX = m_rcTextRect.left + m_ptNextPrintPos.x; if (nY + GetRowHeight() > m_rcTextRect.bottom) break; //-------------------------------------------------------- int nMaxExtent = max(0, rcText.right - nX - 20); int nFit = 0; CSize szText(0, 0); BOOL bResExt = GetTextExtentExPoint( m_bUseOutputDC ? pDC->m_hDC : pDC->m_hAttribDC, // HDC hdc, // handle to DC pTxt, // LPCTSTR lpString, // character string nTextLen_rest, // int nCount, // number of characters nMaxExtent, // maximum extent for string &nFit, // LPINT lpnFit, // maximum number of characters alpDx, // array of partial string widths &szText //LPSIZE lpSize // string dimensions ); VERIFY(bResExt); //nFit = min(nFit, nTextLen_rest); LPCTSTR pTextToDtaw = pTxt; BOOL bAllTextDrawn = (nFit == nTextLen_rest); if (nFit > 0 && nFit <= nTextLen_rest) { CString strSeps = _T(" .,!?)-+=;\\"); //_T(" .,!?)-+=*&^%$#@~`:;\\|/"); int nFit_wb = 0; int nTextLen_wb = nTextLen_rest; LPCTSTR pTxt_wb = pTxt; LPCTSTR p_prev = NULL; int i = 0; for (i = 0; i < nFit; i++) { p_prev = pTxt; pTxt = _tcsinc(pTxt); int nCharLen = int(pTxt - p_prev); i += nCharLen - 1; // skip second byte for MBCS chars. nTextLen_rest--; if ((nFlags & DT_WORDBREAK) && strSeps.Find(*p_prev, 0) >= 0) { nFit_wb = i+1; nTextLen_wb = nTextLen_rest; pTxt_wb = pTxt; } } if (!bAllTextDrawn && (nFlags & DT_WORDBREAK)) { if (nFit_wb >= 0) { nFit = nFit_wb; nTextLen_rest = nTextLen_wb; pTxt = pTxt_wb; } } if (nFit) { m_ptNextPrintPos.x += alpDx[nFit - 1] + 1; } } // Draw text (if need) if (nFit && (nFlags & DT_CALCRECT) == 0) { rcText.left = max(rcText.left, nX); // ENSURE THE TEXT IS CLIPPED APPROPRIATELY pDC->ExtTextOut(nX, nY, ETO_CLIPPED, &rcText, pTextToDtaw, nFit, NULL); } CXTPRowInfo* pRI = GetRowInfo(nRow); if (pRI) pRI->nMaxWidth = m_ptNextPrintPos.x; // Move point to the next line (if need) if (!bAllTextDrawn && (nFlags & DT_SINGLELINE) == 0) { int nIconX = m_rcTextRect.left + m_ptNextPrintPos.x + 3; int nIconY = m_rcTextRect.top + nPosY + m_ptNextPrintPos.y; int nDelta = GetRowHeight() - GetRowHeight()/4; CPen pen1(PS_SOLID, 1, RGB(0,0,0)); CPen pen2(PS_SOLID, 2, RGB(0,0,0)); CPen* pPen_old = pDC->SelectObject(&pen1); pDC->MoveTo(nIconX, nIconY + nDelta/2); pDC->LineTo(nIconX, nIconY + nDelta); pDC->LineTo(nIconX + nDelta/2 - 1, nIconY + nDelta); pDC->SelectObject(&pen2); pDC->MoveTo(nIconX + 1, nIconY + nDelta - 1); pDC->LineTo(nIconX + nDelta/2, nIconY + nDelta/2); pDC->SelectObject(pPen_old); int nSublineOffsetX = m_tmText.tmAveCharWidth * 3; m_ptNextPrintPos.y += GetRowHeight(); m_ptNextPrintPos.x = nSublineOffsetX; if (pRI) pRI->nMaxWidth = m_ptNextPrintPos.x; } else { break; } } if (pnPrintedTextLen) { int nLen0 = int(pTxt - pcszText); *pnPrintedTextLen = (int)_tcsnccnt(pcszText, nLen0); } return m_ptNextPrintPos.y + GetRowHeight(); }
void ChooseAIDestination( int player ) { int testX, testR, testX2, testR2, value, bestValue = -9999999; int x, y; int bestX[kGridAcross*4], bestR[kGridAcross*4], currentBest = -1; int rowDifference, totalTries, temp; bool shouldTry[kGridAcross][4]; timeAI[player] = GameTickCount( ) + 1; moveQuick[player] = true; if( grenade[player] ) { bestValue = 0; currentBest = 2; for( testX = 0; testX < kGridAcross; testX++ ) { rowDifference = GetRowHeight( player, testX ); if( (rowDifference < kGridDown) && (grid[player][testX][rowDifference+1] >= kFirstBlob) && (grid[player][testX][rowDifference+1] <= kLastBlob) ) { value = 0; for( x=0; x<kGridAcross; x++ ) { for( y=0; y<kGridDown; y++ ) { if( grid[player][x][y] == grid[player][testX][rowDifference+1] ) value++; } } if( value > bestValue ) { bestValue = value; currentBest = testX; } } } destinationR[player] = upRotate; destinationX[player] = currentBest; return; } if( (GameTickCount() - startTime) <= 3600 ) { for( testX = 0; testX < kGridAcross; testX++ ) { rowDifference = GetRowHeight( player, testX ) - character[player].autoSetup[testX]; if( rowDifference >= 2 ) { destinationR[player] = downRotate; destinationX[player] = testX; return; } if( rowDifference == 1 ) { destinationX[player] = testX; if( testX > 0 ) { if( GetRowHeight( player, testX-1 ) > character[player].autoSetup[testX-1] ) { destinationR[player] = leftRotate; return; } } if( testX < (kGridAcross-1) ) { if( GetRowHeight( player, testX+1 ) > character[player].autoSetup[testX+1] ) { destinationR[player] = rightRotate; return; } } destinationR[player] = upRotate; return; } } } moveQuick[player] = (emotions[player] == kEmotionSad) || (emotions[player] == kEmotionPanic); totalTries = character[player].intellect; for( testX = 0; testX < kGridAcross; testX++ ) { for( testR = 0; testR < 4; testR++ ) { shouldTry[testX][testR] = --totalTries >= 0; } } for( testX = 0; testX < kGridAcross; testX++ ) { for( testR = 0; testR < 4; testR++ ) { testX2 = RandomBefore( kGridAcross ); testR2 = RandomBefore( 4 ); temp = shouldTry[testX][testR]; shouldTry[testX][testR] = shouldTry[testX2][testR2]; shouldTry[testX2][testR2] = temp; } } shouldTry[0][leftRotate] = false; shouldTry[kGridAcross-1][rightRotate] = false; for( testX = 0; testX < kGridAcross; testX++ ) { for( testR = 0; testR<=3; testR++ ) { if( shouldTry[testX][testR] ) { value = TestAIDestination( player, testX, testR ); if( value > bestValue ) { bestValue = value; currentBest = -1; } if( value == bestValue ) { currentBest++; bestX[currentBest] = testX; bestR[currentBest] = testR; } } } } currentBest = RandomBefore( currentBest + 1 ); destinationX[player] = bestX[currentBest]; destinationR[player] = bestR[currentBest]; }
unsigned long UserWinProcedure(HWND Window,HMSG Message,long Param1,long Param2) { int hlist,i,j; float Midf; switch (Message) { case DIALOGBOXOK: GetPrintPara(); if (PG.Blocks>0) PG.Enable=1; else PG.Enable=0; return(DialogDefaultProcedure(Window, Message, Param1, Param2)); case DIALOGBOXCANCEL: PG.Enable=0; return(DialogDefaultProcedure(Window, Message, Param1, Param2)); case REDRAWMESSAGE: i=DialogDefaultProcedure(Window, Message, Param1, Param2); WaitMessageEmpty(); InitOver=1; InitPrintCut(); CurrentBlock=0; SetPrintPara(); REFLASH; MessageInsert(PrintCutWin[wPAGEADDWIN],WINDOWINIT,0l,0l); ListSetCurrent(WindowList(PrintCutWin[wPAGEADDWIN]),CurrentBlock); REFLASHADD; return i; break; case WINDOWINIT: InitOver=0; i=DialogDefaultProcedure(Window, Message, Param1, Param2); //WaitMessageEmpty(); return i; break; case ADDWIN: GetPrintPara(); if (PG.Blocks<99) PG.Blocks++; CurrentBlock=PG.Blocks-1; if (CurrentBlock>0) CopyBlock(CurrentBlock,CurrentBlock-1); else InitBlock(CurrentBlock); SetPrintPara(); hlist = WindowList(PrintCutWin[wPAGEADDWIN]); MessageGo(PrintCutWin[wPAGEADDWIN],WINDOWINIT,0,0); MessageGo(PrintCutWin[wPAGEADDWIN],WMPAINT,0,ListGetHeight(hlist)*CHARHEIGHT); if (CurrentBlock>=7) ListSetTop(hlist,CurrentBlock-7); else ListSetTop(hlist,0); ListSetCurrent(hlist,CurrentBlock); MessageGo(PrintCutWin[wPAGEADDWIN],REDRAWMESSAGE,0L, MAKELONG(WindowGetWidth(PrintCutWin[wPAGEADDWIN]), WindowGetHeight(PrintCutWin[wPAGEADDWIN])) ); //MessageGo(PrintCutWin[wPAGEADDWIN],KEYDOWN,UP,0l); //MessageGo(PrintCutWin[wPAGEADDWIN],KEYDOWN,DOWN,0l); //ListSetTop(hlist,0); REFLASH; break; case DELETEWIN: GetPrintPara(); for (i=CurrentBlock+1;i<PG.Blocks;i++) CopyBlock1(i-1,i); if (PG.Blocks>0) PG.Blocks--; if (CurrentBlock>=PG.Blocks&&CurrentBlock) CurrentBlock=PG.Blocks-1; SetPrintPara(); hlist = WindowList(PrintCutWin[wPAGEADDWIN]); MessageGo(PrintCutWin[wPAGEADDWIN],WINDOWINIT,0,0); MessageGo(PrintCutWin[wPAGEADDWIN],WMPAINT,0,ListGetHeight(hlist)*CHARHEIGHT); if (CurrentBlock>=7) ListSetTop(hlist,CurrentBlock-7); else ListSetTop(hlist,0); ListSetCurrent(hlist,CurrentBlock); MessageGo(PrintCutWin[wPAGEADDWIN],REDRAWMESSAGE,0L, MAKELONG(WindowGetWidth(PrintCutWin[wPAGEADDWIN]), WindowGetHeight(PrintCutWin[wPAGEADDWIN])) ); REFLASH; break; case DELETETAILWIN: GetPrintPara(); PG.Blocks=CurrentBlock; if (CurrentBlock>=PG.Blocks&&CurrentBlock) CurrentBlock=PG.Blocks-1; SetPrintPara(); hlist = WindowList(PrintCutWin[wPAGEADDWIN]); MessageGo(PrintCutWin[wPAGEADDWIN],WINDOWINIT,0,0); MessageGo(PrintCutWin[wPAGEADDWIN],WMPAINT,0,ListGetHeight(hlist)*CHARHEIGHT); if (CurrentBlock>=7) ListSetTop(hlist,CurrentBlock-7); else ListSetTop(hlist,0); ListSetCurrent(hlist,CurrentBlock); MessageGo(PrintCutWin[wPAGEADDWIN],REDRAWMESSAGE,0L, MAKELONG(WindowGetWidth(PrintCutWin[wPAGEADDWIN]), WindowGetHeight(PrintCutWin[wPAGEADDWIN])) ); REFLASH; break; case COPYWIN: i=GetPrintPara(); if (i<0) switch(i) { case -99: { if (MessageBox("设置打印纸"," 确认您的打印机可使用\n" " 您所定义的纸张大小, \n" " 否则,打印可能出错!" ,2,1)) break; } PaperW=Tmp1; PaperH=Tmp2; if (PaperW<20.0) PaperW=20.0; if (PaperW>1100.0) PaperW=1100.0; if (PaperH<20.0) PaperH=20.0; if (PaperH>1100.0) PaperH=1100.0; printer->xpixel=PaperW*PrinterDPI/25.4; printer->ypixel=PaperH*PrinterDPI/25.4; InitPrintCut(); break; case -5: //Tmp1 = Scale Tmp2=PageH*Tmp4; Tmp1=PageW*Tmp3; if (PG.Blocks) { j=(PG.PageBlock[0].Rotate&1); } else j=0; if (j) { Midf=Tmp2; Tmp2=Tmp1; Tmp1=Midf; } case -1: if (Tmp1>5.0f) { Midf=0.0f; ColLeadNum=0; while (Midf+Tmp1<PaperW) { Midf +=Tmp1; ColLead[ColLeadNum++]=Midf; } } if (Tmp2>5.0f) { Midf=0.0f; RowLeadNum=0; while (Midf+Tmp1<PaperH) { Midf +=Tmp2; RowLead[RowLeadNum++]=Midf; } } break; case -2: ColLeadNum=0; RowLeadNum=0; break; case -3: ColLeadNum=0; break; case -4: RowLeadNum=0; break; case -6: //Auto Scale Fit if (!PG.Blocks) break; PG.Blocks=0; CurrentBlock=0; hlist=PG.PageBlock[0].Rotate; for (i=0;i<RowLeadNum;i++) { for (j=0;j<ColLeadNum;j++) { if (GetColWidth(j)-5.0f>Tmp1+Tmp3&& GetRowHeight(i)-5.0f>Tmp2+Tmp4) { if (hlist&1) { PG.PageBlock[PG.Blocks].Yscale=(GetColWidth(j)-Tmp1-Tmp3)/PageH; PG.PageBlock[PG.Blocks].Xscale=(GetRowHeight(i)-Tmp2-Tmp4)/PageW; } else { PG.PageBlock[PG.Blocks].Xscale=(GetColWidth(j)-Tmp1-Tmp3)/PageW; PG.PageBlock[PG.Blocks].Yscale=(GetRowHeight(i)-Tmp2-Tmp4)/PageH; } PG.PageBlock[PG.Blocks].Xoffset=GetColOffset(j)+Tmp1; PG.PageBlock[PG.Blocks].Yoffset=GetRowOffset(i)+Tmp3; PG.PageBlock[PG.Blocks].PageOffset=0; PG.PageBlock[PG.Blocks++].Rotate=hlist; } if (PG.Blocks>=99) break; } if (PG.Blocks>=99) break; } break; case -7: //Auto Scale Fit if (!PG.Blocks) break; PG.Blocks=0; CurrentBlock=0; hlist=PG.PageBlock[0].Rotate; for (i=0;i<=RowLeadNum;i++) { for (j=0;j<=ColLeadNum;j++) { if (GetColWidth(j)-5.0f>Tmp1+Tmp3&& GetRowHeight(i)-5.0f>Tmp2+Tmp4) { if (hlist&1) { PG.PageBlock[PG.Blocks].Yscale=(GetColWidth(j)-Tmp1-Tmp3)/PageH; PG.PageBlock[PG.Blocks].Xscale=(GetRowHeight(i)-Tmp2-Tmp4)/PageW; } else { PG.PageBlock[PG.Blocks].Xscale=(GetColWidth(j)-Tmp1-Tmp3)/PageW; PG.PageBlock[PG.Blocks].Yscale=(GetRowHeight(i)-Tmp2-Tmp4)/PageH; } PG.PageBlock[PG.Blocks].Xoffset=GetColOffset(j)+Tmp1; PG.PageBlock[PG.Blocks].Yoffset=GetRowOffset(i)+Tmp3; PG.PageBlock[PG.Blocks].PageOffset=0; PG.PageBlock[PG.Blocks++].Rotate=hlist; } if (PG.Blocks>=99) break; } if (PG.Blocks>=99) break; } break; case -8: if (!PG.Blocks) break; PG.Blocks=0; CurrentBlock=0; for (i=0;i<RowLeadNum;i++) { for (j=0;j<ColLeadNum;j++) { if (GetColWidth(j)-5.0f>Tmp1&& GetRowHeight(i)-5.0f>Tmp2) { PG.PageBlock[PG.Blocks].Xoffset=GetColOffset(j)+Tmp1; PG.PageBlock[PG.Blocks].Yoffset=GetRowOffset(i)+Tmp2; PG.PageBlock[PG.Blocks].Xscale=PG.PageBlock[0].Xscale; PG.PageBlock[PG.Blocks].Yscale=PG.PageBlock[0].Yscale; PG.PageBlock[PG.Blocks].PageOffset=0; PG.PageBlock[PG.Blocks++].Rotate=PG.PageBlock[0].Rotate; } if (PG.Blocks>=99) break; } if (PG.Blocks>=99) break; } break; case -9: if (!PG.Blocks) break; PG.Blocks=0; CurrentBlock=0; for (i=0;i<=RowLeadNum;i++) { for (j=0;j<=ColLeadNum;j++) { if (GetColWidth(j)-5.0f>Tmp1&& GetRowHeight(i)-5.0f>Tmp2) { PG.PageBlock[PG.Blocks].Xoffset=GetColOffset(j)+Tmp1; PG.PageBlock[PG.Blocks].Yoffset=GetRowOffset(i)+Tmp2; PG.PageBlock[PG.Blocks].Xscale=PG.PageBlock[0].Xscale; PG.PageBlock[PG.Blocks].Yscale=PG.PageBlock[0].Yscale; PG.PageBlock[PG.Blocks].PageOffset=0; PG.PageBlock[PG.Blocks++].Rotate=PG.PageBlock[0].Rotate; } if (PG.Blocks>=99) break; } if (PG.Blocks>=99) break; } break; } REFLASH; REFLASHADD; break; default: return(DialogDefaultProcedure(Window, Message, Param1, Param2)); } /* return(DialogDefaultProcedure(Window, Message, Param1, Param2)); */ return(TRUE); }