SOL9 Sample: NamedWindow

SOL9 2.0 Samples

1 Screenshot


2 Source code

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


//2017/03/30

#define _CONSOLE_

#include <sol/ModuleFileName.h>
#include <sol/opencv/OpenCVApplicationView.h>

#include <sol/opencv/OpenCVNamedWindow.h>
#include <sol/PushButton.h>
#include <sol/opencv/OpenCVInnerView.h>

namespace SOL {

class MainView :public OpenCVApplicationView {

private:
  //Inner class starts.
  class SimpleView :public OpenCVNamedWindow {
  private:
    cv::Mat image;
    
    void display()
    {
      show(image);
    }
    
  public:
    SimpleView(View* parent, const char* name, Args& args)
    :OpenCVNamedWindow(parent, name, args)
    {
      try {
        const char* filename = (const char*)args.get(XmNimageFileName);
        int imageLoadingFlag = args.get(XmNimageLoadingFlag);

        image = readImage(filename, imageLoadingFlag);
        
      } catch (SOL::Exception ex) {
        caught(ex);
      }
    }
    
    ~SimpleView()
    {
    }
  };
  //Inner class ends.

  SmartPtr<SimpleView>  view;
  SmartPtr<PushButton>  quit;


  void resize(int w, int h)
  {
    if (view && quit) {
      view -> reshape(4, 60, w-100,    h-64);
      quit -> reshape(w-100 + 10, 10, 80, 30);      
    }
  }

  void confirm(Action& action)
  {
    int rc = MessageBox(NULL, "Are you sure to close this window?", "Confirmation", 
                MB_OKCANCEL|MB_ICONEXCLAMATION);
    if (rc == IDOK) {
      exit(action);
    }
  }
  
public:
  MainView(OpenCVApplication& applet, const char* name, Args& args)
  :OpenCVApplicationView(applet, name, args)
  {
    try {
      Args ar;
      ar.set(XmNimageFileName, "..\\images\\flower6.jpg");
      ar.set(XmNimageLoadingFlag, CV_LOAD_IMAGE_COLOR);
      view = new SimpleView(this, "cvwindow", ar); 

      ar.reset();
      quit = new PushButton(this, "Quit", ar);
      quit -> addCallback(XmNactivateCallback, this, 
          (Callback)&MainView::confirm, NULL); 
      addCallback(XmNmenuCallback, IDM_EXIT, this,
          (Callback)&MainView::confirm, NULL);
      
    } catch (Exception& ex) {
      caught(ex);
    }
  }

  ~MainView()
  {
  }
};
}

//
void main(int argc, char** argv) 
{
  cvInitSystem(argc, argv);
  
  try {
    ModuleFileName module(argv[0]);
    
    const char*  name = module.getAppName();
        
    OpenCVApplication applet(name, argc, argv);

    Args args;
    args.set(XmNwidth,  640);
    args.set(XmNheight, 480);
    MainView view(applet, name, args);
    view.realize();

    applet.run();
    
  } catch (SOL::Exception& ex) {
    caught(ex);
  }
}


Last modified: 20 Apr. 2017

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