SOL9 Sample: ImageTransform

SOL9 2.0 Samples

1 Screenshot


2 Source code

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


// SOL++2000
// 2000.06.18

#include <sol\ApplicationView.h>
#include <sol\PaintDC.h>
#include <sol\ClientDC.h>
#include <sol\DIBSection.h>
#include <sol\AffineTransform.h>
#include <sol\MessageFont.h>
#include <sol\CourierFont.h>
#include "resource.h"

// 2008/09/23 Modififed to use MessageFont,CourierFont to draw strings.

namespace SOL {

class ImageTransform :public ApplicationView {
private:
  DIBSection   baseImage;
  DIBSection*  rotatedImage;
  DIBSection*  translatedImage;
  int    num;
  MessageFont  mfont;
  CourierFont  cfont;

  public:
  /**
   * Construtor
   */
  ImageTransform(Application& applet, const TCHAR* label, Args& args)
    :ApplicationView(applet, label, args)
  {
    mfont.create(16);
    cfont.create(12);

    ClientDC cdc(this);

    // Create a baseImage by using DIBSection class.
    createBaseImage(cdc);

    AffineTransform transform;

    // Create a rotatedImage from baseImage by using AffineTransform class.
    rotatedImage = transform.rotate(cdc, baseImage, 30.0);

    // Create a translatedImage from baseImage by using AffineTransform class.
    translatedImage = transform.translate(cdc, baseImage, 50, 20);
  
    addEventHandler(WM_PAINT, this, (Handler)&ImageTransform::paint, NULL);

    addCallback(XmNmenuCallback, IDM_EXIT, this,
      (Callback)&ImageTransform::exit, NULL);
  }

public:
  /**
   * Destructor
   */
  ~ImageTransform() {
    delete rotatedImage;
    delete translatedImage;
  }

private:
  void createBaseImage(DC cdc) {
    num = 255;
    baseImage.create(cdc, num, num);
    for (int r = 0; r<num; r++) {
      for(int g = 0; g<num; g++) {
      int b = 255;
        baseImage.setPixel(g, r, RGB(r, g, b));
      }
    }
    // Draw two text strings into a MemoryDC of the baseImage .
    DC dc = baseImage.getDC();
    const TCHAR* string = _T("SOL9 C++ Class Library");
    const TCHAR* antillia = _T("http://www.antillia.com/");

    HFONT hf = (HFONT)dc.select(&mfont);
    dc.setBkMode(TRANSPARENT);
    dc.setTextColor(RGB(255,255,255));
    dc.textOut(4, 40, string, strlen(string));
    dc.select(hf);

    dc.setTextColor(RGB(0, 0, 0));
    hf =(HFONT)dc.select(&cfont);
    dc.textOut(8, 180, antillia, strlen(antillia));
    dc.select(hf);
  }

private:
  /**
   * WM_PAINT event handler.
   */
  long paint(Event& event)
  {
    PaintDC pdc(this);
    baseImage.draw(pdc, 11, 11);

    if (rotatedImage) {
      rotatedImage->draw(pdc, 11+num+30, 11);  
    }
    if (translatedImage) {
      translatedImage->draw(pdc, 11, 11+num+30);
    }
    return 0;
  }


};

}

//////////////////////////////////////////
// Program Main
void  Main(int argc, TCHAR** argv)
{
  ModuleFileName module(argv[0]);
  const TCHAR* name = module.getFileName();
  try {
    Application applet(name, argc, argv);

    Args args;
    args.set(XmNwidth, 660);
    args.set(XmNheight, 580);
  
    //2009/10/13
    args.set(XmNclassStyle, 0);

    ImageTransform imageTransform(applet, name, args);
    imageTransform.realize();
    applet.run();

  } catch (Exception& ex) {
    caught(ex);
  } catch (...) {
    caught(UnknownException());
  }
}


Last modified: 1 Feb 2017

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