SOL9 Sample: Simple

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * Simple.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */



#include <sol/opengl/OpenGLMainView.h>
#include <sol/opengl/OpenGLView.h>

#include <sol/opengl/OpenGLGC.h>
#include <sol/Panel.h>
#include <sol/Static.h>
#include <sol/PushButton.h>

namespace SOL {

class MainView :public OpenGLMainView {

private:
  //Inner class startss
  class SimpleView :public OpenGLView {
  private:
    SmartPtr<OpenGLGC> gc;

  public:
    virtual void display()
    {
      if (gc) {
        gc -> clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        gc -> loadIdentity();
       
        gc -> begin(GL_TRIANGLES);
        gc -> coloredVertex(1.0, 0.0, 1.0, 0.0, 0.0);
        gc -> coloredVertex(0.5, 0.5, 1.0, -1.0, 0.9);
        gc -> coloredVertex(0.0, 0.0, 0.0, 1.0, 0.9);

        gc -> coloredVertex(1.0, 0.0, 0.0, 0.0, 0.0);
        gc -> coloredVertex(0.0, 0.5, 0.0, -1.0, -0.9);
        gc -> coloredVertex(1.0, 1.0, 0.0, 1.0, -0.9);

        gc -> end();
      }
    }

    virtual void resize(int width, int height)
    {
      //Define your own resize method.
    }

    virtual void initialize()
    {
       gc = new OpenGLGC();
       MainView* parent = (MainView*)getParent();
       
       parent -> setVersion();
    }

  public:
    SimpleView(View* parent, const TCHAR* name, Args& args)
    :OpenGLView(parent, name, args)
    {
    }
    
    ~SimpleView()
    {
    }
  };
  //Inner class endss

  SmartPtr<Panel>       panel;
  SmartPtr<Static>      version;
  SmartPtr<PushButton>  quit;
  SmartPtr<SimpleView> view;

  long size(Event& event)
  {
    int w = 0;
    int h = 0;
    event.getSize(w, h);
    if (view && panel) {
      view -> reshape(0, 0, w/2, h);
      view -> postResizeRequest(w/2, h);
      panel -> reshape(w/2, 0, w/2, h);
    }
//    version -> reshape(20, 10, 300, 30);
//    quit    -> reshape(20, 50, 100, 30);
    return 0L;
  }

  void setVersion()
  {
    char text[256];
    sprintf(text, "OpenGL Version: %s", (const char*)glGetString(GL_VERSION) );
    version -> set(XmNlabelString, (ulong)text);
  }

public:
  MainView(Application& applet, const TCHAR* name, Args& args)
  :OpenGLMainView(applet, name, args)
  {
    Args ar;
    view = new SimpleView(this, "", ar); 

    ar.reset();
    panel = new Panel(this, "", ar);
        
    ar.reset();
    ar.set(XmNx, 20);
    ar.set(XmNy, 20);
    ar.set(XmNwidth, 300);
    ar.set(XmNheight, 30);
    version = new Static(panel, "", ar);

    ar.reset();    

    ar.set(XmNx, 20);
    ar.set(XmNy, 50);
    ar.set(XmNwidth, 100);
    ar.set(XmNheight, 30);
    quit = new PushButton(panel, "Quit", ar);
    quit -> addCallback(XmNactivateCallback, this, (Callback)&MainView::exit, NULL); 
  }

  ~MainView()
  {
  }
};
}

//
void Main(int argc, TCHAR** argv) 
{
  try {
    const char*  name = appName(argv[0]);
    Application applet(name, argc, argv);

    Args args;
    args.set(XmNwidth,  800);
    args.set(XmNheight, 300);
    MainView view(applet, name, args);
    view.realize();

    applet.run();
    
  } catch (Exception& ex) {
   ex.show();
  }
}


Last modified: 25 Feb 2017

Copyright (c) 2017 Antillia.com ALL RIGHTS RESERVED.