void *
sml_matrix_insert(struct sml_matrix *m, uint16_t i, uint16_t j)
{
    struct sol_vector *line = _get_line(&m->data, i, m->elem_size);

    if (!line)
        return NULL;
    return _get_column(line, j, m->elem_size);
}
Example #2
0
hgeFont::hgeFont(const char *szFont, bool bMipmap)
{
  void  *data;
  uint32_t  size;
  char  *desc, *pdesc;
  char  linebuf[256];
  char  buf[MAX_PATH], *pbuf;
  char  chr;
  int   i, x, y, w, h, a, c;

  // Setup variables

  hge = hgeCreate(HGE_VERSION);

  fHeight = 0.0f;
  fScale = 1.0f;
  fProportion = 1.0f;
  fRot = 0.0f;
  fTracking = 0.0f;
  fSpacing = 1.0f;
  hTexture = 0;

  fZ = 0.5f;
  nBlend = BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE;
  dwCol = 0xFFFFFFFF;

  ZeroMemory(&letters, sizeof(letters));
  ZeroMemory(&pre, sizeof(letters));
  ZeroMemory(&post, sizeof(letters));

  // Load font description

  data = hge->Resource_Load(szFont, &size);

  if (!data) {
    return;
  }

  desc = new char[size + 1];
  memcpy(desc, data, size);
  desc[size] = 0;
  hge->Resource_Free(data);

  pdesc = _get_line(desc, linebuf);

  if (strcmp(linebuf, FNTHEADERTAG)) {
    hge->System_Log("Font %s has incorrect format.", szFont);
    delete[] desc;
    return;
  }

  // Parse font description

  while (pdesc = _get_line(pdesc, linebuf)) {
    if (!strncmp(linebuf, FNTBITMAPTAG, sizeof(FNTBITMAPTAG) - 1)) {
      strcpy(buf, szFont);
      pbuf = strrchr(buf, '\\');

      if (!pbuf) {
        pbuf = strrchr(buf, '/');
      }

      if (!pbuf) {
        pbuf = buf;
      } else {
        pbuf++;
      }

      if (!sscanf(linebuf, "Bitmap = %s", pbuf)) {
        continue;
      }

      hTexture = hge->Texture_Load(buf, 0, bMipmap);

      if (!hTexture) {
        delete[] desc;
        return;
      }
    }

    else if (!strncmp(linebuf, FNTCHARTAG, sizeof(FNTCHARTAG) - 1)) {
      pbuf = strchr(linebuf, '=');

      if (!pbuf) {
        continue;
      }

      pbuf++;

      while (*pbuf == ' ') {
        pbuf++;
      }

      if (*pbuf == '\"') {
        pbuf++;
        i = (unsigned char) * pbuf++;
        pbuf++; // skip "
      } else {
        i = 0;

        while ((*pbuf >= '0' && *pbuf <= '9') || (*pbuf >= 'A' && *pbuf <= 'F') || (*pbuf >= 'a'
               && *pbuf <= 'f')) {
          chr = *pbuf;

          if (chr >= 'a') {
            chr -= 'a' - ':';
          }

          if (chr >= 'A') {
            chr -= 'A' - ':';
          }

          chr -= '0';

          if (chr > 0xF) {
            chr = 0xF;
          }

          i = (i << 4) | chr;
          pbuf++;
        }

        if (i < 0 || i > 255) {
          continue;
        }
      }

      sscanf(pbuf, " , %d , %d , %d , %d , %d , %d", &x, &y, &w, &h, &a, &c);

      letters[i] = new hgeSprite(hTexture, (float)x, (float)y, (float)w, (float)h);
      pre[i] = (float)a;
      post[i] = (float)c;

      if (h > fHeight) {
        fHeight = (float)h;
      }
    }
  }

  delete[] desc;
}
Example #3
0
char *fd_get_line(int fd) {
  return _get_line(fd,0);
}
Example #4
0
char *get_line(SOCKET fd) {
  /* are we actually being asked to read from stdout? Then read
     from stdin */
  if ( fd == STDOUT_FILENO ) return _get_line(STDIN_FILENO,0);
  return _get_line((int)fd,1);
}
Example #5
0
// Create a font object from sFileName specified
bool UIFont::Create(const tchar* sFileName)
{
	if(NULL == sFileName)
	{
		return false;
	}

	void	*data;
	uint32	size;
	tchar	*desc, *pdesc;
	tchar	linebuf[256];
	tchar	buf[GT_PATH_MAX_LEN], *pbuf;
	tchar	chr;
	int32	i, x, y, w, h, a, c;

	// Setup variables
	fHeight = 0.0f;
	//fScale = 1.0f;
	fProportion = 1.0f;
	//fRot = 0.0f;
	fTracking = 0.0f;
	fSpacing = 1.0f;
	m_pTexture = NULL;

	fZ = 0.5f;
	//nBlend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE;
	dwCol = 0xFFFFFFFF;

	ClearMemory(&letters, sizeof(letters));
	ClearMemory(&pre, sizeof(pre));
	ClearMemory(&post, sizeof(post));
	
	// Load font description
	data = GOS::LoadFileIntoMemory(sFileName, &size);
	if(NULL == data)
	{
		return false;
	}

	desc = new tchar[size+1];
	memcpy(desc,data,size);
	desc[size]=0;
	free(data);

	pdesc = _get_line(desc,linebuf);
	if(StringCmp(linebuf, FNTHEADERTAG))
	{
		delete[] desc;	
		return false;
	}

	// Parse font description

	while((pdesc = _get_line(pdesc,linebuf)))
	{
		if(!StringNCmp(linebuf, FNTBITMAPTAG, sizeof(FNTBITMAPTAG)-1 ))
		{
			StringCopy(buf, sFileName);
			pbuf = Strrchr(buf,CTEXT('\\'));
			if(!pbuf) pbuf = Strrchr(buf,CTEXT('/'));
			if(!pbuf) pbuf = buf;
			else pbuf++;
			if(!tsscanf(linebuf, CTEXT("Bitmap = %s"), pbuf)) continue;

			//m_pTexture = GameObjectCreation::CreateTexture2D(buf);
			if(NULL == m_pTexture)
			{
				delete[] desc;	
				return false;
			}
		}
		else if(!StringNCmp(linebuf, FNTCHARTAG, sizeof(FNTCHARTAG)-1 ))
		{
			pbuf = Strrchr(linebuf,CTEXT('='));
			if(!pbuf) continue;
			pbuf++;
			while(*pbuf==CTEXT(' ')) pbuf++;
			if(*pbuf==CTEXT('\"'))
			{
				pbuf++;
				i=*pbuf++;
				pbuf++; // skip "
			}
			else
			{
				i=0;
				while((*pbuf>=CTEXT('0') && *pbuf<=CTEXT('9')) ||
					(*pbuf>=CTEXT('A') && *pbuf<=CTEXT('F')) ||
					(*pbuf>=CTEXT('a') && *pbuf<=CTEXT('f')))
				{
					chr=*pbuf;
					if(chr >= CTEXT('a')) chr-=CTEXT('a')-CTEXT(':');
					if(chr >= CTEXT('A')) chr-=CTEXT('A')-CTEXT(':');
					chr-=CTEXT('0');
					if(chr>0xF) chr=0xF;
					i=(i << 4) | chr;
					pbuf++;
				}
				if(i<0 || i>255) continue;
			}
			tsscanf(pbuf, CTEXT(" , %d , %d , %d , %d , %d , %d"), &x, &y, &w, &h, &a, &c);

			letters[i].x = x;
			letters[i].y = y;
			letters[i].w = w;
			letters[i].h = h;

			pre[i]=(float)a;
			post[i]=(float)c;
			if(h>fHeight) fHeight=(float)h;
		}
	}

	delete[] desc;	

	return true;
}
Example #6
0
hgeFont::hgeFont(const char* font, const bool mipmap) {
    uint32_t size;
    char linebuf[256];
    char buf[MAX_PATH], *pbuf;
    int i, x, y, w, h, a, c;

    // Setup variables

    hge_ = hgeCreate(HGE_VERSION);

    height_ = 0.0f;
    scale_ = 1.0f;
    proportion_ = 1.0f;
    rot_ = 0.0f;
    tracking_ = 0.0f;
    spacing_ = 1.0f;
    texture_ = 0;

    z_ = 0.5f;
    blend_ = BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE;
    col_ = 0xFFFFFFFF;

    ZeroMemory( &letters_, sizeof(letters_) );
    ZeroMemory( &pre_, sizeof(letters_) );
    ZeroMemory( &post_, sizeof(letters_) );

    // Load font description

    void* data = hge_->Resource_Load(font, &size);
    if (!data) {
        return;
    }

    char* desc = new char[size + 1];
    memcpy(desc, data, size);
    desc[size] = 0;
    hge_->Resource_Free(data);

    char* pdesc = _get_line(desc, linebuf);
    if (strcmp(linebuf, fnt_header_tag)) {
        hge_->System_Log("Font %s has incorrect format.", font);
        delete[] desc;
        return;
    }

    // Parse font description

    while ((pdesc = _get_line(pdesc, linebuf))) {
        if (!strncmp(linebuf, fnt_bitmap_tag, sizeof(fnt_bitmap_tag) - 1)) {
            strcpy(buf, font);
            pbuf = strrchr(buf, '\\');
            if (!pbuf) {
                pbuf = strrchr(buf, '/');
            }
            if (!pbuf) {
                pbuf = buf;
            }
            else {
                pbuf++;
            }
            if (!sscanf(linebuf, "Bitmap = %s", pbuf)) {
                continue;
            }

            texture_ = hge_->Texture_Load(buf, 0, mipmap);
            if (!texture_) {
                delete[] desc;
                return;
            }
        }

        else if (!strncmp(linebuf, fnt_char_tag, sizeof(fnt_char_tag) - 1)) {
            pbuf = strchr(linebuf, '=');
            if (!pbuf) {
                continue;
            }
            pbuf++;
            while (*pbuf == ' ') {
                pbuf++;
            }
            if (*pbuf == '\"') {
                pbuf++;
                i = static_cast<unsigned char>(*pbuf++);
                pbuf++; // skip "
            }
            else {
                i = 0;
                while ((*pbuf >= '0' && *pbuf <= '9') || (*pbuf >= 'A' && *pbuf <= 'F') || (*pbuf >=
                    'a' && *pbuf <= 'f')) {
                    char chr = *pbuf;
                    if (chr >= 'a') {
                        chr -= 'a' - ':';
                    }
                    if (chr >= 'A') {
                        chr -= 'A' - ':';
                    }
                    chr -= '0';
                    if (chr > 0xF) {
                        chr = 0xF;
                    }
                    i = (i << 4) | chr;
                    pbuf++;
                }
                if (i < 0 || i > 255) {
                    continue;
                }
            }
            sscanf(pbuf, " , %d , %d , %d , %d , %d , %d", &x, &y, &w, &h, &a, &c);

            letters_[i] = new hgeSprite(texture_, 
                                        static_cast<float>(x),
                                        static_cast<float>(y),
                                        static_cast<float>(w),
                                        static_cast<float>(h));
            pre_[i] = static_cast<float>(a);
            post_[i] = static_cast<float>(c);
            if (h > height_) {
                height_ = static_cast<float>(h);
            }
        }
    }

    delete[] desc;
}