view anagram/vaclgui/digset.cpp @ 21:1c9dac05d040

Add lint-style FALLTHROUGH annotations to fallthrough cases. (in the parse engine and thus the output code) Document this, because the old output causes warnings with gcc10.
author David A. Holland
date Mon, 13 Jun 2022 00:04:38 -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.cpp
 */

//#include <iwindow.hpp>
#include <windows.h>

#include "digset.hpp"

//#define INCLUDE_LOGGING
#include "log.h"


DigSetter &DigSetter::setEvent(IPaintEvent &e) {
  //LOGSECTION("DigSetter::setEvent", Log::off);
  LOGSECTION_OFF("DigSetter::setEvent");
  event = &e;
  presSpaceHandle = event->presSpaceHandle();
  SetBkMode(presSpaceHandle, TRANSPARENT);

  LOGV((int) event);
  windowHeight = window->size().height();
  LOGV(currentStyleIndex);
  if (currentStyleIndex == -1) {
    return *this;
  }
  IFont &font = style[currentStyleIndex].font;
  font.beginUsingFont(presSpaceHandle);
  LOGV(windowHeight);
  return *this;
}


DigSetter &DigSetter::closeEvent() {
  if (currentStyleIndex == -1) {
    return *this;
  }
  IFont &font = style[currentStyleIndex].font;
  font.endUsingFont(presSpaceHandle);
  return *this;
}

DigSetter &DigSetter::measureDig(Dig &dig) {
  LOGSECTION("DigSetter::measureDig");
  char *p = dig.text;
  int length = dig.textLength;
  char save = p[length];
  p[length] = 0;
  IFont &currentFont = style[dig.styleIndex].font;
  dig.width = currentFont.textWidth(p);
  p[length] = save;
  int width = 0;
  while (length--) {
    width += currentFont.charWidth(*p++);
  }
  LOGV(dig.width) LCV(width);
  return *this;
}

DigSetter &DigSetter::setDig(const Dig &dig, int reverseVideo) {
  LOGSECTION("DigSetter::setDig");
  char *p = dig.text;
  int length = dig.textLength;
  char save = p[length];
  p[length] = 0;
  cint where = dig.where;
  if (reverseVideo) {
    reverse(makeHole(dig));
  }
  if (dig.styleIndex != currentStyleIndex) {
    if (currentStyleIndex >= 0) {
      IFont &oldFont = style[currentStyleIndex].font;
      oldFont.endUsingFont(presSpaceHandle);
    }
    currentStyleIndex = dig.styleIndex;
    IFont &currentFont = style[currentStyleIndex].font;
    currentFont.beginUsingFont(presSpaceHandle);
  }
  IColor color = reverseVideo ? style[currentStyleIndex].color.bg()
    : style[currentStyleIndex].color.fg();
  where.y -= style[currentStyleIndex].topToBaseline();
  event->drawText(p, IPoint(where.x, where.y), color);

  p[length] = save;
  return *this;
}

DigSetter::Hole DigSetter::makeHole(const Dig &dig) {
  LOGSECTION("DigSetter::makeHole");
  IFont &currentFont = style[dig.styleIndex].font;
  ISize digSize(dig.width, currentFont.maxCharHeight());
  cint where = dig.where;
  where.y -= currentFont.maxAscender();
  return Hole(where, digSize, dig.styleIndex);
}

DigSetter &DigSetter::clear(const Hole &hole) {
  //LOGSECTION("DigSetter::clear", Log::off);
  LOGSECTION_OFF("DigSetter::clear");
  LOGV(hole.styleIndex);
  cint where = hole.where;
  cint size = hole.size;
  const IRectangle rect(IPoint(where.x, where.y),
			ISize(hole.size.x, hole.size.y));
  event->clearBackground(rect, style[hole.styleIndex].color.bg());
  return *this;
}

DigSetter &DigSetter::reverse(const Hole &hole) {
  //LOGSECTION("DigSetter::reverse", Log::off);
  LOGSECTION_OFF("DigSetter::reverse");
  LOGV(hole.styleIndex);
  cint where = hole.where;
  cint size = hole.size;
  LOGV(where) LCV(size);
  const IRectangle rect(IPoint(where.x, where.y),
			ISize(hole.size.x, hole.size.y));
  event->clearBackground(rect, style[hole.styleIndex].color.fg());
  return *this;
}

DigSetter &DigSetter::clear(const IRectangle &r) {
  Hole hole(r);
  clear(hole);
  return *this;
}


DigSetter &DigSetter::refresh(const Hole &hole) {
  //LOGSECTION("refresh hole", Log::off);
  LOGSECTION_OFF("refresh hole");
  cint where = hole.where;
  cint size = hole.size;
  LOGV(where) LCV(size);
  const IRectangle rect(IPoint(where.x, where.y),
			ISize(hole.size.x, hole.size.y));
  LOGV(rect.asString());
  LOGV((int) event) LCV(hole.styleIndex);
  window->refresh(rect);
  return *this;
}

DigSetter &DigSetter::refresh(const Dig &dig) {
  //LOGSECTION("refresh dig", Log::off);
  LOGSECTION_OFF("refresh dig");
  cint where(dig.where.x, top(dig));
  cint size(dig.width, bottom(dig) - where.y);
  LOGV(where) LCV(size);
  const IRectangle rect(IPoint(where.x, where.y), ISize(size.x, size.y));
  LOGV(rect.asString());
  LOGV((int) event) LCV(dig.styleIndex);
  window->refresh(rect);
  return *this;
}