Example #1
0
File: draw.C Project: imv/non
int
gui_draw_string ( int x, int y, int w, int h, int color, const char *s, bool draw )
{
    int rw;

    if ( ! s )
        return 0;

    fl_font( FL_COURIER, min( h, 18 ) );

    rw = fl_width( s );

    if ( fl_not_clipped( x, y, rw, h ) && draw )
    {
        gui_clear_area( x, y, w, h );

        if ( color )
            fl_color( velocity_colors[ color ] );
        else
            fl_color( FL_DARK_CYAN );

        fl_draw( s, x, y + h / 2 + fl_descent() );
    }

    return rw;
}
Example #2
0
void DiagramWindow::DrawBase(
    const unsigned int index,
    const RNAStructure::Base base,
    const float centerX,
    const float centerY,
    const float angleBase,
    const float angleDelta,
    const float radius)
{
    float angle1 = angleBase - (float)index * angleDelta;
    float xPosn1 = centerX + cos(angle1) * radius;
    float yPosn1 = centerY - sin(angle1) * radius - fl_descent() + 0.5 * fl_height();

    fl_color(128, 128, 128);
    switch (base)
    {
	case RNAStructure::A:
	    fl_draw("A", xPosn1 - fl_width('A') * 0.5f, yPosn1);
	    break;
	case RNAStructure::C:
	    fl_draw("C", xPosn1 - fl_width('C') * 0.5f, yPosn1);
	    break;
	case RNAStructure::G:
	    fl_draw("G", xPosn1 - fl_width('G') * 0.5f, yPosn1);
	    break;
	case RNAStructure::U:
	    fl_draw("U", xPosn1 - fl_width('U') * 0.5f, yPosn1);
	    break;
    }
}
Example #3
0
void Fl_Input_Browser::preferred_size(int& w, int& h) const
{
    fl_font(text_font(), float(text_size()));
    h = int(fl_height()+fl_descent()) + box()->dh() + 2;
    if(m_input.maximum_size()>0) {
        int ms = m_input.maximum_size() + 1;
        if (ms > 50) ms = 50;
        w = ms * (int)fl_width((unsigned int)'W') + h;
    }
}
Example #4
0
 FL_EXPORT_C(int,flc_descent)( ){
   return fl_descent();
 }
Example #5
0
// Draw tick marks. These lines cross the passed rectangle perpendicular to
// the slider direction. In the direction parallel to the slider direction
// the box should have the same size as the area the slider moves in.
void Fl_Slider::draw_ticks(int x, int y, int w, int h, int min_spacing)
{
    int x1, y1, x2, y2, dx, dy;
    if (horizontal())
    {
        x1 = x2 = x+(slider_size_-1)/2; dx = 1;
        y1 = y; y2 = y + h; dy = 0;
    }
    else
    {
        x1 = x; x2 = x+w; dx = 0;
        y1 = y2 = y+(slider_size_-1)/2; dy = 1;
        w = h;
    }
    if (w <= 0) return;
    double A = minimum();
    double B = maximum();
    if (A > B) {A = B; B = minimum();}

    // Figure out approximate size of min_spacing at zero:
    double derivative;
    if (!log())
    {
        derivative = (B-A)/w;
    }
    else if (A > 0)
    {
        // log slider
        derivative = A/w*20;
    }
    else
    {
        // squared slider, derivative at edge is zero, use value at 1 pixel
        derivative = B/(w*w)*30;
        if (A < 0) derivative *= 4;
    }
                                 // fix for fill sliders
    if (min_spacing < 1) min_spacing = 10;
    derivative *= min_spacing;
    if (derivative < step()) derivative = step();

    // Find closest multiple of 10 larger than spacing:
    int num = 1;
    while (num < derivative) num *= 10;
    int denom = 10;
    while (num >= derivative*denom) denom *= 10;
    denom /= 10;

    for (int n = 0; ; n++)
    {
        // every ten they get further apart for log slider:
        if (log() && n > 10) {n = 2; num *= 10;}
        double v = double(num*n)/denom;
        if (v > fabs(A) && v > fabs(B)) break;
        int small = n%5 ? 2 : 0;
        if (v >= A && v <= B)
        {
            int t = slider_position(v, w);
            fl_line(x1+dx*t+dy*small, y1+dy*t+dx*small, x2+dx*t, y2+dy*t);
            if (n%10 == 0)
            {
                char buffer[20]; sprintf(buffer,"%g",v);
                char* p = buffer;
                while (p[0]=='0' && p[1]) p++;
                fl_font(text_font(), text_size());
                fl_draw(p, x1+dx*t+1, y1+dy*t+fl_size()-fl_descent());
            }
        }
        if (v && -v >= A && -v <= B)
        {
            int t = slider_position(-v, w);
            fl_line(x1+dx*t+dy*small, y1+dy*t+dx*small, x2+dx*t, y2+dy*t);
            if (n%10 == 0)
            {
                char buffer[20]; sprintf(buffer+1,"%g",v);
                char* p = buffer+1;
                while (p[0]=='0' && p[1]) p++;
                p--; p[0] = '-';
                fl_font(text_font(), text_size());
                fl_draw(p, x1+dx*t+1, y1+dy*t+fl_size()-fl_descent());
            }
        }
    }
}
Example #6
0
/// Draw this item and its children.
void Fl_Tree_Item::draw(int X, int &Y, int W, Fl_Widget *tree, 
                        const Fl_Tree_Prefs &prefs, int lastchild) {
    if ( ! _visible ) return; 
    fl_font(_labelfont, _labelsize);
    int H = _labelsize + fl_descent() + prefs.linespacing();
    // Colors, fonts
    Fl_Color fg = _selected ? prefs.bgcolor()     : _labelfgcolor;
    Fl_Color bg = _selected ? prefs.selectcolor() : _labelbgcolor;
    if ( ! _active ) {
	fg = fl_inactive(fg);
	if ( _selected ) bg = fl_inactive(bg);
    }
    // Update the xywh of this item
    _xywh[0] = X;
    _xywh[1] = Y;
    _xywh[2] = W;
    _xywh[3] = H;
    // Text size
    int textw=0, texth=0;
    fl_measure(_label, textw, texth, 0);
    int textycenter = Y+(H/2);
    int &icon_x = _collapse_xywh[0] = X-1;
    int &icon_y = _collapse_xywh[1] = textycenter - (prefs.openicon()->h()/2);
    int &icon_w = _collapse_xywh[2] = prefs.openicon()->w();
    _collapse_xywh[3] = prefs.openicon()->h();
    // Horizontal connector values
    int hstartx  = X+icon_w/2-1;
    int hendx    = hstartx + prefs.connectorwidth();
    int hcenterx = X + icon_w + ((hendx - (X + icon_w)) / 2);

    // See if we should draw this item
    //    If this item is root, and showroot() is disabled, don't draw.
    //
    char drawthis = ( is_root() && prefs.showroot() == 0 ) ? 0 : 1;
    if ( drawthis ) {
	// Draw connectors
	if ( prefs.connectorstyle() != FL_TREE_CONNECTOR_NONE ) {
	    // Horiz connector between center of icon and text
	    draw_horizontal_connector(hstartx, hendx, textycenter, prefs);
	    if ( has_children() && is_open() ) {
		// Small vertical line down to children
		draw_vertical_connector(hcenterx, textycenter, Y+H, prefs);
	    }
	    // Connectors for last child
	    if ( ! is_root() ) {
		if ( lastchild ) {
		    draw_vertical_connector(hstartx, Y, textycenter, prefs);
		} else {
		    draw_vertical_connector(hstartx, Y, Y+H, prefs);
		}
	    }
	} 
	// Draw collapse icon
	if ( has_children() && prefs.showcollapse() ) {
	    // Draw icon image
	    if ( is_open() ) {
		prefs.closeicon()->draw(icon_x,icon_y);
	    } else {
		prefs.openicon()->draw(icon_x,icon_y);
	    }
	}
	// Background for this item
	int &bx = _label_xywh[0] = X+(icon_w/2-1+prefs.connectorwidth());
	int &by = _label_xywh[1] = Y;
	int &bw = _label_xywh[2] = W-(icon_w/2-1+prefs.connectorwidth());
	int &bh = _label_xywh[3] = texth;
	// Draw bg only if different from tree's bg
	if ( bg != tree->color() || is_selected() ) {
	    if ( is_selected() ) {
		// Selected? Use selectbox() style
		fl_draw_box(prefs.selectbox(), bx, by, bw, bh, bg);
	    } else {
		// Not Selected? use plain filled rectangle
		fl_color(bg);
		fl_rectf(bx, by, bw, bh);
	    }
	}
	// Draw user icon (if any)
	int useroff = (icon_w/2-1+prefs.connectorwidth());
	if ( usericon() ) {
	    // Item has user icon? Use it
	    useroff += prefs.usericonmarginleft();
	    usericon()->draw(X+useroff,icon_y);
	    useroff += usericon()->w();
	} else if ( prefs.usericon() ) {
	    // Prefs has user icon? Use it
	    useroff += prefs.usericonmarginleft();
	    prefs.usericon()->draw(X+useroff,icon_y);
	    useroff += prefs.usericon()->w();
	}
	useroff += prefs.labelmarginleft();
	// Draw label
	if ( widget() ) {
	    // Widget? Draw it
	    int lx = X+useroff;
	    int ly = by;
	    int lw = widget()->w();
	    int lh = bh;
	    if ( widget()->x() != lx || widget()->y() != ly ||
		 widget()->w() != lw || widget()->h() != lh ) {
		widget()->resize(lx, ly, lw, lh);		// fltk will handle drawing this
	    }
	} else {
	    // No label widget? Draw text label
	    if ( _label ) {
		fl_color(fg);
		fl_draw(_label, X+useroff, Y+H-fl_descent()-1);
	    }
	}
	Y += H;
    }			// end drawthis
    // Draw children
    if ( has_children() && is_open() ) {
	int child_x = drawthis ? 			// offset children to right,
	              (hcenterx - (icon_w/2) + 1) : X;	// unless didn't drawthis
	int child_w = W - (child_x-X);
	int child_y_start = Y;
	for ( int t=0; t<children(); t++ ) {
	    int lchild = ((t+1)==children()) ? 1 : 0;
	    _children[t]->draw(child_x, Y, child_w, tree, prefs, lchild);
	}
	if ( has_children() && is_open() ) {
	    Y += prefs.openchild_marginbottom();	// offset below open child tree
	}
	if ( ! lastchild ) {
	    draw_vertical_connector(hstartx, child_y_start, Y, prefs);
	}
    }
}
Example #7
0
void Fl_Combo_Box::preferred_size(int& w, int& h) const
{
    fl_font(text_font(), float(text_size()));
    h = int(fl_height()+fl_descent()) + box()->dh() + 2;
}
Example #8
0
 void preferred_size(int& w,int& h) const { 
     fl_font(parent()->text_font(),parent()->text_size());
     h = int(fl_height()+fl_descent()) + 2;
     w = 15 + box()->dw() + 1; 
 }
  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;
  }
Example #10
0
void console_widget_t::draw()
{
	if (console == NULL) {
		int x_, y_, w_, h_;
		fl_clip_box(x(),y(),w(),h(), x_, y_, w_, h_);
		fl_color(FL_BLACK);
		fl_rectf(x_, y_, w_, h_);
		return;
	}

	fl_font(FL_SCREEN, font_size);

	int x_, y_, w_, h_, cx, cy;	
	fl_clip_box(x(), y(), w(), h(), x_, y_, w_, h_);

	cx = x();
	cy = y();

	cx -= (fit_x - w()) / 2;
	cy -= (fit_y - h()) / 2;
	
	x_ -= cx;
	y_ -= cy;

	int x1 = x_ / letter_x;
	int x2 = (x_ + w_) / letter_x + 1;
	int y1 = y_ / letter_y;
	int y2 = (y_ + h_) / letter_y + 1;

	int yi = 0;

	if (x_ < 0) {
		fl_color(FL_BLACK);
		fl_rectf(x(), y(), -x_, h_);

		x1 = 0;
		cx += x1 * letter_x;
	}

	if (y_ < 0) {
		fl_color(FL_BLACK);
		fl_rectf(cx, y(), fit_x, -y_);
	}

	if (x_ + w_ > fit_x) {
		fl_color(FL_BLACK);
		fl_rectf(cx + fit_x, y(), x_ + w_ - fit_x, h_);

		x2 = console->config.x;
	}

	if (y_ + h_ > fit_y) {
		fl_color(FL_BLACK);
		fl_rectf(cx, cy + fit_y,
			 fit_x, y_ + h_ - fit_y);
	}

	fl_push_clip(x(), y(), w(), h());

	for (yi = y1; yi < y2; yi++) {
		if (yi < 0)
			continue;

		if (yi >= console->config.y)
			break;

		co_console_cell_t* row_start = &console->screen[yi * console->config.x];
		co_console_cell_t* cell;
		co_console_cell_t* start;
		co_console_cell_t* end;
		char               text_buff[0x100];

		start = row_start + x1;
		end   = row_start + x2;
		cell  = start;

		if (end > cell_limit) {
			// co_debug("BUG: end=%p limit=%p row=%p start=%p x1=%d x2=%d y1=%d y2=%d",
			//     end, limit, row_start, start, x1, x2, y1, y2);
			end = cell_limit; // Hack: Fix the overrun!
		}
		
		while (cell < end) {
			while (cell < end  &&  start->attr == cell->attr  &&
			       cell - start < (int)sizeof(text_buff)) {
				text_buff[cell - start] = cell->ch;
				cell++;
			}

			FL_RGB_COLOR((start->attr >> 4) & 0xf);
			fl_rectf(cx + letter_x * (start - row_start), 
				 cy + letter_y * (yi),
				 (cell - start) * letter_x,
				 letter_y);
			
			FL_RGB_COLOR((start->attr) & 0xf);
			fl_draw(text_buff, cell - start, 
				cx + letter_x * (start - row_start), 
				cy + letter_y * (yi + 1) - fl_descent());

			start = cell;
		}

		// The cell under the cursor
		if (cursor_blink_state && console->cursor.y == yi &&
		    console->cursor.x >= x1 && console->cursor.x <= x2 &&
		    console->cursor.height != CO_CUR_NONE) {
			int cursize;

			if (console->cursor.height <= CO_CUR_BLOCK &&
			    console->cursor.height > CO_CUR_NONE)
				cursize = cursize_tab[console->cursor.height];
			else
				cursize = cursize_tab[CO_CUR_DEF];

			fl_color(0xff, 0xff, 0xff);
			fl_rectf(cx + letter_x * console->cursor.x, 
				 cy + letter_y * console->cursor.y + letter_y - cursize,
				 letter_x,
				 cursize);
		}
	}
	
	fl_pop_clip();
}
Example #11
0
void tabbar::draw() {
    const u32 startx = x();
    const u32 endx = x() + w() - 1;

    const u32 gradarea = h() - 2;
    u32 i, j;

    // bg
    u32 r1 = 63, g1 = 72, b1 = 81;
    u32 r2 = 38, g2 = 48, b2 = 59;
    for (i = 0; i <= gradarea; i++) {
        const float pos = i / (float) gradarea;

        fl_color(mix(r1, r2, pos),
                 mix(g1, g2, pos),
                 mix(b1, b2, pos));

        const u32 posy = y() + 1 + i;
        fl_line(startx, posy, endx, posy);
    }

    // Borders
    fl_color(37, 46, 52);
    fl_line(startx, y(), endx, y());
    fl_line(startx, y() + h() - 1, endx, y() + h() - 1);

    // Tabs
    u32 max;
    u32 tabw = calctabw(&max, w());

    bool highborder = false;
    if ((mousex - x()) % tabw > tabw / 2)
        highborder = true;

    u32 posx = x();
    const u32 lowy = y();
    const u32 highy = y() + h() - 1;
    for (i = 0; i < max; i++) {
        bool hover = false;
        // Borders
        fl_color(FL_BLACK);
        if (!i)
            fl_line(posx, lowy, posx, highy);
        fl_line(posx + tabw, lowy, posx + tabw, highy);

        // Bg
        r1 = 83, g1 = 92, b1 = 101;
        r2 = 58, g2 = 68, b2 = 79;

        if (i == g->curtab) {
            r1 = 100, g1 = 160, b1 = 191;
            r2 = 42, g2 = 100, b2 = 125;
        } else if ((mousein && mousex >= posx && mousex <= (posx + tabw - 1)) ||
                   (!firstpress && longorder.size() && longorder[longpress] == i)) {
            r1 = 150, g1 = 150, b1 = 191;
            r2 = 100, g2 = 100, b2 = 155;
            hover = true;
        }

        if (dragging && mousein && mousex >= posx && mousex <= (posx + tabw - 1)) {
            fl_color(FL_WHITE);
            if (!highborder)
                fl_line(posx, lowy, posx, highy);
            else
                fl_line(posx + tabw, lowy, posx + tabw, highy);
        }

        for (j = 0; j <= gradarea; j++) {
            const float pos = j / (float) gradarea;

            fl_color(mix(r1, r2, pos),
                     mix(g1, g2, pos),
                     mix(b1, b2, pos));

            const u32 posy = y() + 1 + j;
            fl_line(posx + 1, posy, posx + tabw - 1, posy);
        }

        // Icon
        Fl_Image *img = g->tabs[i].icon;
        if (!img)
            img = Fl_Shared_Image::get("newtab.png");

        const u32 imgy = y() + (h() - 16) / 2;
        img->draw(posx + 4, imgy, 16, 16);

        // Text
        fl_color(200, 200, 200);
        if (i == g->curtab)
            fl_color(FL_WHITE);
        else if (hover)
            fl_color(230, 230, 230);
        fl_font(labelfont(), labelsize());

        char tmp[80];
        memset(tmp, 0, 80);
        strncpy(tmp, g->tabs[i].title(), 79);

        int textw = 0, texth = 0;
        fl_measure(tmp, textw, texth, 0);

        const u32 textarea = tabw - 2 - 8 - 16 - 4;
        while ((u32) textw >= textarea) {
            // Shorten it until it fits
            const u32 len = strlen(tmp) - 1;
            tmp[len] = '\0';
            tmp[len - 1] = '.';
            tmp[len - 2] = '.';
            tmp[len - 3] = '.';

            textw = texth = 0;
            fl_measure(tmp, textw, texth, 0);
        }

        const u32 texty = y() - fl_descent() + fl_height() + (h() - fl_height())/2;
        fl_draw(tmp, posx + 2 + 8 + 16, texty);

        posx += tabw;
    }
}
Example #12
0
float gl_descent() {return fl_descent();}