Window To Start Centred
BlitzMax Forums/BlitzMax Programming/Window To Start Centred
| ||
I Have BMAX with MAX-GUI installed, Im using MAXGUI for the front end of an emulator with BMAX window for rendering the emulator game in (I need keyhit() etc). The problem is that it looks untidy as the window starts top,left then jumps to the centre of the screen each time you start a new game. Im guessing this requires a module tweak (something like an extra true/false flag to centre window) but im not sure exactly which path/file to look at. I know that I need minGW and thats ok. Its a bit scary as I havent tried any module mods yet but it would be very useful to be able to start a window centred! |
| ||
Ok I found the window module and some code that looks like this at the end, although Im not sure how to change it to centre the window. I was using code like this in my BMAX before; SetWindowPos(hwnd, -2, (desk.R / 2) - ((Window.R-window.L) / 2), (desk.B / 2.1) - ((Window.B-Window.T) / 2), 0, 0, 1) Function Graphics:TGraphics( width,height,depth=0,hertz=60,flags=0 ) EndGraphics flags:|_defaultFlags Local g:TGraphics=CreateGraphics( width,height,depth,hertz,flags ) If Not g Return GraphicsSeq:+1 If Not GraphicsSeq GraphicsSeq=1 SetGraphics g _softSync=True |
| ||
Im not sure of the syntax is there some command like:?? SetGraphicsPos x,y This I have no clues to? |
| ||
I'm centring the window after it's created too. A module tweak would work but I don't want to tweak the module. It would be nice if BRL made a special command that let you preset the window coords before it was created. I'm talking about non-GUI windows here. |
| ||
I usually create the window off-screen. Then the menus and other gadget paraphernalia is added and at the end the window is moved into the center of the desktop with the help of the SetGadgetShape function. No jumping, no flickering, works for me all the time. Here's a quick example: SuperStrict Local style:Int = WINDOW_TITLEBAR|WINDOW_RESIZABLE|WINDOW_MENU|WINDOW_STATUS Local MyWindow:TGadget Local filemenu:TGadget Local editmenu:TGadget Local helpmenu:TGadget Const MENU_NEW:Int=101 Const MENU_OPEN:Int=102 Const MENU_SAVE:Int=103 Const MENU_CLOSE:Int=104 Const MENU_EXIT:Int=105 Const MENU_CUT:Int=106 Const MENU_COPY:Int=107 Const MENU_PASTE:Int=108 Const MENU_ABOUT:Int=109 Global WinWidth:Int=320 Global WinHeight:Int=240 'Create a centered window with client size WinWidth, WinHeight Local wx:Int=(ClientWidth(Desktop())-WinWidth)/2 Local wy:Int=(ClientHeight(Desktop())-WinHeight)/2 MyWindow=CreateWindow("This is centered window", -5000,-5000,WinWidth,WinHeight,Null,style) filemenu=CreateMenu("&File",0,WindowMenu(MyWindow)) CreateMenu"&New",MENU_NEW,filemenu,KEY_N,MODIFIER_COMMAND CreateMenu"&Open",MENU_OPEN,filemenu,KEY_O,MODIFIER_COMMAND CreateMenu"&Close",MENU_CLOSE,filemenu,KEY_W,MODIFIER_COMMAND CreateMenu"",0,filemenu CreateMenu"&Save",MENU_SAVE,filemenu,KEY_S,MODIFIER_COMMAND CreateMenu"",0,filemenu CreateMenu"E&xit",MENU_EXIT,filemenu,KEY_F4,MODIFIER_COMMAND editmenu=CreateMenu("&Edit",0,WindowMenu(MyWindow)) CreateMenu "Cu&t",MENU_CUT,editmenu,KEY_X,MODIFIER_COMMAND CreateMenu "&Copy",MENU_COPY,editmenu,KEY_C,MODIFIER_COMMAND CreateMenu "&Paste",MENU_PASTE,editmenu,KEY_V,MODIFIER_COMMAND helpmenu=CreateMenu("&Help",0,WindowMenu(MyWindow)) CreateMenu "&About",MENU_ABOUT,helpmenu UpdateWindowMenu MyWindow Local MyButton:TGadget=CreateButton("Click me",140,60,80,40,MyWindow) SetGadgetShape(MyWindow,wx,wy,WinWidth,WinHeight) While True WaitEvent Local text$= "Current window size (w,h) is " + ClientWidth(MyWindow)+ "," + ClientHeight(MyWindow) Select EventID() Case EVENT_WINDOWCLOSE End Case EVENT_MENUACTION Select EventData() Case MENU_EXIT End Case MENU_ABOUT Notify "A non-jumping centered window example created by Barney" End Select End Select Wend End Hope this will help... Barney |
| ||
good idea. Shame I can't do that with Non-GUI windows as they just create anywhere on the screen. |
| ||
NO thats nothing like what im talking about, I have no problems centring a window made with MAX-GUI. I use MAX-GUI window as a front-end for my emulator ,you select a game and this starts the new window for rendering the game on. (this is done with the old BMAX graphics command so I still have keyboard input etc.) IT IS A BIG SHORTCOMING, LOOKS LIKE A BODGE BECAUSE IT IS A BODGE WITH WINDOWS BOUNCING AROUND THE SCREEN. TOTALLING UNACCEPTABLE BECUASE THE WINDOW IS REMADE FOR EACH GAME SELECTION. OK so I have the code to move the window to the centre AFTER its creation this is the problem, it has to happen when the window is created to look any good. Im sure this MUST BE DONE BY A MODULE TWEAK. I have no problems attempting this if I can figure the coding, I will just backup the old module. I already tried downloading minGW and tried rebuilding modules - no problems there im ready to go, just dont know how to code modules. what I need to know is how to position a window in the context of coding BMAX modules NOT MAX GUI PROGRAMMING. Prehaps the NO ICON icon issue could be delt to in the same module. |
| ||
This is the only way a window would ever be able to start out centred... by modifing this module.... C:\Program Files\BlitzMax\mod\brl.mod\graphics.mod You can move the window after its creation but this is a BIG shortcoming. Looks bodge! |
| ||
Here is a snippet of code from the graphics module, but I have no idea how to insert code to position the window??? Although MAX-GUI modules seem to be written in a different language, so the code from the GUI module is probably no good. Function CreateGraphics:TGraphics( width,height,depth,hertz,flags ) flags:|_defaultFlags Local g:TGraphics Try g=_driver.CreateGraphics( width,height,depth,hertz,flags ) Catch ex:Object End Try Return g End Function Function AttachGraphics:TGraphics( widget,flags ) flags:|_defaultFlags Local g:TGraphics Try g=_driver.AttachGraphics( widget,flags ) Catch ex:Object End Try Return g End Function Rem bbdoc: Close a graphics object about: Once closed, a graphics object can no longer be used. End Rem Function CloseGraphics( g:TGraphics ) If g=_exGraphics _exGraphics=Null If g=_graphics SetGraphics Null g.Close End Function Rem bbdoc: Set current graphics object about: #SetGraphics will also change the current graphics driver if @g uses a different driver than the current driver. End Rem Function SetGraphics( g:TGraphics ) If Not g If _driver And _graphics _driver.SetGraphics Null _graphics=Null _gWidth=0 _gHeight=0 _gDepth=0 _gHertz=0 _gFlags=0 Return EndIf Local d:TGraphicsDriver=g.Driver() If d<>_driver If _driver And _graphics _driver.SetGraphics Null _graphicsModes=Null _driver=d EndIf g.GetSettings _gWidth,_gHeight,_gDepth,_gHertz,_gFlags d.SetGraphics g _graphics=g End Function THIS CODE IS FROM MAX-GUI MOD PURHAPS THIS COULD BE USEFUL.... void Win32Window::setShape( int x,int y,int w,int h ){ if( style()&32 ){ if( _status ){ RECT sb_rect; ::GetWindowRect( _status,&sb_rect ); h+=sb_rect.bottom-sb_rect.top; } RECT rect={x,y,x+w,y+h}; int wstyle=GetWindowLong( _window.hwnd(),GWL_STYLE ); bool menu=GetMenu( _window.hwnd() ) ? true : false; AdjustWindowRect( &rect,wstyle,menu ); x=rect.left; y=rect.top; w=rect.right-rect.left; h=rect.bottom-rect.top; } _window.setShape(x,y,w,h); // BBWindow::setShape(x,y,w,h); WM_MOVE handler } |
| ||
the mod can be found here, http://www.blitzbasic.com/Community/posts.php?topic=64504 |
| ||
Thanks I told you I know nothing about it.... So the graphics.mod calls that routine to create the window for rendering on, sound like you know what your talking about ,and you even knew that my program has a selection from Open GL or Direct X drivers. |
| ||
lol, well I figured if I didn't say I would make a GL version then all those Mac people would get on me for not being cross platform...the GL is a bit harder to figure out... |
| ||
Thanks dude, I just did the MOD .... Looks so smooooth now its really A++ no more window bounce! ,I didnt want to release my emulator front end with window bounce, it looked ugly! |
| ||
How would you make this function as a new command parameter for the "graphics" command I would be cool if we could add a style string and a true/false flag for centring the window. like for example: graphics 500,300,32,100,WS_VISIBLE,True or a whole new command that makes it backward compatibility friendly |
| ||
here, http://www.blitzbasic.com/Community/posts.php?topic=64504 |
| ||
again, http://www.blitzbasic.com/Community/posts.php?topic=64504 |
| ||
I just want this behaviour standard so I don't have to keep tweaking the modules. |
| ||
Open the window hidden, centered at given coordinates, then unhide it |
| ||
Open the window hidden, centered at given coordinates, then unhide it Can't do that with non-GUI graphics windows. |
| ||
Oh, non-maxgui eh. |
| ||
I just want this behaviour standard so I don't have to keep tweaking the modules. well, you'd have to talk to BRL 'bout that... |
| ||
I already did. (well via a thread just like this a while back). As I don't want to tweak the modules, I'm creating the window then moving it really quickly with a WinAPI call, it's not that neat (cos you see a flicker) but it's better than nothing. |
| ||
Tweak the module, it took me less than 60 seconds , the mod is so straight forward, you can see it must work. Back up the module before you change it, if your not sure. Honestly better than nothing it not good enough for me, I cant think of any software on the net that bounces windows around the screen on there creation, and If I had to live with that I would start looking for a new compiler. Just do the mod! it works great! |
| ||
I might tweak for my current game (I've tweaked the mods in the past to get VSync in Windowed mode), but I don't want to do it for my framework as my framework needs to run on untweaked modules to make it easier for users. |