WgTablePanel::WgTablePanel() { m_bShowHeader = true; m_bAutoScaleHeader = false; m_emptyRowHeight = 0; m_nColumns = 0; m_pColumns = 0; m_nRowColors = 0; m_pRowColors = 0; m_nRowBlocks = 0; m_pRowBlocks = 0; m_sortMarkerAlignment = WG_EAST; m_sortMarkerOfs.x = 0; m_sortMarkerOfs.y = 0; m_clickSortPrio = 0; m_lastClickedRow = -1; m_lastClickedColumn = -1; m_markedRow = -1; m_markedColumn = -1; m_bSortAscend = true; m_contentSize = WgSize(0,0); m_bAutoScrollMarked = false; m_lastSortColumn = 0; m_lastSortColumnAscendStatus = true; m_pMarkedHeader = NULL; m_selectMode = SELECT_SINGLE_ROW; m_nRows = 0; m_selectedRowColor = WgColor(128,128,128,85); }
void WgTablePanel::ShowHeader( bool bShow ) { if( bShow != m_bShowHeader ) { m_bShowHeader = bShow; int newHeight = m_contentSize.h; if( m_pHeaderGfx ) { if( bShow ) newHeight += m_pHeaderGfx->Height(); else newHeight -= m_pHeaderGfx->Height(); } _setContentSize( WgSize( m_contentSize.w, newHeight ) ); _requestRender(); } }
void WgTableColumn::SetVisible( bool bVisible ) { if( m_bVisible != bVisible ) { m_bVisible = bVisible; int width; if( bVisible ) width = m_pTable->m_contentSize.w + m_realWidth; else width = m_pTable->m_contentSize.w - m_realWidth; if( m_pTable ) { m_pTable->_setContentSize( WgSize( width, m_pTable->m_contentSize.h) ); m_pTable->_requestRender(); m_pTable->_updateColumnWidths(); } } }
WgSize WgTablist::PreferredSize() const { if( m_tabs.Size() == 0 ) return WgSize(0,0); // Calculate preferred width int preferredWidth = 0; switch( m_tabWidthMode ) { case UNIFIED_WIDTH: { int widest = 0; int nTabs = 0; WgTab * pTab = m_tabs.First(); while( pTab ) { int w = _calcTabsWantedWidth(pTab); if( w > widest ) widest = w; nTabs++; pTab = pTab->Next(); } preferredWidth = widest*nTabs - m_overlap*(nTabs-1); break; } default: assert(0); // Should never happen, but we will default to INDIVIDUAL_WIDTH if it does. case INDIVIDUAL_WIDTH: { int nTabs = 0; WgTab * pTab = m_tabs.First(); while( pTab ) { preferredWidth += _calcTabsWantedWidth(pTab); nTabs++; pTab = pTab->Next(); } preferredWidth -= m_overlap*(nTabs-1); break; } } // Calculate best height int preferredHeight = 0; WgTab * pTab = m_tabs.First(); while( pTab ) { int h = 0; WgSkinPtr pBg = _tabSkin(pTab); if( pBg ) { h = pBg->PreferredSize().h; int textH = pTab->m_text.Height(); if( h - pBg->ContentPadding().h < textH ) h = textH + pBg->ContentPadding().h; } else h = pTab->m_text.Height(); if( h > preferredHeight ) preferredHeight = h; pTab = pTab->Next(); } // return WgSize( preferredWidth, preferredHeight ); }
WgFiller::WgFiller() { m_preferredSize = WgSize(-1,-1); }
void WgTablePanel::_updateColumnWidths() { // Calculate scale factor float scaleFactor = 1.f; bool bAnyColumnWidthChanged = false; if( m_bAutoScaleHeader && m_contentSize.w != 0 ) scaleFactor = (float)m_widgetSize.w / (float)m_contentSize.w; // Set m_realWidth for each column, flag if changed. for( int i = 0 ; i < m_nColumns ; i++ ) { if( m_pColumns[i].m_bVisible ) { int newWidth = (int) (m_pColumns[i].m_desiredWidth * scaleFactor); if( m_pColumns[i].m_realWidth != newWidth ) { m_pColumns[i].m_bWidthChanged = true; m_pColumns[i].m_realWidth = newWidth; } } else m_pColumns[i].m_realWidth = 0; } // Go through rows, notify widgets of new width, update row height and content height. WgTableRow* pRow = m_rows.First(); while( pRow ) { bool bRecalcHeight = false; for( int n = 0 ; n < pRow->m_nCells ; n++ ) { WgTableHook * pHook = &pRow->m_pCells[n]; if( m_pColumns[n].m_bWidthChanged && pHook->Widget() ) { int w = m_pColumns[n].m_realWidth; int h = pHook->Widget()->HeightForWidth(w); pHook->Widget()->_onNewSize( WgSize( w, h ) ); if( h != pHook->m_height ) { pHook->m_height = h; bRecalcHeight = true; } } } if( bRecalcHeight ) { int newHeight = 0; for( int n = 0 ; n < pRow->m_nCells ; n++ ) { if( pRow->m_pCells[n].m_height > newHeight ) newHeight = pRow->m_pCells[n].m_height; } if( newHeight != pRow->m_height ) { m_contentSize.h += newHeight - pRow->m_height; pRow->m_height = newHeight; } } pRow = pRow->Next(); } // Clear the width changed flags for( int i = 0 ; i < m_nColumns ; i++ ) m_pColumns[i].m_bWidthChanged = false; }
int main(int argc, char **argv) { // Init SDL SDL_Surface * pScreen = initSDL(1024,640); if(!pScreen ) return 1; IMG_Init( IMG_INIT_PNG | IMG_INIT_JPG | IMG_INIT_TIF ); // Init WonderGUI WgBase::Init(); sdl_wglib::MapKeys(); // Load bitmap font WgFont * pFont = sdl_wglib::LoadBitmapFont( "../resources/anuvverbubbla_8x8.png", "../resources/anuvverbubbla_8x8.fnt", WgSurfaceFactorySoft() ); // Set default textprop WgTextprop prop; prop.SetFont(pFont); prop.SetColor( WgColor::white ); prop.SetSize(8); WgBase::SetDefaultTextprop( prop.Register() ); // Setup gfxdevice and gui WgSurfaceSoft * pCanvas = new WgSurfaceSoft( WgSize(1024,640), WG_PIXEL_ARGB_8, (unsigned char *) pScreen->pixels, pScreen->pitch ); WgGfxDeviceSoft * pDevice = new WgGfxDeviceSoft( pCanvas ); pDevice->SetBilinearFiltering( true ); WgRoot * pRoot = setupGUI(pDevice); if( !pRoot ) { delete pDevice; return -1; } WgEventHandler * pEventHandler = pRoot->EventHandler(); // program main loop while (eventLoop( pEventHandler )) { // GET DIRTY RECTS int nDirtyRects; SDL_Rect dirtyRects[100]; if( pRoot->NbDirtyRects() <= 100 ) { nDirtyRects = pRoot->NbDirtyRects(); for( int i = 0 ; i < nDirtyRects ; i++ ) { const WgRect * pR = pRoot->FirstDirtyRect() + i; dirtyRects[i].x = pR->x; dirtyRects[i].y = pR->y; dirtyRects[i].w = pR->w; dirtyRects[i].h = pR->h; } } else { nDirtyRects = 1; const WgRect r = pRoot->Geo(); dirtyRects[0].x = r.x; dirtyRects[0].y = r.y; dirtyRects[0].w = r.w; dirtyRects[0].h = r.h; } // DRAWING STARTS HERE SDL_LockSurface( pScreen ); pRoot->Render(); SDL_UnlockSurface( pScreen ); // DRAWING ENDS HERE // finally, update the screen :) SDL_UpdateRects( pScreen, nDirtyRects, dirtyRects); // Pause for a while SDL_Delay(10); } // end main loop WgBase::Exit(); IMG_Quit(); return 0; }
WgSize WgMenubar::PreferredSize() const { //TODO: Implement! return WgSize(200,20); }