SOL9 Sample: MultipleTitledImageViews

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * MultipleTitledImageViews.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/OpenCVImageView.h>

namespace SOL {

class MainView :public OpenCVApplicationView {

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

        image = imread(filename, imageLoadingFlag);
        
      } catch (SOL::Exception ex) {
        caught(ex);
      }
    }
    
    ~SimpleView()
    {
    }
  };
  //Inner class ends.
  ////////////////////////////////////////////////////////////////////////////////////////
  
  static const int VIEW_COUNT = 3;
  SmartPtr<SimpleView>  view[VIEW_COUNT];


  void resize(int w, int h)
  {
    if (view[0]) {
      for (int i = 0; i<VIEW_COUNT; i++) {
        view[i] -> reshape( w*i/VIEW_COUNT, 0,  w/VIEW_COUNT, h);
      }
    }
  }

  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;
      const char* files[] = {"..\\images\\flower1.jpg", "..\\images\\flower2.jpg", "..\\images\\flower3.jpg"};
      for (int i = 0; i<VIEW_COUNT; i++) {
        char name[128];
        sprintf_s(name, CountOf(name), "cvwindow.%d", i);
        ar.reset();
        ar.set(XmNimageFileName, files[i]);
        ar.set(XmNimageLoadingFlag, i); //CV_LOAD_IMAGE_COLOR);
        view[i] = new SimpleView(this, name, ar); 
      }
      addCallback(XmNmenuCallback, IDM_EXIT, this,
          (Callback)&MainView::confirm, NULL);
      
    } catch (Exception& ex) {
      caught(ex);
    }
  }

  ~MainView()
  {
  }
};

}

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

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

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


Last modified: 2 Dec. 2017

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