BOOL DXContext::StartOrRestartDevice(DXCONTEXT_PARAMS *pParams) { // call this to [re]initialize the DirectX environment with new parameters. // examples: startup; toggle windowed/fullscreen mode; change fullscreen resolution; // and so on. // be sure to clean up all your DirectX stuff first (textures, vertex buffers, // D3DX allocations, etc.) and reallocate it afterwards! // note: for windowed mode, 'pParams->disp_mode' (w/h/r/f) is ignored. // destroy old window if (myWindowState.me) { m_ignore_wm_destroy = 1; if (m_current_mode.screenmode == WINDOWED) SaveWindow(); DestroyWindow(myWindowState.me); myWindowState.me = NULL; m_ignore_wm_destroy = 0; m_hwnd=0; } else if (m_hwnd) { SendMessage(m_hwnd_winamp, WM_WA_IPC, NULL, IPC_SETVISWND); m_ignore_wm_destroy = 1; DestroyWindow(m_hwnd); m_ignore_wm_destroy = 0; m_hwnd = NULL; } if (!m_ready) { // first-time init: create a fresh new device return Internal_Init(pParams, TRUE); } else { // re-init: preserve the DX9 object (m_lpD3D), // but destroy and re-create the DX9 device (m_lpDevice). m_ready = FALSE; SafeRelease(m_lpDevice); // but leave the D3D object! RestoreWinamp(); BOOL rv = Internal_Init(pParams, FALSE); #ifdef MEDIAMONKEY // HACK: post a message to remove the empty VisOut frame, this will come in after we have the new window made. if (pParams && pParams->screenmode == WINDOWED) { PostMessage(m_hwnd, MEDIAMONKEY_HIDE_VISOUT_MSG, 0, 0); } #endif return rv; } }
void MainWindow::HandleMessage( os::Message* pcMessage ) { switch( pcMessage->GetCode() ) { case M_CHANGE_DIR: { os::String zPath; if( pcMessage->FindString( "file/path", &zPath.str() ) != 0 ) break; m_pcView->SetPath( zPath ); m_pcView->Clear(); LoadWindow( true ); m_pcView->ReRead(); /* Get the new directory icon */ os::BitmapImage* pcImage = static_cast<os::BitmapImage*>(m_pcView->GetDirIcon()); if( pcImage ) { pcImage->SetSize( os::Point( 24, 24 ) ); SetIcon( pcImage->LockBitmap() ); delete( pcImage ); } SetTitle( m_pcView->GetPath() ); m_cBackStack.push( m_pcView->GetPath() ); if( m_cBackStack.size() > 1 ) m_pcBackButton->SetEnable( true ); else m_pcBackButton->SetEnable( false ); break; } case M_BACK: { if( m_cBackStack.size() > 1 ) { m_cBackStack.pop(); os::String cNewPath = m_cBackStack.top(); m_cBackStack.pop(); os::Message* pcMsg = new os::Message( M_CHANGE_DIR ); pcMsg->AddString( "file/path", cNewPath ); PostMessage( pcMsg, this ); delete( pcMsg ); } break; } case M_UP: { os::Message* pcMsg = new os::Message( M_CHANGE_DIR ); os::Path cPath( m_pcView->GetPath().c_str() ); pcMsg->AddString( "file/path", cPath.GetDir().GetPath() ); PostMessage( pcMsg, this ); delete( pcMsg ); break; } case M_HOME: { const char *pzHome = getenv( "HOME" ); os::Message* pcMsg = new os::Message( M_CHANGE_DIR ); pcMsg->AddString( "file/path", pzHome ); PostMessage( pcMsg, this ); delete( pcMsg ); break; } case M_RELOAD: { m_pcView->ReRead(); break; } case M_VIEW_ICONS: { m_pcView->SetView( os::IconDirectoryView::VIEW_ICONS ); m_pcView->ReRead(); /* ReRead after view change to ensure that correct-sized icons are used */ break; } case M_VIEW_LIST: { m_pcView->SetView( os::IconDirectoryView::VIEW_LIST ); m_pcView->ReRead(); break; } case M_VIEW_DETAILS: { m_pcView->SetView( os::IconDirectoryView::VIEW_DETAILS ); m_pcView->ReRead(); break; } case M_SAVE_WINDOW: { SaveWindow(); break; } case M_SAVE_DEFAULT: { SaveDefault(); break; } case M_APP_QUIT: { OkToQuit(); break; } break; } }
char TW_Open_Window (char x,char y,char br,char ho,char rahmen, char titelart,char ofs,char *titel) { unsigned char _far *adr; char ret=0,z,zw, rstr[11]; /* TM_Prot(); */ _settextwindow(1,1,25,80); adr=SaveWindow((char)(x-1),(char)(y-1),(char)(br+2),(char)(ho+2)); if (adr!=NULL) { TW_anz_fenster++; ret=1; fenster[TW_anz_fenster].x=x; fenster[TW_anz_fenster].y=y; fenster[TW_anz_fenster].ho=ho; fenster[TW_anz_fenster].br=br; fenster[TW_anz_fenster].adr=adr; switch(rahmen) { case TW_RAHMEN_S1:strcpy(rstr,"дЁз©ыю╢цаб"); break; case TW_RAHMEN_D1:strcpy(rstr,"м╨и╩╪х╣фпр"); break; case TW_RAHMEN_D2:strcpy(rstr,"мЁу╦╬т╢цаб"); break; default:strcpy(rstr," "); } _settextposition(y-1,x-1); printchar(rstr[2]); _settextposition(y-1,x+br); printchar(rstr[3]); _settextposition(y+ho,x+br); printchar(rstr[4]); _settextposition(y+ho,x-1); printchar(rstr[5]); for (z=x;z<x+br;z++) { _settextposition(y-1,z); printchar(rstr[0]); _settextposition(y+ho,z); printchar(rstr[0]); } for (z=y;z<y+ho;z++) { _settextposition(z,x-1); printchar(rstr[1]); for (zw=1;zw<=br;zw++) _outtext(" "); printchar(rstr[1]); } /* Titel setzten */ if (strcmp(titel,"")) { switch (titelart) { case TW_TITEL_OBEN: { _settextposition(y-1,x+ofs); printchar(rstr[6]); _outtext(titel); printchar(rstr[7]); } break; case TW_TITEL_UNTEN: { _settextposition(y+ho,x+ofs); printchar(rstr[6]); _outtext(titel); printchar(rstr[7]); } break; case TW_TITEL_RECHTS: { _settextposition(y+ofs,x-1); printchar(rstr[8]); for (z=1;(size_t)z<strlen(titel);z++) { _settextposition(y+ofs+z,x-1); printchar(titel[z]); } _settextposition(y+ofs+z,x-1); printchar(rstr[9]); } break; case TW_TITEL_LINKS: { _settextposition(y+ofs,x+br); printchar(rstr[8]); for (z=1;(size_t)z<strlen(titel);z++) { _settextposition(y+ofs+z,x+br); printchar(titel[z]); } _settextposition(y+ofs+z,x+br); printchar(rstr[9]); } break; } /*von SWITCH */ } /*von IF*/ _settextwindow((short)y, (short)x, (short)(y+ho-1), (short)(x+br-1)); } /* TM_Prot(); */ return(ret); }
/* ** Do a shell command, with the options allowed to users (input source, ** output destination, save first and load after) in the shell commands ** menu. */ void DoShellMenuCmd(WindowInfo *window, const char *command, int input, int output, int outputReplacesInput, int saveFirst, int loadAfter, int fromMacro) { int flags = 0; char *text; char *subsCommand, fullName[MAXPATHLEN]; int left, right, textLen; int pos, line, column; char lineNumber[11]; WindowInfo *inWindow = window; Widget outWidget; /* Can't do two shell commands at once in the same window */ if (window->shellCmdData != NULL) { XBell(TheDisplay, 0); return; } /* Substitute the current file name for % and the current line number for # in the shell command */ strcpy(fullName, window->path); strcat(fullName, window->filename); pos = TextGetCursorPos(window->lastFocus); TextPosToLineAndCol(window->lastFocus, pos, &line, &column); sprintf(lineNumber, "%d", line); subsCommand = shellCommandSubstitutes(command, fullName, lineNumber); if (subsCommand == NULL) { DialogF(DF_ERR, window->shell, 1, "Shell Command", "Shell command is too long due to\n" "filename substitutions with '%%' or\n" "line number substitutions with '#'", "OK"); return; } /* Get the command input as a text string. If there is input, errors shouldn't be mixed in with output, so set flags to ERROR_DIALOGS */ if (input == FROM_SELECTION) { text = BufGetSelectionText(window->buffer); if (*text == '\0') { XtFree(text); free(subsCommand); XBell(TheDisplay, 0); return; } flags |= ACCUMULATE | ERROR_DIALOGS; } else if (input == FROM_WINDOW) { text = BufGetAll(window->buffer); flags |= ACCUMULATE | ERROR_DIALOGS; } else if (input == FROM_EITHER) { text = BufGetSelectionText(window->buffer); if (*text == '\0') { XtFree(text); text = BufGetAll(window->buffer); } flags |= ACCUMULATE | ERROR_DIALOGS; } else /* FROM_NONE */ text = NULL; /* If the buffer was substituting another character for ascii-nuls, put the nuls back in before exporting the text */ if (text != NULL) { textLen = strlen(text); BufUnsubstituteNullChars(text, window->buffer); } else textLen = 0; /* Assign the output destination. If output is to a new window, create it, and run the command from it instead of the current one, to free the current one from waiting for lengthy execution */ if (output == TO_DIALOG) { outWidget = NULL; flags |= OUTPUT_TO_DIALOG; left = right = 0; } else if (output == TO_NEW_WINDOW) { EditNewFile(GetPrefOpenInTab()?inWindow:NULL, NULL, False, NULL, window->path); outWidget = WindowList->textArea; inWindow = WindowList; left = right = 0; CheckCloseDim(); } else { /* TO_SAME_WINDOW */ outWidget = window->lastFocus; if (outputReplacesInput && input != FROM_NONE) { if (input == FROM_WINDOW) { left = 0; right = window->buffer->length; } else if (input == FROM_SELECTION) { GetSimpleSelection(window->buffer, &left, &right); flags |= ACCUMULATE | REPLACE_SELECTION; } else if (input == FROM_EITHER) { if (GetSimpleSelection(window->buffer, &left, &right)) flags |= ACCUMULATE | REPLACE_SELECTION; else { left = 0; right = window->buffer->length; } } } else { if (GetSimpleSelection(window->buffer, &left, &right)) flags |= ACCUMULATE | REPLACE_SELECTION; else left = right = TextGetCursorPos(window->lastFocus); } } /* If the command requires the file be saved first, save it */ if (saveFirst) { if (!SaveWindow(window)) { if (input != FROM_NONE) XtFree(text); free(subsCommand); return; } } /* If the command requires the file to be reloaded after execution, set a flag for issueCommand to deal with it when execution is complete */ if (loadAfter) flags |= RELOAD_FILE_AFTER; /* issue the command */ issueCommand(inWindow, subsCommand, text, textLen, flags, outWidget, left, right, fromMacro); free(subsCommand); }
/* ============== RenderBumpFlat_f ============== */ void RenderBumpFlat_f( const idCmdArgs &args ) { int width, height; idStr source; int i; idBounds bounds; srfTriangles_t *mesh; // update the screen as we print common->SetRefreshOnPrint( true ); width = height = 256; // check options for ( i = 1 ; i < args.Argc() - 1; i++ ) { const char *s; s = args.Argv( i ); if ( s[0] == '-' ) { i++; s = args.Argv( i ); } if ( !idStr::Icmp( s, "size" ) ) { if ( i + 2 >= args.Argc() ) { i = args.Argc(); break; } width = atoi( args.Argv( i + 1 ) ); height = atoi( args.Argv( i + 2 ) ); i += 2; } else { common->Printf( "WARNING: Unknown option \"%s\"\n", s ); break; } } if ( i != ( args.Argc() - 1 ) ) { common->Error( "usage: renderBumpFlat [-size width height] asefile" ); return; } common->Printf( "Final image size: %i, %i\n", width, height ); // load the source in "fastload" mode, because we don't // need tangent and shadow information source = args.Argv( i ); idRenderModel *highPolyModel = renderModelManager->AllocModel(); highPolyModel->PartialInitFromFile( source ); if ( highPolyModel->IsDefaultModel() ) { common->Error( "failed to load %s", source.c_str() ); } // combine the high poly model into a single polyset if ( highPolyModel->NumSurfaces() != 1 ) { highPolyModel = CombineModelSurfaces( highPolyModel ); } // create normals if not present in file const modelSurface_t *surf = highPolyModel->Surface( 0 ); mesh = surf->geometry; // bound the entire file R_BoundTriSurf( mesh ); bounds = mesh->bounds; SaveWindow(); ResizeWindow( width, height ); // for small images, the viewport may be less than the minimum window qglViewport( 0, 0, width, height ); qglEnable( GL_CULL_FACE ); qglCullFace( GL_FRONT ); qglDisable( GL_STENCIL_TEST ); qglDisable( GL_SCISSOR_TEST ); qglDisable( GL_ALPHA_TEST ); qglDisable( GL_BLEND ); qglEnable( GL_DEPTH_TEST ); qglDisable( GL_TEXTURE_2D ); qglDepthMask( GL_TRUE ); qglDepthFunc( GL_LEQUAL ); qglColor3f( 1, 1, 1 ); qglMatrixMode( GL_PROJECTION ); qglLoadIdentity(); qglOrtho( bounds[0][0], bounds[1][0], bounds[0][2], bounds[1][2], -( bounds[0][1] - 1 ), -( bounds[1][1] + 1 ) ); qglMatrixMode( GL_MODELVIEW ); qglLoadIdentity(); // flat maps are automatically anti-aliased idStr filename; int j, k, c; byte *buffer; int *sumBuffer, *colorSumBuffer; bool flat; int sample; sumBuffer = (int *)Mem_Alloc( width * height * 4 * 4 ); memset( sumBuffer, 0, width * height * 4 * 4 ); buffer = (byte *)Mem_Alloc( width * height * 4 ); colorSumBuffer = (int *)Mem_Alloc( width * height * 4 * 4 ); memset( sumBuffer, 0, width * height * 4 * 4 ); flat = false; //flat = true; for ( sample = 0 ; sample < 16 ; sample++ ) { float xOff, yOff; xOff = ( ( sample & 3 ) / 4.0 ) * ( bounds[1][0] - bounds[0][0] ) / width; yOff = ( ( sample / 4 ) / 4.0 ) * ( bounds[1][2] - bounds[0][2] ) / height; for ( int colorPass = 0 ; colorPass < 2 ; colorPass++ ) { qglClearColor(0.5,0.5,0.5,0); qglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); qglBegin( GL_TRIANGLES ); for ( i = 0 ; i < highPolyModel->NumSurfaces() ; i++ ) { const modelSurface_t *surf = highPolyModel->Surface( i ); mesh = surf->geometry; if ( colorPass ) { // just render the surface color for artist visualization for ( j = 0 ; j < mesh->numIndexes ; j+=3 ) { for ( k = 0 ; k < 3 ; k++ ) { int v; float *a; v = mesh->indexes[j+k]; qglColor3ubv( mesh->verts[v].color ); a = mesh->verts[v].xyz.ToFloatPtr(); qglVertex3f( a[0] + xOff, a[2] + yOff, a[1] ); } } } else { // render as normal map // we can either flat shade from the plane, // or smooth shade from the vertex normals for ( j = 0 ; j < mesh->numIndexes ; j+=3 ) { if ( flat ) { idPlane plane; idVec3 *a, *b, *c; int v1, v2, v3; v1 = mesh->indexes[j+0]; v2 = mesh->indexes[j+1]; v3 = mesh->indexes[j+2]; a = &mesh->verts[ v1 ].xyz; b = &mesh->verts[ v2 ].xyz; c = &mesh->verts[ v3 ].xyz; plane.FromPoints( *a, *b, *c ); // NULLNORMAL is used by the artists to force an area to reflect no // light at all if ( surf->shader->GetSurfaceFlags() & SURF_NULLNORMAL ) { qglColor3f( 0.5, 0.5, 0.5 ); } else { qglColor3f( 0.5 + 0.5*plane[0], 0.5 - 0.5*plane[2], 0.5 - 0.5*plane[1] ); } qglVertex3f( (*a)[0] + xOff, (*a)[2] + yOff, (*a)[1] ); qglVertex3f( (*b)[0] + xOff, (*b)[2] + yOff, (*b)[1] ); qglVertex3f( (*c)[0] + xOff, (*c)[2] + yOff, (*c)[1] ); } else { for ( k = 0 ; k < 3 ; k++ ) { int v; float *n; float *a; v = mesh->indexes[j+k]; n = mesh->verts[v].normal.ToFloatPtr(); // NULLNORMAL is used by the artists to force an area to reflect no // light at all if ( surf->shader->GetSurfaceFlags() & SURF_NULLNORMAL ) { qglColor3f( 0.5, 0.5, 0.5 ); } else { // we are going to flip the normal Z direction qglColor3f( 0.5 + 0.5*n[0], 0.5 - 0.5*n[2], 0.5 - 0.5*n[1] ); } a = mesh->verts[v].xyz.ToFloatPtr(); qglVertex3f( a[0] + xOff, a[2] + yOff, a[1] ); } } } } } qglEnd(); qglFlush(); GLimp_SwapBuffers(); qglReadPixels( 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer ); c = width * height; if ( colorPass ) { // add to the sum buffer for ( i = 0 ; i < c ; i++ ) { colorSumBuffer[i*4+0] += buffer[i*4+0]; colorSumBuffer[i*4+1] += buffer[i*4+1]; colorSumBuffer[i*4+2] += buffer[i*4+2]; colorSumBuffer[i*4+3] += buffer[i*4+3]; } } else { // normalize for ( i = 0 ; i < c ; i++ ) { idVec3 v; v[0] = ( buffer[i*4+0] - 128 ) / 127.0; v[1] = ( buffer[i*4+1] - 128 ) / 127.0; v[2] = ( buffer[i*4+2] - 128 ) / 127.0; v.Normalize(); buffer[i*4+0] = 128 + 127 * v[0]; buffer[i*4+1] = 128 + 127 * v[1]; buffer[i*4+2] = 128 + 127 * v[2]; } // outline into non-drawn areas for ( i = 0 ; i < 8 ; i++ ) { OutlineNormalMap( buffer, width, height, 128, 128, 128 ); } // add to the sum buffer for ( i = 0 ; i < c ; i++ ) { sumBuffer[i*4+0] += buffer[i*4+0]; sumBuffer[i*4+1] += buffer[i*4+1]; sumBuffer[i*4+2] += buffer[i*4+2]; sumBuffer[i*4+3] += buffer[i*4+3]; } } } } c = width * height; // save out the color map for ( i = 0 ; i < c ; i++ ) { buffer[i*4+0] = colorSumBuffer[i*4+0] / 16; buffer[i*4+1] = colorSumBuffer[i*4+1] / 16; buffer[i*4+2] = colorSumBuffer[i*4+2] / 16; buffer[i*4+3] = colorSumBuffer[i*4+3] / 16; } filename = source; filename.StripFileExtension(); filename.Append( "_color.tga" ); R_VerticalFlip( buffer, width, height ); R_WriteTGA( filename, buffer, width, height ); // save out the local map // scale the sum buffer back down to the sample buffer // we allow this to denormalize for ( i = 0 ; i < c ; i++ ) { buffer[i*4+0] = sumBuffer[i*4+0] / 16; buffer[i*4+1] = sumBuffer[i*4+1] / 16; buffer[i*4+2] = sumBuffer[i*4+2] / 16; buffer[i*4+3] = sumBuffer[i*4+3] / 16; } filename = source; filename.StripFileExtension(); filename.Append( "_local.tga" ); common->Printf( "writing %s (%i,%i)\n", filename.c_str(), width, height ); R_VerticalFlip( buffer, width, height ); R_WriteTGA( filename, buffer, width, height ); // free the model renderModelManager->FreeModel( highPolyModel ); // free our work buffer Mem_Free( buffer ); Mem_Free( sumBuffer ); Mem_Free( colorSumBuffer ); RestoreWindow(); // stop updating the screen as we print common->SetRefreshOnPrint( false ); common->Error( "Completed." ); }