SDL mky.mojo2

Started by wombats, September 07, 2021, 18:21:04

Previous topic - Next topic

wombats

Hi,

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.SuperStrict
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()

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

End

fielder

what about:

Function SetWindowTitle( title:String)
Extern "Win32"
Function SetWindowTextW:Int( handle:Int, text$w)
EndExtern
Local hwnd:Int = GetActiveWindow()
If hwnd
AppTitle = title
SetWindowTextW( hwnd, title)
EndIf
EndFunction

Derron

#2
Code (Blitzmax) Select

SuperStrict
Framework mky.mojo2
Import SDL.gl2sdlmax2d
'Import sdl.glsdlgraphics
Import Brl.PNGLoader

Graphics(640, 480, 0)

Local window:TSDLWindow = TSDLGLContext.GetCurrentWindow()
if not window then throw "no window"
window.SetTitle("Hello World")

Local canvas:TCanvas = New TCanvas.CreateCanvas()

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

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:

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.


bye
Ron

wombats

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.

Extern "C"
Function Test(context:Byte Ptr)
EndExtern

Type WinFunc Extends TGLGraphics
Method SetWindowTitle:Int()
Test(_context)
EndMethod
EndType


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

#include <brl.mod/glgraphics.mod/glgraphics.win32.c>

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


This just crashes.