Пример #1
0
int WINAPI wWinMain(HINSTANCE /* hInstance */, HINSTANCE /* hPrevInstance */, LPWSTR lpCmdLine, int /* nCmdShow */)
{
	LPWSTR* arg_list;
	int arg_num = 0;

    // Ignore the return value because we want to continue running even in the
    // unlikely event that HeapSetInformation fails.
    HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);

    if (SUCCEEDED(CoInitialize(NULL)))
    {
		App *app = new App();
		arg_list = CommandLineToArgvW(lpCmdLine, &arg_num);
		if (arg_num == 2)
		{
			CardData data;
			strcpy_s(data.username, ws2s(arg_list[0]).c_str());
			strcpy_s(data.password, ws2s(arg_list[1]).c_str());

			try
			{
				NFC_READER->Initialize();
				NFC_READER->Write(data);
				NFC_READER->Uninitialize();
			}
			catch (...)
			{
				MessageBox(NULL, L"שגיאה התרחשה בכתיבה לכרטיס או שלא נמצא כרטיס...", L"שים/י לב!", STDMSGBOX | MB_ICONWARNING);
				return 1;
			}
			return 0;
		}
        if (SUCCEEDED(app->Initialize()))
        {
			app->ChangeScreenTo(App::Screens::WaitingToCardScreen);
			MSG msg;
			memset(&msg, 0, sizeof(msg));
			while (app->AppMode != -1)
			{
				if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
				{
					TranslateMessage(&msg);
					DispatchMessage(&msg);
				}

				app->Update();
				app->Render();
			}
        }
		delete app;
        CoUninitialize();
    }
	
    return 0;
}
Пример #2
0
/**
 * Available start arguments:
 * /sample-data: Adds a list of sample books and students to the System on startup.
 */
int main(int argc, char *argv[])
{
    // Global instances used in the application:
    LMS* lmsInstance = new LMS();
    IO* ioInstance = new IO();
    App *app = new App(lmsInstance, ioInstance);

    // Build the menu structure:
    Menu* mQuery = new Menu("Query the library");
    mQuery->AddAction("Show book info", Actions::BooksInfo);
    mQuery->AddAction("Show student info", Actions::StudentsInfo);
    mQuery->AddAction("Show borrowed books", Actions::BorrowedBooks);
    mQuery->AddAction("Show overdue books", Actions::OverdueBooks);
    mQuery->AddAction("Show book records", Actions::ShowRecords);
    mQuery->AddAction("Show all registered books", Actions::ShowAllBooks);
    mQuery->AddAction("Show all registered students", Actions::ShowAllStudents);
    
    Menu* mManageData = new Menu("Manage data");
    mManageData->AddAction("Register a new book", Actions::CreateBook);
    mManageData->AddAction("Update a book", Actions::UpdateBook);
    mManageData->AddAction("Remove a book", Actions::RemoveBook);
    mManageData->AddAction("Register a new student", Actions::CreateStudent);
    mManageData->AddAction("Update a student", Actions::UpdateStudent);
    mManageData->AddAction("Remove a student", Actions::RemoveStudent);

    Menu* mExport = new Menu("Export data");
    mExport->AddAction("Export books", Actions::ExportBooks);
    mExport->AddAction("Export students", Actions::ExportStudents);

    Menu* mRoot = new Menu("Main Menu");
    mRoot->AddAction("Borrow a book", Actions::BorrowBook);
    mRoot->AddAction("Return a book", Actions::ReturnBook);
    mRoot->AddSubItem(mManageData);
    mRoot->AddSubItem(mQuery);
    mRoot->AddSubItem(mExport);

    // Show the start screen:
    cout << "Welcome to LMS (Library Management System)!" << endl;
    cout << "Enter the number of an action or menu to navigate through the programme." << endl;
    cout << "You can enter a single 'q' at any moment to quit an action or move a menu up." << endl;
    cout << "Have Fun!" << endl << endl;


    // Add some sample data if requested:
    // hint: argv[0] is the name of the program.
    if (argc > 1 && std::string(argv[1]) == "--sample-data") {
        lmsInstance->AddBook("1234567890", "how to C++", "Hans Hacker", "Coding Inc.", 2012, 3);
        lmsInstance->AddBook("1234567891", "How to Javascript", "Willi Web", "Coding Inc.", 2012, 5);
        lmsInstance->AddBook("1234567892", "How to have fun outside", "Ferdinand Fun", "Better Life Publications", 2012,
                             5);
        lmsInstance->AddStudent("0123456", "Remo Zumsteg", "Department of Industrial Engineering & Management",
                                "*****@*****.**");
        lmsInstance->AddStudent("0123457", "Hans Noetig", "Department of Education", "*****@*****.**");
        lmsInstance->AddStudent("0123458", "Suppe Chasper", "Department of Art", "*****@*****.**");
    }



    // Render the main menu:
    app->Render(mRoot);

    cout << "Good bye!" << endl;
    return 0;
}
Пример #3
0
LRESULT CALLBACK App::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    LRESULT result = 0;

    if (message == WM_CREATE)
    {
        LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam;
        App *pApp = (App *)pcs->lpCreateParams;

        ::SetWindowLongPtrW(
            hwnd,
            GWLP_USERDATA,
            PtrToUlong(pApp)
            );

        result = 1;
    }
    else
    {
        App *pApp = reinterpret_cast<App *>(static_cast<LONG_PTR>(
            ::GetWindowLongPtrW(
                hwnd,
                GWLP_USERDATA
                )));

        bool wasHandled = false;

        if (pApp)
        {
            switch (message)
            {
            case WM_SIZE:
                {
                    UINT width = LOWORD(lParam);
                    UINT height = HIWORD(lParam);
                    pApp->OnResize(width, height);
                }
                result = 0;
                wasHandled = true;
                break;

            case WM_DISPLAYCHANGE:
                {
                    InvalidateRect(hwnd, NULL, FALSE);
                }
                result = 0;
                wasHandled = true;
                break;

            case WM_PAINT:
                {
                    pApp->Render();

                    ValidateRect(hwnd, NULL);
                }
                result = 0;
                wasHandled = true;
                break;

            case WM_DESTROY:
                {
					ins->AppMode = -1;
                    PostQuitMessage(0);
                }
                result = 1;
                wasHandled = true;
                break;
            }
        }

        if (!wasHandled)
        {
            result = DefWindowProc(hwnd, message, wParam, lParam);
        }
    }

    return result;
}
Пример #4
0
int main(int _argc, char** _argv) {
    bool fail = false;

    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        LOG_ERR("SDL_Init() failed");
        return 0;
    }

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);

    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 24);

    SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 8);

    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);

    SDL_WM_SetCaption("Drash", nullptr);

    if (SDL_SetVideoMode(gWindowWidth, gWindowHeight, 32,
                         SDL_HWSURFACE | SDL_OPENGL | SDL_GL_DOUBLEBUFFER) ==
        nullptr) {
        LOG_ERR("SDL_SetVideoMode() failed");
        fail = true;
    }

    glViewport(0, 0, gWindowWidth, gWindowHeight);
    greng::Greng greng;
    greng.GetViewport().SetSize({ gWindowWidth, gWindowHeight });

    if (glewInit() != GLEW_OK) {
        LOG_ERR("glewInit() failed");
        fail = true;
    }

    int img_flags = IMG_INIT_PNG;

    if (IMG_Init(img_flags) != img_flags) {
        LOG_ERR("IMG_Init() failed");
        fail = true;
    }

    LOG_INFO("OpenGL version: " << (const char*)glGetString(GL_VERSION));
    LOG_INFO("Vendor: " << (const char*)glGetString(GL_VENDOR));
    LOG_INFO("GLSL version: " << (const char*)glGetString(
                                     GL_SHADING_LANGUAGE_VERSION));

    App* app = nullptr;

    if (fail == false) {
        for (int i = 0; i < _argc; i++) {
            if (strcmp("--test", _argv[i]) == 0) {
                if (++i < _argc) {
                    app = test::StartApp(greng, _argv[i]);

                    if (app == nullptr) {
                        LOG_ERR("drash::test::StartApp() failed");
                    }

                    break;
                }
            }
        }
    }

    Timer timer;
    timer.Reset(true);

    if (fail == false && app != nullptr) {
        glViewport(0, 0, gWindowWidth, gWindowHeight);
        app->GetGreng().GetCameraManager().SetAspectRatio(gWindowWidth /
                                                          gWindowHeight);
        greng.GetViewport().SetSize({ gWindowWidth, gWindowHeight });
        app->GetUISystem().SetAspectRatio(gWindowWidth / gWindowHeight);
        app->GetUISystem().SetWidth(gWindowWidth);

        bool exit = false;
        SDL_Event e;

        app->SetQuitHandler([&exit]() { exit = true; });

        auto update_cursor = [&app](int _x, int _y) {
            Vec2f pos(_x, _y);
            WindowSpaceToScreenSpace(pos);
            app->SetCursorPos(pos);
            int x;
            int y;
            app->GetUISystem().ScreenSpaceToUISpace(pos, x, y);
            app->GetUISystem().SetCursorPos(x, y);
        };

        for (;;) {
            while (SDL_PollEvent(&e)) {
                if (e.type == SDL_QUIT) {
                    exit = true;
                    break;
                } else if (e.type == SDL_KEYDOWN) {
                    app->GetEventSystem().BeginEvent(
                        ConvertKey(e.key.keysym.sym));
                } else if (e.type == SDL_KEYUP) {
                    app->GetEventSystem().EndEvent(
                        ConvertKey(e.key.keysym.sym));
                } else if (e.type == SDL_MOUSEBUTTONDOWN) {
                    update_cursor(e.button.x, e.button.y);
                    app->GetUISystem().BeginEvent();
                    app->GetEventSystem().BeginEvent(
                        ConvertButton(e.button.button));
                } else if (e.type == SDL_MOUSEBUTTONUP) {
                    update_cursor(e.button.x, e.button.y);
                    app->GetUISystem().EndEvent();
                    app->GetEventSystem().EndEvent(
                        ConvertButton(e.button.button));
                } else if (e.type == SDL_MOUSEMOTION) {
                    update_cursor(e.motion.x, e.motion.y);
                } else if (e.type == SDL_VIDEORESIZE) {
                    gWindowWidth = e.resize.w;
                    gWindowHeight = e.resize.h;
                    if (SDL_SetVideoMode(gWindowWidth, gWindowHeight, 32,
                                         SDL_HWSURFACE | SDL_OPENGL |
                                             SDL_GL_DOUBLEBUFFER) == nullptr) {
                        LOG_ERR("SDL_SetVideoMode() failed");
                        exit = true;
                    }

                    glViewport(0, 0, gWindowWidth, gWindowHeight);
                    app->GetGreng().GetCameraManager().SetAspectRatio(
                        gWindowWidth / gWindowHeight);
                    greng.GetViewport().SetSize(
                        { gWindowWidth, gWindowHeight });
                    app->GetUISystem().SetAspectRatio(gWindowWidth /
                                                      gWindowHeight);
                    app->GetUISystem().SetWidth(gWindowWidth);
                }
            }

            timer.Tick();
            app->Step(timer.GetDeltaTime());
            glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            app->Render();
            SDL_GL_SwapBuffers();

            if (exit == true) {
                break;
            }
        }

        delete app;
        app = nullptr;
    }

    IMG_Quit();
    SDL_Quit();

    return 0;
}