3.3.5.1 CustomScrolledView

 As you know, Open Motif 2.3 and later support the free type fonts XFT(X free type).
To use XFT in Motif, you may explicitly override some XmRenderTable resources (XmNfontName, XmNfontSize) which are predefined in .Xdefaults in your application program as shown below (see createPixmap method in InnerView class).

Please note that you can set a renderTable to a dc (Graphics Context) to draw a compoundString(XmString) to an off-screen pixmap in the followng InnerClass .
  //Inner class starts.
  class InnerView :public CustomScrolledView {
  private:
    Pixmap pixmap;

    virtual Pixmap createPixmap()
    {
      Args ar;
      ar.set(XmNfontName, "Times-a");
      ar.set(XmNfontSize, 28);
      RenderTable renderTable(this, "", ar);

      Display* dsp = getDisplay();

      pixmap = XCreatePixmap(dsp, window, pmWidth, pmHeight,
                        DefaultDepth(dsp,0));
      DC dc(dsp, pixmap);
      
      dc.setRenderTable(renderTable.get());

      const char* string = "Is Motif dead?\n"
                      "Could be.\n" 
                      "Don't mind.\n"
                      "You have been living\n"
                      "in the world after death.\n"; 
                      
      CompoundString cs(string);
      cs.move(50, 50);
      cs.draw(&dc);
      


The following CustomScrolleView program is an example to show a pixmap drawn in InnerView by using XmRenderTable to draw a text by XFT.




//
//CustomScrolledView.h
//Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.

#include <oz++/motif/ApplicationView.h>
#include <oz++/motif/CustomScrolledView.h>
#include <oz++/motif/Color.h>
#include <oz++/motif/DC.h>
#include <oz++/motif/RenderTable.h>

namespace OZ {

class MainView : public ApplicationView {

private:
  /////////////////////////////////////////////////////////////////
  //Inner class starts.
  class InnerView :public CustomScrolledView {
  private:
    Pixmap pixmap;
    int pmWidth;
    int pmHeight;

    void configureNotify(Event& event)
    {
      XEvent* xe = event.getXEvent();
      XConfigureEvent* cev = (XConfigureEvent*)xe;
      printf("configureNotify w=%d, h=%d\n", cev->width, cev->height);

      BulletinBoard* workArea = getWorkArea();
 
      uint ww = workArea->width();
      uint wh = workArea->height();
      printf("workArea w=%d, h=%d\n", ww, wh);

      setScrollBarSliderSize(ww, wh);
    }

    virtual Pixmap getPixmap()
    {
      return pixmap; 
    }

    virtual Pixmap createPixmap()
    {
      Args ar;
      ar.set(XmNfontName, "Times-a");
      ar.set(XmNfontSize, 28);
      RenderTable renderTable(this, "", ar);

      Display* dsp = getDisplay();
      pmWidth  = 640;
      pmHeight = 480;
      Color color(this);
      BulletinBoard* workArea = getWorkArea();

      Window window = workArea->getWindow();

      pixmap = XCreatePixmap(dsp, window, pmWidth, pmHeight,
                        DefaultDepth(dsp,0));
      DC dc(dsp, pixmap);
      dc.setForeground(color.color256(0, 40, 40));
      dc.fillRectangle(0, 0, pmWidth, pmHeight);

      dc.setRenderTable(renderTable.get());

      for (int i = 0; i<100; i++) {
        dc.setForeground(color.color256(255, 100+i, i)); 
        dc.drawRectangle(40+i, 20+i, 200, 100);
      }
 
      dc.setForeground(color.color256(0, 255, 0));  //green
      dc.setArcMode(ArcPieSlice);
      dc.fillArc(60, 140, 130, 130, 45*360, 120*360);

      dc.setForeground(color.color256(0, 0, 255));  //blue
      dc.fillArc(260, 140, 130, 130, 45*360, 120*360);

      const char* string = "Is Motif dead?\n Could be.\n"
                           "Don't mind.\nYou have been living\n"
                           "in the world after death.\n";
                           //"You can reach any star.\n";
      dc.setForeground(color.color256(255, 255, 255)); //white
      CompoundString cs(string);
      cs.move(50, 50);
      cs.draw(&dc);

      setHorizScrollBarRange(0, pmWidth);
      setVertScrollBarRange(0,  pmHeight);

      uint ww = workArea->width();
      uint wh = workArea->height();
      setScrollBarSliderSize(ww, wh);
      return pixmap;
    }

  public:
     InnerView(View* parent, const char* name, Args& args)
     :CustomScrolledView(parent, name, args)
     {
        pixmap = None;
     }

     virtual void display()
     {
        Position hpos, vpos;
        getScrollBarPosition(hpos, vpos);

        Pixmap pixmap = getPixmap();         
        if (pixmap == None) {
          pixmap = createPixmap();
        }
        if (pixmap != None) {
          BulletinBoard* dest = getWorkArea();
          Dimension width  = dest->width();
          Dimension height = dest->height(); 
          Pixmap    source = pixmap;
          DC destDC(dest);
          destDC.copyArea(source, 0, 0, width, height, -hpos, -vpos); 
          //You may need to clear something garbage area.
        }
     }
  };
  //Inner class ends.
  /////////////////////////////////////////////////////////////////

  SmartPtr<InnerView>  innerView;

public:
  MainView(Application& applet, const char* name, Args& args)
  :ApplicationView(applet, name, args)
  {
    Args ar;
    innerView = new InnerView(this, "", ar);
  }

  ~MainView()
  {
  }
};

}

//
int main(int argc, char** argv)
{
  try {
    const char*  appclass = argv[0];
    Application applet(appclass, argc, argv);

    Args args;
    args.set(XmNwidth,  500);
    args.set(XmNheight, 400);
    MainView view(applet, argv[0], args);
    view.realize();

    applet.run();
  } catch (Exception& ex) {
   caught(ex);
  }
  return 0;
}




Last modified: 1 Jan 2017

 Last modified: 1 Jan 2017

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