Exemplo n.º 1
0
void orb_mapctrl::draw() 
{
    // Resize the viewport before drawing
    m_viewport->w(w());
    m_viewport->h(h());

    if ((damage() & FL_DAMAGE_ALL) == 0) 
        return;

    // Fill the area which the viewport does not cover
    fl_rectf(x(), y(), w(), h(), 80, 80, 80);

    // Create an offscreen drawing buffer and send all subsequent commands there
    Fl_Offscreen offscreen;
    offscreen = fl_create_offscreen(m_viewport->w(), m_viewport->h());
    fl_begin_offscreen(offscreen);

    fl_rectf(0, 0, m_viewport->w(), m_viewport->h(), 80, 80, 80);

    // Draw all the layers
    for (std::vector<orb_layer*>::iterator iter=m_layers.begin();iter!=m_layers.end();++iter)
        (*iter)->draw(*m_viewport);

    fl_end_offscreen();
   
    // Blit the generated viewport bitmap onto the widget (centered)
    int dpx = 0, dpy = 0;
    if (w() > (int)m_viewport->w())
        dpx = (w() - (int)m_viewport->w())/2;
    if (h() > (int)m_viewport->h())
        dpy = (h() - (int)m_viewport->h())/2;

    fl_copy_offscreen(x()+dpx, y()+dpy, m_viewport->w(), m_viewport->h(), offscreen, 0, 0);
    fl_delete_offscreen(offscreen);
}
Exemplo n.º 2
0
 void CImgWidget::setImage32(cimg_library::CImg<uint32> * im,int nbRounds)
     {
     std::lock_guard<std::recursive_mutex> lock(_mutim);
     if ((nbRounds<=0)||(im == nullptr) || (im->width() == 0) || (im->height() == 0) || (im->spectrum()<3))
         {
         if (_offbuf != ((Fl_Offscreen)0)) { fl_delete_offscreen((Fl_Offscreen)(_offbuf)); }
         _offbuf = (Fl_Offscreen)0;
         _ox = 0; _oy = 0;
         redraw();
         return;
         }
     if (!_initdraw) // prevent FLTK bug on linux
         {
         delete _saved_im; _saved_im = nullptr;
         delete _saved_im32; _saved_im32 = nullptr;
         _saved_im32 = new cimg_library::CImg<uint32>(*im, false);
         _saved_nbRounds = nbRounds;
         return;
         }
     const int nox = im->width();
     const int noy = im->height();
     if ((nox != _ox) || (noy != _oy))
         {
         if (_offbuf != ((Fl_Offscreen)0)) { fl_delete_offscreen((Fl_Offscreen)(_offbuf)); }
         _offbuf = fl_create_offscreen(nox, noy);
         _ox = nox; _oy = noy;
         MTOOLS_ASSERT(_offbuf != ((Fl_Offscreen)0));
         }
     fl_begin_offscreen((Fl_Offscreen)(_offbuf));
     auto data = std::pair<cimg_library::CImg<uint32>*, int>(im, nbRounds);
     fl_draw_image(_drawLine_callback32, &data, 0, 0, (int)_ox, (int)_oy, 3);
     fl_end_offscreen();
     return;
     }
Exemplo n.º 3
0
void Fl_Rotated_Text::draw(int x, int y, int W, int H, int cx, int cy){
  
  if(!text_) return;
  if(!rot_){ // standard drawing)
    int olf_font = fl_font();
    int old_size = fl_size();
    fl_font(font_,size_);
    fl_push_clip(x, y, W-cx, H-cy);
    fl_draw(text_, x - cx, y - cy, w(), h(), (Fl_Align)align_, (Fl_Image *) 0, 0);
    fl_pop_clip();
    fl_font(olf_font, old_size);
    return;
  }
  if(!array){ // not drawn yet, building rotated bitmap "cache"
    int w_, h_;
    if(rot_ & 1){
      w_ = h();
      h_ = w();
    }else{
      w_ = w();
      h_ = h();
    }
    int bsize = ((w()+7)/8)  * h();
    array = ar2 = new uchar[bsize];
    alloc_array = 1;
    //memset(ar2, 0, bsize);

    int old_font = fl_font();
    int old_size = fl_size();

    Fl_Color old_color = fl_color();
    Fl_Offscreen offscreen = fl_create_offscreen(w_,h_);
    fl_begin_offscreen(offscreen);
    fl_color(0x000000);
    fl_rectf(0,0,w_,h_);
    fl_font(font_, size_);
    fl_color(0x00FF0000); // we use green color to plot to the offscreen

    fl_draw(text_,0, 0, w_, h_, (Fl_Align)align_, (Fl_Image *)0, 0);
    uchar * rgb = fl_read_image(0, 0, 0, w_, h_, 0);
    fl_end_offscreen();
    fl_delete_offscreen(offscreen);
    fl_font(old_font, old_size);
    fl_color(old_color);

    int i,j;

    uchar * start = rgb;
    int i_iter = 0;
    int j_iter = 0;
    switch(rot_){
    case 3:
      start +=  w_ * (h_ - 1)*3 + 1;
      i_iter = - w_ * 3;
      j_iter =  3;
      break;
    case 2:
      start +=  (w_ * h_ - 1)*3 + 1;
      i_iter = -3;
      j_iter = - w_ * 3;
      break;
    case 1:
      start +=  (w_ - 1)*3 + 1;
      i_iter = w_ * 3;
      j_iter = -3;
      break;
    }

    uchar * stj = start;
    uchar c;
    uchar * where;
    uchar * sti;

    for(j = 0; j< h(); j++, stj += j_iter){
      uchar val = 0;
      c = 8;
      where = ar2 + j*((w()+7)/8);
      for(i = 0, sti = stj; i< w(); i++, sti +=i_iter){
        if(*sti >127) val |= c;
        if(c & (uchar)128){ // pushing value to the array
          *where = val;
          where++;
          c =1;
          val = 0;
        }else
          c <<=1;
      }
      if(w() % 8){ //need to push last byte
        * where = val;
        where++;
      }
    }
    
    delete[] rgb;
  }

  Fl_Bitmap::draw(x, y, W, H, cx, cy); // finaly drawing the bitmap

};
Exemplo n.º 4
0
 FL_EXPORT_C(void ,flc_end_offscreen)(){
   fl_end_offscreen();
 }
Exemplo n.º 5
0
void DiagramWindow::draw()
{
    Fl_Color priorColor = fl_color();
    int priorFont = fl_font();
    int priorFontSize = fl_size();

    fl_color(color());
    fl_rectf(0, 0, w(), h());
    fl_color(priorColor);

    Fl_Window::draw();

    // Get the structures. Be sure the reference structure is first.
    RNAStructure* sequences[3];
    StructureManager* structureManager = RNAStructViz::GetInstance()->GetStructureManager();
    for (int j = 0; j < 3; ++j)
    {
	if ((int)(m_menuItems[m_menus[j]->value()].user_data()) == -1)
	{
	    sequences[j] = 0;
	}
	else
	{
	    sequences[j] = structureManager->GetStructure((int)(m_menuItems[m_menus[j]->value()].user_data()));
	}
    }

    int numToDraw = 0;
    if (sequences[0])
    {
	if (sequences[1])
	{
	    if (sequences[2])
	    {
		numToDraw = 3;
		DrawKey3();
	    }
	    else
	    {
		numToDraw = 2;
		DrawKey2(0, 1);
	    }
	}
	else
	{
	    if (sequences[2])
	    {
		sequences[1] = sequences[2];
		DrawKey2(0, 2);
		numToDraw = 2;
	    }
	    else
	    {
		DrawKey1(0);
		numToDraw = 1;
	    }
	}
    }
    else
    {
	if (sequences[1])
	{
	    if (sequences[2])
	    {
		sequences[0] = sequences[1];
		sequences[1] = sequences[2];
		DrawKey2(1, 2);
		numToDraw = 2;
	    }
	    else
	    {
		sequences[0] = sequences[1];
		DrawKey1(1);
		numToDraw = 1;
	    }
	}
	else
	{
	    if (sequences[2])
	    {
		sequences[0] = sequences[2];
		DrawKey1(2);
		numToDraw = 1;
	    }
	    else
	    {
		numToDraw = 0;
	    }
	}
    }

    if (m_redrawStructures)
    {
	{
	    fl_begin_offscreen(m_offscreenImage[0]);
	    RedrawBuffer(sequences, numToDraw, 2048);
	    fl_read_image(m_imageData[0], 0, 0, 2048, 2048);
	    fl_end_offscreen();
	}

	{
	    fl_begin_offscreen(m_offscreenImage[1]);
	    RedrawBuffer(sequences, numToDraw, 1024);
	    fl_read_image(m_imageData[1], 0, 0, 1024, 1024);
	    fl_end_offscreen();
	}

	m_glWindow->UpdateTexture();
	m_redrawStructures = false;
    }

    m_glWindow->redraw();

    fl_color(priorColor);
    fl_font(priorFont, priorFontSize);
    fl_line_style(0);
}
  void flush()
  {
    //1000 should be _totalWidth but it does not work
    int w = 1000, h = _maxHeight;
    Fl_Offscreen offscreen = fl_create_offscreen(w, h);
    fl_begin_offscreen(offscreen);
    fl_color(0, 0, 0);
    fl_rectf(0, 0, w, h);
    fl_color(255, 255, 255);
    int pos = 0;
    for(std::vector<element>::iterator it = _elements.begin(); it != _elements.end();  ++it) {
      fl_font(it->fontId, it->fontSize);
      fl_draw(it->text.c_str(), pos, it->height - fl_descent());
      pos += it->width;
    }
    uchar *data = fl_read_image(NULL, 0, 0, w, h);
    for (int i = 0; i < w * h; ++i) {
      data[i] = data[i * 3];
    }
    fl_end_offscreen();
    fl_delete_offscreen(offscreen);

    //setup matrices
    GLint matrixMode;
    GLuint textureId;
    glGetIntegerv (GL_MATRIX_MODE, &matrixMode);
    glMatrixMode (GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity ();
    glMatrixMode (GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity ();
    float winw = Fl_Window::current()->w();
    float winh = Fl_Window::current()->h();
    glScalef (2.0f / winw, 2.0f /  winh, 1.0f);
    glTranslatef (-winw / 2.0f, -winh / 2.0f, 0.0f);
    //write the texture on screen
    glEnable (GL_TEXTURE_RECTANGLE_ARB);
    glPushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT);
    glDisable(GL_LIGHTING);
    glDisable (GL_DEPTH_TEST);
    glEnable (GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glGenTextures (1, &textureId);
    glBindTexture (GL_TEXTURE_RECTANGLE_ARB, textureId);
    glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_ALPHA, w, h, 0,
                  GL_ALPHA, GL_UNSIGNED_BYTE, data);
    //glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_SRC0_ALPHA);
    //printf("error %i %s\n", __LINE__, gluErrorString(glGetError()));
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

    pos = 0;
    for(std::vector<element>::iterator it = _elements.begin(); it != _elements.end();  ++it) {
      glTranslatef(it->x, it->y, it->z);
      glColor4f(it->r, it->g, it->b, it->alpha);
      int Lx = it->width;
      int Ly = it->height;

      glBegin (GL_QUADS);
      glTexCoord2f(pos, 0);
      glVertex2f(0.0f, Ly);
      glTexCoord2f(pos + Lx, 0);
      glVertex2f(Lx, Ly);
      glTexCoord2f(pos + Lx, Ly);
      glVertex2f(Lx, 0.0f);
      glTexCoord2f(pos, Ly);
      glVertex2f(0.0f, 0.0f);
      glEnd ();
      pos += Lx;
      glTranslatef(-it->x, -it->y, -it->z);
    }
    glDeleteTextures(1, &textureId);

    glPopAttrib();

    // reset original matrices
    glPopMatrix(); // GL_MODELVIEW
    glMatrixMode (GL_PROJECTION);
    glPopMatrix();
    glMatrixMode (matrixMode);
    _elements.clear();
    _maxHeight = 0;
    _totalWidth = 0;
    delete []data;
  }