SOL9 Sample: Canvas

SOL9 2.0 Samples

1 Screenshot


2 Source code

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


// SOL++2000
// 2000.02.18
// 2017/01/29 Update to use Font class 

#include <sol\ApplicationView.h>
#include <sol\PaintDC.h>
#include <sol\Font.h>

#include <sol\DrawingArea.h>
#include <sol\Stdio.h>

#include "resource.h"

namespace SOL {

class CanvasView :public ApplicationView {
private:
  Font        font;
  DrawingArea area1;
  DrawingArea area2;

public:
  /**
   * Constructor
   */
  CanvasView(Application& applet, const TCHAR* label, Args& args)
  :ApplicationView(applet, label, args)
  {
    Args ar;
    ar.set(XmNclassStyle, 0);

    ar.set(XmNenableThumbTrack, TRUE);
    ar.set(XmNexStyle, WS_EX_CLIENTEDGE);
    ar.set(XmNstyle, (ulong)WS_BORDER|WS_VSCROLL|WS_HSCROLL);
    area1.create(this, _T(""), ar);

    ar.reset();
    ar.set(XmNclassStyle, 0);

    ar.set(XmNexStyle, WS_EX_CLIENTEDGE);

    ar.set(XmNstyle, (ulong)WS_BORDER|WS_VSCROLL|WS_HSCROLL);
    area2.create(this, _T(""), ar);

    area1.addCallback(XmNexposeCallback, this, 
      (Callback)&CanvasView::draw1, 
      _T("This is a drawingArea1. Hello world."));
    area2.addCallback(XmNexposeCallback, this, 
      (Callback)&CanvasView::draw2, 
      _T("This is a drawingArea2. Goodbye world."));
    
    //2017/01/29
    ClientDC dc(this);
    int pointSize = 24;
    int logPixel = dc.getDeviceCaps(LOGPIXELSY);

    int nHeight = -MulDiv(pointSize, logPixel, 72); 
    
    ar.reset();
    ar.set(XmNheight, nHeight);
    ar.set(XmNweight,  FW_BOLD);
    ar.set(XmNcharSet, (ulong)dc.getTextCharsetInfo(NULL));
    ar.set(XmNfaceName, _T("Times New Roman"));
    //ar.set(XmNfaceName, _T("MS Gothic"));
    //ar.set(XmNfaceName, _T("MeiryoKe_UIGothic"));
    //ar.set(XmNfaceName, _T("MS UI Gothic"));
    font.create(ar);
    
    addCallback(XmNmenuCallback, IDM_EXIT, this,
      (Callback)&CanvasView::exit, NULL);

  }

private:

  long size(Event& event)
  {
    int w, h;
    event.getSize(w, h);
    area1.reshape(0, 0, w, h/2-1);
    area2.reshape(0, h/2+1, w, h/2-2);
    return 0L;
  }

private:
  void draw1(Action& action)
  {
    PaintDC* pdc = (PaintDC*)action.getValue();
    TCHAR* text = (TCHAR*)action.getData();
    HGDIOBJ hf = pdc->select(font);
    
    int x = (int)area1.get(XmNhorizThumbPosition);
    int y = (int)area1.get(XmNvertThumbPosition);
    pdc -> textOut(-x+10, -y+10, text, strlen(text));
    pdc -> select(hf);
  }

private:
  void CanvasView::draw2(Action& action)
  {
    PaintDC* pdc = (PaintDC*)action.getValue();
    TCHAR* text = (TCHAR*)action.getData();
    HGDIOBJ hf = pdc->select(font);

    int x = (int)area2.get(XmNhorizThumbPosition);
    int y = (int)area2.get(XmNvertThumbPosition);
    pdc -> textOut(-x+40, -y+40, text, strlen(text));
    pdc -> select(hf);

  }
};

}

//
//
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(XmNclassStyle, 0);

    args.set(XmNwidth,  400);
    args.set(XmNheight, 400);
    CanvasView canvas(applet, name, args);
    canvas.realize();

    applet.run();

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


Last modified: 1 Feb 2017

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