Exemple #1
0
static int
Clear(Engine *engine, int always)
{
  XEngine *xeng = (XEngine *)engine;
  if (!xeng->w) return 1;
  if ((always || xeng->e.marked) && xeng->w==xeng->win) {
    int tm = xeng->topMargin;
    int lm = xeng->leftMargin;
    if (tm || lm) {
      int xmax = (int)xeng->swapped.window.xmax;
      int ymax = (int)xeng->swapped.window.ymin;
      if (xmax > lm+xeng->wtop) xmax = lm+xeng->wtop;
      if (ymax > tm+xeng->htop) ymax = tm+xeng->htop;
      if (xeng->clipping) {
        p_clip(xeng->w, 0,0,0,0);
        xeng->clipping = 0;
      }
      p_color(xeng->w, P_BG);
      p_rect(xeng->w, lm, tm, xmax, ymax, 0);
    } else {
      p_clear(xeng->w);
    }
  }
  if (xeng->e.colorChange) ChangePalette(engine);
  xeng->e.marked = 0;
  return 0;
}
Exemple #2
0
static int
DrwText(Engine *engine, GpReal x0, GpReal y0, const char *text)
{
  XEngine *xeng = (XEngine *)engine;
  p_win *w = xeng->w;
  GpXYMap *map = &xeng->e.map;
  int ix, iy, len, xbox[2], ybox[2], xn, xx, yn, yx;
  const char *txt;
  char *caret= "^";

  if (!w || !xeng->mapped) return 1;
  chk_clipping(xeng);

  current_fsize = (int)((xeng->dpi/ONE_INCH)*gistA.t.height);
  if (current_fsize<4) current_fsize = 4;     /* totally illegible */
  if (current_fsize>180) current_fsize = 180; /* way too big */
  current_fsym = T_SYMBOL | (gistA.t.font&3);
  current_scr = xeng->s;
  current_win = w;

  /* get current window */
  xn = (int)(gistT.window.xmin*map->x.scale + map->x.offset);
  xx = (int)(gistT.window.xmax*map->x.scale + map->x.offset);
  yn = (int)(gistT.window.ymin*map->y.scale + map->y.offset);
  yx = (int)(gistT.window.ymax*map->y.scale + map->y.offset);
  if (yn > yx) { int tmp=yn ; yn=yx; yx=tmp ; }

  /* handle multi-line strings */
  len = GxJustifyText(map, x0, y0, text, &ix, &iy, xbox, ybox);
  if (len < 0) return 0;

  /* consider whether string is completely clipped */
  if (ybox[0]>yx || ybox[1]<yn || xbox[0]>xx || xbox[1]<xn) return 0;

  /* erase background if string is opaque */
  if (gistA.t.opaque) {
    p_color(w, P_BG);
    p_rect(w, xbox[0], ybox[0], xbox[1], ybox[1], 0);
  }
  p_color(w, gistA.t.color);

  do {
    if (len>0) {
      if (len==1 && (current_state&4) && text[0]==']') txt = caret;
      else txt = text;
      p_text(w, ix, iy, txt, len);
    }
    len = GxJustifyNext(&text, &ix, &iy);
  } while (len>=0);

  xeng->e.marked = 1;
  return 0;
}
Exemple #3
0
    Button::Button(ButtonStyle style, const FontHolder& fonts, const TextureHolder& textures)
    : mStyle(style),
      mFonts(fonts),
      mTextures(textures),
      mIsFocusable(true),
      mIsFixedSize(true),
      mCallback(),
      p_mShape(nullptr),
      p_mSprite(nullptr),
      p_mText(nullptr),
      mColor(COLOR_ON_RELEASED),
      mTextColor(TEXT_COLOR_DEFAULT),
      mScale(1.f, 1.f),
      mState(State::OnReleased)
    {
        if (mStyle == Button::Sprite)
        {
            std::unique_ptr<sf::Sprite> p_sprite(new sf::Sprite());
            p_sprite->setTexture(textures.get(Textures::Button));
            Graphics::centerOrigin(*p_sprite);
            p_mSprite = std::move(p_sprite);
            setText("");
        }
        else
        {
            std::unique_ptr<sf::RectangleShape> p_rect(
                new sf::RectangleShape(sf::Vector2f(BUTTON_WIDTH, BUTTON_HEIGHT)));
            Graphics::centerOrigin(*p_rect);
            p_mShape = std::move(p_rect);

            if (mStyle == ButtonStyle::Text)
            {
                std::unique_ptr<sf::Text> p_text(new sf::Text());
                p_text->setFont(fonts.get(Fonts::Chinese));
                //p_text->setCharacterSize(30);
                p_text->setColor(mTextColor);
                p_text->setString("Button");
                Graphics::centerOrigin(*p_text);
                
                p_mShape->setFillColor(TEXT_BG_COLOR_RELEASED);
                p_mShape->setOutlineThickness(OUT_LINE_THICKNESS);
                p_mShape->setOutlineColor(mTextColor);

                p_mText = std::move(p_text);
            }

            setText("");
        }
    }
Exemple #4
0
static void
ClearArea(Engine *engine, GpBox *box)
{
  XEngine *xeng= (XEngine *)engine;
  p_win *w = xeng->w;
  int x0, y0, x1, y1;
  if (!w) return;
  /* if this is animation mode, do not try to clear window */
  if (w==xeng->win) {
    int lm = xeng->leftMargin;
    int tm = xeng->topMargin;
    GetXRectangle(&engine->devMap, box, &x0, &y0, &x1, &y1);
    if (x0 < lm) x0 = lm;
    if (x1 > lm+xeng->wtop) x1 = lm+xeng->wtop;
    if (y0 < tm) y0 = tm;
    if (y1 > tm+xeng->htop) y1 = tm+xeng->htop;
    p_color(w, P_BG);
    p_rect(w, x0, y0, x1, y1, 0);
  }
}