SyntaxBomb - Indie Coders

Languages & Coding => BlitzMax / BlitzMax NG => Topic started by: wombats on September 07, 2021, 18:21:04

Title: SDL mky.mojo2
Post by: wombats on September 07, 2021, 18:21:04

I'm trying to find a way to change the window title after it's created. SDL lets you do this with Max2D, but I can't figure out the way to do it with mojo2...if it's even possible.

I know this example doesn't work anyway. I don't know for sure mojo2 and SDL are even compatible.
Code: [Select]
Framework mky.mojo2
Import sdl.glsdlgraphics
'Import brl.GLGraphics
Import brl.pngloader

Graphics(640, 480, 0)

Local window:TSDLWindow = TSDLGLContext.GetCurrentWindow()
window.SetTitle("Hello World")

Local canvas:TCanvas = New TCanvas.CreateCanvas()

canvas.SetScissor(0, 0, GraphicsWidth(), GraphicsHeight())
canvas.Clear(0, 0, 0)
canvas.DrawRect(10, 10, 100, 100)
Until KeyHit(KEY_ESCAPE) Or AppTerminate()

Title: Re: SDL mky.mojo2
Post by: fielder on September 29, 2021, 22:04:06
what about:

Code: [Select]
Function SetWindowTitle( title:String)
Extern "Win32"
Function SetWindowTextW:Int( handle:Int, text$w)
Local hwnd:Int = GetActiveWindow()
If hwnd
AppTitle = title
SetWindowTextW( hwnd, title)
Title: Re: SDL mky.mojo2
Post by: Derron on September 30, 2021, 07:25:10
Code: BlitzMax
  1. SuperStrict
  2. Framework mky.mojo2
  3. Import SDL.gl2sdlmax2d
  4. 'Import sdl.glsdlgraphics
  5. Import Brl.PNGLoader
  7. Graphics(640, 480, 0)
  9. Local window:TSDLWindow = TSDLGLContext.GetCurrentWindow()
  10. if not window then throw "no window"
  11. window.SetTitle("Hello World")
  13. Local canvas:TCanvas = New TCanvas.CreateCanvas()
  15. Repeat
  16.         canvas.SetScissor(0, 0, GraphicsWidth(), GraphicsHeight())
  17.         canvas.Clear(0, 0, 0)
  18.         canvas.DrawRect(10, 10, 100, 100)
  19.         canvas.Flush()
  20.         Flip
  21. Until KeyHit(KEY_ESCAPE) Or AppTerminate()
  23. End
this works for me - dunno what the max2d-thing loads and might be incompatible once adding more modules.

Yet it is better to use some less invasive method like fielder suggested.

glgraphics.linux.c (glgraphics.mod) changes the window title this way:
Code: [Select]
XChangeProperty( xdisplay,window, XInternAtom( xdisplay,"_NET_WM_NAME",True ),
XInternAtom( xdisplay,"UTF8_STRING",True ), 8,PropModeReplace,appTitle,strlen( appTitle ) );

all the required things are stored somewhere (xdisplay, window, apptitle) so if one extended glgraphics.mod (for linux) for an "SetAppTitle" you could possibly simply call it from your app then. Do it for windows and mac too and it is "cross platform".

Yet some of my Pull Requests are open so I won't do that.

Title: Re: SDL mky.mojo2
Post by: wombats on October 01, 2021, 18:31:50
Thanks for the replies.

I'm looking for a cross-platform solution if possible (I know each platform needs its own code at some level), and GetActiveWindow relies on the game actually being the active window, right?

It would be nice to be able to do it without hacking the modules.

Code: [Select]
Extern "C"
Function Test(context:Byte Ptr)

Type WinFunc Extends TGLGraphics
Method SetWindowTitle:Int()

Is this the right way to access the context in TGLGraphics? Then how would I handle it in a C file?

Code: [Select]
#include <brl.mod/glgraphics.mod/glgraphics.win32.c>

void Test(BBGLContext *context) {
  SetWindowTextW(context->hwnd, "hello");

This just crashes.
SimplePortal 2.3.6 © 2008-2014, SimplePortal