- Joined
- Jan 2, 2020
- Messages
- 569
Simple native code example how to create a window that fills the complete desktop screen in Mojo1.
[CODE lang="cpp" title="commands.cpp"]namespace commands
{
// ------------------------------------------------------------------
void setWindowPosition(int X, int Y)
{
glfwSetWindowPos(BBGlfwGame::GlfwGame()->GetGLFWwindow(), X, Y);
return;
}
// ------------------------------------------------------------------
void getMonitorCanvas(Array<int> output, bool minimumHeight=false)
{
int count;
GLFWmonitor** monitors = glfwGetMonitors(&count);
int minx = 0;
int miny = 0;
int width = 0;
int height = 0;
for (int i = 0; i < count; i++)
{
GLFWmonitor* monitor = monitors;
int xpos, ypos;
const GLFWvidmode* video = glfwGetVideoMode(monitor);
width += video->width;
if (!minimumHeight)
{
height += video->height;
}
else
{
if ((i == 0) || video->height < height)
{
height = video->height;
}
}
glfwGetMonitorPos(monitor, &xpos, &ypos);
if (xpos < minx)
{
minx = xpos;
}
if (ypos < miny)
{
miny = ypos;
}
}
output[0] = minx;
output[1] = miny;
output[2] = width;
output[3] = height;
return;
}
// ------------------------------------------------------------------
Array<int> getMonitorCanvas(bool minimumHeight=false)
{
Array<int> output = Array<int>(4);
getMonitorCanvas(output, minimumHeight);
return output;
}
// ------------------------------------------------------------------
}[/CODE]
code_language.cerberus:
#GLFW_WINDOW_TITLE = "Invisible"
#GLFW_WINDOW_SAMPLES = 0
#GLFW_WINDOW_RESIZABLE = False
#GLFW_WINDOW_DECORATED = False
#GLFW_WINDOW_FLOATING = False
#GLFW_WINDOW_FULLSCREEN = False
#GLFW_WINDOW_WIDTH = 0 ' crashes Mojo2
#GLFW_WINDOW_HEIGHT = 0 ' crashes Mojo2
Strict
' Public
Import mojo
Import "commands.cpp"
Extern ' Bindings
Function SetWindowPosition:Void(X:Int, Y:Int) = "commands::setWindowPosition"
Function GetMonitorCanvas:Void(Output:Int[], MinimumHeight:Bool=False) = "commands::getMonitorCanvas"
Function GetMonitorCanvas:Int[](MinimumHeight:Bool=False) = "commands::getMonitorCanvas"
Public
' -------------------------------------------------
Function Main:Int()
New Application()
Return 0
End
Class Application Extends App Final
Field Color:Float
Field canvas:Canvas
Method OnCreate:Int()
' canvas = New Canvas()
SetUpdateRate 0
Local Desktop := GetMonitorCanvas()
SetDeviceWindow(Desktop[2],Desktop[3],0)
SetWindowPosition(Desktop[0],Desktop[1])
Return 0
End
Method OnUpdate:Int()
If KeyHit(KEY_ESCAPE) Then OnClose()
Color = Sin(Float(Millisecs()/10))*255
Return 0
End
Method OnRender:Int()
Cls Color,0.0,0.0
' canvas.Flush
Return 0
End
End
' -------------------------------------------------
[CODE lang="cpp" title="commands.cpp"]namespace commands
{
// ------------------------------------------------------------------
void setWindowPosition(int X, int Y)
{
glfwSetWindowPos(BBGlfwGame::GlfwGame()->GetGLFWwindow(), X, Y);
return;
}
// ------------------------------------------------------------------
void getMonitorCanvas(Array<int> output, bool minimumHeight=false)
{
int count;
GLFWmonitor** monitors = glfwGetMonitors(&count);
int minx = 0;
int miny = 0;
int width = 0;
int height = 0;
for (int i = 0; i < count; i++)
{
GLFWmonitor* monitor = monitors;
int xpos, ypos;
const GLFWvidmode* video = glfwGetVideoMode(monitor);
width += video->width;
if (!minimumHeight)
{
height += video->height;
}
else
{
if ((i == 0) || video->height < height)
{
height = video->height;
}
}
glfwGetMonitorPos(monitor, &xpos, &ypos);
if (xpos < minx)
{
minx = xpos;
}
if (ypos < miny)
{
miny = ypos;
}
}
output[0] = minx;
output[1] = miny;
output[2] = width;
output[3] = height;
return;
}
// ------------------------------------------------------------------
Array<int> getMonitorCanvas(bool minimumHeight=false)
{
Array<int> output = Array<int>(4);
getMonitorCanvas(output, minimumHeight);
return output;
}
// ------------------------------------------------------------------
}[/CODE]