void GameGui::CloseWindowCallback(Gwen::Controls::Base* window) { CloseWindow(*(Gwen::Controls::WindowControl*)window); }
BOOL render_init( render_info_t * info ) { HRESULT LastError; render_viewport_t viewport; // should get this from d3d caps bSquareOnly = FALSE; // default gamma table build_gamma_table(1.0); // Set up Direct3D interface object lpD3D = Direct3DCreate9(D3D_SDK_VERSION); if (!lpD3D) { DebugPrintf("couldnt create d3d9\n"); return FALSE; } // create d3d device D3DPRESENT_PARAMETERS d3dpp; ZeroMemory (&d3dpp, sizeof(d3dpp)); // d3dpp.Windowed = !info->fullscreen; // // presentation settings // d3dpp.hDeviceWindow = GetActiveWindow(); // the window handle d3dpp.BackBufferCount = 1; // we only have one swap chain d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // does not protect the contents of the backbuffer after flipping (faster) // shouldn't we specify D3DSWAPEFFECT_FLIP ? // wouldn't D3DSWAPEFFECT_OVERLAY be fastest ? d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; // display refresh d3dpp.EnableAutoDepthStencil = TRUE; // let d3d manage the z-buffer if(info->vsync) d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; // enable vsync else d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // disable vsync // 16 bit zbuffer //d3dpp.AutoDepthStencilFormat = D3DFMT_D15S1; // 16 bit depth buffer with 1 bit stencil d3dpp.AutoDepthStencilFormat = D3DFMT_D16; // 16 bit depth buffer // 32 bit back buffer // Also supports 32 bit zbuffer if( SUCCEEDED(lpD3D->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, d3dpp.Windowed))) { bpp = 32; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; //d3dpp.AutoDepthStencilFormat = D3DFMT_D32; // 32 bit depth buffer d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; // 24 bit depth buffer with 8 bit stencil buffer DebugPrintf("picked 24 bit D3DFMT_X8R8G8B8 back buffer\n"); } // 16 bit else if(SUCCEEDED(lpD3D->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X1R5G5B5, D3DFMT_X1R5G5B5, d3dpp.Windowed))) { d3dpp.BackBufferFormat = D3DFMT_X1R5G5B5; DebugPrintf("picked 16 bit D3DFMT_X1R5G5B5 back buffer\n"); } // 16 bit else if(SUCCEEDED(lpD3D->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_R5G6B5, D3DFMT_R5G6B5, d3dpp.Windowed))) { d3dpp.BackBufferFormat = D3DFMT_R5G6B5; DebugPrintf("picked 16 bit D3DFMT_R5G6B5 back buffer\n"); } // failed else { CloseWindow(d3dpp.hDeviceWindow); Msg("Failed to find a suitable back buffer format"); exit(1); } // // Enumerates display modes // picking info->default_mode if it exists // or picking the biggest mode possible :] // #if 0 // done by sdl now { int mode = 0; int desired_mode = -1; int best_mode = 0; // default to the first mode int i; int x = 0; int count = (int) lpD3D->GetAdapterModeCount( D3DADAPTER_DEFAULT, d3dpp.BackBufferFormat ); info->Mode = (render_display_mode_t *) malloc( count * sizeof(render_display_mode_t) ); D3DDISPLAYMODE * modes = (D3DDISPLAYMODE *) malloc( count * sizeof(D3DDISPLAYMODE) ); for ( i = 0; i < count; i++ ) { // get the mode description lpD3D->EnumAdapterModes( D3DADAPTER_DEFAULT, d3dpp.BackBufferFormat, i, &modes[i] ); DebugPrintf("Enumerated mode: %dx%d @ %dhz , format=%d\n", modes[i].Width,modes[i].Height,modes[i].RefreshRate,modes[i].Format); // ignore modes under 640x480 if(modes[i].Width < 640 || modes[i].Height < 480) { DebugPrintf("Skipping mode because it's to small for anyone to want...\n"); continue; } // save the mode info->Mode[x].h = modes[i].Height; info->Mode[x].w = modes[i].Width; info->Mode[x].bpp = bpp; // if this is the mode the user wanted pick it if( info->Mode[x].w == info->default_mode.w && info->Mode[x].h == info->default_mode.h ) { desired_mode = x; } // smallest mode as default if( info->Mode[x].w < info->Mode[best_mode].w && info->Mode[x].h < info->Mode[best_mode].h ) { best_mode = x; } // biggest mode by width as default //if(info->Mode[x].w > info->Mode[best_mode].w ) // best_mode = x; // 800x600 @ 60 as default //if( info->Mode[x].w == 800 && info->Mode[x].h == 600 ) // desired_mode = x; // go to next storage location x++; } info->NumModes = x; if( desired_mode >= 0 ) { mode = desired_mode; } else { mode = best_mode; } info->CurrMode = mode; info->ThisMode = info->Mode[ info->CurrMode ]; info->WindowsDisplay = info->Mode[ info->CurrMode ]; info->window_size.cx = info->ThisMode.w; info->window_size.cy = info->ThisMode.h; info->WindowsDisplay.w = info->ThisMode.w; info->WindowsDisplay.h = info->ThisMode.h; free(modes); } #endif // done by sdl now d3dpp.BackBufferWidth = info->ThisMode.w; d3dpp.BackBufferHeight = info->ThisMode.h; info->aspect_ratio = (float) info->ThisMode.w / (float) info->ThisMode.h; DebugPrintf("Using display mode: %dx%d\n", info->ThisMode.w,info->ThisMode.h); // try to create a device falling back to less capable versions // // TODO // the docs say that pure devices don't support Get* calls // which explains why people are crashing on FSGet* functions for no reason // to support pure device we'd have to track our own states // /* LastError = lpD3D->CreateDevice( D3DADAPTER_DEFAULT, // the default video card D3DDEVTYPE_HAL, // device type - hal = Hardware rasterization d3dpp.hDeviceWindow, // the window handle // these define how the device is created D3DCREATE_HARDWARE_VERTEXPROCESSING | // do vertex processing in hardware D3DCREATE_PUREDEVICE, // D3D will not support Get* calls for anything that can be stored in state blocks. // and not to provide any emulation services for vertex processing. // Thus if the device does not support vertex processing, // then the application can use only post-transformed vertices. &d3dpp, // presentation parameters defined above &lpD3DDevice // pointer that will contain the returned device ); if (SUCCEEDED(LastError)) { Msg("pure"); } if (FAILED(LastError)) */ { LastError = lpD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3dpp.hDeviceWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &lpD3DDevice); if (SUCCEEDED(LastError)) { DebugPrintf("d3d device created: hardware\n"); } else { const char * error = render_error_description(LastError); DebugPrintf("d3d device create failed with hardware: %s\n",error); } } if (FAILED(LastError)) { LastError = lpD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3dpp.hDeviceWindow, D3DCREATE_MIXED_VERTEXPROCESSING, // do vertex processing in both hardware and software &d3dpp, &lpD3DDevice); if (SUCCEEDED(LastError)) { DebugPrintf("d3d device created: mixed\n"); } else { const char * error = render_error_description(LastError); DebugPrintf("d3d device create failed with mixed: %s\n",error); } } if (FAILED(LastError)) { LastError = lpD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3dpp.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, // do vertex processing in software only &d3dpp, &lpD3DDevice); if (SUCCEEDED(LastError)) { DebugPrintf("d3d device created: software\n"); } else { const char * error = render_error_description(LastError); DebugPrintf("d3d device create failed with software: %s\n",error); } } if (FAILED(LastError)) { CloseWindow(d3dpp.hDeviceWindow); Msg("Failed to create a suitable d3d device:\n%s", render_error_description(LastError)); exit(1); } info->ok_to_render = TRUE; viewport.X = 0; viewport.Y = 0; /* do "after device created" stuff */ ZeroMemory( &viewport, sizeof(viewport) ); { WINDOWPLACEMENT placement; placement.length = sizeof(WINDOWPLACEMENT); if(GetWindowPlacement( d3dpp.hDeviceWindow, &placement )) { viewport.X = placement.rcNormalPosition.left; viewport.Y = placement.rcNormalPosition.top; } } viewport.Width = d3dpp.BackBufferWidth; viewport.Height = d3dpp.BackBufferHeight; viewport.MinZ = 0.0f; viewport.MaxZ = 1.0f; LastError = FSSetViewPort(&viewport); if (!LastError) { DebugPrintf("couldn't set viewport\n"); } if(!init_render_states( info )) return FALSE; return TRUE; }
int main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available) InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader"); // Define the camera to look into our 3d world Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }}; Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture Shader shader = LoadShader("resources/shaders/base.vs", "resources/shaders/grayscale.fs"); // Load model shader SetModelShader(&dwarf, shader); // Set shader effect to 3d model SetModelTexture(&dwarf, texture); // Bind texture to model Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position // Setup orbital camera SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode SetCameraPosition(camera.position); // Set internal camera position to match our camera position SetCameraTarget(camera.target); // Set internal camera target to match our camera target SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update internal camera and our camera //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); Begin3dMode(camera); DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture DrawGrid(10.0, 1.0); // Draw a grid End3dMode(); DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY); DrawFPS(10, 10); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadShader(shader); // Unload shader UnloadTexture(texture); // Unload texture UnloadModel(dwarf); // Unload model CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
bool StressTest::OpenFile(const WCHAR *fileName) { wprintf(L"%s\n", fileName); fflush(stdout); LoadArgs args(fileName); args.forceReuse = rand() % 3 != 1; WindowInfo *w = LoadDocument(args); if (!w) return false; if (w == win) { // WindowInfo reused if (!win->IsDocLoaded()) return false; } else if (!w->IsDocLoaded()) { // new WindowInfo CloseWindow(w, false); return false; } // transfer ownership of stressTest object to a new window and close the // current one assert(this == win->stressTest); if (w != win) { if (win->IsDocLoaded()) { // try to provoke a crash in RenderCache cleanup code ClientRect rect(win->hwndFrame); rect.Inflate(rand() % 10, rand() % 10); SendMessage(win->hwndFrame, WM_SIZE, 0, MAKELONG(rect.dx, rect.dy)); if (win->AsFixed()) win->cbHandler->RequestRendering(1); win->RepaintAsync(); } WindowInfo *toClose = win; w->stressTest = win->stressTest; win->stressTest = nullptr; win = w; CloseWindow(toClose, false); } if (!win->IsDocLoaded()) return false; win->ctrl->SetDisplayMode(DM_CONTINUOUS); win->ctrl->SetZoomVirtual(ZOOM_FIT_PAGE); win->ctrl->GoToFirstPage(); if (win->tocVisible || gGlobalPrefs->showFavorites) SetSidebarVisibility(win, win->tocVisible, gGlobalPrefs->showFavorites); currPage = pageRanges.At(0).start; win->ctrl->GoToPage(currPage, false); currPageRenderTime.Start(); ++filesCount; pageForSearchStart = (rand() % win->ctrl->PageCount()) + 1; // search immediately in single page documents if (1 == pageForSearchStart) { // use text that is unlikely to be found, so that we search all pages win::SetText(win->hwndFindBox, L"!z_yt"); FindTextOnThread(win, FIND_FORWARD, true); } int secs = SecsSinceSystemTime(stressStartTime); ScopedMem<WCHAR> tm(FormatTime(secs)); ScopedMem<WCHAR> s(str::Format(L"File %d: %s, time: %s", filesCount, fileName, tm)); win->ShowNotification(s, NOS_PERSIST, NG_STRESS_TEST_SUMMARY); return true; }
p_npaspuskForm::p_npaspuskForm(bool AddEdit, int recnum, QWidget *parent) : QDialog(parent), ui(new Ui::p_npaspuskForm) { ui->setupUi(this); // Соединяем сигналы со слотами: connect (ui->buttonBox, SIGNAL(accepted()), this, SLOT (SaveRecord())); //кнопка "Ok" connect (ui->buttonBox, SIGNAL(rejected()), this, SLOT (CloseWindow())); // кнопка "Закрыть" // Грузим установки формы из конфигурационного файла qTC->formLoad(this, FormSetFile, false); // Если жобавляем новую запись, то идем сюда if (AddEdit == true) { QString tmpString = tr("Новое погружение "); setWindowTitle(tmpString.append(getCurrentTS().typeTS)); //Наименование ТС ui->labelTSName->setText(getCurrentTS().nameTS); // Найдем макс № погружения и услужливо подставим его // Если при вычислении max индекса возникла ошибка, ф-ция возвращает '-1' int maxInt = MaxCode("z18_spts.p_sgaspusk","nomp"); // Если почему-то max № не выбрался - пишем в Edit '1' if (maxInt == -1) { ui->lineEditNumber->setText("1"); } else { maxInt++; ui->lineEditNumber->setText(QString::number(maxInt)); } // берем текущую дату QDate curdate = QDate::currentDate(); ui->dateEditPogruzh->clear(); ui->dateEditPogruzh->setDate(curdate); // берем текущее время QTime curtime = QTime::currentTime(); ui->timeEditStartPogruzh->clear(); ui->timeEditStartPogruzh->setTime(curtime); } else // Если редактируем существующую запись, то идем сюда { /* QSqlQuery QPogruzh; // value: 0 1 2 3 4 5 6 7 QPogruzh.prepare("SELECT code,name,nomp,datep,begintime,endtime,codesh,prizn FROM z18_spts.p_sgapred WHERE code = :precnum"); QPogruzh.bindValue(":precnum",recnum); if (!QPogruzh.exec()) { QMessageBox::critical(0, tr("Редактирование записи"), msgErrorOpenEditRecord.toLatin1(), QMessageBox::Ok); CloseWindow(); } QPogruzh.first(); QString tmpString = tr("Погружение №").append(QPogruzh.value(2).toString()); setWindowTitle(tmpString); ui->labelTSName->setText(getCurrentTS().nameTS); ui->lineEditNumber->setText(QPogruzh.value(2).toString()); // берем дату погружения из записи QDate pogrdate = QPogruzh.value(3).toDate(); ui->dateEditPogruzh->clear(); ui->dateEditPogruzh->setDate(pogrdate); // берем время начала из записи QTime pogrstarttime = QPogruzh.value(4).toTime(); ui->timeEditStartPogruzh->clear(); ui->timeEditStartPogruzh->setTime(pogrstarttime); // берем время конца из записи QTime pogrendtime = QPogruzh.value(5).toTime(); ui->timeEditEndPogruzh->clear(); ui->timeEditEndPogruzh->setTime(pogrendtime); // Готов или не готов bool YesNoReady = QPogruzh.value(7).toBool(); if (YesNoReady == false) { ui->sostLabel->setText(tr("Не готов")); ui->sostLabel->setPalette(QPalette(getNotReadyColor())); } else { ui->sostLabel->setText(tr("Готов")); ui->sostLabel->setPalette(QPalette(getReadyColor())); } */ } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 切换查看菜单状态 VOID CMainWnd::OnViewMenu(UINT uCmd, BOOL bInitialize) { UINT i; BOOL bChecked; const PTSTR STR_KeyNames[] = { INI_Toolbar, INI_StatusBar, INI_AlwaysOnTop, INI_MinToTray, INI_ShowSplash, INI_ShowOpen, INI_PlayOnOpen }; // 获取 INI 键名索引号 i = uCmd - IDM_View_Toolbar; // 如果是有效命令 if (i < _NumOf(STR_KeyNames)) { // 切换菜单项 bChecked = !IsMenuChecked(uCmd); CheckCommand(uCmd, bChecked); // 如果不是初始化指定的切换,记录到 INI 中 if (bInitialize == FALSE) { CIni::SetInt(STR_KeyNames[i], bChecked); } switch (uCmd) { case IDM_View_Toolbar: case IDM_View_StatusBar: CClientWnd::ToggleBar(); break; case IDM_View_AlwaysOnTop: // 总在最前 SetWindowPos(m_hWnd, bChecked ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); return; case IDM_View_MinToTray: // 最小化到系统托盘 if (bChecked && (bInitialize == FALSE)) { CloseWindow(m_hWnd); } return; default: return; } } // 如果是初始化菜单项 else if (bInitialize) { // 初始化菜单项 for (i = 0; i < _NumOf(STR_KeyNames); i++) { // 默认是否选择 bChecked = IsMenuChecked(IDM_View_Toolbar + i); // 如果默认选择与 INI 中不一样 if (bChecked != (BOOL) CIni::GetInt(STR_KeyNames[i], bChecked)) { // 切换菜单项 OnViewMenu(IDM_View_Toolbar + i, TRUE); } } } }
//The implementation code of CreateButton. HANDLE CreateBitmapButton(HANDLE hParent,TCHAR* pszText, DWORD dwButtonId,int x,int y, int cxbmp,int cybmp, LPVOID pBitmap, LPVOID pExtension) { HANDLE hButton = NULL; __WINDOW* pBtnWnd = NULL; __BITMAP_BUTTON* pButton = NULL; BOOL bResult = FALSE; __WINDOW* pParent = (__WINDOW*)hParent; __WINDOW_MESSAGE msg; int height = 0; //Total width. int width = 0; //Total height. int txtheight = 0; int txtwidth = 0; int ntxtlen = 0; HANDLE hDC = NULL; if(NULL == hParent) //Invalid. { return NULL; } hDC = GetWindowDC(hParent); pButton = (__BITMAP_BUTTON*)KMemAlloc(sizeof(__BITMAP_BUTTON),KMEM_SIZE_TYPE_ANY); if(NULL == pButton) { goto __TERMINAL; } //Initialize button. pButton->dwBmpButtonId = dwButtonId; ntxtlen = strlen(pszText); if(ntxtlen >= BMPBTN_TEXT_LENGTH - 1) //Text too long. { goto __TERMINAL; } strcpy(pButton->ButtonText,pszText); pButton->x = x; //+ pParent->xclient; pButton->y = y; //+ pParent->yclient; txtheight = GetTextMetric(hDC,pszText,TM_HEIGHT); txtheight += TXT_MARGIN; //Uper margin. txtheight += TXT_MARGIN; //Bottom margin. pButton->cy = cybmp + txtheight; pButton->txtheight = txtheight; width = GetTextMetric(hDC,pszText,TM_WIDTH); if(width > cxbmp - TXT_MARGIN * 2) //Too long. { goto __TERMINAL; } pButton->cx = cxbmp; pButton->xtxt = (pButton->cx - width) / 2; pButton->ytxt = cybmp + TXT_MARGIN; pButton->txtwidth = width; pButton->dwBmpBtnStatus = BUTTON_STATUS_NORMAL; pButton->pBmpData = pBitmap; pButton->pButtonExtension = pExtension; //Set default button colors. pButton->FaceClr = DEFAULT_BMPBTN_FACECOLOR; pButton->TxtBackground = DEFAULT_BMPBTN_TXTBACKGROUND; pButton->TxtColor = DEFAULT_BMPBTN_TXTCOLOR; //Allocate memory for bitmap data. if(pBitmap) { pButton->pBmpData = KMemAlloc(cxbmp * cybmp * sizeof(__COLOR),KMEM_SIZE_TYPE_ANY); if(NULL == pButton->pBmpData) { goto __TERMINAL; } memcpy(pButton->pBmpData,pBitmap,cxbmp * cybmp * sizeof(__COLOR)); } //Create the button window. hButton = CreateWindow(0, //Without any caption and border. NULL, //Without title. pButton->x + pParent->x, pButton->y + pParent->y, pButton->cx, pButton->cy, BmpButtonWndProc, hParent, NULL, GlobalParams.COLOR_BTNFACE, NULL); if(NULL == hButton) { goto __TERMINAL; } pBtnWnd = (__WINDOW*)hButton; pBtnWnd->lpWndExtension = (LPVOID)pButton; //Save button information to window's ext. //Send WM_PAINT message to button to re-draw itself. msg.hWnd = hButton; msg.message = WM_PAINT; msg.wParam = 0; msg.lParam = 0; SendWindowMessage(hButton,&msg); bResult = TRUE; __TERMINAL: if(!bResult) { if(pButton) { if(pButton->pBmpData) { KMemFree(pButton->pBmpData,KMEM_SIZE_TYPE_ANY,0); } KMemFree(pButton,KMEM_SIZE_TYPE_ANY,0); } if(hButton) { CloseWindow(hButton); } hButton = NULL; } return hButton; }
void ProgressDialog::close() { CloseWindow(_hSelf); }
// реакция окна ввода даты на сообщение WM_COMMAND LRESULT CALLBACK tagMAINWINDOW::STW_WM_COMMAND_reaction(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId = LOWORD(wParam); int wmEvent = HIWORD(wParam); switch (wmId) { //////////// case STW_Ok_ID: CloseWindow(hWnd); if(stwy) SetWindowText(this->StYearNum, lpchy); if(stwm) SetWindowText(this->StMonthNum, lpchm); if(stwd) SetWindowText(this->StDayNum, lpchd); if(stwh) SetWindowText(this->StHourNum, lpchh); SetNewDate = true; ZeroMemory(KeyFocusSTW,sizeof(KeyFocusSTW)); break; case STW_Cn_ID: pary = parm = pard = parh = 0; CloseWindow(hWnd); ZeroMemory(KeyFocusSTW,sizeof(KeyFocusSTW)); break; //////////// case STW_Y_ID: switch(wmEvent) { case EN_SETFOCUS: GetWindowText((HWND)lParam, lpchy, 20); for(lpchiter = lpchy; *lpchiter > 47 && *lpchiter < 58 ; lpchiter ++); *lpchiter = L'\0'; SetWindowText ((HWND)lParam, lpchy); KeyFocusSTW[0] = true; break; case EN_KILLFOCUS: GetWindowText((HWND)lParam, lpchy, 20); for(lpchiter = lpchy; *lpchiter > 47 && *lpchiter < 58 ; lpchiter ++); *lpchiter = L'\0'; pary = _wtoi(lpchy); stwy = true; swprintf_s(lpch, L"%d год", pary); SetWindowText((HWND)lParam, lpch); KeyFocusSTW[0] = false; break; case EN_CHANGE: break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case STW_M_ID: switch(wmEvent) { case EN_SETFOCUS: GetWindowText((HWND)lParam,lpchm,20); for(lpchiter=lpchm; *lpchiter>47 && *lpchiter<58 ; lpchiter++); *lpchiter=L'\0'; SetWindowText((HWND)lParam,lpchm); KeyFocusSTW[1] = true; break; case EN_KILLFOCUS: GetWindowText((HWND)lParam,lpchm,20); for(lpchiter=lpchm; *lpchiter>47 && *lpchiter<58 ; lpchiter++); *lpchiter=L'\0'; parm = _wtoi(lpchm); stwm = true; swprintf_s(lpch,L"%d мес",parm); SetWindowText((HWND)lParam,lpch); KeyFocusSTW[1] = false; break; case EN_CHANGE: GetWindowText((HWND)lParam,lpchm,20); for(lpchiter=lpchm; *lpchiter>47 && *lpchiter<58 ; lpchiter++); *lpchiter=L'\0'; parm = _wtoi(lpchm); if(parm>12) SetWindowText((HWND)lParam,L"12"); if(parm<1) SetWindowText((HWND)lParam,L"01"); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case STW_D_ID: switch(wmEvent) { case EN_SETFOCUS: GetWindowText((HWND)lParam,lpchd,20); for(lpchiter=lpchd; *lpchiter>47 && *lpchiter<58 ; lpchiter++); *lpchiter=L'\0'; SetWindowText((HWND)lParam,lpchd); KeyFocusSTW[2] = true; break; case EN_KILLFOCUS: GetWindowText((HWND)lParam,lpchd,20); for(lpchiter=lpchd; *lpchiter>47 && *lpchiter<58 ; lpchiter++); *lpchiter=L'\0'; pard= _wtoi(lpchd); stwd = true; swprintf_s(lpch,L"%d день",pard); SetWindowText((HWND)lParam,lpch); KeyFocusSTW[2] = false; break; case EN_CHANGE: GetWindowText((HWND)lParam,lpchd,20); for(lpchiter=lpchd; *lpchiter>47 && *lpchiter<58 ; lpchiter++); *lpchiter=L'\0'; pard = _wtoi(lpchd); if(pard>31)SetWindowText((HWND)lParam,L"31"); if(pard<1)SetWindowText((HWND)lParam,L"01"); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case STW_H_ID: switch(wmEvent) { case EN_SETFOCUS: GetWindowText((HWND)lParam,lpchh,20); for(lpchiter=lpchh; *lpchiter>47 && *lpchiter<58; lpchiter++); *lpchiter=L'\0'; SetWindowText((HWND)lParam,lpchh); KeyFocusSTW[3] = true; break; case EN_KILLFOCUS: GetWindowText((HWND)lParam,lpchh,20); for(lpchiter=lpchh; *lpchiter>47 && *lpchiter<58 ; lpchiter++); *lpchiter=L'\0'; parh = _wtoi(lpchh); stwh = true; swprintf_s(lpch,L"%d час",parh); SetWindowText((HWND)lParam,lpch); KeyFocusSTW[3] = false; break; case EN_CHANGE: GetWindowText((HWND)lParam,lpchd,20); for(lpchiter=lpchd; *lpchiter>47 && *lpchiter<58 ; lpchiter++); *lpchiter=L'\0'; pard = _wtoi(lpchd); if(pard>23)SetWindowText((HWND)lParam,L"23"); if(pard<0)SetWindowText((HWND)lParam,L"00"); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; /////////// default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
int main(void) { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 800; const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera"); Rectangle player = { 400, 280, 40, 40 }; Rectangle buildings[MAX_BUILDINGS] = { 0 }; Color buildColors[MAX_BUILDINGS] = { 0 }; int spacing = 0; for (int i = 0; i < MAX_BUILDINGS; i++) { buildings[i].width = GetRandomValue(50, 200); buildings[i].height = GetRandomValue(100, 800); buildings[i].y = screenHeight - 130 - buildings[i].height; buildings[i].x = -6000 + spacing; spacing += buildings[i].width; buildColors[i] = (Color){ GetRandomValue(200, 240), GetRandomValue(200, 240), GetRandomValue(200, 250), 255 }; } Camera2D camera = { 0 }; camera.target = (Vector2){ player.x + 20, player.y + 20 }; camera.offset = (Vector2){ 0, 0 }; camera.rotation = 0.0f; camera.zoom = 1.0f; SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if (IsKeyDown(KEY_RIGHT)) { player.x += 2; // Player movement camera.offset.x -= 2; // Camera displacement with player movement } else if (IsKeyDown(KEY_LEFT)) { player.x -= 2; // Player movement camera.offset.x += 2; // Camera displacement with player movement } // Camera target follows player camera.target = (Vector2){ player.x + 20, player.y + 20 }; // Camera rotation controls if (IsKeyDown(KEY_A)) camera.rotation--; else if (IsKeyDown(KEY_S)) camera.rotation++; // Limit camera rotation to 80 degrees (-40 to 40) if (camera.rotation > 40) camera.rotation = 40; else if (camera.rotation < -40) camera.rotation = -40; // Camera zoom controls camera.zoom += ((float)GetMouseWheelMove()*0.05f); if (camera.zoom > 3.0f) camera.zoom = 3.0f; else if (camera.zoom < 0.1f) camera.zoom = 0.1f; // Camera reset (zoom and rotation) if (IsKeyPressed(KEY_R)) { camera.zoom = 1.0f; camera.rotation = 0.0f; } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); BeginMode2D(camera); DrawRectangle(-6000, 320, 13000, 8000, DARKGRAY); for (int i = 0; i < MAX_BUILDINGS; i++) DrawRectangleRec(buildings[i], buildColors[i]); DrawRectangleRec(player, RED); DrawLine(camera.target.x, -screenHeight*10, camera.target.x, screenHeight*10, GREEN); DrawLine(-screenWidth*10, camera.target.y, screenWidth*10, camera.target.y, GREEN); EndMode2D(); DrawText("SCREEN AREA", 640, 10, 20, RED); DrawRectangle(0, 0, screenWidth, 5, RED); DrawRectangle(0, 5, 5, screenHeight - 10, RED); DrawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, RED); DrawRectangle(0, screenHeight - 5, screenWidth, 5, RED); DrawRectangle( 10, 10, 250, 113, Fade(SKYBLUE, 0.5f)); DrawRectangleLines( 10, 10, 250, 113, BLUE); DrawText("Free 2d camera controls:", 20, 20, 10, BLACK); DrawText("- Right/Left to move Offset", 40, 40, 10, DARKGRAY); DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, DARKGRAY); DrawText("- A / S to Rotate", 40, 80, 10, DARKGRAY); DrawText("- R to reset Zoom and Rotation", 40, 100, 10, DARKGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
void cPlayer::Destroyed() { CloseWindow(false); m_ClientHandle = NULL; }
void WindowBase::MainBreak() { CloseWindow(); }
int main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture formats loading"); // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) Texture2D sonic[NUM_TEXTURES]; sonic[PNG_R8G8B8A8] = LoadTexture("resources/texture_formats/sonic.png"); // Load UNCOMPRESSED PVR texture data sonic[PVR_GRAYSCALE] = LoadTexture("resources/texture_formats/sonic_GRAYSCALE.pvr"); sonic[PVR_GRAY_ALPHA] = LoadTexture("resources/texture_formats/sonic_L8A8.pvr"); sonic[PVR_R5G6B5] = LoadTexture("resources/texture_formats/sonic_R5G6B5.pvr"); sonic[PVR_R5G5B5A1] = LoadTexture("resources/texture_formats/sonic_R5G5B5A1.pvr"); sonic[PVR_R4G4B4A4] = LoadTexture("resources/texture_formats/sonic_R4G4B4A4.pvr"); // Load UNCOMPRESSED DDS texture data sonic[DDS_R5G6B5] = LoadTexture("resources/texture_formats/sonic_R5G6B5.dds"); sonic[DDS_R5G5B5A1] = LoadTexture("resources/texture_formats/sonic_A1R5G5B5.dds"); sonic[DDS_R4G4B4A4] = LoadTexture("resources/texture_formats/sonic_A4R4G4B4.dds"); sonic[DDS_R8G8B8A8] = LoadTexture("resources/texture_formats/sonic_A8R8G8B8.dds"); // Load COMPRESSED DXT DDS texture data (if supported) sonic[DDS_DXT1_RGB] = LoadTexture("resources/texture_formats/sonic_DXT1_RGB.dds"); sonic[DDS_DXT1_RGBA] = LoadTexture("resources/texture_formats/sonic_DXT1_RGBA.dds"); sonic[DDS_DXT3_RGBA] = LoadTexture("resources/texture_formats/sonic_DXT3_RGBA.dds"); sonic[DDS_DXT5_RGBA] = LoadTexture("resources/texture_formats/sonic_DXT5_RGBA.dds"); // Load COMPRESSED ETC texture data (if supported) sonic[PKM_ETC1_RGB] = LoadTexture("resources/texture_formats/sonic_ETC1_RGB.pkm"); sonic[PKM_ETC2_RGB] = LoadTexture("resources/texture_formats/sonic_ETC2_RGB.pkm"); sonic[PKM_ETC2_EAC_RGBA] = LoadTexture("resources/texture_formats/sonic_ETC2_EAC_RGBA.pkm"); sonic[KTX_ETC1_RGB] = LoadTexture("resources/texture_formats/sonic_ETC1_RGB.ktx"); sonic[KTX_ETC2_RGB] = LoadTexture("resources/texture_formats/sonic_ETC2_RGB.ktx"); sonic[KTX_ETC2_EAC_RGBA] = LoadTexture("resources/texture_formats/sonic_ETC2_EAC_RGBA.ktx"); // Load COMPRESSED ASTC texture data (if supported) sonic[ASTC_4x4_LDR] = LoadTexture("resources/texture_formats/sonic_ASTC_4x4_ldr.astc"); sonic[ASTC_8x8_LDR] = LoadTexture("resources/texture_formats/sonic_ASTC_8x8_ldr.astc"); // Load COMPRESSED PVR texture data (if supported) sonic[PVR_PVRT_RGB] = LoadTexture("resources/texture_formats/sonic_PVRT_RGB.pvr"); sonic[PVR_PVRT_RGBA] = LoadTexture("resources/texture_formats/sonic_PVRT_RGBA.pvr"); int selectedFormat = PNG_R8G8B8A8; Rectangle selectRecs[NUM_TEXTURES]; for (int i = 0; i < NUM_TEXTURES; i++) { if (i < NUM_TEXTURES/2) selectRecs[i] = (Rectangle){ 40, 30 + 32*i, 150, 30 }; else selectRecs[i] = (Rectangle){ 40 + 152, 30 + 32*(i - NUM_TEXTURES/2), 150, 30 }; } // Texture sizes in KB float textureSizes[NUM_TEXTURES] = { 512*512*32/8/1024, //PNG_R8G8B8A8 (32 bpp) 512*512*8/8/1024, //PVR_GRAYSCALE (8 bpp) 512*512*16/8/1024, //PVR_GRAY_ALPHA (16 bpp) 512*512*16/8/1024, //PVR_R5G6B5 (16 bpp) 512*512*16/8/1024, //PVR_R5G5B5A1 (16 bpp) 512*512*16/8/1024, //PVR_R4G4B4A4 (16 bpp) 512*512*16/8/1024, //DDS_R5G6B5 (16 bpp) 512*512*16/8/1024, //DDS_R5G5B5A1 (16 bpp) 512*512*16/8/1024, //DDS_R4G4B4A4 (16 bpp) 512*512*32/8/1024, //DDS_R8G8B8A8 (32 bpp) 512*512*4/8/1024, //DDS_DXT1_RGB (4 bpp) -Compressed- 512*512*4/8/1024, //DDS_DXT1_RGBA (4 bpp) -Compressed- 512*512*8/8/1024, //DDS_DXT3_RGBA (8 bpp) -Compressed- 512*512*8/8/1024, //DDS_DXT5_RGBA (8 bpp) -Compressed- 512*512*4/8/1024, //PKM_ETC1_RGB (4 bpp) -Compressed- 512*512*4/8/1024, //PKM_ETC2_RGB (4 bpp) -Compressed- 512*512*8/8/1024, //PKM_ETC2_EAC_RGBA (8 bpp) -Compressed- 512*512*4/8/1024, //KTX_ETC1_RGB (4 bpp) -Compressed- 512*512*4/8/1024, //KTX_ETC2_RGB (4 bpp) -Compressed- 512*512*8/8/1024, //KTX_ETC2_EAC_RGBA (8 bpp) -Compressed- 512*512*8/8/1024, //ASTC_4x4_LDR (8 bpp) -Compressed- 512*512*2/8/1024, //ASTC_8x8_LDR (2 bpp) -Compressed- 512*512*4/8/1024, //PVR_PVRT_RGB (4 bpp) -Compressed- 512*512*4/8/1024, //PVR_PVRT_RGBA (4 bpp) -Compressed- }; SetTargetFPS(60); // Set our game to run at 60 frames-per-second //--------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if (IsKeyPressed(KEY_DOWN)) { selectedFormat++; if (selectedFormat >= NUM_TEXTURES) selectedFormat = 0; } else if (IsKeyPressed(KEY_UP)) { selectedFormat--; if (selectedFormat < 0) selectedFormat = NUM_TEXTURES - 1; } else if (IsKeyPressed(KEY_RIGHT)) { if (selectedFormat < NUM_TEXTURES/2) selectedFormat += NUM_TEXTURES/2; } else if (IsKeyPressed(KEY_LEFT)) { if (selectedFormat >= NUM_TEXTURES/2) selectedFormat -= NUM_TEXTURES/2; } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); // Draw rectangles for (int i = 0; i < NUM_TEXTURES; i++) { if (i == selectedFormat) { DrawRectangleRec(selectRecs[i], SKYBLUE); DrawRectangleLines(selectRecs[i].x, selectRecs[i].y, selectRecs[i].width, selectRecs[i].height, BLUE); DrawText(formatText[i], selectRecs[i].x + selectRecs[i].width/2 - MeasureText(formatText[i], 10)/2, selectRecs[i].y + 11, 10, DARKBLUE); } else { DrawRectangleRec(selectRecs[i], LIGHTGRAY); DrawRectangleLines(selectRecs[i].x, selectRecs[i].y, selectRecs[i].width, selectRecs[i].height, GRAY); DrawText(formatText[i], selectRecs[i].x + selectRecs[i].width/2 - MeasureText(formatText[i], 10)/2, selectRecs[i].y + 11, 10, DARKGRAY); } } // Draw selected texture if (sonic[selectedFormat].id != 0) { DrawTexture(sonic[selectedFormat], 350, -10, WHITE); } else { DrawRectangleLines(488, 165, 200, 110, DARKGRAY); DrawText("FORMAT", 550, 180, 20, MAROON); DrawText("NOT SUPPORTED", 500, 210, 20, MAROON); DrawText("ON YOUR GPU", 520, 240, 20, MAROON); } DrawText("Select texture format (use cursor keys):", 40, 10, 10, DARKGRAY); DrawText("Required GPU memory size (VRAM):", 40, 427, 10, DARKGRAY); DrawText(FormatText("%4.0f KB", textureSizes[selectedFormat]), 240, 420, 20, DARKBLUE); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- for (int i = 0; i < NUM_TEXTURES; i++) UnloadTexture(sonic[i]); CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
void IRA_Dialog::Minimize(HWND hwnd) { _CSTD CloseWindow(hwnd); }
XWindow::~XWindow() { CloseWindow(); }
void CCEGLView::release() { CloseWindow(); }
int main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)"); InitAudioDevice(); // Initialize audio device PlayMusicStream("resources/audio/guitar_noodling.ogg"); // Play music stream int framesCounter = 0; float timePlayed = 0.0f; //float volume = 1.0; SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- framesCounter++; // Testing music fading from one file to another /* if (framesCounter > 600) // Wait for 10 seconds (600 frames) { volume -= 0.01; // Decrement music volume level // When music volume level equal or lower than 0, // restore volume level and init another music file if (volume <= 0) { volume = 1.0; framesCounter = 0; PlayMusicStream("resources/audio/another_file.ogg"); } SetMusicVolume(volume); } */ if (IsWindowMinimized()) PauseMusicStream(); else ResumeMusicStream(); timePlayed = GetMusicTimePlayed()/GetMusicTimeLength()*100*4; // We scale by 4 to fit 400 pixels UpdateMusicStream(); // Update music buffer with new stream data //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawText("MUSIC SHOULD BE PLAYING!", 255, 200, 20, LIGHTGRAY); DrawRectangle(200, 250, 400, 12, LIGHTGRAY); DrawRectangle(200, 250, (int)timePlayed, 12, MAROON); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseAudioDevice(); // Close audio device (music streaming is automatically stopped) CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
int main(int argc, char **argv) { struct myargs args = {NULL}; struct RDArgs *rda; if ((IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0))) { if ((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0))) { if ((DOSBase = (struct DosLibrary *) OpenLibrary("dos.library",0))) { rda = ReadArgs("LEFT/K/N,TOP/K/N,WIDTH/N,HEIGHT/N,DEPTH/K/N,MODEID/K,OVERSCAN/K/N,SCROLL/K/N,DRAG/K/N,LIKEWB/K/N", (IPTR *)&args, NULL); if (rda) { struct Screen *screen; struct Window *w1; ULONG oserr = 0; struct TagItem tags[] = { {SA_Width, 640 }, {SA_Height, 480 }, {SA_Depth, 4 }, {TAG_IGNORE, 0 }, {TAG_IGNORE, 0 }, {TAG_IGNORE, 0 }, {TAG_IGNORE, 0 }, {TAG_IGNORE, 0 }, {TAG_IGNORE, 0 }, {TAG_IGNORE, 0 }, {SA_Title, (IPTR)"Screen opening and movement test"}, {SA_ErrorCode, (IPTR)&oserr }, {TAG_DONE, 0 } }; if (args.width) tags[0].ti_Data = *args.width; if (args.height) tags[1].ti_Data = *args.height; if (args.depth) tags[2].ti_Data = *args.depth; printf("Opening screen, size: %lux%lu, depth: %lu\n", tags[0].ti_Data, tags[1].ti_Data, tags[3].ti_Data); if (args.mode) { tags[3].ti_Tag = SA_DisplayID; tags[3].ti_Data = strtoul(args.mode, NULL, 16); printf("ModeID: 0x%08lX\n", tags[3].ti_Data); } if (args.scroll) { tags[4].ti_Tag = SA_AutoScroll; tags[4].ti_Data = *args.scroll; printf("SA_AutoScroll: %ld\n", tags[4].ti_Data); } if (args.drag) { tags[5].ti_Tag = SA_Draggable; tags[5].ti_Data = *args.drag; printf("SA_Draggable: %ld\n", tags[5].ti_Data); } if (args.likewb) { tags[6].ti_Tag = SA_LikeWorkbench; tags[6].ti_Data = *args.likewb; printf("SA_LikeWorkbench: %ld\n", tags[6].ti_Data); } if (args.oscan) { tags[7].ti_Tag = SA_Overscan; tags[7].ti_Data = *args.oscan; printf("SA_Overscan: %ld\n", tags[7].ti_Data); } if (args.left) { tags[8].ti_Tag = SA_Left; tags[8].ti_Data = *args.left; printf("SA_Left: %ld\n", tags[8].ti_Data); } if (args.top) { tags[9].ti_Tag = SA_Top; tags[9].ti_Data = *args.top; printf("SA_Top: %ld\n", tags[9].ti_Data); } screen = OpenScreenTagList(NULL, tags); if (screen) { w1 = openwindow(screen, "Screen data", W1_LEFT, W1_TOP, W1_WIDTH, W1_HEIGHT); if (w1) { WORD x = w1->BorderLeft; WORD y = w1->BorderTop; struct BitMap *bitmap = screen->RastPort.BitMap; y = drawtext(w1, x, y, "Requested size: %lux%lu", tags[0].ti_Data, tags[1].ti_Data); y = drawtext(w1, x, y, "Requested depth: %lu", tags[2].ti_Data); if (args.mode) y = drawtext(w1, x, y, "Requested ModeID: 0x%08lX", tags[3].ti_Data); y = drawtext(w1, x, y, "Actual size: %ux%u", screen->Width, screen->Height); y = drawtext(w1, x, y, "Actual ModeID: 0x%08X", screen->ViewPort.ColorMap->VPModeID); y = drawtext(w1, x, y, "Flags: 0x%04lX", screen->Flags); y = drawtext(w1, x, y, "BitMap size: %ux%u", GetBitMapAttr(bitmap, BMA_WIDTH), GetBitMapAttr(bitmap, BMA_HEIGHT)); y = drawtext(w1, x, y, "BitMap depth: %u", GetBitMapAttr(bitmap, BMA_DEPTH)); handleevents(w1, screen, x, y); CloseWindow(w1); } CloseScreen(screen); } else printf("Failed to open screen, error: %d\n", (int)oserr); FreeArgs(rda); } else printf("Error parsing arguments\n"); CloseLibrary((struct Library *)DOSBase); } CloseLibrary((struct Library *)GfxBase); } CloseLibrary((struct Library *) IntuitionBase); } return 0; } /* main */
KButton::~KButton() { if(hwnd!=0) CloseWindow(hwnd); }
bool Shell::OpenWindow(const char* name, bool attach_opengl) { WNDCLASS window_class; // Fill out the window class struct. window_class.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; window_class.lpfnWndProc = WindowProcedure; window_class.cbClsExtra = 0; window_class.cbWndExtra = 0; window_class.hInstance = instance_handle; window_class.hIcon = LoadIcon(NULL, IDI_WINLOGO); window_class.hCursor = LoadCursor(NULL, IDC_ARROW); window_class.hbrBackground = NULL; window_class.lpszMenuName = NULL; window_class.lpszClassName = name; if (!RegisterClass(&window_class)) { DisplayError("Could not register window class."); CloseWindow(); return false; } window_handle = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, name, // Window class name. name, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW, 0, 0, // Window position. 0, 0, // Window size. NULL, NULL, instance_handle, NULL); if (!window_handle) { DisplayError("Could not create window."); CloseWindow(); return false; } instance_name = name; DWORD style = WS_OVERLAPPEDWINDOW & ~WS_SIZEBOX & ~WS_MAXIMIZEBOX; DWORD extended_style = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Adjust the window size to take into account the edges RECT window_rect; window_rect.top = 0; window_rect.left = 0; window_rect.right = 1024; window_rect.bottom = 768; AdjustWindowRectEx(&window_rect, style, FALSE, extended_style); SetWindowLong(window_handle, GWL_EXSTYLE, extended_style); SetWindowLong(window_handle, GWL_STYLE, style); // Resize the window. SetWindowPos(window_handle, HWND_TOP, 0, 0, window_rect.right - window_rect.left, window_rect.bottom - window_rect.top, SWP_NOACTIVATE); // Display the new window ShowWindow(window_handle, SW_SHOW); SetForegroundWindow(window_handle); SetFocus(window_handle); // Attach OpenGL if necessary if (attach_opengl) { opengl_attached = AttachOpenGL(); if (!opengl_attached) return false; } return true; }
static int get_key(AIN_DeviceID ID, int *keycode, int *offset) { static char *window_text; struct Window *window; AIN_InputEvent *event; int done = 0; window_text = translate_text(IDS_PRESS_KEY_BUTTON); *keycode = *offset = -1; /* no key */ if (ID != -1) { ai_handle[0] = AIN_ObtainDevice(CTX, ID); if (ai_handle[0] != NULL) { AIN_SetDeviceParameter(CTX, ai_handle[0], AINDP_EVENT, TRUE); } } window = OpenWindowTags(NULL, WA_Title, (ULONG)"", WA_Flags, WFLG_NOCAREREFRESH|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_RMBTRAP|WFLG_GIMMEZEROZERO, WA_IDCMP, IDCMP_CLOSEWINDOW|WFLG_REPORTMOUSE|IDCMP_RAWKEY|IDCMP_CHANGEWINDOW, WA_Left, 100, WA_Top, 100, WA_Width, 100, WA_Height, 40, WA_Activate, TRUE, TAG_DONE); if (window != NULL) { struct IntuiMessage *imsg = NULL; ULONG imCode, imClass; /* Resize window and set pens */ int length = TextLength(window->RPort, window_text, strlen(window_text)); ChangeWindowBox(window, 100, 100, window->BorderLeft+length+window->BorderRight+8, window->BorderTop+window->IFont->tf_YSize*2+window->BorderBottom); SetAPen(window->RPort, 1); SetBPen(window->RPort, 0); /* Wait until window has been resized */ while (done == 0) { /* Wait for messages */ Wait((1L << window->UserPort->mp_SigBit) | (1L << ai_port->mp_SigBit)); /* Check for IDCMP messages */ while ((imsg = (struct IntuiMessage *)GetMsg(window->UserPort))) { imClass = imsg->Class; imCode = imsg->Code; ReplyMsg((struct Message *)imsg); if (imClass == IDCMP_CHANGEWINDOW) { Move(window->RPort, 4, window->IFont->tf_YSize); Text(window->RPort, window_text, strlen(window_text)); } else if (imClass == IDCMP_RAWKEY) { imCode &= 0x7f; if (imCode != 69) { *keycode = imCode; } done = 1; /* KEY ok */ } else if (imClass == IDCMP_CLOSEWINDOW) { done = -1; /* cancel */ } } /* Check for AI messages */ if (ai_handle[0] != NULL) { while ((event = AIN_GetEvent(CTX))) { switch(event->Type) { case AINET_AXIS: if ((event->Value >= (ONOFF_VALUE)) || (event->Value <= (-(ONOFF_VALUE)))) { *offset = event->Index; done = 2; /* AI ok */ } break; case AINET_BUTTON: *offset = event->Index; done = 2; /* AI ok */ break; case AINET_HAT: *offset = event->Index; done = 2; /* AI ok */ break; default: break; } AIN_FreeEvent(CTX, event); } } } CloseWindow(window); } if (ai_handle[0] != NULL) { AIN_SetDeviceParameter(CTX, ai_handle[0], AINDP_EVENT, FALSE); /* Remove pending AI messages */ while ((event = AIN_GetEvent(CTX))) { AIN_FreeEvent(CTX, event); } AIN_ReleaseDevice(CTX, ai_handle[0]); ai_handle[0] = NULL; } return done; }
/* HandleAvailable() * =================================================================== */ int HandleAvailable( int button, WORD *msg ) { int quit; int dclick; FON_PTR curptr; dclick = FALSE; quit = FALSE; /* Handle Double-clicking of the objects */ if( ( button != -1 ) && ( button & 0x8000 ) ) { button &= 0x7FFF; dclick = TRUE; } switch( button ) { case IEXIT: Deselect( IEXIT ); ClearFnodes( installed_list ); ClearFnodes( available_list ); Reset_Tree( ad_front ); CheckInstallAll( FALSE ); mover_setup( installed_list, installed_count, FBASE, FSLIDER, FUP, FDOWN, LINE0, LINE13, LINEBASE, 0, FRONT_HEIGHT ); HideObj( LINEBASE ); Objc_draw( tree, ROOT, MAX_DEPTH, NULL ); ShowObj( LINEBASE ); RedrawBase( tree, LINEBASE ); break; case ILINE0: case ILINE1: case ILINE2: case ILINE3: case ILINE4: case ILINE5: case ILINE6: case ILINE7: case ILINE8: case ILINE9: case ILINE10: case ILINE11: case ILINE12: case ILINE13: if( dclick ) { curptr = Active_Slit[ button - First_Obj ]; if( !curptr ) return( quit ); DoPoints( tree, button ); } else mover_button( button, dclick ); break; case IUP: case IDOWN: case IBASE: case ISLIDER: mover_button( button, dclick ); break; case IINSTALL: if( IsChanged( available_list ) ) { /* ASK if we want it install these fonts first.*/ if( form_alert( 1, alert58 ) == 2 ) { XDeselect( tree, IINSTALL ); return( quit ); } MoveToInstalled( FALSE ); } XDeselect( tree, IINSTALL ); break; case ICONFIG: Deselect( ICONFIG ); if( DoPoints( ad_inactive, 0 )) XDeselect( tree, ICONFIG ); break; case ISELECT: DoSelectAll(); XDeselect( tree, ISELECT ); break; default: if( button == -1 ) { switch( msg[0] ) { case WM_REDRAW: break; case AC_CLOSE: quit = TRUE; break; case WM_CLOSED: quit = TRUE; CloseWindow(); break; case CT_KEY: if( msg[3] == UNDO ) Undo_Fnodes( available_list, ( FON_PTR )NULL ); break; default: break; } } else Undo_Fnodes( available_list, ( FON_PTR )NULL ); break; } return( quit ); }
int main(void) { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 800; const int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [core] example - storage save/load values"); int score = 0; int hiscore = 0; int framesCounter = 0; SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if (IsKeyPressed(KEY_R)) { score = GetRandomValue(1000, 2000); hiscore = GetRandomValue(2000, 4000); } if (IsKeyPressed(KEY_ENTER)) { StorageSaveValue(STORAGE_SCORE, score); StorageSaveValue(STORAGE_HISCORE, hiscore); } else if (IsKeyPressed(KEY_SPACE)) { // NOTE: If requested position could not be found, value 0 is returned score = StorageLoadValue(STORAGE_SCORE); hiscore = StorageLoadValue(STORAGE_HISCORE); } framesCounter++; //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawText(FormatText("SCORE: %i", score), 280, 130, 40, MAROON); DrawText(FormatText("HI-SCORE: %i", hiscore), 210, 200, 50, BLACK); DrawText(FormatText("frames: %i", framesCounter), 10, 10, 20, LIME); DrawText("Press R to generate random numbers", 220, 40, 20, LIGHTGRAY); DrawText("Press ENTER to SAVE values", 250, 310, 20, LIGHTGRAY); DrawText("Press SPACE to LOAD values", 252, 350, 20, LIGHTGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
wnd::~wnd(){ ReleaseDC(whandle, hdc); CloseWindow(whandle); }
int main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 1280; int screenHeight = 960; InitWindow(screenWidth, screenHeight, "raylib example - Bunnymark"); Texture2D texBunny = LoadTexture("resources/wabbit_alpha.png"); Bunny *bunnies = (Bunny *)malloc(MAX_BUNNIES*sizeof(Bunny)); // Bunnies array int bunniesCount = 0; // Bunnies counter SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) { // Create more bunnies for (int i = 0; i < 100; i++) { bunnies[bunniesCount].position = GetMousePosition(); bunnies[bunniesCount].speed.x = (float)GetRandomValue(250, 500)/60.0f; bunnies[bunniesCount].speed.y = (float)(GetRandomValue(250, 500) - 500)/60.0f; bunniesCount++; } } // Update bunnies for (int i = 0; i < bunniesCount; i++) { bunnies[i].position.x += bunnies[i].speed.x; bunnies[i].position.y += bunnies[i].speed.y; if ((bunnies[i].position.x > GetScreenWidth()) || (bunnies[i].position.x < 0)) bunnies[i].speed.x *= -1; if ((bunnies[i].position.y > GetScreenHeight()) || (bunnies[i].position.y < 0)) bunnies[i].speed.y *= -1; } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); for (int i = 0; i < bunniesCount; i++) { // NOTE: When internal QUADS batch limit is reached, a draw call is launched and // batching buffer starts being filled again; before launching the draw call, // updated vertex data from internal buffer is send to GPU... it seems it generates // a stall and consequently a frame drop, limiting number of bunnies drawn at 60 fps DrawTexture(texBunny, bunnies[i].position.x, bunnies[i].position.y, RAYWHITE); } DrawRectangle(0, 0, screenWidth, 40, LIGHTGRAY); DrawText("raylib bunnymark", 10, 10, 20, DARKGRAY); DrawText(FormatText("bunnies: %i", bunniesCount), 400, 10, 20, RED); DrawFPS(260, 10); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- free(bunnies); CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
int main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [texture] example - texture rectangle"); // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) Texture2D guybrush = LoadTexture("resources/guybrush.png"); // Texture loading Vector2 position = { 350.0f, 240.0f }; Rectangle frameRec = { 0, 0, guybrush.width/7, guybrush.height }; int currentFrame = 0; //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if (IsKeyPressed(KEY_RIGHT)) { currentFrame++; if (currentFrame > 6) currentFrame = 0; frameRec.x = currentFrame*guybrush.width/7; } //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawTexture(guybrush, 35, 40, WHITE); DrawRectangleLines(35, 40, guybrush.width, guybrush.height, LIME); DrawTextureRec(guybrush, frameRec, position, WHITE); // Draw part of the texture DrawRectangleLines(35 + frameRec.x, 40 + frameRec.y, frameRec.width, frameRec.height, RED); DrawText("PRESS RIGHT KEY to", 540, 310, 10, GRAY); DrawText("CHANGE DRAWING RECTANGLE", 520, 330, 10, GRAY); DrawText("Guybrush Ulysses Threepwood,", 100, 300, 10, GRAY); DrawText("main character of the Monkey Island series", 80, 320, 10, GRAY); DrawText("of computer adventure games by LucasArts.", 80, 340, 10, GRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadTexture(guybrush); // Texture unloading CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
int main() { // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 800; const int screenHeight = 450; SetConfigFlags(FLAG_MSAA_4X_HINT); InitWindow(screenWidth, screenHeight, "raylib [shaders] example - basic lighting"); // Camera initialization Camera camera = {{ 8.0f, 8.0f, 8.0f }, { 0.0f, 3.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }}; // Model initialization Vector3 position = { 0.0f, 0.0f, 0.0f }; Model model = LoadModel("resources/model/dwarf.obj"); Shader shader = LoadShader("resources/shaders/phong.vs", "resources/shaders/phong.fs"); SetModelShader(&model, shader); // Shader locations initialization int lIntensityLoc = GetShaderLocation(shader, "light_intensity"); int lAmbientLoc = GetShaderLocation(shader, "light_ambientColor"); int lDiffuseLoc = GetShaderLocation(shader, "light_diffuseColor"); int lSpecularLoc = GetShaderLocation(shader, "light_specularColor"); int lSpecIntensityLoc = GetShaderLocation(shader, "light_specIntensity"); int mAmbientLoc = GetShaderLocation(shader, "mat_ambientColor"); int mSpecularLoc = GetShaderLocation(shader, "mat_specularColor"); int mGlossLoc = GetShaderLocation(shader, "mat_glossiness"); // Camera and light vectors shader locations int cameraLoc = GetShaderLocation(shader, "cameraPos"); int lightLoc = GetShaderLocation(shader, "lightPos"); // Model and View matrix locations (required for lighting) int modelLoc = GetShaderLocation(shader, "modelMatrix"); //int viewLoc = GetShaderLocation(shader, "viewMatrix"); // Not used // Light and material definitions Light light; Material matBlinn; // Light initialization light.position = (Vector3){ 4.0f, 2.0f, 0.0f }; light.direction = (Vector3){ 5.0f, 1.0f, 1.0f }; light.intensity = 1.0f; light.diffuse = WHITE; light.ambient = (Color){ 150, 75, 0, 255 }; light.specular = WHITE; light.specIntensity = 1.0f; // Material initialization matBlinn.colDiffuse = WHITE; matBlinn.colAmbient = (Color){ 50, 50, 50, 255 }; matBlinn.colSpecular = WHITE; matBlinn.glossiness = 50.0f; // Setup camera SetCameraMode(CAMERA_FREE); // Set camera mode SetCameraPosition(camera.position); // Set internal camera position to match our camera position SetCameraTarget(camera.target); // Set internal camera target to match our camera target SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update camera position // NOTE: Model transform can be set in model.transform or directly with params at draw... WATCH OUT! SetShaderValueMatrix(shader, modelLoc, model.transform); // Send model matrix to shader //SetShaderValueMatrix(shader, viewLoc, GetCameraMatrix(camera)); // Not used // Glossiness input control if(IsKeyDown(KEY_UP)) matBlinn.glossiness += SHININESS_SPEED; else if(IsKeyDown(KEY_DOWN)) { matBlinn.glossiness -= SHININESS_SPEED; if( matBlinn.glossiness < 0) matBlinn.glossiness = 0.0f; } // Light X movement if (IsKeyDown(KEY_D)) light.position.x += LIGHT_SPEED; else if(IsKeyDown(KEY_A)) light.position.x -= LIGHT_SPEED; // Light Y movement if (IsKeyDown(KEY_LEFT_SHIFT)) light.position.y += LIGHT_SPEED; else if (IsKeyDown(KEY_LEFT_CONTROL)) light.position.y -= LIGHT_SPEED; // Light Z movement if (IsKeyDown(KEY_S)) light.position.z += LIGHT_SPEED; else if (IsKeyDown(KEY_W)) light.position.z -= LIGHT_SPEED; // Send light values to shader SetShaderValue(shader, lIntensityLoc, &light.intensity, 1); SetShaderValue(shader, lAmbientLoc, ColorToFloat(light.ambient), 3); SetShaderValue(shader, lDiffuseLoc, ColorToFloat(light.diffuse), 3); SetShaderValue(shader, lSpecularLoc, ColorToFloat(light.specular), 3); SetShaderValue(shader, lSpecIntensityLoc, &light.specIntensity, 1); // Send material values to shader SetShaderValue(shader, mAmbientLoc, ColorToFloat(matBlinn.colAmbient), 3); SetShaderValue(shader, mSpecularLoc, ColorToFloat(matBlinn.colSpecular), 3); SetShaderValue(shader, mGlossLoc, &matBlinn.glossiness, 1); // Send camera and light transform values to shader SetShaderValue(shader, cameraLoc, VectorToFloat(camera.position), 3); SetShaderValue(shader, lightLoc, VectorToFloat(light.position), 3); //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); Begin3dMode(camera); DrawModel(model, position, 4.0f, matBlinn.colDiffuse); DrawSphere(light.position, 0.5f, GOLD); DrawGrid(20, 1.0f); End3dMode(); DrawFPS(10, 10); // Draw FPS EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadShader(shader); UnloadModel(model); CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
IGraphicsWin::~IGraphicsWin() { CloseWindow(); FREE_NULL(mCustomColorStorage); }
static INT_PTR CALLBACK LangOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { HWND hwndList = GetDlgItem(hwndDlg, IDC_LANGLIST); LVITEM lvi; switch(msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); hwndLangOpt = hwndDlg; ListView_SetExtendedListViewStyle(hwndList, LVS_EX_FULLROWSELECT|LVS_EX_LABELTIP); ListView_SetImageList(hwndList, CreateRadioImages(ListView_GetBkColor(hwndList), ListView_GetTextColor(hwndList)), LVSIL_STATE); /* auto-destroyed */ { LVCOLUMN lvc; lvc.mask = LVCF_TEXT; lvc.pszText = TranslateT("Installed Languages"); ListView_InsertColumn(hwndList, 0, &lvc); } if ( ServiceExists(MS_FLAGS_LOADFLAGICON)) ListView_SetImageList(hwndList, ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR24, 8, 8), LVSIL_SMALL); TCHAR szPath[MAX_PATH]; GetPackPath(szPath, SIZEOF(szPath), FALSE, _T("")); SetDlgItemText(hwndDlg, IDC_SKINROOTFOLDER, szPath); SendMessage(hwndDlg, M_RELOADLIST, 0, 0); SendMessage(hwndDlg, M_SHOWFILECOL, 0, 1); return TRUE; case M_RELOADLIST: /* init list */ ListView_DeleteAllItems(hwndList); ListView_DeleteColumn(hwndList, 1); /* if present */ { HIMAGELIST himl = ListView_GetImageList(hwndList, LVSIL_SMALL); ImageList_RemoveAll(himl); /* enum all packs */ EnumPacks(InsertPackItemEnumProc, _T("langpack_*.txt"), "Miranda Language Pack Version 1", (WPARAM)hwndList, (LPARAM)himl); /* make it use current langpack locale for sort */ ListView_SortItems(hwndList, CompareListItem, CallService(MS_LANGPACK_GETLOCALE, 0, 0)); //CheckDlgButton(hwndDlg, IDC_ENABLEAUTOUPDATES, db_get_b(NULL, "LangMan", "EnableAutoUpdates", SETTING_ENABLEAUTOUPDATES_DEFAULT) != 0); /* show selection */ int iItem = ListView_GetNextItem(hwndList, -1, LVNI_SELECTED); if (iItem != -1) ListView_EnsureVisible(hwndList, iItem, FALSE); } return TRUE; case M_SHOWFILECOL: if ((BOOL)lParam && ListView_GetItemCount(hwndList) > 1) { /* add column */ LVCOLUMN lvc; ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE_USEHEADER); lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; lvc.pszText = TranslateT("File"); lvc.cx = 160; ListView_InsertColumn(hwndList, lvc.iSubItem = 1, &lvc); ListView_SetColumnWidth(hwndList, 0, ListView_GetColumnWidth(hwndList, 0) - lvc.cx); /* add text */ lvi.mask = LVIF_PARAM; lvi.iSubItem = 0; for (lvi.iItem = 0; ListView_GetItem(hwndList, &lvi); ++lvi.iItem) { LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam; ListView_SetItemText(hwndList, lvi.iItem, 1, (pack->flags&LPF_DEFAULT) ? TranslateT("built-in") : pack->szFileName); } } else { ListView_DeleteColumn(hwndList, 1); ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE_USEHEADER); } return TRUE; case WM_DESTROY: ListView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_LANGLIST)); return TRUE; case WM_THEMECHANGED: case WM_SETTINGCHANGE: { HIMAGELIST himl = ListView_SetImageList(hwndList, CreateRadioImages(ListView_GetBkColor(hwndList), ListView_GetTextColor(hwndList)), LVSIL_STATE); /* auto-destroyed */ if (himl != NULL) ImageList_Destroy(himl); } break; case WM_CTLCOLORLISTBOX: /* mimic readonly edit */ return (BOOL)SendMessage(hwndDlg, WM_CTLCOLORSTATIC, wParam, lParam); case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_LANGEMAIL: { char buf[512]; lstrcpyA(buf, "mailto:"); if (GetWindowTextA(GetDlgItem(hwndDlg, LOWORD(wParam)), &buf[7], sizeof(buf)-7)) CallService(MS_UTILS_OPENURL, FALSE, (LPARAM)buf); return TRUE; } case IDC_MORELANG: CallService(MS_UTILS_OPENURL, TRUE, (LPARAM)"http://miranda-ng.org/"); return TRUE; } break; case WM_CONTEXTMENU: if (GetDlgCtrlID((HWND)wParam) == IDC_LANGLIST) { /* get item */ LVHITTESTINFO hti; POINTSTOPOINT(hti.pt, MAKEPOINTS(lParam)); if (hti.pt.x == -1 && hti.pt.y == -1) { /* keyboard invoked */ hti.iItem = ListView_GetNextItem((HWND)wParam, -1, LVNI_SELECTED); if (hti.iItem != -1) break; RECT rc; if (!ListView_GetItemRect((HWND)wParam, hti.iItem, &rc, LVIR_SELECTBOUNDS)) break; hti.pt.x = rc.left + (rc.right - rc.left) / 2; hti.pt.y = rc.top + (rc.bottom - rc.top) / 2; ClientToScreen((HWND)wParam, &hti.pt); } else { ScreenToClient((HWND)wParam, &hti.pt); if (ListView_HitTest((HWND)wParam, &hti) == -1 || !(hti.flags&LVHT_ONITEM)) break; POINTSTOPOINT(hti.pt, MAKEPOINTS(lParam)); } /* param */ lvi.iItem = hti.iItem; lvi.iSubItem = 0; lvi.mask = LVIF_PARAM; if (!ListView_GetItem((HWND)wParam, &lvi)) break; /* context menu */ LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam; if (!(pack->flags & LPF_DEFAULT)) { HMENU hContextMenu = CreatePopupMenu(); if (hContextMenu != NULL) { AppendMenu(hContextMenu, MF_STRING, 2, TranslateT("&Remove...")); if (TrackPopupMenuEx(hContextMenu, TPM_RETURNCMD | TPM_NONOTIFY | TPM_TOPALIGN | TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_HORPOSANIMATION | TPM_VERPOSANIMATION, hti.pt.x, hti.pt.y, (HWND)wParam, NULL)) DeletePackFile(hwndDlg, (HWND)wParam, hti.iItem, pack); DestroyMenu(hContextMenu); } } return TRUE; } break; case WM_NOTIFYFORMAT: SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, NFR_UNICODE); return TRUE; case WM_NOTIFY: NMHDR *nmhdr = (NMHDR*)lParam; switch (nmhdr->idFrom) { case IDC_LANGLIST: switch (nmhdr->code) { case LVN_DELETEITEM: lvi.iItem = ((NMLISTVIEW*)lParam)->iItem; /* nmlv->lParam is invalid */ lvi.iSubItem = 0; lvi.mask = LVIF_PARAM; if (ListView_GetItem(nmhdr->hwndFrom, &lvi)) mir_free((LANGPACK_INFO*)lvi.lParam); break; case LVN_ITEMCHANGED: { NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam; if (!(nmlv->uChanged&LVIF_STATE)) break; /* display info and check radio item */ if (nmlv->uNewState&LVIS_SELECTED && !(nmlv->uOldState&LVIS_SELECTED)) { ListView_SetItemState(nmhdr->hwndFrom, nmlv->iItem, INDEXTOSTATEIMAGEMASK(2), LVIS_STATEIMAGEMASK); DisplayPackInfo(hwndDlg, (LANGPACK_INFO*)nmlv->lParam); } /* disable all other radio items */ else if (nmlv->uNewState&INDEXTOSTATEIMAGEMASK(2)) { for (int iItem = ListView_GetItemCount(nmhdr->hwndFrom) - 1; iItem != -1; --iItem) if (iItem != nmlv->iItem) ListView_SetItemState(nmhdr->hwndFrom, iItem, INDEXTOSTATEIMAGEMASK(1), LVIS_STATEIMAGEMASK); /* enable apply */ if (nmlv->uOldState) { SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); ShowWindow(GetDlgItem(hwndDlg, IDC_RESTART), SW_SHOW); } } } break; case LVN_KEYDOWN: { int iItem = ListView_GetNextItem(nmhdr->hwndFrom, -1, LVNI_SELECTED); switch (((NMLVKEYDOWN*)lParam)->wVKey) { case VK_SPACE: ListView_SetItemState(nmhdr->hwndFrom, iItem, INDEXTOSTATEIMAGEMASK(2), LVIS_STATEIMAGEMASK); break; case VK_DELETE: lvi.iItem = iItem; lvi.iSubItem = 0; lvi.mask = LVIF_PARAM; if (ListView_GetItem(nmhdr->hwndFrom, &lvi)) { LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam; if (!(pack->flags&LPF_DEFAULT)) DeletePackFile(hwndDlg, nmhdr->hwndFrom, iItem, pack); } break; } } break; case NM_CLICK: LVHITTESTINFO hti; lParam = GetMessagePos(); POINTSTOPOINT(hti.pt, MAKEPOINTS(lParam)); ScreenToClient(nmhdr->hwndFrom, &hti.pt); if (ListView_HitTest(nmhdr->hwndFrom, &hti) != -1) if (hti.flags&(LVHT_ONITEMSTATEICON | LVHT_ONITEMICON)) /* one of them */ ListView_SetItemState(nmhdr->hwndFrom, hti.iItem, LVIS_SELECTED, LVIS_SELECTED); } break; case 0: switch (nmhdr->code) { case PSN_APPLY: lvi.mask = LVIF_STATE | LVIF_PARAM; lvi.stateMask = LVIS_STATEIMAGEMASK; lvi.iSubItem = 0; for (lvi.iItem = 0; ListView_GetItem(hwndList, &lvi); ++lvi.iItem) { LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam; if (lvi.state&INDEXTOSTATEIMAGEMASK(2) && !(pack->flags & LPF_ENABLED)) { if(!(pack->flags & LPF_DEFAULT)) db_set_ws(NULL, "LangMan", "Langpack", pack->szFileName); else db_unset(NULL, "LangMan", "Langpack"); TCHAR szPath[MAX_PATH]; GetPackPath(szPath, SIZEOF(szPath), FALSE, pack->szFileName); CallService(MS_LANGPACK_RELOAD, 0, (LPARAM)szPath); pack->flags |= LPF_ENABLED; CloseWindow(GetParent(hwndDlg)); DestroyWindow(GetParent(hwndDlg)); } else pack->flags &= ~LPF_ENABLED; } return TRUE; } } break; } return FALSE; }
void SampleApp::TerminateApp() { TerminateD3D11(); CloseWindow(); }