DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2689
Version: 1.3-current


There's somethng a bit weird going on with the expansion of symbols, in
particualr the "@" symbol, when using fl_draw.

This was initially flagged in the following thread:

http://www.fltk.org/newsgroups.php?gfltk.general+v:33384 

The attached patch I think illustrates the problem.

Or maybe I just don't understand what it's meant to do?

In any case, the behaviour seems wrong.

NOTE: 1.3.x and 1.1.x behave in the same way, as of r8868.

What I see:

A string with a single @ symbol and "draw_symbols" disabled (i.e. not the
default draw_symbols state) is *not* correctly drawn if the string has to
wrap to fit the box, particularly if the wrap-point occurs within the word
that starts with the "@" symbol.
If the wrap does not "interact" with the "@" symbol, the string seems to
draw more as I'd expect.

In addition, turning off symbol-parsing by starting the string with "@."
does not seem to be having quite the effect I'd anticiapted.

I suspect there is something awry with measuring the string and symbol
expansion...

The example allows various combinations of escaped (i.e. "@@") and
not-escaped strings to be drawn, with and without symbol expansion.

The results are puzzling and not what I had expected.

Is it a bug? I think it may well be.


Link: http://www.fltk.org/str.php?L2689
Version: 1.3-current
/***********************************************************/
// compile as:
// fltk-config --compile draw_test.cxx
//
#include <string.h>
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Round_Button.H>
#include <FL/Fl_Check_Button.H>
#include <FL/fl_draw.H>

static Fl_Double_Window *main_win;
static Fl_Group *str_grp=(Fl_Group *)0;
static Fl_Round_Button *bt1=(Fl_Round_Button *)0;
static Fl_Round_Button *bt2=(Fl_Round_Button *)0;
static Fl_Round_Button *bt3=(Fl_Round_Button *)0;
static Fl_Check_Button *dr_symbs=(Fl_Check_Button *)0;
static Fl_Check_Button *use_esc=(Fl_Check_Button *)0;

static int draw_symbols = 0;
static int use_escaped = 0;
static int string_state = 2;

static const char s1[] = "first @second third"; // plain string
static const char s2[] = "first @@second third"; // escaped string
static const char s3[] = "@.first @second third"; // no-expansion string

// "escaped" versions of the above for display purposes...
static const char s1e[] = "first @@second third";
static const char s2e[] = "first @@@@second third";
static const char s3e[] = "@@.first @@second third";

/***********************************************************/
class tst_box : public Fl_Box {
protected:
  void draw(void);
  const char *line;
public:
  tst_box(int X, int Y, int W, int H) : Fl_Box(X,Y,W,H)
    {line = NULL;}

  void set_data(const char *newdat);
};
/***********************************************************/
void tst_box::set_data(const char *newdat) {
  line = newdat;
}

/***********************************************************/
void tst_box::draw(void) {
  int wd = w(), ht = h();
  int xo = x(), yo = y();

  // first clear out the view
  fl_color(FL_WHITE); // background colour
  fl_rectf(xo, yo, wd, ht);

  if (!line) return;

  fl_color(FL_DARK_BLUE); // text colour
  fl_font(FL_COURIER, 14); // text face
  fl_draw(line, xo, yo, wd, ht, (Fl_Align)(FL_ALIGN_CLIP | FL_ALIGN_TOP_LEFT | 
FL_ALIGN_WRAP), 0, draw_symbols);
}

/***********************************************************/
static tst_box *box_2; // image box

/***********************************************************/
void quit_cb(Fl_Button *, void *) {
  main_win->hide();
}

/***********************************************************/
static void cb_bt1(Fl_Round_Button*, void*) {
  string_state = 1;
  if(use_escaped) {
    box_2->set_data(s1e);
  }
  else
    box_2->set_data(s1);
  main_win->redraw();
}


/***********************************************************/
static void cb_bt2(Fl_Round_Button*, void*) {
  string_state = 2;
  if(use_escaped) {
    box_2->set_data(s2e);
  }
  else
    box_2->set_data(s2);
  main_win->redraw();
}


/***********************************************************/
static void cb_bt3(Fl_Round_Button*, void*) {
  string_state = 3;
  if(use_escaped) {
    box_2->set_data(s3e);
  }
  else
    box_2->set_data(s3);
  main_win->redraw();
}


/***********************************************************/
static void cb_dr_symbs(Fl_Check_Button*, void*) {
  draw_symbols = dr_symbs->value();
  main_win->redraw();
}

/***********************************************************/
static void cb_use_esc(Fl_Check_Button*, void*) {
  use_escaped = use_esc->value();
  switch(string_state){
  case 1: cb_bt1(NULL, NULL); break;
  case 2: cb_bt2(NULL, NULL); break;
  case 3: cb_bt3(NULL, NULL); break;
  }
  main_win->redraw();
}

/***********************************************************/
int main(int argc, char **argv) {
  int WW = 60, HH = 60;

  main_win = new Fl_Double_Window(460, 210);
  main_win->begin();

  box_2 = new tst_box(10, 10, WW, HH);

  str_grp = new Fl_Group(10, HH + 20, 300, 120);
  str_grp->box(FL_ENGRAVED_BOX);
    bt1 = new Fl_Round_Button(15, HH + 30, 280, 25, s1e);
    bt1->type(102);
    bt1->down_box(FL_ROUND_DOWN_BOX);
    bt1->callback((Fl_Callback*)cb_bt1);

    bt2 = new Fl_Round_Button(15, HH + 65, 280, 25, s2e);
    bt2->type(102);
    bt2->value(1);
    bt2->down_box(FL_ROUND_DOWN_BOX);
    bt2->callback((Fl_Callback*)cb_bt2);

    bt3 = new Fl_Round_Button(15, HH + 100, 280, 25, s3e);
    bt3->type(102);
    bt3->down_box(FL_ROUND_DOWN_BOX);
    bt3->callback((Fl_Callback*)cb_bt3);

    Fl_Box *dummy1 = new Fl_Box(297, HH+30, 1, 1);
  str_grp->end();
  str_grp->resizable(dummy1);

  dr_symbs = new Fl_Check_Button(330, HH + 20, 120, 25, "Draw Symbols");
  dr_symbs->down_box(FL_DOWN_BOX);
  dr_symbs->value(0);
  dr_symbs->callback((Fl_Callback*)cb_dr_symbs);

  use_esc = new Fl_Check_Button(330, HH + 20 + 20, 120, 25, "Escaped string");
  use_esc->down_box(FL_DOWN_BOX);
  use_esc->value(0);
  use_esc->callback((Fl_Callback*)cb_use_esc);

  Fl_Button *quit = new Fl_Button(330, HH + 20 + 120 - 30, 60, 30, "Quit");
  quit->callback((Fl_Callback *)quit_cb);


  main_win->end();
  main_win->resizable(box_2);
  main_win->show(argc, argv);

  // test string to be displayed
  box_2->set_data(s2);

  // run the main loop
  return Fl::run();
}

/* End of File */
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to