Page 1 of 6

TextOut y value

Posted: 26 Jan 2012, 02:13
by mattallen37
NBC/NXC Guide wrote:Values of Y other than these constants will be adjusted so that text and numbers are on one of 8 fixed line positions.
So that's a FW implemented limitation? Is there any good reason for it? I just wrote out the entire supported list of ASCII characters as bitmaps for RIC arrays so that I could use any y value I wanted.

Re: TextOut y value

Posted: 26 Jan 2012, 15:55
by afanofosc
The reason for this is that the code is simpler to fill the memory that is drawn to the LCD since every byte represents a vertical strip of 8 pixels and 100 bytes is a row that is displayed on the LCD. If you could draw text to any Y pixel (0..63) then the text drawing code would have had to take some bits from the desired character and put them in the bytes that represent line N and take some other bits from the character and put them in the bytes that represent line N+1. That's not terribly hard to do but it is more complicated. If someone clever looked at the firmware code and showed me how to change it to support drawing at any Y value I'd happily make the change, so long as it was not a ton of code. I could probably figure it all out on my own but I've just not ever had it sufficiently high on my priority list to dig into it and figure out how to make it work.

John Hansen

Re: TextOut y value

Posted: 26 Jan 2012, 18:45
by ronmcrae
mattallen37 wrote:
NBC/NXC Guide wrote:just wrote out the entire supported list of ASCII characters as bitmaps for RIC arrays so that I could use any y value I wanted.
You did get your RIC array version to work on any Y pixel, right? I created a RIC font file that mimics the standard NXT font, but it can be written to any Y pixel using the enhanced RIC font-type functions, so there are definitely work-arounds for the F/W limitation.

Re: TextOut y value

Posted: 26 Jan 2012, 20:01
by HaWe
I think matt knows how to use ric fonts to display strings and numbers, we have been discussing this before already in the old nextasy forum
I'm always using sort of this:

Code: Select all

#download    "Fixed_6.ric"

string __gFTFontName;
inline void SetFont(string name) { __gFTFontName = name; }

#define printfg( _x, _y, _format1, _value1) { \
  string sval1 = FormatNum(_format1, _value1); \
  FontTextOut(_x, _y, __gFTFontName, sval1); \
}

task main() {
   SetFont("Fixed_6.ric");
   
   printfg( 9,39,"%s", "print graphic test");
   printfg(29,19,"%d", 1234);
   printfg(19,13,"%5.2f", 123.456789);

   while(1);
}
I suppose matt meant how to use the original display functions (NumOut, TextOut, print, printf ) at any (x,y) without having to use downloaded ric fonts, CMIIW

Re: TextOut y value

Posted: 26 Jan 2012, 22:36
by mattallen37
I didn't know how to use nxtRICeditV2 until I was doing some research last night, and happened upon a tutorial that explained it to some degree.

What I did, was make an array like this:

Code: Select all

byte ric_ASCII_8_6_data [] = { RICOpSprite(1, 8, 1, RICSpriteData(
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00)),
  RICOpCopyBits(0, 1, RICImgRect( RICImgPoint(0, 0), 6, 8), RICImgPoint(0, 0))
};
as a template, and then I filled in the 8 bytes at elements 10-18 with the values that represented the ASCII character I wanted to print. I made those arrays like this:

Code: Select all

byte ric_space_[] = {
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00};

byte ric_ex_[] = {
0x20,
0x70,
0x70,
0x20,
0x20,
0x00,
0x20,
0x00};

byte ric_quote_[] = {
0xd8,
0xd8,
0x90,
0x00,
0x00,
0x00,
0x00,
0x00};

byte ric_hash_[] = {
0x00,
0x50,
0xf8,
0x50,
0x50,
0xf8,
0x50,
0x00};

byte ric_dollar_[] = {
0x40,
0x70,
0x80,
0x60,
0x10,
0xe0,
0x20,
0x00};

byte ric_percent_[] = {
0xc8,
0xc8,
0x10,
0x20,
0x40,
0x98,
0x98,
0x00};

byte ric_and_[] = {
0x00,
0x30,
0x40,
0x40,
0xa8,
0x90,
0x68,
0x00};

byte ric_apost_[] = {
0x60,
0x60,
0x40,
0x00,
0x00,
0x00,
0x00,
0x00};

byte ric_spar_[] = {
0x20,
0x40,
0x40,
0x40,
0x40,
0x40,
0x20,
0x00};

byte ric_epar_[] = {
0x40,
0x20,
0x20,
0x20,
0x20,
0x20,
0x40,
0x00};

byte ric_star_[] = {
0x00,
0x50,
0x70,
0xf8,
0x70,
0x50,
0x00,
0x00};

byte ric_plus_[] = {
0x00,
0x20,
0x20,
0xf8,
0x20,
0x20,
0x00,
0x00};

byte ric_comma_[] = {
0x00,
0x00,
0x00,
0x00,
0x00,
0x60,
0x60,
0x80};

byte ric_minus_[] = {
0x00,
0x00,
0x00,
0xf8,
0x00,
0x00,
0x00,
0x00};

byte ric_period_[] = {
0x00,
0x00,
0x00,
0x00,
0x00,
0x60,
0x60,
0x00};

byte ric_div_[] = {
0x00,
0x00,
0x08,
0x10,
0x20,
0x40,
0x80,
0x00};

byte ric_0[] = {
0x70,
0x88,
0x98,
0xa8,
0xc8,
0x88,
0x70,
0x00};

byte ric_1[] = {
0x20,
0x60,
0x20,
0x20,
0x20,
0x20,
0x70,
0x00};

byte ric_2[] = {
0x70,
0x88,
0x08,
0x30,
0x40,
0x80,
0xf8,
0x00};

byte ric_3[] = {
0x70,
0x88,
0x08,
0x70,
0x08,
0x88,
0x70,
0x00};

byte ric_4[] = {
0x10,
0x30,
0x50,
0x90,
0xf8,
0x10,
0x10,
0x00};

byte ric_5[] = {
0xF8,
0x80,
0x80,
0xf0,
0x08,
0x88,
0x70,
0x00};

byte ric_6[] = {
0x30,
0x40,
0x80,
0xf0,
0x88,
0x88,
0x70,
0x00};

byte ric_7[] = {
0xf8,
0x08,
0x10,
0x20,
0x40,
0x40,
0x40,
0x00};

byte ric_8[] = {
0x70,
0x88,
0x88,
0x70,
0x88,
0x88,
0x70,
0x00};

byte ric_9[] = {
0x70,
0x88,
0x88,
0x78,
0x08,
0x10,
0x60,
0x00};

byte ric_colon_[] = {
0x00,
0x00,
0x60,
0x60,
0x00,
0x60,
0x60,
0x00};

byte ric_scolon_[] = {
0x00,
0x00,
0x60,
0x60,
0x00,
0x60,
0x60,
0x40};

byte ric_lessthn_[] = {
0x10,
0x20,
0x40,
0x80,
0x40,
0x20,
0x10,
0x00};

byte ric_equal_[] = {
0x00,
0x00,
0xf8,
0x00,
0x00,
0xf8,
0x00,
0x00};

byte ric_gtrthn_[] = {
0x80,
0x40,
0x20,
0x10,
0x20,
0x40,
0x80,
0x00};

byte ric_quest_[] = {
0x70,
0x88,
0x08,
0x30,
0x20,
0x00,
0x20,
0x00};

byte ric_at_[] = {
0x70,
0x88,
0xb8,
0xa8,
0xb8,
0x80,
0x70,
0x00};

byte ric_A[] = {
0x70,
0x88,
0x88,
0x88,
0xf8,
0x88,
0x88,
0x00};

byte ric_B[] = {
0xf0,
0x88,
0x88,
0xf0,
0x88,
0x88,
0xf0,
0x00};

byte ric_C[] = {
0x70,
0x88,
0x80,
0x80,
0x80,
0x88,
0x70,
0x00};

byte ric_D[] = {
0xf0,
0x88,
0x88,
0x88,
0x88,
0x88,
0xf0,
0x00};

byte ric_E[] = {
0xf8,
0x80,
0x80,
0xf0,
0x80,
0x80,
0xf8,
0x00};

byte ric_F[] = {
0xf8,
0x80,
0x80,
0xf0,
0x80,
0x80,
0x80,
0x00};

byte ric_G[] = {
0x70,
0x88,
0x80,
0xb8,
0x88,
0x88,
0x78,
0x00};

byte ric_H[] = {
0x88,
0x88,
0x88,
0xf8,
0x88,
0x88,
0x88,
0x00};

byte ric_I[] = {
0x70,
0x20,
0x20,
0x20,
0x20,
0x20,
0x70,
0x00};

byte ric_J[] = {
0x08,
0x08,
0x08,
0x08,
0x88,
0x88,
0x70,
0x00};

byte ric_K[] = {
0x88,
0x90,
0xa0,
0xc0,
0xa0,
0x90,
0x88,
0x00};

byte ric_L[] = {
0x80,
0x80,
0x80,
0x80,
0x80,
0x80,
0xf8,
0x00};

byte ric_M[] = {
0x88,
0xd8,
0xa8,
0x88,
0x88,
0x88,
0x88,
0x00};

byte ric_N[] = {
0x88,
0xc8,
0xa8,
0x98,
0x88,
0x88,
0x88,
0x00};

byte ric_O[] = {
0x70,
0x88,
0x88,
0x88,
0x88,
0x88,
0x70,
0x00};

byte ric_P[] = {
0xf0,
0x88,
0x88,
0xf0,
0x80,
0x80,
0x80,
0x00};

byte ric_Q[] = {
0x70,
0x88,
0x88,
0x88,
0xa8,
0x90,
0x68,
0x00};

byte ric_R[] = {
0xf0,
0x88,
0x88,
0xf0,
0x90,
0x88,
0x88,
0x00};

byte ric_S[] = {
0x70,
0x88,
0x80,
0x70,
0x08,
0x88,
0x70,
0x00};

byte ric_T[] = {
0xf8,
0x20,
0x20,
0x20,
0x20,
0x20,
0x20,
0x00};

byte ric_U[] = {
0x88,
0x88,
0x88,
0x88,
0x88,
0x88,
0x70,
0x00};

byte ric_V[] = {
0x88,
0x88,
0x88,
0x88,
0x88,
0x50,
0x20,
0x00};

byte ric_W[] = {
0x88,
0x88,
0xa8,
0xa8,
0xa8,
0xa8,
0x50,
0x00};

byte ric_X[] = {
0x88,
0x88,
0x50,
0x20,
0x50,
0x88,
0x88,
0x00};

byte ric_Y[] = {
0x88,
0x88,
0x88,
0x50,
0x20,
0x20,
0x20,
0x00};

byte ric_Z[] = {
0xf0,
0x10,
0x20,
0x40,
0x80,
0x80,
0xf0,
0x00};

byte ric_sbrack_[] = {
0x70,
0x40,
0x40,
0x40,
0x40,
0x40,
0x70,
0x00};

byte ric_bslash_[] = {
0x00,
0x80,
0x40,
0x20,
0x10,
0x08,
0x00,
0x00};

byte ric_ebrack_[] = {
0x70,
0x10,
0x10,
0x10,
0x10,
0x10,
0x70,
0x00};

byte ric_carret_[] = {
0x20,
0x50,
0x88,
0x00,
0x00,
0x00,
0x00,
0x00};

byte ric_underscore_[] = {
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0xf8};

byte ric_degree_[] = {
0x20,
0x50,
0x20,
0x00,
0x00,
0x00,
0x00,
0x00};

byte ric_a[] = {
0x00,
0x00,
0x70,
0x08,
0x78,
0x88,
0x78,
0x00};

byte ric_b[] = {
0x80,
0x80,
0xf0,
0x88,
0x88,
0x88,
0xf0,
0x00};

byte ric_c[] = {
0x00,
0x00,
0x70,
0x88,
0x80,
0x88,
0x70,
0x00};

byte ric_d[] = {
0x08,
0x08,
0x78,
0x88,
0x88,
0x88,
0x78,
0x00};

byte ric_e[] = {
0x00,
0x00,
0x70,
0x88,
0xf0,
0x80,
0x70,
0x00};

byte ric_f[] = {
0x30,
0x40,
0x40,
0xf0,
0x40,
0x40,
0x40,
0x00};

byte ric_g[] = {
0x00,
0x00,
0x78,
0x88,
0x88,
0x78,
0x08,
0x38};

byte ric_h[] = {
0x80,
0x80,
0xe0,
0x90,
0x90,
0x90,
0x90,
0x00};

byte ric_i[] = {
0x20,
0x00,
0x20,
0x20,
0x20,
0x20,
0x30,
0x00};

byte ric_j[] = {
0x10,
0x00,
0x30,
0x10,
0x10,
0x10,
0x90,
0x60};

byte ric_k[] = {
0x80,
0x80,
0x90,
0xa0,
0xc0,
0xa0,
0x90,
0x00};

byte ric_l[] = {
0x20,
0x20,
0x20,
0x20,
0x20,
0x20,
0x30,
0x00};

byte ric_m[] = {
0x00,
0x00,
0xd0,
0xa8,
0xa8,
0x88,
0x88,
0x00};

byte ric_n[] = {
0x00,
0x00,
0xe0,
0x90,
0x90,
0x90,
0x90,
0x00};

byte ric_o[] = {
0x00,
0x00,
0x70,
0x88,
0x88,
0x88,
0x70,
0x00};

byte ric_p[] = {
0x00,
0x00,
0xf0,
0x88,
0x88,
0x88,
0xf0,
0x80};

byte ric_q[] = {
0x00,
0x00,
0x78,
0x88,
0x88,
0x88,
0x78,
0x08};

byte ric_r[] = {
0x00,
0x00,
0xb0,
0x48,
0x40,
0x40,
0xe0,
0x00};

byte ric_s[] = {
0x00,
0x00,
0x70,
0x80,
0x70,
0x08,
0x70,
0x00};

byte ric_t[] = {
0x00,
0x40,
0xf0,
0x40,
0x40,
0x50,
0x20,
0x00};

byte ric_u[] = {
0x00,
0x00,
0x90,
0x90,
0x90,
0xb0,
0x50,
0x00};

byte ric_v[] = {
0x00,
0x00,
0x88,
0x88,
0x88,
0x50,
0x20,
0x00};

byte ric_w[] = {
0x00,
0x00,
0x88,
0x88,
0xa8,
0xf8,
0x50,
0x00};

byte ric_x[] = {
0x00,
0x00,
0x90,
0x90,
0x60,
0x90,
0x90,
0x00};

byte ric_y[] = {
0x00,
0x00,
0x90,
0x90,
0x90,
0x70,
0x20,
0xc0};

byte ric_z[] = {
0x00,
0x00,
0xf0,
0x10,
0x60,
0x80,
0xf0,
0x00};

byte ric_sbrace_[] = {
0x30,
0x40,
0x40,
0xc0,
0x40,
0x40,
0x30,
0x00};

byte ric_vert_[] = {
0x20,
0x20,
0x20,
0x00,
0x20,
0x20,
0x20,
0x00};

byte ric_ebrace_[] = {
0x60,
0x10,
0x10,
0x18,
0x10,
0x10,
0x60,
0x00};

byte ric_about_[] = {
0x00,
0x50,
0xa0,
0x00,
0x00,
0x00,
0x00,
0x00};

byte ric_chkmrk_[] = {
0x08,
0x08,
0x08,
0x10,
0x90,
0x50,
0x20,
0x00};
I used a switch as a look-up table for the character I wanted to print:

Code: Select all

void RICTextOut(byte x, byte y, string msg, unsigned int options = 0){
  byte Chars = strlen(msg);
  byte msg_array[];
  ArrayInit(msg_array, 0, Chars)
  UnflattenVar(msg, msg_array);
  byte tempArr [8];
  for (int i=0; i < Chars; i++){
    char charactor = msg_array[i];
    switch (charactor){
      case 32:
        tempArr = ric_space_;
      break;
      case 33:
        tempArr = ric_ex_;
      break;
      case 34:
        tempArr = ric_quote_;
      break;
      case 35:
        tempArr = ric_hash_;
      break;
      case 36:
        tempArr = ric_dollar_;
      break;
      case 37:
        tempArr = ric_percent_;
      break;
      case 38:
        tempArr = ric_and_;
      break;
      case 39:
        tempArr = ric_apost_;
      break;
      case 40:
        tempArr = ric_spar_;
      break;
      case 41:
        tempArr = ric_epar_;
      break;
      case 42:
        tempArr = ric_star_;
      break;
      case 43:
        tempArr = ric_plus_;
      break;
      case 44:
        tempArr = ric_comma_;
      break;
      case 45:
        tempArr = ric_minus_;
      break;
      case 46:
        tempArr = ric_period_;
      break;
      case 47:
        tempArr = ric_div_;
      break;
      case 48:
        tempArr = ric_0;
      break;
      case 49:
        tempArr = ric_1;
      break;
      case 50:
        tempArr = ric_2;
      break;
      case 51:
        tempArr = ric_3;
      break;
      case 52:
        tempArr = ric_4;
      break;
      case 53:
        tempArr = ric_5;
      break;
      case 54:
        tempArr = ric_6;
      break;
      case 55:
        tempArr = ric_7;
      break;
      case 56:
        tempArr = ric_8;
      break;
      case 57:
        tempArr = ric_9;
      break;
      case 58:
        tempArr = ric_colon_;
      break;
      case 59:
        tempArr = ric_scolon_;
      break;
      case 60:
        tempArr = ric_lessthn_;
      break;
      case 61:
        tempArr = ric_equal_;
      break;
      case 62:
        tempArr = ric_gtrthn_;
      break;
      case 63:
        tempArr = ric_quest_;
      break;
      case 64:
        tempArr = ric_at_;
      break;
      case 65:
        tempArr = ric_A;
      break;
      case 66:
        tempArr = ric_B;
      break;
      case 67:
        tempArr = ric_C;
      break;
      case 68:
        tempArr = ric_D;
      break;
      case 69:
        tempArr = ric_E;
      break;
      case 70:
        tempArr = ric_F;
      break;
      case 71:
        tempArr = ric_G;
      break;
      case 72:
        tempArr = ric_H;
      break;
      case 73:
        tempArr = ric_I;
      break;
      case 74:
        tempArr = ric_J;
      break;
      case 75:
        tempArr = ric_K;
      break;
      case 76:
        tempArr = ric_L;
      break;
      case 77:
        tempArr = ric_M;
      break;
      case 78:
        tempArr = ric_N;
      break;
      case 79:
        tempArr = ric_O;
      break;
      case 80:
        tempArr = ric_P;
      break;
      case 81:
        tempArr = ric_Q;
      break;
      case 82:
        tempArr = ric_R;
      break;
      case 83:
        tempArr = ric_S;
      break;
      case 84:
        tempArr = ric_T;
      break;
      case 85:
        tempArr = ric_U;
      break;
      case 86:
        tempArr = ric_V;
      break;
      case 87:
        tempArr = ric_W;
      break;
      case 88:
        tempArr = ric_X;
      break;
      case 89:
        tempArr = ric_Y;
      break;
      case 90:
        tempArr = ric_Z;
      break;
      case 91:
        tempArr = ric_sbrack_;
      break;
      case 92:
        tempArr = ric_bslash_;
      break;
      case 93:
        tempArr = ric_ebrack_;
      break;
      case 94:
        tempArr = ric_carret_;
      break;
      case 95:
        tempArr = ric_underscore_;
      break;
      case 96:
        tempArr = ric_degree_;
      break;
      case 97:
        tempArr = ric_a;
      break;
      case 98:
        tempArr = ric_b;
      break;
      case 99:
        tempArr = ric_c;
      break;
      case 100:
        tempArr = ric_d;
      break;
      case 101:
        tempArr = ric_e;
      break;
      case 102:
        tempArr = ric_f;
      break;
      case 103:
        tempArr = ric_g;
      break;
      case 104:
        tempArr = ric_h;
      break;
      case 105:
        tempArr = ric_i;
      break;
      case 106:
        tempArr = ric_j;
      break;
      case 107:
        tempArr = ric_k;
      break;
      case 108:
        tempArr = ric_l;
      break;
      case 109:
        tempArr = ric_m;
      break;
      case 110:
        tempArr = ric_n;
      break;
      case 111:
        tempArr = ric_o;
      break;
      case 112:
        tempArr = ric_p;
      break;
      case 113:
        tempArr = ric_q;
      break;
      case 114:
        tempArr = ric_r;
      break;
      case 115:
        tempArr = ric_s;
      break;
      case 116:
        tempArr = ric_t;
      break;
      case 117:
        tempArr = ric_u;
      break;
      case 118:
        tempArr = ric_v;
      break;
      case 119:
        tempArr = ric_w;
      break;
      case 120:
        tempArr = ric_x;
      break;
      case 121:
        tempArr = ric_y;
      break;
      case 122:
        tempArr = ric_z;
      break;
      case 123:
        tempArr = ric_sbrace_;
      break;
      case 124:
        tempArr = ric_vert_;
      break;
      case 125:
        tempArr = ric_ebrace_;
      break;
      case 126:
        tempArr = ric_about_;
      break;
      case 127:
        tempArr = ric_chkmrk_;
      break;
    }
    for (int ii=0; ii<8; ii++){
      ric_ASCII_8_6_data[ii+10] = tempArr[ii];
    }
    GraphicArrayOut(x+(i*6), y, ric_ASCII_8_6_data);
  }
}

void RICNumOut(byte x, byte y, float var, unsigned int options = 0){
  string msg = NumToStr(var);
  RICTextOut(x, y, msg, options);
}
I see now, that you can actually use just one RIC file, with some special parameters (VarMaps) to make a font package. That's what I will probably use now instead.

@Ford, I actually didn't know how to until yesterday, but now that I do, I want to start experimenting some.

Also, I found font packages on the nxtRICeditV2 site for 3x4 (actually 4x4), 5x6, and 10x10. Is there a RIC file around somewhere for the standard 6x8?

Re: TextOut y value

Posted: 27 Jan 2012, 09:42
by HaWe
matt,
it seldom happens that I actually overestimate your facilities... ;)
I ususally use this package including fonts and the RicFont.exe editor (you may load and convert all windows fonts of all sizes you like):
Fonts.zip
(415.08 KiB) Downloaded 500 times
font6x8 is probably what you're looking for but there are several others in different sizes:
Sans is proportional sans_serife which is like Helvetica
Serife is proportional almost like TimesRoman
Fixed is fixed_space which is like Type Writer Courier
Tiny is a Small Font (fixed IIRC)
Symbol and nxtDings both contain symbols and foreign characters/letters
NI7seg is a LCD-like 7 segmented font
StarJedi and StarTrek are proportional from Outer Space (by some good old friends of mine) ;)

HTH!

Re: TextOut y value

Posted: 27 Jan 2012, 15:54
by ronmcrae
The file font6x8.ric that Doc posted is the one that mimics the standard NXT font via a RIC. For some reason that file looks somewhat familiar to me. Use it to write text to any Y coordinate with something along the lines...

Code: Select all

task main()
{
    while(true)
    {
      for (int y=56;y>0;y--)
       {FontTextOut(17,y, "font6x8.ric", "HELLO WORLD",DRAW_OPT_NORMAL);
        Wait(100);
        FontTextOut(17,y, "font6x8.ric", "HELLO WORLD",DRAW_OPT_NORMAL|DRAW_OPT_LOGICAL_XOR);
       }
     }
}

Re: TextOut y value

Posted: 27 Jan 2012, 21:46
by mattallen37
Thanks guys!

Re: TextOut y value

Posted: 06 Feb 2012, 18:21
by afanofosc
In case it slipped past without being noticed, please read this post:

https://sourceforge.net/apps/phpbb/mind ... 150#p12086

I mention in it that the latest enhanced NBC/NXC firmware (see the test_releases folder) now supports drawing text to any Y value. This capability may be buggy but it appears to work for non-boundary conditions, at least.

John Hansen

Re: TextOut y value

Posted: 06 Feb 2012, 18:36
by HaWe
do I understand you correctly that TextOut now also works like

Code: Select all

// 9 lines!
TextOut(0,56,"Cicero scripsit:");
TextOut(0,49,"Neque porro quisquam");
TextOut(0,42,"est, qui dolorem");
TextOut(0,35,"ipsum,quia dolor sit,"
TextOut(0,28,"amet, consectetur,");
TextOut(0,21,"adipisci con velit-");
TextOut(0,14,"Sed Cicero");
TextOut(0, 7,"erat iniuriam:");
TextOut(0, 0,"Jackass est!");

?