In Allegro, I can set the Window to be resizeable by running
al_set_new_display_flags(ALLEGRO_RESIZABLE);
before
display = al_create_display(800, 600);
however, if I resize the window, how will I know how big the window is that I resize?
use al_get_window_constraints(ALLEGRO_DISPLAY *display,
int *min_w, int *min_h, int *max_w, int *max_h).
Source
If you want to respond dynamically as the window is resized, you should listen for ALLEGRO_EVENT_DISPLAY_RESIZE. Note that you'll have to register your display as a source for your event queue first:
al_register_event_source(event_queue, al_get_display_event_source(display));
Related
I need an image to be resized to entire window and maintain the option to shrink/resize window.
As a separate task it is easily accomplished but not together.
Example code that I use is:
myWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(myWindow), "name");
gtk_window_set_default_size(GTK_WINDOW(myWindow), myWidth, myHeight);
gtk_window_set_resizable(GTK_WINDOW(myWindow), TRUE);
g_signal_connect(myWindow, "delete-event", G_CALLBACK(PrivDeleteEvent), this);
g_signal_connect(myWindow, "destroy", G_CALLBACK(PrivOnDestroy), this);
myImage = gtk_image_new();
GtkWidget* container = gtk_alignment_new(0, 0, 1, 1);
gtk_container_add(GTK_CONTAINER(myWindow), container);
gtk_container_add(GTK_CONTAINER(container), myImage);
g_signal_connect(myImage, "expose-event", G_CALLBACK(PrivOnImageExposeEvent), this);
gtk_widget_show_all(myWindow);
gtk_main();
void
PrivSetImage()
{
GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(...);
gtk_image_set_from_pixbuf(GTK_IMAGE(myImage), pixbuf);
}
After image widget resized I call some rendering stuff and then show it in the GtkImage itself. This works good, i see image and I am able to resize window. But after gtk_image_set_from_pixbuf called I no longer able to shrink window smaller than size used to create Pixbuf. As if somewhere inside there is a call to gtk_widget_set_size_request with Pixbuf dimensions which blocks window to shrink past pixbuf size.
Any suggestion ?
I'm very new to Qt and trying to create application, that includes main window, QDockWidget and a button.
Suppose my main window has 1280 x 720 resolution. Then I want to implement QDockWidget that pop up from the left side, width of dockWidth and height of 720 without windowTitleBar. The button has size of (buttonWidth, 720). At first its hidden, and only the button is present, when we click the button dock pops up, button changes position to the right edge of dock.
Here is my code:
window::window(unsigned int h, unsigned int v, QWidget *parent) {
this->setFixedSize(h, v);
ui.setupUi(this);
createDockWindow();
}
void window::createDockWindow() {
dock = new QDockWidget(this);
dock->setTitleBarWidget(new QMainWindow());
dock->setGeometry(QRect(this->rect().topLeft(),
QSize(dockWidth, this->height())));
dock->setFloating(true);
dock->hide();
path_button = new QPushButton(">", this);
path_button->setGeometry(QRect(this->rect().topLeft(),
QSize(buttonWidth, this->height())));
connect(path_button, SIGNAL (released()), this, SLOT (showDock()));
}
void rubrick::showDock() {
if(dock->isHidden()){
dock->show();
path_button->setGeometry(QRect(dock->rect().topRight(),
QSize(buttonWidth, this->height())));
} else {
dock->hide();
path_button->setGeometry(QRect(dock->rect().topLeft(),
QSize(buttonWidth, this->height())));
}
}
So button works perfectly, at first my app looks like that screenshot:
But when the dock shows, it blocks app window title bar, like that: screenshot
I figured, this->rect().topLeft() returns top left of screen, but doesn't take into consideration window Title Bar, I tried to get menuBar height, but it return 30, and I found out that if I move left top by (0, 45) with 0 being width and 45 being height, the dock would be perfectly in place.
What am I doing wrong and how to fix that problem?
The method you're probably looking for is QWidget::frameGeometry, which returns the geometry of the window with the frame included. The rect method returns only the internal area. If you look at QWidget::rect in Qt Assistant, you'll find a link to a "Window Geometry" description that explains all of these interactions reasonably well.
In SDL2 when you resize the window by dragging the corners during runtime, a window resized event is triggered and can be used like this:
SDL_Event e;
int width, height;
SDL_PollEvent(&e);
if(e.type == SDL_WINDOWEVENT && e.window.event == SDL_WINDOWEVENT_RESIZED)
{
width = e.window.data1;
height = e.window.data2;
}
If I resize a window manually like this:
SDL_SetWindowSize(window, myWidth, myHeight);
(documentation)
Will this trigger a window event like above?
Yes, just like SDL_SetWindowFullscreen (). SDL_SetWindowSize () triggers window events. Technically, I think it just resizes the window, which is treated as if the user manually resized it.
Using SDL_WINDOWEVENT_RESIZED, the answer is no. But an SDL_WINDOWEVENT_SIZE_CHANGED event is triggered.
The problem occurs when
SDL_RestoreWindow(gameWindow);
is called on a minimised window. The window does not re-appear.
I've made a little dummy program simulating the sort of SDL calls that my main program is calling, and the problem reproduces. Here is the code:
#include <SDL.h>
int main(int argn, char **argv)
{
// The windows
SDL_Window *gameWindow;
// Initialise
SDL_Init(SDL_INIT_EVERYTHING);
// Create window
gameWindow = SDL_CreateWindow(
"Game Window",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
640,
480,
SDL_WINDOW_OPENGL
);
// Minimise/ hide or whatever?
SDL_MinimizeWindow(gameWindow);
// Wait
SDL_Delay(1000);
// Attempt to bring back the window
SDL_RestoreWindow(gameWindow);
// program would run here
SDL_Delay(1000);
// quit out
SDL_DestroyWindow(gameWindow);
// Clean up
SDL_Quit();
return 0;
}
Any ideas as to why this gameWindow is not re-appearing?
Is SDL_Restore not designed to restore a minimised window?
Also FYI This is running on Ubuntu 13.10 and compiling with gcc 4.8.1 and Gnome metacity 2.34.13
Short answer
Make sure you call one of the functions that let SDL process events: SDL_PollEvent() or SDL_WaitEvent() or SDL_PumpEvents().
Longer answer
It is possible that the reason why the window can't be restored is because it does not have SDL_WINDOW_MINIMIZED flag assigned to it.
Here is the source code of the SDL_RestoreWindow() function:
void
SDL_RestoreWindow(SDL_Window * window)
{
CHECK_WINDOW_MAGIC(window,);
if (!(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
return;
}
if (_this->RestoreWindow) {
_this->RestoreWindow(_this, window);
}
}
If neither SDL_WINDOW_MAXIMIZED nor SDL_WINDOW_MINIMIZED are set, the _this->RestoreWindow() will not be called (and the window will not be restored).
Normally when a window is being minimized the SDL_WINDOW_MINIMIZED flag is set by SDL in SDL_SendWindowEvent() function:
case SDL_WINDOWEVENT_MINIMIZED:
if (window->flags & SDL_WINDOW_MINIMIZED) {
return 0;
}
window->flags &= ~SDL_WINDOW_MAXIMIZED;
window->flags |= SDL_WINDOW_MINIMIZED;
SDL_OnWindowMinimized(window);
break;
This will happen when SDL processes events queue. Processing of the events should be triggered by your application as described in the documentation:
Internally, SDL stores all the events waiting to be handled in an
event queue. Using functions like SDL_PollEvent(), SDL_PeepEvents()
and SDL_WaitEvent() you can observe and handle waiting input events.
If you do not want to receive and handle input events, you can call SDL_PumpEvents() function to let SDL process the events:
This function updates the event queue and internal input device state.
Often the need for calls to SDL_PumpEvents() is hidden from the user since SDL_PollEvent() and SDL_WaitEvent() implicitly call SDL_PumpEvents(). However, if you are not polling or waiting for events (e.g. you are filtering them), then you must call SDL_PumpEvents() to force an event queue update.
I am doing work on project. In which I have developed a full size screen displaying images using XCreateWindow. Now I want to display a dialog on this screen. I have created a QDialog it does'nt show on the full size screen but it is displayed on screen when it is not full size. Any Help. My code for creating screen and dialogbox is as follows
XSetWindowAttributes attribs;
XClassHint *classhints;
XSizeHints *sizehints;
int wndwidth, wndheight;
long input_mask, ic_input_mask;
XEvent xevent;
wndwidth = fullscreen ? WidthOfScreen(screen) : width;
wndheight = fullscreen ? HeightOfScreen(screen) : height;
attribs.background_pixel = BlackPixelOfScreen(screen);
attribs.backing_store = ownbackstore ? NotUseful : Always;
attribs.override_redirect = fullscreen;
wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, wndwidth,
wndheight, 0, CopyFromParent, InputOutput, CopyFromParent,
CWBackPixel | CWBackingStore | CWOverrideRedirect, &attribs);
XRaiseWindow(display, wnd);
//QDialog I want to show on wnd(XCreateWindow)
ToolbarDialog *objToolbarDialog= new ToolbarDialog();
objToolbarDialog->setVisible(true);
objToolbarDialog->showNormal();
your examples aren't Qt code - so did you mixed up sth.?
Please note: Don't mix up Qt code and direct calls to the X11 lib! The most Qt classes need an QApplication object to work.
ciao,
Chris