Ejemplo n.º 1
0
//Draw all visible windows.
void WindowManager::draw()
{
    GFXHudMode( true );            //Load identity matrices.
    GFXColorf( GUI_OPAQUE_WHITE() );

    GFXDisable( DEPTHTEST );
    GFXEnable( DEPTHWRITE );
    GFXDisable( LIGHTING );
    GFXDisable( CULLFACE );
    GFXClear( GFXTRUE );
    GFXDisable( DEPTHWRITE );
    GFXBlendMode( SRCALPHA, INVSRCALPHA );
    GFXDisable( TEXTURE1 );
    GFXEnable( TEXTURE0 );
    //Just loop through all the windows, and remember if anything gets drawn.
    //Since the first window in the list is drawn first, z-order is
    //maintained.  First entry is the bottom window, last is the top window.
    //FIXME mbyron -- I think the event manager needs to get involved with window z-order.
    //(Mouse events should go to windows in zorder, shouldn't they?)
    for (size_t i = 0; i < m_windows.size(); i++) 
    {
        if ( m_windows[i]->controller() )//it's a controller
            m_windows[i]->controller()->draw();//that can draw
        if ( i < m_windows.size() ) 
        m_windows[i]->draw();
    }
    //Emulate EndGUIFrame.
    static VSSprite MouseVSSprite( "mouse.spr", BILINEAR, GFXTRUE );
    static Texture  dummy( "white.bmp", 0, NEAREST, TEXTURE2D, TEXTURE_2D, GFXTRUE );
    GFXDisable( CULLFACE );
    ConditionalCursorDraw( true );
    //Figure position of cursor sprite.
    float sizex     = 0.0, sizey = 0.0;
    const Point loc = globalEventManager().mouseLoc();
    MouseVSSprite.GetSize( sizex, sizey );
    float tempx     = 0.0, tempy = 0.0;
    MouseVSSprite.GetPosition( tempx, tempy );
    MouseVSSprite.SetPosition( tempx+loc.x+sizex/2, tempy+loc.y+sizey/2 );

    dummy.MakeActive();
    GFXBlendMode( SRCALPHA, INVSRCALPHA );
    GFXColorf( GUI_OPAQUE_WHITE() );

    //Draw the cursor sprite.
    GFXEnable( TEXTURE0 );
    GFXDisable( DEPTHTEST );
    GFXDisable( TEXTURE1 );
    MouseVSSprite.Draw();

    GFXHudMode( false );
    GFXEnable( CULLFACE );
    MouseVSSprite.SetPosition( tempx, tempy );
}
void CoordinateSelect::Draw () {
  if (CoordinateSelectChange) {
    UpdateMouse();
  }
  GFXLoadIdentity (MODEL);
  
  GFXPushBlendMode();
  //  VSFileSystem::Fprintf (stderr,"Location: %f %f %f", LocalPosition.i, LocalPosition.j, LocalPosition.k);
  GFXBlendMode(ONE,ONE);
  LocSelAni.SetPosition(LocalPosition);
  LocSelAni.Draw();
  GFXPopBlendMode();

}
Ejemplo n.º 3
0
static void TerrainMakeActive( const TerrainTexture &text )
{
    if (text.tex.t) {
        GFXEnable( TEXTURE0 );
        text.tex.t->MakeActive();
    } else {
        GFXDisable( TEXTURE0 );
    }
    GFXBlendMode( text.blendSrc, text.blendDst );
    if (text.reflect)
        GFXEnable( TEXTURE1 );
    else
        GFXDisable( TEXTURE1 );
    GFXSelectMaterial( text.material );
}
Ejemplo n.º 4
0
int TextPlane::Draw(const string & newText, int offset,bool startlower, bool force_highquality, bool automatte)
{
  int retval=1;
  bool drawbg = (bgcol.a!=0);
  static unsigned int * display_lists=CreateLists ();
	// some stuff to draw the text stuff
  string::const_iterator text_it = newText.begin();
  static bool use_bit = force_highquality||XMLSupport::parse_bool(vs_config->getVariable ("graphics","high_quality_font","false"));
  static float font_point = XMLSupport::parse_float (vs_config->getVariable ("graphics","font_point","16"));
  static bool font_antialias = XMLSupport::parse_bool (vs_config->getVariable ("graphics","font_antialias","true"));
  void * fnt = getFont();
  static float std_wid=glutStrokeWidth (GLUT_STROKE_ROMAN,'W');
  myFontMetrics.i=font_point*std_wid/(119.05+33.33);
  if (use_bit)
	  myFontMetrics.i=glutBitmapWidth(fnt,'W');
  myFontMetrics.j=font_point;
  myFontMetrics.i/=.5*g_game.x_resolution;
  myFontMetrics.j/=.5*g_game.y_resolution;
  float tmp,row, col;
  float origcol,origrow;
  GetPos (row,col);
  GetPos(row,origcol);
  float rowheight=use_bit?getFontHeight():myFontMetrics.j;
  myFontMetrics.j=rowheight;
  
	  
  if (startlower) {
      row -= rowheight;

  }
  GFXPushBlendMode();
  glLineWidth (1);
  if (!use_bit&&font_antialias) {
    GFXBlendMode (SRCALPHA,INVSRCALPHA);
	if(gl_options.smooth_lines)
	{
		glEnable(GL_LINE_SMOOTH);
	}
  }else {
	GFXBlendMode (SRCALPHA,INVSRCALPHA);
	if(gl_options.smooth_lines)
	{
		glDisable(GL_LINE_SMOOTH);
	}
  }
  GFXColorf(this->col);

  GFXDisable (DEPTHTEST);
  GFXDisable (CULLFACE);

  GFXDisable (LIGHTING);

  GFXDisable (TEXTURE0);
  GFXDisable (TEXTURE1);

  glPushMatrix();
  glLoadIdentity();
  if (!automatte&&drawbg) {
	GFXColorf(this->bgcol);
	DrawSquare(col,this->myDims.i,row-rowheight*.25,row+rowheight);
  }
  GFXColorf(this->col);

  int entercount=0;
  for (;entercount<offset&&text_it!=newText.end();text_it++) {
    if (*text_it=='\n')
      entercount++;
  }
  glTranslatef(col,row,0);  
  //  glRasterPos2f (g_game.x_resolution*(1-(col+1)/2),g_game.y_resolution*(row+1)/2);
  glRasterPos2f (0,0);
  float scalex=1;
  float scaley=1;
  int potentialincrease=0;
  if (!use_bit) {
    int numplayers=1;
    if (_Universe) // _Universe can be NULL during bootstrap.
      numplayers = (_Universe->numPlayers()>3?_Universe->numPlayers()/2:
                    _Universe->numPlayers());
    scalex=numplayers*myFontMetrics.i/std_wid;
    scaley=myFontMetrics.j/(119.05+33.33);
  }
  glScalef (scalex,scaley,1);
  bool firstThroughLoop=true;
  GFXColor currentCol (this->col);
  while(text_it != newText.end() && (firstThroughLoop||row>myDims.j-rowheight*.25)) {
    unsigned char myc = *text_it;
    if (myc=='_') {
      myc = ' ';
    }
    float shadowlen = 0;
    if(myc=='\t') {
      shadowlen=glutBitmapWidth(fnt,' ')*5./(.5*g_game.x_resolution);
    } else {
      if (use_bit) {
        shadowlen = glutBitmapWidth (fnt,myc)/(float)(.5*g_game.x_resolution); // need to use myc -- could have transformed '_' to ' '
      } else {
        shadowlen = myFontMetrics.i*glutStrokeWidth(GLUT_STROKE_ROMAN,myc)/std_wid;
      }
    }
    
    if (*text_it=='#') {
      if (newText.end()-text_it>6) {
	float r,g,b;
	r = TwoCharToFloat (*(text_it+1),*(text_it+2));
	g = TwoCharToFloat (*(text_it+3),*(text_it+4));
	b = TwoCharToFloat (*(text_it+5),*(text_it+6));
	if (r==0&&g==0&&b==0) {
		currentCol = this->col;
	}else {
		currentCol = GFXColor(r, g, b, this->col.a);
	}
	GFXColorf(currentCol);
        static bool setRasterPos= XMLSupport::parse_bool(vs_config->getVariable("graphics","set_raster_text_color","true"));
        if (use_bit&&setRasterPos)
          glRasterPos2f(col-origcol,0);
	text_it = text_it+6;
      } else {
        break;
      }
      text_it++;
      continue;
    }else if(*text_it>=32) {//always true
	  if(automatte){
		GFXColorf(this->bgcol);
		DrawSquare(col-origcol,col-origcol+shadowlen/scalex,-rowheight*.25/scaley,rowheight*.75/scaley);
		GFXColorf(currentCol);
	  }
      //glutStrokeCharacter (GLUT_STROKE_ROMAN,*text_it);
      retval+=potentialincrease;
      potentialincrease=0;
      int lists = display_lists[myc+(isInside()?128:0)];
      if (lists) {
	    GFXCallList(lists);
	  }else{
		 if (use_bit){
	        glutBitmapCharacter (fnt,myc);
		  }
		 else{
           glutStrokeCharacter (GLUT_STROKE_ROMAN,myc);
		 }
      }
	}
    if(*text_it=='\t') {
	  if(automatte){
		GFXColorf(this->bgcol);
		DrawSquare(col-origcol,col-origcol+shadowlen*5/(.5*g_game.x_resolution),-rowheight*.25/scaley,rowheight*.75/scaley);
		GFXColorf(currentCol);
	  }
      col+=shadowlen;
      glutBitmapCharacter (fnt,' ');
      glutBitmapCharacter (fnt,' ');
      glutBitmapCharacter (fnt,' ');
      glutBitmapCharacter (fnt,' ');
      glutBitmapCharacter (fnt,' ');
    } else {
      col+=shadowlen;
    }
    if(doNewLine(text_it,newText.end(),col,myDims.i, myFontMetrics.i,row-rowheight<=myDims.j)){
      GetPos (tmp,col);
      firstThroughLoop=false;
      row -= rowheight;
      glPopMatrix();
      glPushMatrix ();
      glLoadIdentity();
	  if (!automatte&&drawbg) {
		GFXColorf(this->bgcol);
		DrawSquare(col,this->myDims.i,row-rowheight*.25,row+rowheight*.75);
	  }
      if (*text_it=='\n') {
	    currentCol = this->col;
      }
	  GFXColorf(currentCol);
      glTranslatef (col,row,0);
      glScalef(scalex,scaley,1);
      glRasterPos2f(0,0);
      potentialincrease++;
	}
    text_it++;
  }
  if(gl_options.smooth_lines)
  {
	  glDisable(GL_LINE_SMOOTH);
  }
  glPopMatrix();

  
  GFXPopBlendMode();
  GFXColorf(this->col);
  return retval;
}
Ejemplo n.º 5
0
static void TerrainMakeClearActive( const TerrainTexture &text )
{
    TerrainMakeActive( text );
    GFXBlendMode( text.blendDst != ZERO ? text.blendSrc : SRCALPHA, INVSRCALPHA );
}
void GFXVertexList::Draw( enum POLYTYPE *mode, const INDEX index, const int numlists, const int *offsets )
{
    //Hardware support for this seems... sketchy
    if (vbo_data == 0 && display_list != 0) {
        //Big issue: display lists cannot discriminate between lines/points/triangles,
        //so, for now, we'll limit smoothing to single-mode GFXVertexLists, which, by the way,
        //are the only ones being used, AFAIK.
        bool blendchange = false;
        if ( unique_mode && (numlists > 0) ) {
            switch (*mode)
            {
            case GFXLINE:
            case GFXLINESTRIP:
            case GFXPOLY:
            case GFXPOINT:
                if ( ( (*mode == GFXPOINT)
                      && gl_options.smooth_points ) || ( (*mode != GFXPOINT) && gl_options.smooth_lines ) ) {
                    BLENDFUNC src, dst;
                    GFXGetBlendMode( src, dst );
                    if ( (dst != ZERO) && ( (src == ONE) || (src == SRCALPHA) ) ) {
                        GFXPushBlendMode();
                        GFXBlendMode( SRCALPHA, dst );
                        GFXEnable( SMOOTH );
                        blendchange = true;
                    }
                }
                break;
            default:
                break;
            }
        }
        GFXCallList( display_list );
        if (blendchange) {
            GFXPopBlendMode();
            GFXDisable( SMOOTH );
        }
        
        ++gl_batches_this_frame;
    } else {
        int totoffset = 0;
        if (changed&HAS_INDEX) {
            long   stride    = changed&HAS_INDEX;
            GLenum indextype = (changed&INDEX_BYTE)
                               ? GL_UNSIGNED_BYTE
                               : ( (changed&INDEX_SHORT)
                                  ? GL_UNSIGNED_SHORT
                                  : GL_UNSIGNED_INT );
            bool use_vbo = vbo_data != 0;
            use_vbo = use_vbo && memcmp( &index, &this->index, sizeof (INDEX) ) == 0;
            if (use_vbo) {
            #ifndef NO_VBO_SUPPORT
                GFXBindElementBuffer( display_list );
            #else
                use_vbo = false;
            #endif
            } else {
            #ifndef NO_VBO_SUPPORT
                if (vbo_data)
                    GFXBindElementBuffer( 0 );
            #endif
            }
            if (glMultiDrawElements_p != NULL && numlists > 1) {
                static std::vector< bool >   drawn;
                static std::vector< const GLvoid* >glindices;
                static std::vector< GLsizei >glcounts;

                drawn.clear();
                drawn.resize( numlists, false );
                for (int i = 0; i < numlists; totoffset += offsets[i++])
                    if (!drawn[i]) {
                        glindices.clear();
                        glcounts.clear();
                        int totcount = 0;
                        for (long j = i, offs = totoffset; j < numlists; offs += offsets[j++]) {
                            totcount += offsets[j];
                            if ( !drawn[j] && (mode[j] == mode[i]) ) {
                                glindices.push_back( use_vbo ? (GLvoid*) (stride*offs)
                                                     : (GLvoid*) &index.b[stride*offs] );
                                glcounts.push_back( offsets[j] );
                                drawn[j] = true;
                            }
                        }
                        if (glindices.size() == 1)
                            glDrawElements( PolyLookup( mode[i] ), glcounts[0], indextype, glindices[0] );

                        else
                            glMultiDrawElements_p( PolyLookup(
                                                      mode[i] ), &glcounts[0], indextype, &glindices[0], glindices.size() );
                        ++gl_batches_this_frame;
                        gl_vertices_this_frame += totcount;
                    }
            } else {
                for (int i = 0; i < numlists; i++) {
                    glDrawElements( PolyLookup( mode[i] ), offsets[i], indextype,
                                    use_vbo ? (GLvoid*) (stride*totoffset)
                                    : (GLvoid*)&index.b[stride*totoffset] );                     //changed&INDEX_BYTE == stride!
                    totoffset += offsets[i];
                    ++gl_batches_this_frame;
                    gl_vertices_this_frame += offsets[i];
                }
            }
        } else {
            if (glMultiDrawArrays_p) {
                static std::vector< bool >   drawn;
                static std::vector< GLint >  gloffsets;
                static std::vector< GLsizei >glcounts;

                drawn.clear();
                drawn.resize( numlists, false );
                for (int i = 0; i < numlists; totoffset += offsets[i++])
                    if (!drawn[i]) {
                        gloffsets.clear();
                        glcounts.clear();
                        int totcount = 0;
                        for (int j = i, offs = totoffset; j < numlists; offs += offsets[j++]) {
                            totcount += offsets[j];
                            if ( !drawn[j] && (mode[j] == mode[i]) ) {
                                gloffsets.push_back( offs );
                                glcounts.push_back( offsets[j] );
                                drawn[j] = true;
                            }
                        }
                        bool blendchange = false;
                        switch (mode[i])
                        {
                        case GFXLINE:
                        case GFXLINESTRIP:
                        case GFXPOLY:
                        case GFXPOINT:
                            if ( ( (mode[i] == GFXPOINT)
                                  && gl_options.smooth_points ) || ( (mode[i] != GFXPOINT) && gl_options.smooth_lines ) ) {
                                BLENDFUNC src, dst;
                                GFXGetBlendMode( src, dst );
                                if ( (dst != ZERO) && ( (src == ONE) || (src == SRCALPHA) ) ) {
                                    GFXPushBlendMode();
                                    GFXBlendMode( SRCALPHA, dst );
                                    GFXEnable( SMOOTH );
                                    blendchange = true;
                                }
                            }
                            break;
                        default:
                            break;
                        }
                        if (gloffsets.size() == 1)
                            glDrawArrays( PolyLookup( mode[i] ), gloffsets[0], glcounts[0] );

                        else
                            glMultiDrawArrays_p( PolyLookup( mode[i] ), &gloffsets[0], &glcounts[0], gloffsets.size() );
                        if (blendchange) {
                            GFXPopBlendMode();
                            GFXDisable( SMOOTH );
                        }
                        ++gl_batches_this_frame;
                        gl_vertices_this_frame += totcount;
                    }
            } else {
                for (int i = 0; i < numlists; i++) {
                    bool blendchange = false;
                    switch (mode[i])
                    {
                    case GFXLINE:
                    case GFXLINESTRIP:
                    case GFXPOLY:
                    case GFXPOINT:
                        if ( ( (mode[i] == GFXPOINT)
                              && gl_options.smooth_points ) || ( (mode[i] != GFXPOINT) && gl_options.smooth_lines ) ) {
                            BLENDFUNC src, dst;
                            GFXGetBlendMode( src, dst );
                            if ( (dst != ZERO) && ( (src == ONE) || (src == SRCALPHA) ) ) {
                                GFXPushBlendMode();
                                GFXBlendMode( SRCALPHA, dst );
                                GFXEnable( SMOOTH );
                                blendchange = true;
                            }
                        }
                        break;
                    default:
                        break;
                    }
                    glDrawArrays( PolyLookup( mode[i] ), totoffset, offsets[i] );
                    totoffset += offsets[i];
                    if (blendchange) {
                        GFXPopBlendMode();
                        GFXDisable( SMOOTH );
                    }
                    ++gl_batches_this_frame;
                    gl_vertices_this_frame += offsets[i];
                }
            }
        }
    }
}
Ejemplo n.º 7
0
void Stars::Draw() {
    static bool stars_dont_move = XMLSupport::parse_bool (vs_config->getVariable("graphics","stars_dont_move","false"));
    if (stars_dont_move)return;
    const QVector cp (_Universe->AccessCamera()->GetPosition());
    UpdatePosition(cp);
    //  GFXLightContextAmbient(GFXColor(0,0,0,1));
    GFXColor (1,1,1,1);
    GFXLoadIdentity(MODEL);
    GFXDisable(DEPTHWRITE);
    GFXDisable (TEXTURE0);
    GFXDisable (TEXTURE1);
    GFXEnable (DEPTHTEST);
    static bool near_stars_alpha=XMLSupport::parse_bool(vs_config->getVariable("graphics","near_stars_alpha","false"));
    static bool near_stars_alpha_blend=XMLSupport::parse_bool(vs_config->getVariable("graphics","near_stars_alpha_blend","false"));
    static float AlphaTestingCutoff =XMLSupport::parse_float(vs_config->getVariable("graphics","stars_alpha_test_cutoff",".2"));

    if (near_stars_alpha) {
        GFXAlphaTest (GREATER,AlphaTestingCutoff);
        if (!near_stars_alpha_blend) {
            GFXBlendMode(ONE,ZERO);
        } else {
            GFXBlendMode(SRCALPHA,INVSRCALPHA);
        }
        GFXEnable(DEPTHWRITE);
    } else {
        if (blend) {
            GFXBlendMode (ONE,ONE);
        } else {
            GFXBlendMode (ONE,ZERO);
        }
    }
    int ligh;
    GFXSelectMaterial (0);
    if (fade) {
        static float star_spread_attenuation = XMLSupport::parse_float(vs_config->getVariable("graphics","star_spread_attenuation",".2"));
        GFXPushGlobalEffects();
        GFXLight FadeLight (true, GFXColor (cp.i,cp.j,cp.k), GFXColor (0,0,0,1), GFXColor (0,0,0,1), GFXColor (1,1,1,1), GFXColor (.01,0,1/(star_spread_attenuation*star_spread_attenuation*spread*spread)));
        GFXCreateLight (ligh,FadeLight,true);
        GFXEnable (LIGHTING);
    } else {
        GFXDisable (LIGHTING);
    }

    _Universe->AccessCamera()->UpdateGFX(GFXFALSE,GFXFALSE,GFXFALSE);
    int LC=0,LN=vlist->NumTextures();
    for (LC=0; LC<LN; ++LC) {
        bool stretch=vlist->BeginDrawState(_Universe->AccessCamera()->GetR().Scale(-spread).Cast(),_Universe->AccessCamera()->GetVelocity(),_Universe->AccessCamera()->GetAngularVelocity(),false,false,LC);
        int i;
        for (i=0; i<STARnumvlist; i++) {
            if (i>=1)
                GFXTranslateModel (pos[i]-pos[i-1]);
            else
                GFXTranslateModel (pos[i]);
            vlist->Draw(stretch,LC);
        }
        GFXTranslateModel(-pos[i-1]);
        vlist->EndDrawState(stretch,LC);

    }
    if (near_stars_alpha) {
        GFXAlphaTest(ALWAYS,0);
    } else {
        GFXEnable(DEPTHWRITE);
    }
    GFXBlendMode(ONE,ZERO);
    _Universe->AccessCamera()->UpdateGFX(GFXTRUE,GFXFALSE,GFXFALSE)	  ;

    GFXEnable (TEXTURE0);
    GFXEnable (TEXTURE1);
    if (fade) {
        GFXDeleteLight (ligh);
        GFXPopGlobalEffects();
    }
    GFXLoadIdentity(MODEL);
}
Ejemplo n.º 8
0
void Box::ProcessDrawQueue( int )
{
    if ( !draw_queue[0].size() ) return;
    GFXBlendMode( SRCALPHA, INVSRCALPHA );
    GFXColor( 0.0, .90, .3, .4 );
    GFXDisable( LIGHTING );
    GFXDisable( TEXTURE0 );
    GFXDisable( TEXTURE1 );
    GFXDisable( DEPTHWRITE );
    GFXDisable( CULLFACE );
    //GFXBlendMode(ONE, ONE);
    while ( draw_queue[0].size() ) {
        GFXLoadMatrixModel( draw_queue[0].back().mat );
        draw_queue[0].pop_back();

        GFXBegin( GFXQUAD );
        GFXColor4f( 0.0, 1.0, 0.0, 0.2 );

        GFXVertex3f( corner_max.i, corner_min.j, corner_max.k );
        GFXVertex3f( corner_max.i, corner_max.j, corner_max.k );
        GFXVertex3f( corner_min.i, corner_max.j, corner_max.k );
        GFXVertex3f( corner_min.i, corner_min.j, corner_max.k );

        GFXColor4f( 0.0, 1.0, 0.0, 0.2 );
        GFXVertex3f( corner_min.i, corner_min.j, corner_min.k );
        GFXVertex3f( corner_min.i, corner_max.j, corner_min.k );
        GFXVertex3f( corner_max.i, corner_max.j, corner_min.k );
        GFXVertex3f( corner_max.i, corner_min.j, corner_min.k );

        GFXColor4f( 0.0, .70, 0.0, 0.2 );

        GFXVertex3f( corner_max.i, corner_min.j, corner_max.k );
        GFXVertex3f( corner_min.i, corner_min.j, corner_max.k );
        GFXVertex3f( corner_min.i, corner_min.j, corner_min.k );
        GFXVertex3f( corner_max.i, corner_min.j, corner_min.k );

        GFXColor4f( 0.0, .70, 0.0, 0.2 );
        GFXVertex3f( corner_max.i, corner_max.j, corner_min.k );
        GFXVertex3f( corner_min.i, corner_max.j, corner_min.k );
        GFXVertex3f( corner_min.i, corner_max.j, corner_max.k );
        GFXVertex3f( corner_max.i, corner_max.j, corner_max.k );

        GFXColor4f( 0.0, .90, .3, 0.2 );
        GFXVertex3f( corner_max.i, corner_max.j, corner_max.k );
        GFXVertex3f( corner_max.i, corner_min.j, corner_max.k );
        GFXVertex3f( corner_max.i, corner_min.j, corner_min.k );
        GFXVertex3f( corner_max.i, corner_max.j, corner_min.k );

        GFXColor4f( 0.0, .90, .3, 0.2 );
        GFXVertex3f( corner_min.i, corner_max.j, corner_min.k );
        GFXVertex3f( corner_min.i, corner_min.j, corner_min.k );
        GFXVertex3f( corner_min.i, corner_min.j, corner_max.k );
        GFXVertex3f( corner_min.i, corner_max.j, corner_max.k );
        GFXEnd();

        /*
         *  vlist->Draw();
         *  if(quadstrips!=NULL) {
         *   for(int a=0; a<numQuadstrips; a++)
         *     quadstrips[a]->Draw()
         *       ;
         *       }
         */
    }
    GFXEnable( DEPTHWRITE );
}
Ejemplo n.º 9
0
// Draw specified lines of text.
void PaintText::drawLines(int start, int count) const {
    // Make sure we hav a display list.
    calcLayoutIfNeeded();
    // Make sure we have something to do.
    if(m_lines.empty()) {
        return;
    }

    // Initialize the graphics state.
    GFXToggleTexture(false,0);
    if(gl_options.smooth_lines)
    {
	    glEnable(GL_LINE_SMOOTH);
    }
    GFXPushBlendMode();
    GFXBlendMode(SRCALPHA,INVSRCALPHA);
    glPushMatrix();

    // Keep track of line position.
    float lineTop = m_rect.top();

    // Figure ending line index.
    const int end = guiMin(start + count, m_lines.size());

    // Loop through the display list lines.
    for(int i=start; i<end; i++) {
        const TextLine& line = m_lines[i];
        // Make sure we can paint this line in the vertical space we have left.
        if(lineTop - line.height*LINE_HEIGHT_EPSILON < m_rect.origin.y) {
            // Not enough space to draw this line.
            break;
        }

        // Position at the start of the line.
        glLoadIdentity();
        glTranslatef(m_rect.origin.x+line.x, lineTop-line.baseLine, 0.0);
        if (line.fragments.size()) {
          GFXColorf(line.fragments[0].color);
        }        
        if (!useStroke()){
          glRasterPos2f(0,0);
        }else
          glScaled(m_horizontalScaling, m_verticalScaling, 1.0);
        float rasterpos=0;
        // Draw each fragment.
        for(vector<TextFragment>::const_iterator frag=line.fragments.begin(); frag!=line.fragments.end(); frag++) {
            if(frag->start == ELLIPSIS_FRAGMENT) {
                // We have a special-case for the ellipsis at the end of a line.
                drawChars(ELLIPSIS_STRING, 0, 2, frag->font, frag->color,rasterpos);
            } else {
                rasterpos=drawChars(m_text, frag->start, frag->end, frag->font, frag->color,rasterpos);
            }
        }

        // Top of next line.
        lineTop -= line.height;
    }
    glRasterPos2f(0,0);
    // Undo graphics state
    GFXPopBlendMode();
    if(gl_options.smooth_lines)
    {
	    glDisable(GL_LINE_SMOOTH);
    }
    glPopMatrix();
    GFXToggleTexture(true,0);
}