view anagram/vaclgui/digset.hpp @ 13:43d8b194fb4e

Remove unused variables.
author David A. Holland
date Tue, 31 May 2022 00:59:00 -0400
parents 13d2b8934445
children
line wrap: on
line source

/*
 * AnaGram, A System for Syntax Directed Programming
 * Copyright 1997-2002 Parsifal Software. All Rights Reserved.
 * See the file COPYING for license and usage terms.
 *
 * digset.hpp
 */

#ifndef DIGSET_HPP
#define DIGSET_HPP

#include <icolor.hpp>
#include <ifont.hpp>
#include <ipainevt.hpp>
//#include <ipoint.hpp>
#include <irect.hpp>

#include "cint.h"
#include "dspar.hpp"


class DigSetter
{
public:
  struct Style {
    FontSpec &font;
    ColorSpec &color;
    Style()
      : color(ColorSpec::defaultSetting)
      , font(FontSpec::defaultSetting)
    {}
    Style(FontSpec &f, ColorSpec &color_)
      : font(f)
      , color(color_)
    {}
    int enWidth() {
      IFont &f = font;
      return f.avgCharWidth();
    }
    int height() {
      IFont &f = font;
      return f.maxSize().height();
    }
    int topToBaseline() {
      IFont &f = font;
      return f.maxAscender();
    }
    int descender() {
      IFont &f = font;
      return f.maxDescender();
    }
  };

  struct Dig {
    char *text;
    int textLength;
    cint where;
    int width;
    int styleIndex;
    Dig() {}
    Dig(char *text_, const int length, const cint where_, const int index)
      : text(text_)
      , textLength(length)
      , where(where_)
      , styleIndex(index)
      , width(0)
    {}
    Dig(const Dig &dig)
      : text(dig.text)
      , textLength(dig.textLength)
      , where(dig.where)
      , styleIndex(dig.styleIndex)
      , width(dig.width)
    {}
    int operator < (const Dig &d) const { return where < d.where; }
  };

  struct Hole {
    cint where;
    cint size;
    int styleIndex;
    Hole() {}
    Hole(cint where_, cint size_, int index)
      : where(where_)
      , size(size_)
      , styleIndex(index)
    {}
    Hole(IRectangle r, int index = 0)
      : where(r.minX(), r.minY())
      , size(r.size().width(), r.size().height())
      , styleIndex(index)
    {}
    int operator < (const Hole &d) const { return where < d.where; }
  };

protected:
  IWindow *window;
  IPaintEvent *event;
  Style *style;
  int currentStyleIndex;
  int windowHeight;
  IPresSpaceHandle presSpaceHandle;

public:
  DigSetter(IWindow *window_, Style *style_, int index = -1)
    : event(0)
    , window(window_)
    , style(style_)
    , currentStyleIndex(index)
    , windowHeight(0)
  {}

  DigSetter &setEvent(IPaintEvent &e);
  DigSetter &closeEvent();

  int top(Dig d) {
    return d.where.y - style[d.styleIndex].topToBaseline();
  }
  int bottom(Dig d) {
    return d.where.y + style[d.styleIndex].descender();
  }

  DigSetter &measureDig(Dig &dig);
  DigSetter &setDig(const Dig &dig, int reverseVideo = 0);
  DigSetter &clear(const Hole &hole);
  DigSetter &reverse(const Hole &hole);
  DigSetter &clear(const IRectangle &r);

  DigSetter &refresh(const Hole &hole);
  DigSetter &refresh(const Dig &dig);

  Hole makeHole(const Dig &dig);
};


#endif /* DIGSET_HPP */