Beispiel #1
0
//------------------------------------------------------------------------------
void CNetscapeStatusBar::SetPercentDone(const int32 nPercent)
{
	// Destroying the context in response to the window being destroyed
	// sometimes calls this, so we need to check that the window
	// still exists or we die.

	if (!m_hWnd)
		return;

	if( m_nDone != nPercent )
    {
        if( m_iAnimRef && (nPercent == 0) )
        {
            m_nDone = -1;
        }
        else
        {
    		m_nDone = nPercent;
        }
        
		DrawProgressBar();
        
        if( m_nDone >= 100 )
        {
            //
            // Ensure progress never sits on 100% i.e., the back end might never
            // reset progress to 0 after specifying 100. 
            //
            m_nDone = m_iAnimRef ? -1 : 0;
            DrawProgressBar();            
        }
	}
}
Beispiel #2
0
void CHud::DrawDamageBar(LPDIRECT3DDEVICE9 pd3dDevice, const SPlayer* player, int x, int y, int segmentWidth){
	float dmg = player->fCurrDamage;
	int width = segmentWidth * 3 / 4;
	std::stringstream ss;

	if (player->nLives > 0){
		int div = (int) dmg / 100;
		for (int k = max(0,div-1); k <= div; k++){
			dmg = player->fCurrDamage - 100.f * k;
			bool bDrawBack = (div == 0);
			DrawProgressBar(pd3dDevice, x, y, 16, width, 
				min(dmg, 100.f) / 100.f,  // percent
				SColor(153,max(0,255 - (51 * k)),0), //color 
				bDrawBack);
		}
		ss << (int) player->fCurrDamage << "%";
	}
	else { // Dead
		DrawProgressBar(pd3dDevice, x, y, 16, width, 
			1.f,  // percent
			SColor(103, 103, 103), //color (gray) 
			true);
		ss << "DEAD";
	}

	// Write health amount over bar
	DrawHUDText(m_BigFont, ss.str().c_str(), x, y - 12,
		42, width, DT_CENTER | DT_VCENTER, SColor(255,255,255));
}
Beispiel #3
0
// Window proc for gauge
LRESULT APIENTRY
GaugeWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	DWORD	dwStyle;
	RECT	rect;

	switch (msg) {
		case WM_NCCREATE:
			dwStyle = GetWindowLong(hWnd, GWL_STYLE);
			SetWindowLong(hWnd, GWL_STYLE, dwStyle | WS_BORDER);
			return TRUE;

		case WM_CREATE:
			// Figure out the maximum number of bars that can be displayed
			GetClientRect(hWnd, &rect);
			dlgInfo.nBars = 0;
			dlgInfo.nMaxBars = (rect.right - rect.left - 2 * BAR_MARGIN + BAR_SPACING) /
				(BAR_WIDTH + BAR_SPACING);

			// Size the gauge to exactly fit the maximum number of bars
			SizeToFitGauge(hWnd);
			return TRUE;

		case WM_NCPAINT:
			DrawGaugeBorder(hWnd);
			return TRUE;

		case WM_PAINT:
			DrawProgressBar(hWnd);
			return TRUE;
	}

	return DefWindowProc(hWnd, msg, wParam, lParam);
}
void UpdateVolumeBar(char vol, char old_vol){

  //Use the progressbar element to show the volume
  ProgressBar1.Position = vol;
  DrawProgressBar(&ProgressBar1);
  
}
Beispiel #5
0
void CHud::DrawMyPlayerInfo(LPDIRECT3DDEVICE9 pd3dDevice){
	int segmentWidth = m_nWidth / 2;
	int segmentHeight = m_nHeight / 5;

	// Draw Damage Bar
	DrawDamageBar(pd3dDevice, pMyPlayer, 
		m_nX + segmentWidth / 8,	// x
		segmentHeight / 4,			// y
		segmentWidth);				// width

	// Draw Charge Bar
	std::stringstream ss;
	ss << "Charge";
	DrawProgressBar(pd3dDevice, 
		m_nX + segmentWidth / 8, segmentHeight / 2, 
		16, segmentWidth * 3 / 4, pMyPlayer->fCurrCharge / pMyPlayer->fMaxCharge, SColor(0,0,255) , true);
	DrawHUDText(m_BigFont, ss.str().c_str(), 
		m_nX + segmentWidth / 8, (segmentHeight / 2) - 12, 
		42, segmentWidth * 3 / 4, DT_CENTER | DT_VCENTER, SColor(255,255,255));

	// Draw Lives
	DrawLiveIcons(pMyPlayer->nLives,
		m_nX + (segmentWidth / 8),	// x
		m_nY + segmentHeight * 3 / 4,		// y
		segmentWidth);
}
Beispiel #6
0
//------------------------------------------------------------------------------
void CNetscapeStatusBar::OnPaint()
{
#if defined(MSVC4)
	CStatusBar::OnPaint();
	CClientDC dc(this);
#else
	CPaintDC dc(this);
	// Do not call CStatusBar::OnPaint()!
    CNetscapeStatusBarBase::DoPaint( &dc );
#endif	// MSVC4

    //
    // Special per mode painting
    //
    switch( m_enStatBarMode )
    {
        case eSBM_Panes:
        {
           // Nothing to do
            break;
        }
        
        case eSBM_Simple:
        default:
        {
           // Nothing to do
           break;
        }
    }
    
    DrawSecureStatus(dc.m_hDC);
	DrawSignedStatus(dc.m_hDC);
   	DrawProgressBar();
}
Beispiel #7
0
// Window proc for Download gauge
BOOL CALLBACK
GaugeDownloadWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	DWORD	dwStyle;
	RECT	rect;

	switch(msg)
  {
		case WM_NCCREATE:
			dwStyle = GetWindowLong(hWnd, GWL_STYLE);
			SetWindowLong(hWnd, GWL_STYLE, dwStyle | WS_BORDER);
			return(TRUE);

		case WM_CREATE:
			// Figure out the maximum number of bars that can be displayed
			GetClientRect(hWnd, &rect);
			dlgInfo.nFileBars = 0;
			dlgInfo.nMaxFileBars = (rect.right - rect.left - 2 * BAR_LIBXPNET_MARGIN + BAR_LIBXPNET_SPACING) / (BAR_LIBXPNET_WIDTH + BAR_LIBXPNET_SPACING);

			// Size the gauge to exactly fit the maximum number of bars
			SizeToFitGauge(hWnd, dlgInfo.nMaxFileBars);
			return(FALSE);

		case WM_NCPAINT:
			DrawGaugeBorder(hWnd);
			return(FALSE);

		case WM_PAINT:
			DrawProgressBar(hWnd, dlgInfo.nFileBars);
			return(FALSE);
	}

	return(DefWindowProc(hWnd, msg, wParam, lParam));
}
Beispiel #8
0
// Processes a sound file to include the response in the recorder
// track. The response is interpolated with another response to
// suggest the perception of movement from one location to the other
RecorderTrack* RecorderTrack::Process(RecorderTrack* const other,
                                      SoundFile* const sound_file)
                                      const {
	RecorderTrack* result = new RecorderTrack();
	RecorderTrack& _result = *result;
	const RecorderTrack& _this = *this;
	const RecorderTrack& _other = *other;
	const unsigned int sound_length = sound_file->sample_length;
	const float flt_samples = 1.0f / (float) sound_length;
	const unsigned int len = (std::max)(
		real_length,other->real_length);
	const unsigned int first = (std::min)(
		first_sample,other->first_sample);
	for( unsigned int i = 0; i < sound_length; i ++ ) {
		const float i1 = i * flt_samples;
		const float i2 = 1.0f - i1;
		const float sfs = sound_file->data[i];
		int index = i + sound_file->offset + first;
		for ( unsigned int j = first; j < len; j ++ ) {
			const float p = i2 * _this[j] + i1 * _other[j];
			_result[index++] += sfs * p;
		}
		DrawProgressBar(i,sound_length);
	}
	return result;
}
Beispiel #9
0
void DrawRenderProgressBar()
{
    int rp = renderImage.GetNumRenderedPixels();
    int np = renderImage.GetWidth() * renderImage.GetHeight();
    if ( rp >= np ) return;
    float done = (float) rp / (float) np;
    DrawProgressBar(done);
}
Beispiel #10
0
VOID
ProgressSetStepCount(
    IN PPROGRESSBAR Bar,
    IN ULONG StepCount)
{
    Bar->CurrentStep = 0;
    Bar->StepCount = StepCount;

    Bar->Progress = 0;
    Bar->Pos = 0;

    DrawProgressBar(Bar);
}
Beispiel #11
0
void GlutDisplay()
{
    switch ( viewMode ) {
        case VIEWMODE_OPENGL:
            if ( dofImage ) {
                if ( dofDrawCount < MAX_DOF_DRAW ) {
                    DrawScene();
                    glReadPixels( 0, 0, camera.imgWidth, camera.imgHeight, GL_RGB, GL_UNSIGNED_BYTE, dofBuffer );
                    for ( int i=0; i<camera.imgWidth*camera.imgHeight; i++ ) {
                        dofImage[i] = (dofImage[i]*dofDrawCount + dofBuffer[i].ToColor())/(dofDrawCount+1);
                    }
                    dofDrawCount++;
                }
                glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
                glDrawPixels( camera.imgWidth, camera.imgHeight, GL_RGB, GL_FLOAT, dofImage );
                if ( dofDrawCount < MAX_DOF_DRAW ) {
                    DrawProgressBar(float(dofDrawCount)/MAX_DOF_DRAW);
                    glutPostRedisplay();
                }
            } else {
                DrawScene();
            }
            break;
        case VIEWMODE_IMAGE:
            glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
            glDrawPixels( renderImage.GetWidth(), renderImage.GetHeight(), GL_RGB, GL_UNSIGNED_BYTE, renderImage.GetPixels() );
            DrawRenderProgressBar();
            break;
        case VIEWMODE_Z:
            glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
            if ( ! renderImage.GetZBufferImage() ) renderImage.ComputeZBufferImage();
            glDrawPixels( renderImage.GetWidth(), renderImage.GetHeight(), GL_LUMINANCE, GL_UNSIGNED_BYTE, renderImage.GetZBufferImage() );
            break;
        case VIEWMODE_SAMPLECOUNT:
            glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
            if ( ! renderImage.GetSampleCountImage() ) renderImage.ComputeSampleCountImage();
            glDrawPixels( renderImage.GetWidth(), renderImage.GetHeight(), GL_LUMINANCE, GL_UNSIGNED_BYTE, renderImage.GetSampleCountImage() );
            break;
        case VIEWMODE_IRRADCOMP:
            glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
            if ( renderImage.GetIrradianceComputationImage() ) {
                glDrawPixels( renderImage.GetWidth(), renderImage.GetHeight(), GL_LUMINANCE, GL_UNSIGNED_BYTE, renderImage.GetIrradianceComputationImage() );
            }
            break;
    }
    
    glutSwapBuffers();
}
Beispiel #12
0
void CDownloadMonitorDlg::DoPaint(CDC& dc)
{
	CRect rc;

	m_wndProgress.GetWindowRect( &rc );
	ScreenToClient( &rc );

	DrawProgressBar( &dc, &rc );

	m_wndGraph.GetWindowRect( &rc );
	ScreenToClient( &rc );

	dc.Draw3dRect( &rc, 0, 0 );
	rc.DeflateRect( 1, 1 );

	m_pGraph->BufferedPaint( &dc, &rc );
}
Beispiel #13
0
// Processes a sound file to include the response in the recorder
// track. The response is not interpolated with a successive response
RecorderTrack* RecorderTrack::Process(SoundFile* const sound_file)
                                      const {
	RecorderTrack* result = new RecorderTrack();
	RecorderTrack& _result = *result;
	const RecorderTrack& _this = *this;
	const unsigned int len = this->real_length;
	const unsigned int sound_length = sound_file->sample_length;
	for ( unsigned int i = 0; i < sound_length; ++ i ) {
		const float sfs = sound_file->data[i];
		int index = i + sound_file->offset + first_sample;
		for ( unsigned int j = first_sample; j < len; ++ j ) {
			_result[index++] += sfs * _this[j];
		}
		DrawProgressBar(i,sound_length);
	}
	return result;
}
Beispiel #14
0
void ThemeManager::DrawListProgress(HDC hdc, const LPRECT rect,
                                    ListProgressType type) {
  auto& item = list_progress_[type];

  // Solid
  if (item.type == L"solid") {
    HBRUSH hbrSolid = CreateSolidBrush(item.value[0]);
    FillRect(hdc, rect, hbrSolid);
    DeleteObject(hbrSolid);

  // Gradient
  } else if (item.type == L"gradient") {
    GradientRect(hdc, rect, item.value[0], item.value[1], item.value[2] > 0);

  // Progress bar
  } else if (item.type == L"progress") {
    DrawProgressBar(hdc, rect, item.value[0], item.value[1], item.value[2]);
  }
}
Beispiel #15
0
// Checks if devices are available, prints name of device being detected for slow init devices
void populateDeviceAvailability() {
	if(PAD_ButtonsHeld(0) & PAD_BUTTON_B) {
		deviceHandler_setAllDevicesAvailable();
		return;
	}
	uiDrawObj_t *msgBox = DrawPublish(DrawProgressBar(true, 0, "Detecting devices ...\nThis can be skipped by holding B next time"));
	int i;
	for(i = 0; i < MAX_DEVICES; i++) {
		if(allDevices[i] != NULL && !deviceHandler_getDeviceAvailable(allDevices[i])) {
			print_gecko("Checking device availability for device %s\r\n", allDevices[i]->deviceName);
			deviceHandler_setDeviceAvailable(allDevices[i], allDevices[i]->test());
		}
		if(PAD_ButtonsHeld(0) & PAD_BUTTON_B) {
			deviceHandler_setAllDevicesAvailable();
			break;
		}
	}
	DrawDispose(msgBox);
}
Beispiel #16
0
void CSListCtrl::DrawItem(int nItem, int nSubItem, CDC* pDC)
{
	//Color
	COLORREF crText  = m_crWindowText;
	COLORREF crBkgnd = m_crWindow;
	GetDrawColors(nItem, nSubItem, crText, crBkgnd);
	
	//Rectangle
	CRect rect;
	GetSubItemRect(nItem, nSubItem, LVIR_BOUNDS, rect);

	//Paint background
	CRect rcTemp = rect;
	rcTemp.bottom -= 1;
	pDC->FillSolidRect(&rcTemp, crBkgnd);

	//Sub Item data
	CListSubItemData* pSubItemData = GetSubItemData(nItem, nSubItem);
	ASSERT(pSubItemData);

	//1. Draw Check Box
	if(pSubItemData->m_nCheckState != SHC_NONE_CHECK_BOX)
	{
		DrawCheckBox(nItem, nSubItem, pDC);
	}

	//2. Draw Image
	if(pSubItemData->m_pListImage != NULL)
	{
		DrawImage(nItem, nSubItem, pDC);
	}

	//3. Draw Text or Progress
	if(pSubItemData->m_pListPrgsBar != NULL)
	{
		DrawProgressBar(nItem, nSubItem, pDC);
	}
	else
	{
		DrawText(nItem, nSubItem, pDC);
	}	
}
Beispiel #17
0
int HUD_Redraw( float flTime, int state )
{
	switch( state )
	{
	case CL_LOADING:
		DrawProgressBar();
		break;
	case CL_ACTIVE:
		gHUD.Redraw( flTime );
		break;
	case CL_PAUSED:
		gHUD.Redraw( flTime );
		DrawPause();
		break;
	case CL_CHANGELEVEL:
		DrawImageBar( 100, "m_loading" );
		break;
	}
	return 1;
}
void CStatusLineCtrl::OnPaint(wxPaintEvent&)
{
	wxPaintDC dc(this);

	wxRect rect = GetRect();

	int refresh = 0;
	if (!m_data.IsOk() || rect.GetWidth() != m_data.GetWidth() || rect.GetHeight() != m_data.GetHeight()) {
		m_mdc.reset();
		m_data = wxBitmap(rect.GetWidth(), rect.GetHeight());
		m_mdc = std::make_unique<wxMemoryDC>(m_data);
		// Use same layout direction as the DC which bitmap is drawn on.
		// This avoids problem with mirrored characters on RTL locales.
		m_mdc->SetLayoutDirection(dc.GetLayoutDirection());
		refresh = 31;
	}

	fz::duration elapsed;
	int left = -1;
	wxFileOffset rate;
	wxString bytes_and_rate;
	int bar_split = -1;
	int permill = -1;

	if (status_.empty()) {
		if (m_previousStatusText != m_statusText) {
			// Clear background
			m_mdc->SetFont(GetFont());
			m_mdc->SetPen(GetBackgroundColour());
			m_mdc->SetBrush(GetBackgroundColour());
			m_mdc->SetTextForeground(GetForegroundColour());
			m_mdc->DrawRectangle(0, 0, rect.GetWidth(), rect.GetHeight());
			wxCoord h = (rect.GetHeight() - m_textHeight) / 2;
			m_mdc->DrawText(m_statusText, 50, h);
			m_previousStatusText = m_statusText;
			refresh = 0;
		}
	}
	else {
		if (!m_previousStatusText.empty()) {
			m_previousStatusText.clear();
			refresh = 31;
		}

		int elapsed_milli_seconds = 0;
		if (!status_.started.empty()) {
			elapsed = fz::datetime::now() - status_.started;
			elapsed_milli_seconds = static_cast<int>(elapsed.get_milliseconds()); // Assume it doesn't overflow
		}

		if (elapsed_milli_seconds / 1000 != m_last_elapsed_seconds) {
			refresh |= 1;
			m_last_elapsed_seconds = elapsed_milli_seconds / 1000;
		}

		if (COptions::Get()->GetOptionVal(OPTION_SPEED_DISPLAY))
			rate = GetMomentarySpeed();
		else
			rate = GetAverageSpeed(elapsed_milli_seconds);

		if (status_.totalSize > 0 && elapsed_milli_seconds >= 1000 && rate > 0) {
			wxFileOffset r = status_.totalSize - status_.currentOffset;
			left = r / rate + 1;
			if (r)
				++left;

			if (left < 0)
				left = 0;
		}

		if (m_last_left != left) {
			refresh |= 2;
			m_last_left = left;
		}

		const wxString bytestr = CSizeFormat::Format(status_.currentOffset, true, CSizeFormat::bytes, COptions::Get()->GetOptionVal(OPTION_SIZE_USETHOUSANDSEP) != 0, 0);
		if (elapsed_milli_seconds >= 1000 && rate > -1) {
			CSizeFormat::_format format = static_cast<CSizeFormat::_format>(COptions::Get()->GetOptionVal(OPTION_SIZE_FORMAT));
			if (format == CSizeFormat::bytes)
				format = CSizeFormat::iec;
			const wxString ratestr = CSizeFormat::Format(rate, true,
														 format,
														 COptions::Get()->GetOptionVal(OPTION_SIZE_USETHOUSANDSEP) != 0,
														 COptions::Get()->GetOptionVal(OPTION_SIZE_DECIMALPLACES));
			bytes_and_rate.Printf(_("%s (%s/s)"), bytestr, ratestr );
		}
		else
			bytes_and_rate.Printf(_("%s (? B/s)"), bytestr);

		if (m_last_bytes_and_rate != bytes_and_rate) {
			refresh |= 8;
			m_last_bytes_and_rate = bytes_and_rate;
		}

		if (status_.totalSize > 0) {
			bar_split = static_cast<int>(status_.currentOffset * (PROGRESSBAR_WIDTH - 2) / status_.totalSize);
			if (bar_split > (PROGRESSBAR_WIDTH - 2))
				bar_split = PROGRESSBAR_WIDTH - 2;

			if (status_.currentOffset > status_.totalSize)
				permill = 1001;
			else
				permill = static_cast<int>(status_.currentOffset * 1000 / status_.totalSize);
		}

		if (m_last_bar_split != bar_split || m_last_permill != permill) {
			refresh |= 4;
			m_last_bar_split = bar_split;
			m_last_permill = permill;
		}
	}

	if (refresh) {
		m_mdc->SetFont(GetFont());
		m_mdc->SetPen(GetBackgroundColour());
		m_mdc->SetBrush(GetBackgroundColour());
		m_mdc->SetTextForeground(GetForegroundColour());

		// Get character height so that we can center the text vertically.
		wxCoord h = (rect.GetHeight() - m_textHeight) / 2;

		if (refresh & 1) {
			m_mdc->DrawRectangle(0, 0, m_fieldOffsets[0], rect.GetHeight());
			DrawRightAlignedText(*m_mdc, wxTimeSpan::Milliseconds(elapsed.get_milliseconds()).Format(_("%H:%M:%S elapsed")), m_fieldOffsets[0], h);
		}
		if (refresh & 2) {
			m_mdc->DrawRectangle(m_fieldOffsets[0], 0, m_fieldOffsets[1] - m_fieldOffsets[0], rect.GetHeight());
			if (left != -1) {
				wxTimeSpan timeLeft(0, 0, left);
				DrawRightAlignedText(*m_mdc, timeLeft.Format(_("%H:%M:%S left")), m_fieldOffsets[1], h);
			}
			else
				DrawRightAlignedText(*m_mdc, _("--:--:-- left"), m_fieldOffsets[1], h);
		}
		if (refresh & 8) {
			m_mdc->DrawRectangle(m_fieldOffsets[3], 0, rect.GetWidth() - m_fieldOffsets[3], rect.GetHeight());
			m_mdc->DrawText(bytes_and_rate, m_fieldOffsets[3], h);
		}
		if (refresh & 16) {
			m_mdc->DrawRectangle(m_fieldOffsets[1], 0, m_fieldOffsets[2] - m_fieldOffsets[1], rect.GetHeight());
		}
		if (refresh & 4) {
			m_mdc->DrawRectangle(m_fieldOffsets[2], 0, m_fieldOffsets[3] - m_fieldOffsets[2], rect.GetHeight());
			if (bar_split != -1)
				DrawProgressBar(*m_mdc, m_fieldOffsets[2], 1, rect.GetHeight() - 2, bar_split, permill);
		}
	}
	dc.Blit(0, 0, rect.GetWidth(), rect.GetHeight(), m_mdc.get(), 0, 0);
}
Beispiel #19
0
void pawsProgressBar::Draw()
{
    ClipToParent(false);

    int alpha = 255;
    int Time  = csGetTicks();
    int primary_r;
    int primary_g;
    int primary_b;

    if(parent && !parent->GetBackground().IsEmpty() && parent->isFadeEnabled() && parent->GetMaxAlpha() != parent->GetMinAlpha())
    {
        alpha = (int) (255 - (parent->GetMinAlpha() + (parent->GetMaxAlpha()-parent->GetMinAlpha()) * parent->GetFadeVal() * 0.010));
    }
    DrawBackground();
    if( flashLevel > 0 )
    {
        if( ( (flashLow && percent<flashLevel) || (!flashLow && percent>flashLevel) ) )
        {
            if( flashLastTime+flashRate <= Time )
            {
                On=!On;
                flashLastTime = Time;
            }
        }
        else
        {
            On=true;
        }
    }
    if( warnLevel > 0 && ( (warnLow && percent < warnLevel) || (!warnLow && percent >warnLevel) ) )
    {
        if( dangerLevel > 0 && ( (dangerLow && percent < dangerLevel) || (!dangerLow && percent >dangerLevel) ) )
        {
            primary_r = danger_r;
            primary_g = danger_g;
            primary_b = danger_b;
        }
        else
        {
            primary_r = warn_r;
            primary_g = warn_g;
            primary_b = warn_b;
        }
    }
    else
    {
        primary_r = start_r;
        primary_g = start_g;
        primary_b = start_b;
    }
    if( On )
    {
        DrawProgressBar(screenFrame, PawsManager::GetSingleton().GetGraphics3D(), percent,
                        primary_r, primary_g, primary_b,
                        diff_r,  diff_g,  diff_b, alpha);
    }
    else
    {
        DrawProgressBar(screenFrame, PawsManager::GetSingleton().GetGraphics3D(), percent,
                        flash_r, flash_g, flash_b,
                        flash_r, flash_g, flash_b, alpha);
    }
    DrawChildren();
    DrawMask();
}
Beispiel #20
0
int patch_gcm(file_handle *file, ExecutableFile *filesToPatch, int numToPatch, int multiDol) {
	int i, num_patched = 0;
	
	// If the current device isn't SD Gecko, init SD Gecko Slot A or B to write patches.
	if(deviceHandler_initial != &initial_SD0 && deviceHandler_initial != &initial_SD1) {
		deviceHandler_setStatEnabled(0);
		if(deviceHandler_FAT_init(&initial_SD0)) {
			savePatchDevice = 0;
		}
		else if(deviceHandler_FAT_init(&initial_SD1)) {
			savePatchDevice = 1;
		}
		deviceHandler_setStatEnabled(1);
	}
	// Already using SD Gecko
	if(deviceHandler_initial == &initial_SD0)
		savePatchDevice = 0;
	else if(deviceHandler_initial == &initial_SD1)
		savePatchDevice = 1;
		
	if(savePatchDevice == -1) {
		DrawFrameStart();
		DrawMessageBox(D_FAIL, "No writable device present\nA SD Gecko must be inserted in\n order to utilise patches for this game.");
		DrawFrameFinish();
		sleep(5);
		return 0;
	}

	char patchFileName[256];
	char patchDirName[256];
	char patchBaseDirName[256];
	char gameID[8];
	memset(&gameID, 0, 8);
	memset(&patchDirName, 0, 256);
	memset(&patchBaseDirName, 0, 256);
	strncpy((char*)&gameID, (char*)&GCMDisk, 4);
	sprintf(&patchDirName[0],"%s:/swiss_patches/%s",(savePatchDevice ? "sdb":"sda"), &gameID[0]);
	sprintf(&patchBaseDirName[0],"%s:/swiss_patches",(savePatchDevice ? "sdb":"sda"));
	print_gecko("Patch dir will be: %s if required\r\n", patchDirName);
	*(u32*)VAR_EXECD_OFFSET = 0xFFFFFFFF;
	// Go through all the possible files we think need patching..
	for(i = 0; i < numToPatch; i++) {
		u32 patched = 0, crc32 = 0;

		sprintf(txtbuffer, "Patching File %i/%i",i+1,numToPatch);
		DrawFrameStart();
		DrawProgressBar((int)(((float)(i+1)/(float)numToPatch)*100), txtbuffer);
		DrawFrameFinish();
			
		// Round up to 32 bytes
		if(filesToPatch[i].size % 0x20) {
			filesToPatch[i].size += (0x20-(filesToPatch[i].size%0x20));
		}
		
		if(filesToPatch[i].size > 8*1024*1024) {
			print_gecko("Skipping %s %iKB too large\r\n", filesToPatch[i].name, filesToPatch[i].size/1024);
			continue;
		}
		print_gecko("Checking %s %iKb\r\n", filesToPatch[i].name, filesToPatch[i].size/1024);
		if(strstr(filesToPatch[i].name, "execD.")) {
			*(u32*)VAR_EXECD_OFFSET = filesToPatch[i].offset;
		}
		if(strstr(filesToPatch[i].name, "iwanagaD.dol") || strstr(filesToPatch[i].name, "switcherD.dol")) {
			continue;	// skip unused PSO files
		}
		int sizeToRead = filesToPatch[i].size;
		u8 *buffer = (u8*)memalign(32, sizeToRead);
		
		deviceHandler_seekFile(file,filesToPatch[i].offset, DEVICE_HANDLER_SEEK_SET);
		if(deviceHandler_readFile(file,buffer,sizeToRead)!= sizeToRead) {
			DrawFrameStart();
			DrawMessageBox(D_FAIL, "Failed to read!");
			DrawFrameFinish();
			sleep(5);
			return 0;
		}
		
		if(curDevice != DVD_DISC) {
			u32 ret = Patch_DVDLowLevelRead(buffer, sizeToRead, filesToPatch[i].type);
			if(READ_PATCHED_ALL != ret)	{
				DrawFrameStart();
				DrawMessageBox(D_FAIL, "Failed to find necessary functions for patching!");
				DrawFrameFinish();
				sleep(5);
			}
			else
				patched += 1;
		}
				
		if(swissSettings.debugUSB && usb_isgeckoalive(1) && !swissSettings.wiirdDebug) {
			patched += Patch_Fwrite(buffer, sizeToRead);
		}
		
		if(swissSettings.wiirdDebug || getEnabledCheatsSize() > 0) {
			Patch_CheatsHook(buffer, sizeToRead, filesToPatch[i].type);
		}
		
		if(curDevice == DVD_DISC && is_gamecube()) {
			patched += Patch_DVDLowLevelReadForDVD(buffer, sizeToRead, filesToPatch[i].type);
			patched += Patch_DVDReset(buffer, sizeToRead);
		}
		
		patched += Patch_VidMode(buffer, sizeToRead, filesToPatch[i].type);
		patched += Patch_FontEnc(buffer, sizeToRead);
		if(swissSettings.forceWidescreen)
			Patch_WideAspect(buffer, sizeToRead, filesToPatch[i].type);
		if(swissSettings.forceAnisotropy)
			Patch_TexFilt(buffer, sizeToRead, filesToPatch[i].type);
		if(patched) {
			// File handle for a patch we might need to write
			FILE *patchFile = 0;
			memset(patchFileName, 0, 256);
		
			// Make a base patches dir if we don't have one already
			if(mkdir(&patchBaseDirName[0], 0777) != 0) {
				if(errno != EEXIST) {
					return -2;
				}
			}
			if(mkdir(&patchDirName[0], 0777) != 0) {
				if(errno != EEXIST) {
					return -2;
				}
			}
			sprintf(patchFileName, "%s/%i",patchDirName, num_patched);

			// Work out the crc32
			crc32 = Crc32_ComputeBuf( 0, buffer, (u32) sizeToRead);

			// See if this file already exists, if it does, match crc
			patchFile = fopen( patchFileName, "rb" );
			if(patchFile) {
				//print_gecko("Old Patch exists\r\n");
				u32 oldCrc32 = 0;
				fseek(patchFile, 0L, SEEK_END);
				u32 file_size = ftell(patchFile);
				fseek(patchFile, file_size-4, SEEK_SET);
				fread(&oldCrc32, 1, 4, patchFile);
				if(oldCrc32 == crc32) {
					num_patched++;
					fclose(patchFile);
					free(buffer);
					print_gecko("CRC matched, no need to patch again\r\n");
					continue;
				}
				else {
					remove(patchFileName);
					fclose(patchFile);
					print_gecko("CRC mismatch, writing patch again\r\n");
				}
			}
			// Otherwise, write a file out for this game with the patched buffer inside.
			print_gecko("Writing patch file: %s %i bytes (disc offset %08X)\r\n", patchFileName, sizeToRead, filesToPatch[i].offset);
			patchFile = fopen(patchFileName, "wb");
			fwrite(buffer, 1, sizeToRead, patchFile);
			u32 magic = SWISS_MAGIC;
			fwrite(&filesToPatch[i].offset, 1, 4, patchFile);
			fwrite(&filesToPatch[i].size, 1, 4, patchFile);
			fwrite(&magic, 1, 4, patchFile);
			fwrite(&crc32, 1, 4, patchFile);
			fclose(patchFile);
			num_patched++;
		}
		free(buffer);
	}

	return num_patched;
}
Beispiel #21
0
/****************************************************************************
* Main
****************************************************************************/
int main () 
{
	// Setup defaults (if no config is found)
	memset(&swissSettings, 0 , sizeof(SwissSettings));

	// Register all devices supported (order matters for boot devices)
	int i = 0;
	for(i = 0; i < MAX_DEVICES; i++)
		allDevices[i] = NULL;
	i = 0;
	allDevices[i++] = &__device_wkf;
	allDevices[i++] = &__device_wode;
	allDevices[i++] = &__device_sd_a;
	allDevices[i++] = &__device_sd_b;
	allDevices[i++] = &__device_card_a;
	allDevices[i++] = &__device_card_b;
	allDevices[i++] = &__device_dvd;
	allDevices[i++] = &__device_ide_a;
	allDevices[i++] = &__device_ide_b;
	allDevices[i++] = &__device_qoob;
	allDevices[i++] = &__device_smb;
	allDevices[i++] = &__device_sys;
	allDevices[i++] = &__device_usbgecko;
	allDevices[i++] = &__device_ftp;
	allDevices[i++] = &__device_fsp;
	allDevices[i++] = NULL;
	
	// Set current devices
	devices[DEVICE_CUR] = NULL;
	devices[DEVICE_DEST] = NULL;
	devices[DEVICE_TEMP] = NULL;
	devices[DEVICE_CONFIG] = NULL;
	devices[DEVICE_PATCHES] = NULL;
	
	Initialise();
	
	// Sane defaults
	refreshSRAM(&swissSettings);
	swissSettings.debugUSB = 0;
	swissSettings.gameVMode = 0;	// Auto video mode
	swissSettings.exiSpeed = 1;		// 32MHz
	swissSettings.uiVMode = 0; 		// Auto UI mode
	swissSettings.aveCompat = 1;
	swissSettings.enableFileManagement = 0;

	needsDeviceChange = 1;
	needsRefresh = 1;
	
	//debugging stuff
	if(swissSettings.debugUSB) {
		if(usb_isgeckoalive(1)) {
			usb_flush(1);
		}
		print_gecko("Arena Size: %iKb\r\n",(SYS_GetArena1Hi()-SYS_GetArena1Lo())/1024);
		print_gecko("DVD Drive Present? %s\r\n",swissSettings.hasDVDDrive?"Yes":"No");
		print_gecko("GIT Commit: %s\r\n", GITREVISION);
		print_gecko("GIT Revision: %s\r\n", GITVERSION);
	}
	
	// Go through all devices with FEAT_BOOT_DEVICE feature and set it as current if one is available
	for(i = 0; i < MAX_DEVICES; i++) {
		if(allDevices[i] != NULL && (allDevices[i]->features & FEAT_BOOT_DEVICE)) {
			print_gecko("Testing device %s\r\n", allDevices[i]->deviceName);
			if(allDevices[i]->test()) {
				deviceHandler_setDeviceAvailable(allDevices[i], true);
				devices[DEVICE_CUR] = allDevices[i];
				break;
			}
		}
	}
	if(devices[DEVICE_CUR] != NULL) {
		print_gecko("Detected %s\r\n", devices[DEVICE_CUR]->deviceName);
		if(devices[DEVICE_CUR]->init(devices[DEVICE_CUR]->initial)) {
			if(devices[DEVICE_CUR]->features & FEAT_AUTOLOAD_DOL) {
				load_auto_dol();
			}
			memcpy(&curFile, devices[DEVICE_CUR]->initial, sizeof(file_handle));
			needsDeviceChange = 0;
		}
	}

	// Scan here since some devices would already be initialised (faster)
	populateDeviceAvailability();

	// If there's no default config device, set it to the first writable device available
	if(swissSettings.configDeviceId == DEVICE_ID_UNK) {
		for(int i = 0; i < MAX_DEVICES; i++) {
			if(allDevices[i] != NULL && (allDevices[i]->features & FEAT_WRITE) && deviceHandler_getDeviceAvailable(allDevices[i])) {
				swissSettings.configDeviceId = allDevices[i]->deviceUniqueId;
				print_gecko("No default config device found, using [%s]\r\n", allDevices[i]->deviceName);
				syssramex* sramex = __SYS_LockSramEx();
				sramex->__padding0 = swissSettings.configDeviceId;
				__SYS_UnlockSramEx(1);
				while(!__SYS_SyncSram());
				break;
			}
		}
	}
	
	// Try to open up the config .ini in case it hasn't been opened already
	if(config_init()) {
		// TODO notification area this
		print_gecko("Loaded %i entries from the config file\r\n",config_get_count());
	}
	
	if(swissSettings.initNetworkAtStart) {
		// Start up the BBA if it exists
		uiDrawObj_t *msgBox = DrawPublish(DrawProgressBar(true, 0, "Initialising Network"));
		init_network();
		init_httpd_thread();
		DrawDispose(msgBox);
	}
	
	// DVD Motor off setting; Always stop the drive if we only started it to read the ID out
	if((swissSettings.stopMotor && swissSettings.hasDVDDrive) || (swissSettings.hasDVDDrive == 2)) {
		dvd_motor_off();
	}

	// Swiss video mode force
	GXRModeObj *forcedMode = getVideoModeFromSwissSetting(swissSettings.uiVMode);
	
	if((forcedMode != NULL) && (forcedMode != getVideoMode())) {
		setVideoMode(forcedMode);
	}

	while(1) {
		menu_loop();
	}
	return 0;
}
Beispiel #22
0
void CUploadTipCtrl::OnPaint(CDC* pDC, CUploadTransfer* pUpload)
{
	CPoint pt( 0, 0 );
	CSize sz( m_sz.cx, TIP_TEXTHEIGHT );

	DrawText( pDC, &pt, m_pUploadFile->m_sName );
	pt.y += TIP_TEXTHEIGHT;
	DrawText( pDC, &pt, m_sAddress );
	pDC->SelectObject( &CoolInterface.m_fntNormal );
	pt.y += TIP_TEXTHEIGHT;

	int nFlagIndex = Flags.GetFlagIndex( pUpload->m_sCountry );
	if ( nFlagIndex >= 0 )
	{
		Flags.Draw( nFlagIndex, pDC->GetSafeHdc(), pt.x, pt.y, CoolInterface.m_crTipBack );
		pDC->ExcludeClipRect( pt.x, pt.y, pt.x + 16, pt.y + 16 );
	}
	pt.x += 16 + 4;
	DrawText( pDC, &pt, pUpload->m_sCountryName );
	pt.x -= 16 + 4;
	pt.y += 16;

	DrawRule( pDC, &pt );

	CString strStatus, strSpeed, strText;
	CString strOf;
	LoadString( strOf, IDS_GENERAL_OF );

	strSpeed.Format( _T("%s %s %s (%s)"),
		(LPCTSTR)Settings.SmartSpeed( pUpload->GetMeasuredSpeed() ),
		(LPCTSTR)strOf,
		(LPCTSTR)Settings.SmartSpeed( pUpload->m_nBandwidth ),
		(LPCTSTR)Settings.SmartSpeed( pUpload->GetMaxSpeed() ) );

	int nQueue = UploadQueues.GetPosition( pUpload, FALSE );
	if ( m_pUploadFile != pUpload->m_pBaseFile || pUpload->m_nState == upsNull )
	{
		LoadString( strStatus, IDS_TIP_INACTIVE );
	}
	else if ( nQueue == 0 )
	{
		if ( pUpload->m_nState == upsQueued )
		{
			LoadString( strText, IDS_TIP_NEXT );
			strStatus.Format( _T("%s: %s"),
				(LPCTSTR)pUpload->m_pQueue->m_sName, (LPCTSTR)strText );
		}
		else
		{
			LoadString( strText, IDS_TIP_ACTIVE );
			strStatus.Format( _T("%s: %s"),
				(LPCTSTR)pUpload->m_pQueue->m_sName, (LPCTSTR)strText );
		}
	}
	else if ( nQueue > 0 )
	{
		strStatus.Format( _T("%s: %i %s %u"),
			(LPCTSTR)pUpload->m_pQueue->m_sName,
			nQueue, (LPCTSTR)strOf, pUpload->m_pQueue->GetQueuedCount() );
	}
	else
	{
		LoadString( strStatus, IDS_TIP_ACTIVE );
	}

	LoadString( strText, IDS_TIP_STATUS );
	DrawText( pDC, &pt, strText );
	DrawText( pDC, &pt, strStatus, 80 );
	pt.y += TIP_TEXTHEIGHT;

	LoadString( strText, IDS_TIP_SPEED );
	DrawText( pDC, &pt, strText );
	DrawText( pDC, &pt, strSpeed, 80 );
	pt.y += TIP_TEXTHEIGHT;

	LoadString( strText, IDS_TIP_USERAGENT );
	DrawText( pDC, &pt, strText );
	DrawText( pDC, &pt, pUpload->m_sUserAgent, 80 );
	pt.y += TIP_TEXTHEIGHT;

	pt.y += TIP_GAP;

	DrawProgressBar( pDC, &pt, m_pUploadFile );
	pt.y += TIP_GAP;

	CRect rc( pt.x, pt.y, m_sz.cx, pt.y + 40 );
	pDC->Draw3dRect( &rc, CoolInterface.m_crTipBorder, CoolInterface.m_crTipBorder );
	rc.DeflateRect( 1, 1 );
	if ( m_pGraph)
		m_pGraph->BufferedPaint( pDC, &rc );
	rc.InflateRect( 1, 1 );
	pDC->ExcludeClipRect( &rc );
	pt.y += 40;
	pt.y += TIP_GAP;

	if ( Settings.General.GUIMode != GUI_BASIC )
	{
		if ( m_nHeaders != pUpload->m_pHeaderName.GetSize() )
		{
			ShowImpl( true );
			return;
		}
		for ( int nHeader = 0 ; nHeader < m_nHeaders ; nHeader++ )
		{
			CString strName = pUpload->m_pHeaderName.GetAt( nHeader ) + _T(':');
			CString strValue = pUpload->m_pHeaderValue.GetAt( nHeader );
			DrawText( pDC, &pt, strName );
			pt.x += m_nHeaderWidth;
			sz.cx -= m_nHeaderWidth;
			DrawText( pDC, &pt, strValue, &sz );
			pt.x -= m_nHeaderWidth;
			sz.cx += m_nHeaderWidth;
			pt.y += TIP_TEXTHEIGHT;
		}
	}
}
Beispiel #23
0
/* Initialise Video, PAD, DVD, Font */
void Initialise (void)
{
	VIDEO_Init ();
	PAD_Init ();  
	DVD_Init(); 
	*(volatile unsigned long*)0xcc00643c = 0x00000000; //allow 32mhz exi bus
	
	// Disable IPL modchips to allow access to IPL ROM fonts
	ipl_set_config(6); 
	usleep(1000); //wait for modchip to disable (overkill)
	
	
	__SYS_ReadROM(IPLInfo,256,0);	// Read IPL tag

	// By default, let libOGC figure out the video mode
	GXRModeObj *vmode = VIDEO_GetPreferredMode(NULL); //Last mode used
	if(is_gamecube()) {	// Gamecube, determine based on IPL
		int retPAD = 0, retCnt = 10000;
		while(retPAD <= 0 && retCnt >= 0) { retPAD = PAD_ScanPads(); usleep(100); retCnt--; }
		// L Trigger held down ignores the fact that there's a component cable plugged in.
		if(VIDEO_HaveComponentCable() && !(PAD_ButtonsDown(0) & PAD_TRIGGER_L)) {
			if(strstr(IPLInfo,"MPAL")!=NULL) {
				swissSettings.sramVideo = 2;
				vmode = &TVMpal480Prog; //Progressive 480p
			}
			else if((strstr(IPLInfo,"PAL")!=NULL)) {
				swissSettings.sramVideo = 1;
				vmode = &TVPal576ProgScale; //Progressive 576p
			}
			else {
				swissSettings.sramVideo = 0;
				vmode = &TVNtsc480Prog; //Progressive 480p
			}
		}
		else {
			//try to use the IPL region
			if(strstr(IPLInfo,"MPAL")!=NULL) {
				swissSettings.sramVideo = 2;
				vmode = &TVMpal480IntDf;        //PAL-M
			}
			else if(strstr(IPLInfo,"PAL")!=NULL) {
				swissSettings.sramVideo = 1;
				vmode = &TVPal576IntDfScale;         //PAL
			}
			else {
				swissSettings.sramVideo = 0;
				vmode = &TVNtsc480IntDf;        //NTSC
			}
		}
	}
	setVideoMode(vmode);

	init_font();
	DrawInit();
	
	drive_version(&driveVersion[0]);
	swissSettings.hasDVDDrive = *(u32*)&driveVersion[0] ? 1 : 0;
	
	if(!driveVersion[0]) {
		// Reset DVD if there was a IPL replacement that hasn't done that for us yet
		uiDrawObj_t *progBox = DrawPublish(DrawProgressBar(true, 0, "Initialise DVD .. (HOLD B if NO DVD Drive)"));
		dvd_reset();	// low-level, basic
		dvd_read_id();
		if(!(PAD_ButtonsHeld(0) & PAD_BUTTON_B)) {
			dvd_set_streaming(*(char*)0x80000008);
		}
		drive_version(&driveVersion[0]);
		swissSettings.hasDVDDrive = *(u32*)&driveVersion[0] ? 2 : 0;
		if(!swissSettings.hasDVDDrive) {
			DrawDispose(progBox);
			progBox = DrawPublish(DrawMessageBox(D_INFO, "No DVD Drive Detected !!"));
			sleep(2);
		}
		DrawDispose(progBox);
	}
}
Beispiel #24
0
int main(int argc, char **argv)
{
	int i, j, k, treeNo, sumLength;
	char ch;
	TTree **treeSet;
	FILE *text_fv;
	clock_t totalStart;
	double totalSecs, scale, sum;
	char *ancestor;

	totalStart = clock();

	ReadParams(argc, argv);

	if (rateHetero == CodonRates && invariableSites) {
		fprintf(stderr, "Invariable sites model cannot be used with codon rate heterogeneity.\n");
		exit(4);
	}

	if (writeAncestors && fileFormat == NEXUSFormat) {
		fprintf(stderr, "Warning - When writing ancestral sequences, relaxed PHYLIP format is used.\n");
	}

	if (writeAncestors && maxPartitions > 1) {
		fprintf(stderr, "Writing ancestral sequences can only be used for a single partition.\n");
		exit(4);
	}
			
	if (!userSeed)
		randomSeed = CreateSeed();
		
	SetSeed(randomSeed);

	if (!quiet)
 		PrintTitle();
	
	numTrees = OpenTreeFile();

	/* if (!treeFile) { */
		ReadFileParams();
	/*} */


	if ((ancestorSeq>0 && !hasAlignment) || ancestorSeq>numSequences) {
		fprintf(stderr, "Bad ancestral sequence number: %d (%d sequences loaded)\n", ancestorSeq, numSequences);
		exit(4);
	}
	
	if (textFile) {
		if ( (text_fv=fopen(textFileName, "rt"))==NULL ) {
			fprintf(stderr, "Error opening text file for insertion into output: '%s'\n", textFileName);
			exit(4);
		}
	}

	ancestor=NULL;
	if (hasAlignment) {
		AllocateMemory();	
		ReadFile();
		
		if (numSites<0)
			numSites=numAlignmentSites;		
			
		if (ancestorSeq>0) {
			if (numSites!=numAlignmentSites) {
				fprintf(stderr, "Ancestral sequence is of a different length to the simulated sequences (%d)\n", numAlignmentSites);
				exit(4);
			}
			ancestor=sequences[ancestorSeq-1];
		}
	} else if (numSites<0)
		numSites=1000;
	
	SetModel(model);
	
	numTaxa=-1;
	scale=1.0;
	
	treeSet = (TTree **)malloc(sizeof(TTree **) * maxPartitions);
	if (treeSet==NULL) {
		fprintf(stderr, "Out of memory\n");
		exit(5);
	}
	
	partitionLengths = (int *)malloc(sizeof(int) * maxPartitions);
	if (partitionLengths==NULL) {
		fprintf(stderr, "Out of memory\n");
		exit(5);
	}
	
	partitionRates = (double *)malloc(sizeof(double) * maxPartitions);
	if (partitionRates==NULL) {
		fprintf(stderr, "Out of memory\n");
		exit(5);
	}
	
	for (i = 0; i < maxPartitions; i++) {
		if ((treeSet[i]=NewTree())==NULL) {
			fprintf(stderr, "Out of memory\n");
			exit(5);
		}
	}
					
	CreateRates();
	
	treeNo=0;
	do {
		partitionLengths[0] = -1;
		ReadTree(tree_fv, treeSet[0], treeNo+1, 0, NULL, &partitionLengths[0], &partitionRates[0]);

		if (treeNo==0) {
			numTaxa=treeSet[0]->numTips;
			
			if (!quiet)
				fprintf(stderr, "Random number generator seed: %ld\n\n", randomSeed);
				
			if (fileFormat == NEXUSFormat) {
				fprintf(stdout, "#NEXUS\n");
				fprintf(stdout, "[\nGenerated by %s %s\n\n", PROGRAM_NAME, VERSION_NUMBER);
				PrintVerbose(stdout);
				fprintf(stdout, "]\n\n");
			}
		} else if (treeSet[0]->numTips != numTaxa) {
			fprintf(stderr, "All trees must have the same number of tips.\n");
			exit(4);
		}
		
		if (maxPartitions == 1) {
			if (partitionLengths[0] != -1) {
				fprintf(stderr, "\nWARNING: The treefile contained partion lengths but only one partition\n");
				fprintf(stderr, "was specified.\n");
			}
			partitionLengths[0] = numSites;
		}

		sumLength = partitionLengths[0];
		i = 1;
		while (sumLength < numSites && i <= maxPartitions) {
			if (!IsTreeAvail(tree_fv)) {
				fprintf(stderr, "\nA set of trees number %d had less partition length (%d) than\n", treeNo + 1, sumLength);
				fprintf(stderr, "was required to make a sequence of length %d.\n", numSites);
				exit(4);
			}
				
			ReadTree(tree_fv, treeSet[i], treeNo+1, treeSet[0]->numTips, treeSet[0]->names, 
						&partitionLengths[i], &partitionRates[i]);
						
			if (treeSet[i]->numTips != numTaxa) {
				fprintf(stderr, "All trees must have the same number of tips.\n");
				exit(4);
			}
			
			sumLength += partitionLengths[i];
			i++;
		}
		if (i > maxPartitions) {
			fprintf(stderr, "\nA set of trees number %d had more partitions (%d) than\n", treeNo + 1, i);
			fprintf(stderr, "was specified in the user options (%d).\n", maxPartitions);
		}
		numPartitions = i;
				
		if (sumLength != numSites) {
			fprintf(stderr, "The sum of the partition lengths in the treefile does not equal\n");
			fprintf(stderr, "the specified number of sites.\n");
			exit(4);
		}
			
		for (i = 0; i < numPartitions; i++)
			CreateSequences(treeSet[i], partitionLengths[i]);
		
		if (numPartitions > 1) {
			sum = 0.0;
			for (i = 0; i < numPartitions; i++)
				sum += partitionRates[i] * partitionLengths[i];
				
			for (i = 0; i < numPartitions; i++)
				partitionRates[i] *= numSites / sum;
		}
		
		if (treeNo==0 && verbose && !quiet) {
			PrintVerbose(stderr);
			InitProgressBar(numTrees*numDatasets);
			DrawProgressBar();
		}

		for (i=0; i<numDatasets; i++) {
			SetCategories();
			
			k = 0;
			for (j = 0; j < numPartitions; j++) {
				scale = partitionRates[j];
				
				if (scaleTrees) { 
					if (!treeSet[j]->rooted) {
						fprintf(stderr, "To scale tree length, they must be rooted and ultrametric.\n");
						exit(4);
					}
					scale *= treeScale/treeSet[j]->totalLength;
				} else if (scaleBranches)
					scale *= branchScale;

				EvolveSequences(treeSet[j], k, partitionLengths[j], scale, ancestor);
				k += partitionLengths[j];
			}
			
			if (writeAncestors)
				WriteAncestralSequences(stdout, treeSet[0]);
			else
				WriteSequences(stdout, (numTrees > 1 ? treeNo+1 : -1), (numDatasets > 1 ? i+1 : -1), treeSet, partitionLengths);

			if (writeRates) {
				WriteRates(stderr);
			}

			if (textFile) {
				while (!feof(text_fv)) {
					ch = fgetc(text_fv);
					if (!feof(text_fv))
						fputc(ch, stdout);
				}
				fputc('\n', stdout);
				rewind(text_fv);
			}
			
			if (verbose && !quiet)
				ProgressBar();
		}
				
		for (i = 0; i < numPartitions; i++)
			DisposeTree(treeSet[i]);
			
		treeNo++;
	} while (IsTreeAvail(tree_fv));
	
/*	for (i = 0; i < maxPartitions; i++)
		FreeTree(treeSet[i]);	*/
	
	if (treeFile)
		fclose(tree_fv);

	if (textFile)
		fclose(text_fv);

	totalSecs = (double)(clock() - totalStart) / CLOCKS_PER_SEC;
	if (!quiet) {
		fprintf(stderr, "Time taken: %G seconds\n", totalSecs);
		if (verboseMemory)
			fprintf(stderr, "Total memory used: %ld\n", totalMem);
	}
	
	return 0;
}
Beispiel #25
0
void CStatusLineCtrl::OnPaint(wxPaintEvent& event)
{
	wxPaintDC dc(this);

	wxRect rect = GetRect();

	int refresh = 0;
	if (!m_data.IsOk() || rect.GetWidth() != m_data.GetWidth() || rect.GetHeight() != m_data.GetHeight())
	{
		delete m_mdc;
		m_data = wxBitmap(rect.GetWidth(), rect.GetHeight());
		m_mdc = new wxMemoryDC(m_data);
		refresh = 15;
	}

	int elapsed_seconds = 0;
	wxTimeSpan elapsed;
	int left = -1;
	wxFileOffset rate;
	wxString bytes_and_rate;
	int bar_split = -1;
	int permill = -1;

	if (!m_pStatus)
	{
		if (!m_pPreviousStatusText || *m_pPreviousStatusText != m_statusText)
		{
			// Clear background
			m_mdc->SetFont(GetFont());
			m_mdc->SetPen(GetBackgroundColour());
			m_mdc->SetBrush(GetBackgroundColour());
			m_mdc->SetTextForeground(GetForegroundColour());
			m_mdc->DrawRectangle(0, 0, rect.GetWidth(), rect.GetHeight());
			wxCoord h = (rect.GetHeight() - m_textHeight) / 2;
			m_mdc->DrawText(m_statusText, 50, h);
			delete m_pPreviousStatusText;
			m_pPreviousStatusText = new wxString(m_statusText);
			refresh = 0;
		}
	}
	else
	{
		if (m_pPreviousStatusText)
		{
			delete m_pPreviousStatusText;
			m_pPreviousStatusText = 0;
			refresh = 15;
		}

		if (m_pStatus->started.IsValid())
		{
			elapsed = wxDateTime::Now().Subtract(m_pStatus->started);
			elapsed_seconds = elapsed.GetSeconds().GetLo(); // Assume GetHi is always 0
		}

		if (elapsed_seconds != m_last_elapsed_seconds)
		{
			refresh |= 1;
			m_last_elapsed_seconds = elapsed_seconds;
		}

		if (COptions::Get()->GetOptionVal(OPTION_SPEED_DISPLAY))
			rate = GetCurrentSpeed();
		else
		    rate = GetSpeed(elapsed_seconds);

		if (elapsed_seconds && rate > -1)
		{
			left = ((m_pStatus->totalSize - m_pStatus->startOffset) / rate) - elapsed_seconds;
			if (left < 0)
				left = 0;
		}

		if (m_last_left != left)
		{
			refresh |= 2;
			m_last_left = left;
		}

		const wxString bytestr = CSizeFormat::Format(m_pStatus->currentOffset, true, CSizeFormat::bytes, COptions::Get()->GetOptionVal(OPTION_SIZE_USETHOUSANDSEP) != 0, 0);
		if (elapsed_seconds && rate > -1)
		{
			if (rate > (1000*1000))
				bytes_and_rate.Printf(_("%s (%d.%d MB/s)"), bytestr.c_str(), (int)(rate / 1000 / 1000), (int)((rate / 1000 / 100) % 10));
			else if (rate > 1000)
				bytes_and_rate.Printf(_("%s (%d.%d KB/s)"), bytestr.c_str(), (int)(rate / 1000), (int)((rate / 100) % 10));
			else
				bytes_and_rate.Printf(_("%s (%d B/s)"), bytestr.c_str(), (int)rate);
		}
		else
			bytes_and_rate.Printf(_("%s (? B/s)"), bytestr.c_str());

		if (m_last_bytes_and_rate != bytes_and_rate)
		{
			refresh |= 8;
			m_last_bytes_and_rate = bytes_and_rate;
		}

		if (m_pStatus->totalSize > 0)
		{
			bar_split = wxLongLong(m_pStatus->currentOffset * (PROGRESSBAR_WIDTH - 2) / m_pStatus->totalSize).GetLo();
			if (bar_split > (PROGRESSBAR_WIDTH - 2))
				bar_split = PROGRESSBAR_WIDTH - 2;

			if (m_pStatus->currentOffset > m_pStatus->totalSize)
				permill = 1001;
			else
				permill = wxLongLong(m_pStatus->currentOffset * 1000 / m_pStatus->totalSize).GetLo();
		}

		if (m_last_bar_split != bar_split || m_last_permill != permill)
		{
			refresh |= 4;
			m_last_bar_split = bar_split;
			m_last_permill = permill;
		}
	}

	if (refresh)
	{
		m_mdc->SetFont(GetFont());
		m_mdc->SetPen(GetBackgroundColour());
		m_mdc->SetBrush(GetBackgroundColour());
		m_mdc->SetTextForeground(GetForegroundColour());
	
		// Get character height so that we can center the text vertically.
		wxCoord h = (rect.GetHeight() - m_textHeight) / 2;

		if (refresh & 1)
		{
			m_mdc->DrawRectangle(0, 0, m_fieldOffsets[0], rect.GetHeight());
			DrawRightAlignedText(*m_mdc, elapsed.Format(_("%H:%M:%S elapsed")), m_fieldOffsets[0], h);
		}
		if (refresh & 2)
		{
			m_mdc->DrawRectangle(m_fieldOffsets[0], 0, m_fieldOffsets[1] - m_fieldOffsets[0], rect.GetHeight());
			if (left != -1)
			{
				wxTimeSpan timeLeft(0, 0, left);
				DrawRightAlignedText(*m_mdc, timeLeft.Format(_("%H:%M:%S left")), m_fieldOffsets[1], h);
			}
			else
				DrawRightAlignedText(*m_mdc, _("--:--:-- left"), m_fieldOffsets[1], h);
		}
		if (refresh & 8)
		{
			m_mdc->DrawRectangle(m_fieldOffsets[3], 0, rect.GetWidth() - m_fieldOffsets[3], rect.GetHeight());
			m_mdc->DrawText(bytes_and_rate, m_fieldOffsets[3], h);
		}
		if (refresh & 4)
		{
			if (bar_split != -1)
				DrawProgressBar(*m_mdc, m_fieldOffsets[2], 1, rect.GetHeight() - 2, bar_split, permill);
			else
				m_mdc->DrawRectangle(m_fieldOffsets[2], 0, m_fieldOffsets[3] - m_fieldOffsets[2], rect.GetHeight());
		}
	}
	dc.Blit(0, 0, rect.GetWidth(), rect.GetHeight(), m_mdc, 0, 0);
}
Beispiel #26
0
//--------------------------------------------------------------------------------------
// Name: NuiMenu::Render()
// Desc: Renders the menu items and the cursor.
//--------------------------------------------------------------------------------------
VOID NuiMenu::Render() const
{
    assert( m_pd3dDevice != NULL );

    // Nothing to render.
    if( m_pMenuItemList == NULL )
    {
        return;
    }

    // Render each item in listed order
    for( DWORD dwItemIndex = 0; dwItemIndex < m_dwItemCount; ++ dwItemIndex )
    {
        // Only render items that aren't hidden
        if( ! m_pMenuItemList[ dwItemIndex ].bHidden )
        {
            switch( m_pMenuItemList[ dwItemIndex ].eItemType )
            {
            // Render a button. Buttons are shown in different colors depending on whether they are disabled,
            // selectable or selected
            case NUI_MENU_ITEM_BUTTON:
            {
                D3DCOLOR color = m_settings.staticColor;
                if( m_pMenuItemList[ dwItemIndex ].dwItemID == m_dwHoveredItemID )
                {
                    color = m_settings.selectedColor;
                }
                else if( m_pMenuItemList[ dwItemIndex ].bEnabled && ! m_bIsDisabled )
                {
                    color = m_settings.selectableColor;
                }

                DrawButton( &m_pMenuItemList[ dwItemIndex ].Location, m_pMenuItemList[ dwItemIndex ].szText, color );
                break;
            }

            // Render a check box. Check boxes are shown in different colors depending on whether they are disabled,
            // selectable or selected
            case NUI_MENU_ITEM_CHECK_BOX:
            {
                D3DCOLOR color = m_settings.staticColor;
                if( m_pMenuItemList[ dwItemIndex ].dwItemID == m_dwHoveredItemID )
                {
                    color = m_settings.selectedColor;
                }
                else if( m_pMenuItemList[ dwItemIndex ].bEnabled && ! m_bIsDisabled )
                {
                    color = m_settings.selectableColor;
                }


                DrawCheckBox( &m_pMenuItemList[ dwItemIndex ].Location, m_pMenuItemList[ dwItemIndex ].szText, color, m_pMenuItemList[ dwItemIndex ].fValue > 0.0f );
                break;
            }

            case NUI_MENU_ITEM_FRAME:
                DrawFrame( &m_pMenuItemList[ dwItemIndex ].Location, m_settings.staticColor );
                break;

            case NUI_MENU_ITEM_PANEL:
                DrawPanel( &m_pMenuItemList[ dwItemIndex ].Location, m_settings.panelColor );
                break;

            case NUI_MENU_ITEM_PROGRESS_BAR:
                DrawProgressBar( &m_pMenuItemList[ dwItemIndex ].Location, m_pMenuItemList[ dwItemIndex ].fValue, m_settings.staticColor );
                break;

            case NUI_MENU_ITEM_SPINNER:
                DrawSpinner( &m_pMenuItemList[ dwItemIndex ].Location, m_pMenuItemList[ dwItemIndex ].fValue, m_settings.staticColor );
                break;

            case NUI_MENU_ITEM_TEXT:
                DrawText( &m_pMenuItemList[ dwItemIndex ].Location, m_pMenuItemList[ dwItemIndex ].szText, m_settings.staticColor, m_pMenuItemList[ dwItemIndex ].dwValue );
                break;

            default:
                assert( false );
                break;
            }
        }
    }

    // Add an alignment grid on top of the menu, if requested.
    if( m_settings.bDrawGuide )
    {
        DrawAlignmentGrid();
    }

    // Draw the cursor last, unless the whole menu is disabled
    if( ! m_bIsDisabled )
    {
        DrawCursor();
    }

}