Skip to content

Instantly share code, notes, and snippets.

@jerstlouis
Last active May 18, 2022 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerstlouis/7ac6e61f53f8128b0a7a8c88533a2e2f to your computer and use it in GitHub Desktop.
Save jerstlouis/7ac6e61f53f8128b0a7a8c88533a2e2f to your computer and use it in GitHub Desktop.
#define MODULE_NAME "HelloCube"
#include "ecere.hpp"
class HelloCube : public Window
{
public:
Cube cube;
Light light;
Camera camera;
REGISTER() { REG_Window(HelloCube); }
CONSTRUCT(HelloCube, Window)
{
caption = $("HelloCube -- Sample 3D App using Ecere Toolkit/C++ Bindings");
background = DefinedColor::black;
size = { 640, 480 };
borderStyle = BorderStyle::sizable;
hasClose = true;
hasMaximize = true;
hasMinimize = true;
displayDriver = "OpenGL";
camera.position = { 0, 0, -300 };
camera.fov = 53;
light.orientation = Euler(30, 10);
light.diffuse = DefinedColor::lightCoral;
}
bool onLoadGraphics()
{
cube.create(displaySystem);
Transform transform;
transform.scaling = { 100, 100, 100 };
transform.orientation = Euler(50, 30, 50);
cube.transform = transform;
cube.updateTransform();
return true;
}
void onUnloadGraphics()
{
cube.free(displaySystem);
}
void onResize(int w, int h)
{
camera.setup(w, h, null);
camera.update();
}
void onRedraw(Surface & surface)
{
surface.clear(ClearType::depthBuffer);
display->setLight(0, light);
display->setCamera(surface, camera);
display->drawObject(cube);
display->setCamera(surface, Camera(null));
}
bool onKeyDown(Key key, unichar ch)
{
if(key == KeyCode::escape)
destroy(0);
return true;
}
};
GuiApplication app;
REGISTER_CLASS_DEF(HelloCube, Window, app);
HelloCube cube;
MAIN_DEFINITION;
#define MODULE_NAME "HelloForm"
#include "ecere.hpp"
class HelloForm : public Window
{
public:
Button button;
HelloForm()
{
caption = $("Sample App using Ecere Toolkit/C++ Bindings");
borderStyle = BorderStyle::sizable;
clientSize = { 640, 480 };
hasClose = true;
hasMaximize = true;
hasMinimize = true;
background = SystemColor::formColor;
font = { "Arial", 30 };
button.parent = this;
button.position = { 200, 200 };
button.caption = $("Yay!!");
button.notifyClicked = [](Window & owner, Button & btn, int x, int y, Modifiers mods) -> bool
{
HelloForm & self = (HelloForm &)owner;
MessageBox msgBox;
msgBox.caption = self.button.caption;
msgBox.contents = $("C++ Bindings!");
msgBox.modal();
return true;
};
onRedraw = [](Window & w, Surface & surface) { surface.writeTextf(100, 100, $("Instance Method!")); };
}
};
extern "C" int
#if defined(__WIN32__) && !defined(__CONSOLE_APP__)
__stdcall WinMain(void * hInstance, void * hPrevInst, char * cmdLine, int show)
#else
main(int argc, char * argv[])
#endif
{
GuiApplication app;
HelloForm hello;
#if !defined(__WIN32__) || defined(__CONSOLE_APP__)
eC_setArgs(app.impl, argc, argv);
#endif
app.main();
unloadTranslatedStrings(MODULE_NAME);
return app.exitCode;
}
#define MODULE_NAME "HelloForm"
#include "ecere.hpp"
class HelloForm : public Window
{
public:
Button button;
CONSTRUCT(HelloForm, Window)
{
caption = $("Sample App using Ecere Toolkit/C++ Bindings");
borderStyle = BorderStyle::sizable;
displayDriver = "OpenGL";
clientSize = { 640, 480 };
hasClose = true;
hasMaximize = true;
hasMinimize = true;
background = SystemColor::formColor;
font = { "Arial", 30 };
button.parent = this;
button.position = { 200, 200 };
button.caption = $("Yay!!");
button.notifyClicked = [](Window & owner, Button & btn, int x, int y, Modifiers mods) -> bool
{
HelloForm & self = (HelloForm &)owner;
MessageBox msgBox;
msgBox.caption = self.button.caption;
msgBox.contents = $("C++ Bindings!");
msgBox.modal();
return true;
};
onRedraw = [](Window & w, Surface & surface) { surface.writeTextf(100, 100, $("Instance Method!")); };
}
};
GuiApplication app;
REGISTER_CLASS_DEF(HelloForm, Window, app);
HelloForm hello;
MAIN_DEFINITION;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment