Пример #1
0
//	HINSTANCE InHInstance,
void FLinuxWindow::Initialize( FLinuxApplication* const Application, const TSharedRef< FGenericWindowDefinition >& InDefinition, const TSharedPtr< FLinuxWindow >& InParent, const bool bShowImmediately )
{
	Definition = InDefinition;
	OwningApplication = Application;
	ParentWindow = InParent;

	if (!FPlatformMisc::PlatformInitMultimedia()) //	will not initialize more than once
	{
		UE_LOG(LogInit, Fatal, TEXT("FLinuxWindow::Initialize() : PlatformInitMultimedia() failed, cannot initialize window."));
		// unreachable
		return;
	}

#if DO_CHECK
	uint32 InitializedSubsystems = SDL_WasInit(SDL_INIT_EVERYTHING);
	check(InitializedSubsystems & SDL_INIT_VIDEO);
#endif // DO_CHECK

	// Finally, let's initialize the new native window object.  Calling this function will often cause OS
	// window messages to be sent! (such as activation messages)
	uint32 WindowExStyle = 0;
	uint32 WindowStyle = 0;

	RegionWidth = RegionHeight = INDEX_NONE;

	const float XInitialRect = Definition->XDesiredPositionOnScreen;
	const float YInitialRect = Definition->YDesiredPositionOnScreen;

	const float WidthInitial = Definition->WidthDesiredOnScreen;
	const float HeightInitial = Definition->HeightDesiredOnScreen;

	int32 X = FMath::TruncToInt( XInitialRect + 0.5f );
	int32 Y = FMath::TruncToInt( YInitialRect + 0.5f );
	int32 ClientWidth = FMath::TruncToInt( WidthInitial + 0.5f );
	int32 ClientHeight = FMath::TruncToInt( HeightInitial + 0.5f );
	int32 WindowWidth = ClientWidth;
	int32 WindowHeight = ClientHeight;

	WindowStyle |= SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;

	if ( !Definition->HasOSWindowBorder )
	{
		WindowStyle |= SDL_WINDOW_BORDERLESS;

		if (Definition->IsTopmostWindow)
		{
			WindowStyle |= SDL_WINDOW_ALWAYS_ON_TOP;
		}

		if (!Definition->AppearsInTaskbar)
		{
			WindowStyle |= SDL_WINDOW_SKIP_TASKBAR;
		}

		if (Definition->IsRegularWindow && Definition->HasSizingFrame)
		{
			WindowStyle |= SDL_WINDOW_RESIZABLE;
		}
	}

	// This is a tool tip window.
	if (!InParent.IsValid() && !Definition->HasOSWindowBorder &&
		!Definition->AcceptsInput && Definition->IsTopmostWindow && 
		!Definition->AppearsInTaskbar && !Definition->HasSizingFrame &&
		!Definition->IsModalWindow && !Definition->IsRegularWindow &&
		Definition->SizeWillChangeOften)
	{
		WindowStyle |= SDL_WINDOW_TOOLTIP;
		bIsTooltipWindow = true;
		UE_LOG(LogLinuxWindowType, Verbose, TEXT("*** New Window is a Tooltip Window ***"));
	}
	// This is a notification window.
	else if (InParent.IsValid() && !Definition->HasOSWindowBorder &&
		Definition->AcceptsInput && !Definition->IsTopmostWindow && 
		!Definition->AppearsInTaskbar && !Definition->HasSizingFrame &&
		!Definition->IsModalWindow && !Definition->IsRegularWindow &&
		!Definition->ActivateWhenFirstShown && Definition->SizeWillChangeOften)
	{
		WindowStyle |= SDL_WINDOW_NOTIFICATION;
		bIsNotificationWindow = true;
		UE_LOG(LogLinuxWindowType, Verbose, TEXT("*** New Window is a Notification Window ***"));
	}
	// Is it another notification window?
	else if (InParent.IsValid() && !Definition->HasOSWindowBorder &&
		Definition->AcceptsInput && !Definition->IsTopmostWindow && 
		!Definition->AppearsInTaskbar && !Definition->HasSizingFrame &&
		Definition->IsModalWindow && !Definition->IsRegularWindow &&
		Definition->ActivateWhenFirstShown && !Definition->SizeWillChangeOften)
	{
		WindowStyle |= SDL_WINDOW_NOTIFICATION;
		bIsNotificationWindow = true;
		UE_LOG(LogLinuxWindowType, Verbose, TEXT("*** New Window is another Notification Window ***"));
	}
	// This is a popup menu window?
	else if (InParent.IsValid() && !Definition->HasOSWindowBorder &&
		Definition->AcceptsInput && !Definition->IsTopmostWindow && 
		!Definition->AppearsInTaskbar && !Definition->HasSizingFrame &&
		!Definition->IsModalWindow && !Definition->IsRegularWindow &&
		Definition->ActivateWhenFirstShown && !Definition->SizeWillChangeOften)
	{
		WindowStyle |= SDL_WINDOW_POPUP_MENU;
		bIsPopupWindow = true;
		UE_LOG(LogLinuxWindowType, Verbose, TEXT("*** New Window is a Popup Menu Window ***"));
	}
	// Is it a console window?
	else if( InParent.IsValid() && !Definition->HasOSWindowBorder &&
		Definition->AcceptsInput && !Definition->IsTopmostWindow && 
		!Definition->AppearsInTaskbar && !Definition->HasSizingFrame &&
		!Definition->IsModalWindow && !Definition->IsRegularWindow &&
		!Definition->ActivateWhenFirstShown && !Definition->SizeWillChangeOften)
	{
		WindowStyle |= SDL_WINDOW_POPUP_MENU;
		bIsConsoleWindow = true;
		bIsPopupWindow = true;
		UE_LOG(LogLinuxWindowType, Verbose, TEXT("*** New Window is a Console Window ***"));
	}
	// Is it a drag and drop window?
	else if (!InParent.IsValid() && !Definition->HasOSWindowBorder &&
		!Definition->AcceptsInput && Definition->IsTopmostWindow && 
		!Definition->AppearsInTaskbar && !Definition->HasSizingFrame &&
		!Definition->IsModalWindow && !Definition->IsRegularWindow &&
		!Definition->ActivateWhenFirstShown && !Definition->SizeWillChangeOften)
	{
		// TODO Experimental (The SDL_WINDOW_DND sets focus)
		WindowStyle |= SDL_WINDOW_DND;
		bIsDragAndDropWindow = true;
		UE_LOG(LogLinuxWindowType, Verbose, TEXT("*** New Window is a Drag and Drop Window ***"));
	}
	// Is modal dialog window?
	else if (InParent.IsValid() && !Definition->HasOSWindowBorder &&
		Definition->AcceptsInput && !Definition->IsTopmostWindow && 
		Definition->AppearsInTaskbar && !Definition->HasSizingFrame &&
		Definition->IsModalWindow && Definition->IsRegularWindow &&
		Definition->ActivateWhenFirstShown && !Definition->SizeWillChangeOften)
	{
		WindowStyle |= SDL_WINDOW_DIALOG;
		bIsDialogWindow = true;
		UE_LOG(LogLinuxWindowType, Verbose, TEXT("*** New Window is a Modal Dialog Window ***"));
	}
	// Is a Blueprint, Cascade, etc. utility window.
	else if (InParent.IsValid() && !Definition->HasOSWindowBorder &&
		Definition->AcceptsInput && !Definition->IsTopmostWindow && 
		Definition->AppearsInTaskbar && Definition->HasSizingFrame &&
		!Definition->IsModalWindow && Definition->IsRegularWindow &&
		Definition->ActivateWhenFirstShown && !Definition->SizeWillChangeOften)
	{
		WindowStyle |= SDL_WINDOW_DIALOG;
		bIsUtilityWindow = true;
		UE_LOG(LogLinuxWindowType, Verbose, TEXT("*** New Window is a BP, Cascade, etc. Window ***"));
	}
	else
	{
		UE_LOG(LogLinuxWindowType, Verbose, TEXT("*** New Window is TopLevel Window ***"));
		bIsTopLevelWindow = true;
	}

	//	The SDL window doesn't need to be reshaped.
	//	the size of the window you input is the sizeof the client.
	HWnd = SDL_CreateWindow( TCHAR_TO_ANSI( *Definition->Title ), X, Y, ClientWidth, ClientHeight, WindowStyle  );
	SDL_SetWindowHitTest( HWnd, FLinuxWindow::HitTest, this );

	/* 
		Do not set for Notification Windows the transient flag because the WM's usually raise the the parent window
		if the Notificaton Window gets raised. That behaviour is to aggresive and disturbs users doing other things 
		while UE4 calculates lights and other things and pop ups notifications. Notifications will be handled so that 
		they are some sort of independend but will be raised if the TopLevel Window gets focused or activated.
	*/
	// Make the Window modal for it's parent.
	if (bIsUtilityWindow || bIsDialogWindow || bIsConsoleWindow || bIsDialogWindow)
	{
		SDL_SetWindowModalFor(HWnd, InParent->GetHWnd());
	}

	VirtualWidth  = ClientWidth;
	VirtualHeight = ClientHeight;

	// attempt to early cache native properties
	CacheNativeProperties();

	// We call reshape window here because we didn't take into account the non-client area
	// in the initial creation of the window. Slate should only pass client area dimensions.
	// Reshape window may resize the window if the non-client area is encroaching on our
	// desired client area space.
	ReshapeWindow( X, Y, ClientWidth, ClientHeight );

	if (HWnd == nullptr)
	{
		// @todo Error message should be localized!
		checkf(false, TEXT("Window creation failed (%s)"), UTF8_TO_TCHAR(SDL_GetError()));
		return;
	}

	if ( Definition->TransparencySupport == EWindowTransparency::PerWindow )
	{
		SetOpacity( Definition->Opacity );
	}

	// TODO This can be removed later - for debugging purposes.
	WindowSDLID = SDL_GetWindowID( HWnd );
}
Пример #2
0
int main(int argc, char **argv)
{
    int done = 0;
    SDL_Window *window;
    SDL_Renderer *renderer;

    /* !!! FIXME: check for errors. */
    SDL_Init(SDL_INIT_VIDEO);
    window = SDL_CreateWindow("Drag the red boxes", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE);
    renderer = SDL_CreateRenderer(window, -1, 0);

    if (SDL_SetWindowHitTest(window, hitTest, NULL) == -1) {
        SDL_Log("Enabling hit-testing failed!\n");
        SDL_Quit();
        return 1;
    }

    while (!done)
    {
        SDL_Event e;
        int nothing_to_do = 1;

        SDL_SetRenderDrawColor(renderer, 0, 0, 127, 255);
        SDL_RenderClear(renderer);
        SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
        SDL_RenderFillRects(renderer, areas, SDL_arraysize(drag_areas));
        SDL_RenderPresent(renderer);

        while (SDL_PollEvent(&e)) {
            nothing_to_do = 0;

            switch (e.type)
            {
                case SDL_MOUSEBUTTONDOWN:
                    SDL_Log("button down!\n");
                    break;

                case SDL_MOUSEBUTTONUP:
                    SDL_Log("button up!\n");
                    break;

                case SDL_WINDOWEVENT:
                    if (e.window.event == SDL_WINDOWEVENT_MOVED) {
                        SDL_Log("Window event moved to (%d, %d)!\n", (int) e.window.data1, (int) e.window.data2);
                    }
                    break;

                case SDL_KEYDOWN:
                    if (e.key.keysym.sym == SDLK_ESCAPE) {
                        done = 1;
                    } else if (e.key.keysym.sym == SDLK_x) {
                        if (!areas) {
                            areas = drag_areas;
                            numareas = SDL_arraysize(drag_areas);
                        } else {
                            areas = NULL;
                            numareas = 0;
                        }
                    }
                    break;

                case SDL_QUIT:
                    done = 1;
                    break;
            }
        }

        if (nothing_to_do) {
            SDL_Delay(50);
        }
    }

    SDL_Quit();
    return 0;
}