void RegionChooser::motion_resize_region(int x, int y) { const int w = get_width() - 1; Glib::RefPtr<Gdk::Window> window = get_window(); int k = int(double(x) / w * 128.0 + 0.5); if (k < resize.min) k = resize.min; else if (k > resize.max) k = resize.max; if (k != resize.pos) { if (resize.mode == resize.undecided) { if (k < resize.pos) { // edit high limit of prev_region resize.max = resize.region->KeyRange.low; resize.region = resize.prev_region; resize.mode = resize.moving_high_limit; } else { // edit low limit of region resize.min = resize.prev_region->KeyRange.high + 1; resize.mode = resize.moving_low_limit; } } Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc(); Glib::RefPtr<const Gdk::GC> white = get_style()->get_white_gc(); if (region == resize.region) { gc->set_foreground(red); white = gc; } Glib::RefPtr<const Gdk::GC> bg = get_style()->get_bg_gc(Gtk::STATE_NORMAL); int prevx = int(w * resize.pos / 128.0 + 0.5); x = int(w * k / 128.0 + 0.5); if (resize.mode == resize.moving_high_limit) { if (k > resize.pos) { window->draw_rectangle(white, true, prevx, 1, x - prevx, h1 - 2); window->draw_line(black, prevx, 0, x, 0); window->draw_line(black, prevx, h1 - 1, x, h1 - 1); } else { int xx = ((resize.pos == resize.max && resize.max != 128) ? 1 : 0); window->draw_rectangle(bg, true, x + 1, 0, prevx - x - xx, h1); } } else { if (k < resize.pos) { window->draw_rectangle(white, true, x + 1, 1, prevx - x, h1 - 2); window->draw_line(black, x, 0, prevx, 0); window->draw_line(black, x, h1 - 1, prevx, h1 - 1); } else { int xx = ((resize.pos == resize.min && resize.min != 0) ? 1 : 0); window->draw_rectangle(bg, true, prevx + xx, 0, x - prevx - xx, h1); } } window->draw_line(black, x, 1, x, h1 - 2); resize.pos = k; } }
bool RedBlueLevelSelector::redraw(GdkEventExpose */*bleh*/) { //!Check if the window we want draw is ready Glib::RefPtr<Gdk::Window> window = get_window(); if(!window) return true; const int w(get_width()),h(get_height()); Gdk::Color color; Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(window)); int i; // Draw the gradient for(i=0;i<w;i++) { float red_blue(((float(i)/float(w)+0.5f)-1.0f)/2.0f+1.0f); float blue_red(2.0f-(red_blue)); if(red_blue>1.0f)red_blue=1.0f; if(blue_red>1.0f)blue_red=1.0f; color.set_rgb( round_to_int(min(red_blue,1.0f)*65535), round_to_int(sqrt(min(red_blue,blue_red))*65535), round_to_int(min(blue_red,1.0f)*65535) ); gc->set_rgb_fg_color(color); window->draw_rectangle(gc, true, i, 0, 1, h); } // Draw a frame gc->set_rgb_fg_color(Gdk::Color("#000000")); window->draw_rectangle(gc, false, 0, 0, w-1, h-1); // Draw the position of the current value i=(int)(((level-1.0f)*2.0f+1.0f-0.5f)*w+0.5); gc->set_rgb_fg_color(Gdk::Color("#00ff00")); window->draw_rectangle(gc, true, i, 1, 1, h-1); // Print out the value Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_pango_context())); layout->set_text(etl::strprintf("%0.02f",level)); layout->set_alignment(Pango::ALIGN_CENTER); gc->set_rgb_fg_color(Gdk::Color("#a00000")); window->draw_layout(gc, w/2, 4, layout); return true; }
void draw_rectangle_on_pixmap ( int x, int y, int lx, int ly, bool fill = true ) { m_pixmap->draw_rectangle(m_gc, fill, x, y, lx, ly); }
void perfroll::draw_background_on( Glib::RefPtr<Gdk::Drawable> a_draw, int a_sequence ) { long tick_offset = m_4bar_offset * c_ppqn * 16; long first_measure = tick_offset / m_measure_length; a_sequence -= m_sequence_offset; int y = c_names_y * a_sequence; int h = c_names_y; m_gc->set_foreground(m_white); a_draw->draw_rectangle(m_gc,true, 0, y, m_window_x, h ); m_gc->set_foreground(m_black); for ( int i = first_measure; i < first_measure + (m_window_x * m_perf_scale_x / (m_measure_length)) + 1; i++ ) { int x_pos = ((i * m_measure_length) - tick_offset) / m_perf_scale_x; a_draw->draw_drawable(m_gc, m_background, 0, 0, x_pos, y, c_perfroll_background_x, c_names_y ); } }
void draw_rectangle ( Glib::RefPtr<Gdk::Drawable> & drawable, int x, int y, int lx, int ly, bool fill = true ) { drawable->draw_rectangle(m_gc, fill, x, y, lx, ly); }
void draw_rectangle ( Glib::RefPtr<Gdk::Pixmap> & pixmap, int x, int y, int lx, int ly, bool fill = true ) { pixmap->draw_rectangle(m_gc, fill, x, y, lx, ly); }
bool VisDrwArea::on_expose_event(GdkEventExpose* aEvent) { DrawingArea::on_expose_event(aEvent); Glib::RefPtr<Gdk::Window> drw = get_window(); Glib::RefPtr<Gtk::Style> style = get_style(); Glib::RefPtr<Gdk::GC> gc = style->get_fg_gc(get_state()); Allocation alc = get_allocation(); drw->draw_rectangle(gc, false, 0, 0, alc.get_width() - 1, alc.get_height() - 1); }
bool BlackLevelSelector::redraw(GdkEventExpose */*bleh*/) { //!Check if the window we want draw is ready Glib::RefPtr<Gdk::Window> window = get_window(); if(!window) return true; const int w(get_width()),h(get_height()); Gdk::Color color; Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(window)); int i; // Draw the gradient for(i=0;i<w;i++) { color.set_rgb(i*65536/w,i*65536/w,i*65536/w); gc->set_rgb_fg_color(color); window->draw_rectangle(gc, true, i, 0, 1, h); } // Draw a frame gc->set_rgb_fg_color(Gdk::Color("#000000")); window->draw_rectangle(gc, false, 0, 0, w-1, h-1); // Draw the position of the current value i=(int)(level*w+0.5); gc->set_rgb_fg_color(Gdk::Color("#ff0000")); window->draw_rectangle(gc, true, i, 1, 1, h-1); // Print out the value Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_pango_context())); layout->set_text(etl::strprintf("%0.01f%%",level*100.0f)); layout->set_alignment(Pango::ALIGN_CENTER); gc->set_rgb_fg_color(Gdk::Color("#a00000")); window->draw_layout(gc, w/2, 4, layout); return true; }
void PaletteWindow::DrawGrid (Glib::RefPtr<Gdk::Window> area, Glib::RefPtr<Gdk::GC>& gc) { gc->set_rgb_fg_color(Gdk::Color("black")); area->draw_rectangle(gc, true, 0, 0, 161, 161); gc->set_rgb_fg_color(Gdk::Color("white")); for (uint8_t c = 0; c <= 16; ++c) { area->draw_line(gc, c*10, 0, c*10, 161); area->draw_line(gc, 0, c*10, 161, c*10); } }
void studio::render_gradient_to_window(const Glib::RefPtr<Gdk::Drawable>& window,const Gdk::Rectangle& ca,const synfig::Gradient &gradient) { int height = ca.get_height(); int width = ca.get_width()-4; float sample_width(1.0f/(float)width); Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(window)); const Color bg1(0.25, 0.25, 0.25); const Color bg2(0.5, 0.5, 0.5); Gdk::Color gdk_c; int i; for(i=0;i<width;i++) { const Color c(gradient(float(i)/float(width),sample_width)); const Color c1(Color::blend(c,bg1,1.0).clamped()); const Color c2(Color::blend(c,bg2,1.0).clamped()); gushort r1(256*App::gamma.r_F32_to_U8(c1.get_r())); gushort g1(256*App::gamma.g_F32_to_U8(c1.get_g())); gushort b1(256*App::gamma.b_F32_to_U8(c1.get_b())); gushort r2(256*App::gamma.r_F32_to_U8(c2.get_r())); gushort g2(256*App::gamma.g_F32_to_U8(c2.get_g())); gushort b2(256*App::gamma.b_F32_to_U8(c2.get_b())); if((i*2/height)&1) { gdk_c.set_rgb(r1,g1,b1); gc->set_rgb_fg_color(gdk_c); window->draw_rectangle(gc, true, ca.get_x()+i+2, ca.get_y(), 1, height/2); gdk_c.set_rgb(r2,g2,b2); gc->set_rgb_fg_color(gdk_c); window->draw_rectangle(gc, true, ca.get_x()+i+2, ca.get_y()+height/2, 1, height/2); } else { gdk_c.set_rgb(r2,g2,b2); gc->set_rgb_fg_color(gdk_c); window->draw_rectangle(gc, true, ca.get_x()+i+2, ca.get_y(), 1, height/2); gdk_c.set_rgb(r1,g1,b1); gc->set_rgb_fg_color(gdk_c); window->draw_rectangle(gc, true, ca.get_x()+i+2, ca.get_y()+height/2, 1, height/2); } } gc->set_rgb_fg_color(Gdk::Color("#ffffff")); window->draw_rectangle(gc, false, ca.get_x()+1, ca.get_y()+1, ca.get_width()-3, height-3); gc->set_rgb_fg_color(Gdk::Color("#000000")); window->draw_rectangle(gc, false, ca.get_x(), ca.get_y(), ca.get_width()-1, height-1); }
bool ClassificationCell::on_expose_event(GdkEventExpose *e) { char buf[10]; sprintf (buf, "%.0f", round(value)); // std::stringstream buf; //buf.precision(0); //buf.setf(std::ios::fixed, std::ios::floatfield); int w=0, h=0; Glib::RefPtr<Gdk::Window> window = get_window(); if (value > 50.0) window->set_background(green); else if (value > 25.0) window->set_background(lightgreen); else if (value > 0.05) window->set_background(lightred); else window->set_background(white); window->clear(); window->draw_rectangle(gc, false, 0, 0, 39, 29); // buf << value; // printf ("string %s\n", buf.str().c_str()); Glib::RefPtr<Pango::Layout> p = create_pango_layout(Glib::ustring(buf)); p->set_alignment(Pango::ALIGN_CENTER); p->get_pixel_size(w, h); int nx = (40-w) / 2 + 1; int ny = (30-h) / 2 + 1; window->draw_layout(gc, nx, ny, p); window->invalidate_rect(Gdk::Rectangle(0,0,40,30), false); return true; }
void RegionChooser::draw_region(int from, int to, const Gdk::Color& color) { const int h = KEYBOARD_HEIGHT; const int w = get_width() - 1; const int bh = int(h * 0.55); Glib::RefPtr<Gdk::Window> window = get_window(); gc->set_foreground(color); for (int i = from ; i < to ; i++) { int note = (i + 3) % 12; int x = int(w * i / 128.0 + 0.5) + 1; int x2 = int(w * (i + 1.5) / 128.0 + 0.5); int x3 = int(w * (i + 1) / 128.0 + 0.5); int x4 = int(w * (i - 0.5) / 128.0 + 0.5); int w1 = x3 - x; switch (note) { case 0: case 5: case 10: window->draw_rectangle(gc, true, x, h1 + 1, w1, bh); window->draw_rectangle(gc, true, x4 + 1, h1 + bh + 1, x2 - x4 - 1, h - bh - 2); break; case 2: case 7: window->draw_rectangle(gc, true, x, h1 + 1, w1, bh); window->draw_rectangle(gc, true, x4 + 1, h1 + bh + 1, x3 - x4 - 1, h - bh - 2); break; case 3: case 8: window->draw_rectangle(gc, true, x, h1 + 1, w1, bh); window->draw_rectangle(gc, true, x, h1 + bh + 1, x2 - x, h - bh - 2); if (note == 3) draw_digit(i); break; default: window->draw_rectangle(gc, true, x, h1 + 1, w1, bh - 1); break; } } }
void CellRenderer_TimeTrack::render_vfunc( const Glib::RefPtr<Gdk::Drawable>& window, Gtk::Widget& widget, const Gdk::Rectangle& /*background_area*/, const Gdk::Rectangle& area_, const Gdk::Rectangle& /*expose_area*/, Gtk::CellRendererState /*flags*/) { if(!window) return; Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(window)); Glib::RefPtr<Gdk::GC> inactive_gc(Gdk::GC::create(window)); Gtk::Adjustment *adjustment=get_adjustment(); // Gtk::StateType state = Gtk::STATE_ACTIVE; // Gtk::ShadowType shadow; Gdk::Color curr_time_color("#0000ff"), inactive_color("#000000"), keyframe_color("#a07f7f"); Gdk::Color activepoint_color[2]; activepoint_color[0]=Gdk::Color("#ff0000"); activepoint_color[1]=Gdk::Color("#00ff00"); inactive_gc->set_rgb_fg_color(inactive_color); inactive_gc->set_stipple(Gdk::Bitmap::create(stipple_xpm,2,2)); inactive_gc->set_fill(Gdk::STIPPLED); synfig::Canvas::Handle canvas(property_canvas().get_value()); synfigapp::ValueDesc value_desc = property_value_desc().get_value(); synfig::ValueNode *base_value = value_desc.get_value_node().get(); // synfig::ValueNode_Animated *value_node=dynamic_cast<synfig::ValueNode_Animated*>(base_value); synfig::ValueNode_DynamicList *parent_value_node(0); if(property_value_desc().get_value().parent_is_value_node()) parent_value_node=dynamic_cast<synfig::ValueNode_DynamicList*>(property_value_desc().get_value().get_parent_value_node().get()); // If the canvas is defined, then load up the keyframes if(canvas) { const synfig::KeyframeList& keyframe_list(canvas->keyframe_list()); synfig::KeyframeList::const_iterator iter; for(iter=keyframe_list.begin(); iter!=keyframe_list.end(); ++iter) { if(!iter->get_time().is_valid()) continue; const int x((int)((float)area_.get_width()/(adjustment->get_upper()-adjustment->get_lower())*(iter->get_time()-adjustment->get_lower()))); if(iter->get_time()>=adjustment->get_lower() && iter->get_time()<adjustment->get_upper()) { gc->set_rgb_fg_color(keyframe_color); window->draw_rectangle(gc, true, area_.get_x()+x, area_.get_y(), 1, area_.get_height()+1); } } } //render all the time points that exist { const synfig::Node::time_set *tset = get_times_from_vdesc(value_desc); if(tset) { const synfig::Time time_offset = get_time_offset_from_vdesc(value_desc); synfig::Node::time_set::const_iterator i = tset->begin(), end = tset->end(); float lower = adjustment->get_lower(), upper = adjustment->get_upper(); Glib::RefPtr<Gdk::GC> gc = Gdk::GC::create(widget.get_window()); Gdk::Rectangle area(area_); gc->set_clip_rectangle(area); gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER); bool valselected = sel_value.get_value_node() == base_value && !sel_times.empty(); float cfps = get_canvas()->rend_desc().get_frame_rate(); vector<Time> drawredafter; Time diff = actual_time - actual_dragtime;//selected_time-drag_time; for(; i != end; ++i) { //find the coordinate in the drawable space... Time t_orig = i->get_time(); if(!t_orig.is_valid()) continue; Time t = t_orig - time_offset; if(t<adjustment->get_lower() || t>adjustment->get_upper()) continue; //if it found it... (might want to change comparison, and optimize // sel_times.find to not produce an overall nlogn solution) bool selected=false; //not dragging... just draw as per normal //if move dragging draw offset //if copy dragging draw both... if(valselected && sel_times.find(t_orig) != sel_times.end()) { if(dragging) //skip if we're dragging because we'll render it later { if(mode & COPY_MASK) // draw both blue and red moved { drawredafter.push_back(t + diff.round(cfps)); gc->set_rgb_fg_color(Gdk::Color("#00EEEE")); } else if(mode & DELETE_MASK) //it's just red... { gc->set_rgb_fg_color(Gdk::Color("#EE0000")); selected=true; } else //move - draw the red on top of the others... { drawredafter.push_back(t + diff.round(cfps)); continue; } } else { gc->set_rgb_fg_color(Gdk::Color("#EE0000")); selected=true; } } else { gc->set_rgb_fg_color(Gdk::Color("#00EEEE")); } //synfig::info("Displaying time: %.3f s",(float)t); const int x = (int)((t-lower)*area.get_width()/(upper-lower)); //should draw me a grey filled circle... Gdk::Rectangle area2( area.get_x() - area.get_height()/2 + x + 1, area.get_y() + 1, area.get_height()-2, area.get_height()-2 ); render_time_point_to_window(window,area2,*i - time_offset,selected); /*window->draw_arc(gc,true, area.get_x() + x - area.get_height()/4, area.get_y() + area.get_height()/8, area.get_height()/2, area.get_height()*3/4, 0, 64*360); gc->set_rgb_fg_color(Gdk::Color("#000000")); window->draw_arc(gc,false, area.get_x() + x - area.get_height()/4, area.get_y() + area.get_height()/8, area.get_height()/2, area.get_height()*3/4, 0, 64*360); */ } { vector<Time>::iterator i = drawredafter.begin(), end = drawredafter.end(); for(; i != end; ++i) { //find the coordinate in the drawable space... Time t = *i; if(!t.is_valid()) continue; //synfig::info("Displaying time: %.3f s",(float)t); const int x = (int)((t-lower)*area.get_width()/(upper-lower)); //should draw me a grey filled circle... Gdk::Rectangle area2( area.get_x() - area.get_height()/2 + x + 1, area.get_y() + 1, area.get_height()-2, area.get_height()-2 ); render_time_point_to_window(window,area2,*i,true); /* gc->set_rgb_fg_color(Gdk::Color("#EE0000")); window->draw_arc(gc,true, area.get_x() + x - area.get_height()/4, area.get_y() + area.get_height()/8, area.get_height()/2, area.get_height()*3/4, 0, 64*360); gc->set_rgb_fg_color(Gdk::Color("#000000")); window->draw_arc(gc,false, area.get_x() + x - area.get_height()/4, area.get_y() + area.get_height()/8, area.get_height()/2, area.get_height()*3/4, 0, 64*360); */ } } } } /* THIS IS NOW HANDLED ENTIRELY BY THE TIMEPOINT SYSTEM // This this is an animated value node, then render the waypoints if(value_node) { //now render the actual waypoints synfig::ValueNode_Animated::WaypointList::iterator iter; for( iter=value_node->waypoint_list().begin(); iter!=value_node->waypoint_list().end(); iter++ ) { if(!iter->get_time().is_valid()) continue; int x; bool selected=false; if(is_selected(*iter)) { Time t(iter->get_time()); if(dragging) t=(t+selected_time-drag_time).round(get_canvas()->rend_desc().get_frame_rate()); x=(int)((float)area.get_width()/(adjustment->get_upper()-adjustment->get_lower())*(t-adjustment->get_lower())); shadow=Gtk::SHADOW_IN; selected=true; } else { x=(int)((float)area.get_width()/(adjustment->get_upper()-adjustment->get_lower())*(iter->get_time()-adjustment->get_lower())); shadow=Gtk::SHADOW_OUT; selected=false; } widget.get_style()->paint_diamond( Glib::RefPtr<Gdk::Window>::cast_static(window), state, shadow, area, widget, "solid", area.get_x()+x-area.get_height()/4, area.get_y()+area.get_height()/4, area.get_height()/2, area.get_height()/2 ); } } */ Gdk::Rectangle area(area_); // If the parent of this value node is a dynamic list, then // render the on and off times if(parent_value_node) { const int index(property_value_desc().get_value().get_index()); const synfig::ValueNode_DynamicList::ListEntry& list_entry(parent_value_node->list[index]); const synfig::ValueNode_DynamicList::ListEntry::ActivepointList& activepoint_list(list_entry.timing_info); synfig::ValueNode_DynamicList::ListEntry::ActivepointList::const_iterator iter,next; bool is_off(false); if(!activepoint_list.empty()) is_off=!activepoint_list.front().state; int xstart(0); int x=0 /*,prevx=0*/; for(next=activepoint_list.begin(),iter=next++; iter!=activepoint_list.end(); iter=next++) { x=((int)((float)area.get_width()/(adjustment->get_upper()-adjustment->get_lower())*(iter->time-adjustment->get_lower()))); if(x<0)x=0; if(x>area.get_width())x=area.get_width(); bool status_at_time=0; if(next!=activepoint_list.end()) { status_at_time=!list_entry.status_at_time((iter->time+next->time)/2.0); } else status_at_time=!list_entry.status_at_time(Time::end()); if(!is_off && status_at_time) { xstart=x; is_off=true; } else if(is_off && !status_at_time) { window->draw_rectangle(inactive_gc, true, area.get_x()+xstart, area.get_y(), x-xstart, area.get_height()); is_off=false; } /* if(!is_off && iter!=activepoint_list.end() && next->state==false && iter->state==false) { xstart=x; is_off=true; } else if(is_off && next!=activepoint_list.end() && iter->state==false && next->state==true) { window->draw_rectangle(inactive_gc, true, area.get_x()+xstart, area.get_y(), x-xstart, area.get_height()); is_off=false; } else if(is_off && iter!=activepoint_list.end() && iter->state==true) { window->draw_rectangle(inactive_gc, true, area.get_x()+xstart, area.get_y(), prevx-xstart, area.get_height()); is_off=false; } */ if(iter->time>=adjustment->get_lower() && iter->time<adjustment->get_upper()) { int w(1); if(selected==*iter) w=3; gc->set_rgb_fg_color(activepoint_color[iter->state]); window->draw_rectangle(gc, true, area.get_x()+x-w/2, area.get_y(), w, area.get_height()); } //prevx=x; } if(is_off) { window->draw_rectangle(inactive_gc, true, area.get_x()+xstart, area.get_y(), area.get_width()-xstart, area.get_height()); } } // Render a line that defines the current tick in time { gc->set_rgb_fg_color(curr_time_color); const int x((int)((float)area.get_width()/(adjustment->get_upper()-adjustment->get_lower())*(adjustment->get_value()-adjustment->get_lower()))); if(adjustment->get_value()>=adjustment->get_lower() && adjustment->get_value()<adjustment->get_upper()) window->draw_rectangle(gc, true, area.get_x()+x, area.get_y(), 1, area.get_height()); } }
void seqroll::draw_events_on( Glib::RefPtr<Gdk::Drawable> a_draw ) { long tick_s; long tick_f; int note; int note_x; int note_width; int note_y; int note_height; bool selected; int velocity; draw_type dt; int start_tick = m_scroll_offset_ticks ; int end_tick = (m_window_x * m_zoom) + m_scroll_offset_ticks; sequence *seq = NULL; for( int method=0; method<2; ++method ) { if ( method == 0 && m_drawing_background_seq ){ if ( m_perform->is_active( m_background_sequence )){ seq =m_perform->get_sequence( m_background_sequence ); } else { method++; } } else if ( method == 0 ){ method++; } if ( method==1){ seq = m_seq; } /* draw boxes from sequence */ m_gc->set_foreground( m_black ); seq->reset_draw_marker(); while ( (dt = seq->get_next_note_event( &tick_s, &tick_f, ¬e, &selected, &velocity )) != DRAW_FIN ) { if ((tick_s >= start_tick && tick_s <= end_tick) || ( (dt == DRAW_NORMAL_LINKED) && (tick_f >= start_tick && tick_f <= end_tick)) ) { /* turn into screen corrids */ note_x = tick_s / m_zoom; note_y = c_rollarea_y -(note * c_key_y) - c_key_y - 1 + 2; note_height = c_key_y - 3; // printf( "DEBUG: drawing note[%d] tick_s[%d] tick_f[%d] start_tick[%d] end_tick[%d]\n", // note, tick_s, tick_f, start_tick, end_tick ); // printf( "DEBUG: seq.get_lenght() = %d\n", m_seq->get_length()); int in_shift = 0; int length_add = 0; if ( dt == DRAW_NORMAL_LINKED ){ if (tick_f >= tick_s) { note_width = (tick_f - tick_s) / m_zoom; if ( note_width < 1 ) note_width = 1; } else { note_width = (m_seq->get_length() - tick_s) / m_zoom; } } else { note_width = 16 / m_zoom; } if ( dt == DRAW_NOTE_ON ){ in_shift = 0; length_add = 2; } if ( dt == DRAW_NOTE_OFF ){ in_shift = -1; length_add = 1; } note_x -= m_scroll_offset_x; note_y -= m_scroll_offset_y; m_gc->set_foreground(m_black); /* draw boxes from sequence */ if ( method == 0 ) m_gc->set_foreground( m_dk_grey ); a_draw->draw_rectangle( m_gc,true, note_x, note_y, note_width, note_height); if (tick_f < tick_s) { a_draw->draw_rectangle( m_gc,true, 0, note_y, tick_f/m_zoom, note_height); } /* draw inside box if there is room */ if ( note_width > 3 ){ if ( selected ) m_gc->set_foreground(m_red); else m_gc->set_foreground(m_white); if ( method == 1 ) { if (tick_f >= tick_s) { a_draw->draw_rectangle( m_gc,true, note_x + 1 + in_shift, note_y + 1, note_width - 3 + length_add, note_height - 3); } else { a_draw->draw_rectangle( m_gc,true, note_x + 1 + in_shift, note_y + 1, note_width , note_height - 3); a_draw->draw_rectangle( m_gc,true, 0, note_y + 1, (tick_f/m_zoom) - 3 + length_add, note_height - 3); } } } } } } }
void RegionChooser::motion_move_region(int x, int y) { const int w = get_width() - 1; Glib::RefPtr<Gdk::Window> window = get_window(); int k = int(double(x - move.from_x) / w * 128.0 + 0.5); if (k == move.pos) return; int new_k; bool new_touch_left; bool new_touch_right; int a = 0; if (k > move.pos) { for (gig::Region* r = regions.first() ; ; r = regions.next()) { if (r != region) { int b = r ? r->KeyRange.low : 128; // gap: from a to b (not inclusive b) if (region->KeyRange.high + move.pos >= b) { // not found the current gap yet, just continue } else { if (a > region->KeyRange.low + k) { // this gap is too far to the right, break break; } int newhigh = std::min(region->KeyRange.high + k, b - 1); int newlo = newhigh - (region->KeyRange.high - region->KeyRange.low); if (newlo >= a) { // yes it fits - it's a candidate new_k = newlo - region->KeyRange.low; new_touch_left = a > 0 && a == newlo; new_touch_right = b < 128 && newhigh + 1 == b; } } if (!r) break; a = r->KeyRange.high + 1; } } } else { for (gig::Region* r = regions.first() ; ; r = regions.next()) { if (r != region) { int b = r ? r->KeyRange.low : 128; // gap from a to b (not inclusive b) if (region->KeyRange.high + k >= b) { // not found the current gap yet, just continue } else { if (a > region->KeyRange.low + move.pos) { // this gap is too far to the right, break break; } int newlo = std::max(region->KeyRange.low + k, a); int newhigh = newlo + (region->KeyRange.high - region->KeyRange.low); if (newhigh < b) { // yes it fits - break as the first one is the best new_k = newlo - region->KeyRange.low; new_touch_left = a > 0 && a == newlo; new_touch_right = b < 128 && newhigh + 1 == b; break; } } if (!r) break; a = r->KeyRange.high + 1; } } } k = new_k; if (k == move.pos) return; Glib::RefPtr<const Gdk::GC> bg = get_style()->get_bg_gc(Gtk::STATE_NORMAL); int prevx = int(w * (move.pos + region->KeyRange.low) / 128.0 + 0.5); x = int(w * (k + region->KeyRange.low) / 128.0 + 0.5); int prevx2 = int(w * (move.pos + region->KeyRange.high + 1) / 128.0 + 0.5); int x2 = int(w * (k + region->KeyRange.high + 1) / 128.0 + 0.5); Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc(); gc->set_foreground(red); if (!new_touch_left) window->draw_line(black, x, 1, x, h1 - 2); if (!new_touch_right) window->draw_line(black, x2, 1, x2, h1 - 2); if (k > move.pos) { window->draw_rectangle(bg, true, prevx + (move.touch_left ? 1 : 0), 0, std::min(x, prevx2 + 1 - (move.touch_right ? 1 : 0)) - (prevx + (move.touch_left ? 1 : 0)), h1); window->draw_line(black, std::max(x, prevx2 + 1), 0, x2, 0); window->draw_line(black, std::max(x, prevx2 + 1), h1 - 1, x2, h1 - 1); window->draw_rectangle(gc, true, std::max(x + 1, prevx2), 1, x2 - std::max(x + 1, prevx2), h1 - 2); } else { window->draw_rectangle(bg, true, std::max(x2 + 1, prevx + (move.touch_left ? 1 : 0)), 0, prevx2 + 1 - (move.touch_right ? 1 : 0) - std::max(x2 + 1, prevx + (move.touch_left ? 1 : 0)), h1); window->draw_line(black, x, 0, std::min(x2, prevx - 1), 0); window->draw_line(black, x, h1 - 1, std::min(x2, prevx - 1), h1 - 1); window->draw_rectangle(gc, true, x + 1, 1, std::min(x2 - 1, prevx) - x, h1 - 2); } move.pos = k; move.touch_left = new_touch_left; move.touch_right = new_touch_right; }
void ValidationPanel::refresh() { // update the label crn::StringUTF8 lab = "<span font_desc=\"" + Config::GetFont() + "\">" + title + "</span>"; lab += " ("; lab += nelem; lab += ")"; auto *labw = get_label_widget(); auto *llab = dynamic_cast<Gtk::Label*>(labw); if (llab) llab->set_markup(lab.CStr()); else set_label(lab.CStr()); if (/*(positions.size() != elements.size()) ||*/ (dispw <= 0) || (disph <= 0) || locked) return; Glib::RefPtr<Gdk::Window> win = da.get_window(); if (win) { // if the drawing area is fully created // create a buffer Glib::RefPtr<Gdk::Pixmap> pm = Gdk::Pixmap::create(win, dispw, disph); // clear the buffer pm->draw_rectangle(da_gc, true, 0, 0, dispw, disph); int offset = -int(scroll.get_value()); Cairo::RefPtr<Cairo::Context> cc = pm->create_cairo_context(); // draw the words for (const ValidationPanel::ElementList::value_type &el : elements) { if (!el.second.empty()) { int by = positions[el.second.begin()->first].Y; int ey = by; for (const ValidationPanel::ElementCluster::value_type &w : el.second) { int y = positions[w.first].Y + w.second.img->get_height(); if (y > ey) ey = y; } if ((el.first == elements.rbegin()->first) && (ey < disph)) { // fill till the end of the display ey = disph; } ValidationPanel::set_color(cc, el.first); cc->rectangle(0, by + offset, dispw, ey - by); cc->fill(); } for (const ValidationPanel::ElementCluster::value_type &w : el.second) { Glib::RefPtr<Gdk::Pixbuf> wpb = w.second.img; pm->draw_pixbuf(da_gc, wpb, 0, 0, positions[w.first].X, positions[w.first].Y + offset, w.second.img->get_width(), w.second.img->get_height(), Gdk::RGB_DITHER_NONE, 0, 0); } } // draw the mark if (mark.size() > 1) { cc->set_source_rgb(1.0, 0, 0); cc->move_to(mark.front().X, mark.front().Y + offset); for (size_t tmp = 1; tmp < mark.size(); ++tmp) { cc->line_to(mark[tmp].X, mark[tmp].Y + offset); } cc->stroke(); } // copy pixmap to drawing area win->draw_drawable(da_gc, pm, 0, 0, 0, 0); } }
bool RegionChooser::on_expose_event(GdkEventExpose* event) { Glib::RefPtr<Gdk::Window> window = get_window(); window->clear(); const int h = KEYBOARD_HEIGHT; const int w = get_width() - 1; const int bh = int(h * 0.55); Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc(); Glib::RefPtr<const Gdk::GC> white = get_style()->get_white_gc(); window->draw_rectangle(black, false, 0, h1, w, h - 1); gc->set_foreground(grey1); int x1 = int(w * 20.5 / 128.0 + 0.5); int x2 = int(w * 109.5 / 128.0 + 0.5); window->draw_rectangle(gc, true, 1, h1 + 1, x1 - 1, h - 2); window->draw_rectangle(white, true, x1 + 1, h1 + 1, x2 - x1 - 1, h - 2); window->draw_rectangle(gc, true, x2 + 1, h1 + 1, w - x2 - 1, h - 2); for (int i = 0 ; i < 128 ; i++) { int note = (i + 3) % 12; int x = int(w * i / 128.0 + 0.5); if (note == 1 || note == 4 || note == 6 || note == 9 || note == 11) { int x2 = int(w * (i + 0.5) / 128.0 + 0.5); window->draw_line(black, x2, h1 + bh, x2, h1 + h); int x3 = int(w * (i + 1) / 128.0 + 0.5); window->draw_rectangle(black, true, x, h1 + 1, x3 - x + 1, bh); } else if (note == 3 || note == 8) { window->draw_line(black, x, h1 + 1, x, h1 + h); } if (note == 3) draw_digit(i); } if (instrument) { int i = 0; gig::Region *next_region; int x3 = -1; for (gig::Region *r = regions.first() ; r ; r = next_region) { if (x3 < 0) x3 = int(w * (r->KeyRange.low) / 128.0 + 0.5); next_region = regions.next(); if (!next_region || r->KeyRange.high + 1 != next_region->KeyRange.low) { int x2 = int(w * (r->KeyRange.high + 1) / 128.0 + 0.5); window->draw_line(black, x3, 0, x2, 0); window->draw_line(black, x3, h1 - 1, x2, h1 - 1); window->draw_line(black, x2, 1, x2, h1 - 2); window->draw_rectangle(white, true, x3 + 1, 1, x2 - x3 - 1, h1 - 2); x3 = -1; } i++; } for (gig::Region *r = regions.first() ; r ; r = regions.next()) { int x = int(w * (r->KeyRange.low) / 128.0 + 0.5); window->draw_line(black, x, 1, x, h1 - 2); } if (region) { int x1 = int(w * (region->KeyRange.low) / 128.0 + 0.5); int x2 = int(w * (region->KeyRange.high + 1) / 128.0 + 0.5); gc->set_foreground(red); window->draw_rectangle(gc, true, x1 + 1, 1, x2 - x1 - 1, h1 - 2); } } return true; }
void perfroll::draw_sequence_on (Glib::RefPtr<Gdk::Drawable> a_draw, int a_sequence) { if ((a_sequence < m_sequence_max) && perf().is_active(a_sequence)) { long tick_offset = m_4bar_offset * m_ticks_per_bar; long x_offset = tick_offset / m_perf_scale_x; m_sequence_active[a_sequence] = true; sequence * seq = perf().get_sequence(a_sequence); seq->reset_draw_trigger_marker(); a_sequence -= m_sequence_offset; long sequence_length = seq->get_length(); int length_w = sequence_length / m_perf_scale_x; long tick_on; long tick_off; long offset; bool selected; while (seq->get_next_trigger(&tick_on, &tick_off, &selected, &offset)) { if (tick_off > 0) { long x_on = tick_on / m_perf_scale_x; long x_off = tick_off / m_perf_scale_x; int w = x_off - x_on + 1; int x = x_on; int y = m_names_y * a_sequence + 1; // + 2 int h = m_names_y - 2; // - 4 x -= x_offset; /* adjust to screen coordinates */ if (selected) m_gc->set_foreground(grey()); else m_gc->set_foreground(white()); a_draw->draw_rectangle ( m_gc, true, x, y, w, h ); m_gc->set_foreground(black()); a_draw->draw_rectangle ( m_gc, false, x, y, w, h ); m_gc->set_foreground(black()); a_draw->draw_rectangle ( m_gc, false, x, y, m_size_box_w, m_size_box_w // ? ); a_draw->draw_rectangle ( m_gc, false, x + w - m_size_box_w, y + h - m_size_box_w, m_size_box_w, m_size_box_w // ? ); m_gc->set_foreground(black()); long length_marker_first_tick = ( tick_on - (tick_on % sequence_length) + (offset % sequence_length) - sequence_length ); long tick_marker = length_marker_first_tick; while (tick_marker < tick_off) { long tick_marker_x = (tick_marker / m_perf_scale_x) - x_offset; if (tick_marker > tick_on) { m_gc->set_foreground(light_grey()); a_draw->draw_rectangle ( m_gc, true, tick_marker_x, y + 4, 1, h - 8 ); } int lowest_note = seq->get_lowest_note_event(); int highest_note = seq->get_highest_note_event(); int height = highest_note - lowest_note + 2; int length = seq->get_length(); long tick_s; long tick_f; int note; bool selected; int velocity; draw_type dt; seq->reset_draw_marker(); m_gc->set_foreground(black()); while ( ( dt = seq->get_next_note_event ( &tick_s, &tick_f, ¬e, &selected, &velocity ) ) != DRAW_FIN ) { int note_y = ( (m_names_y-6) - ((m_names_y-6) * (note-lowest_note)) / height ) + 1; int tick_s_x = ((tick_s * length_w) / length) + tick_marker_x; int tick_f_x = ((tick_f * length_w) / length) + tick_marker_x; if (dt == DRAW_NOTE_ON || dt == DRAW_NOTE_OFF) tick_f_x = tick_s_x + 1; if (tick_f_x <= tick_s_x) tick_f_x = tick_s_x + 1; if (tick_s_x < x) tick_s_x = x; if (tick_f_x > x + w) tick_f_x = x + w; if (tick_f_x >= x && tick_s_x <= x + w) { m_pixmap->draw_line ( m_gc, tick_s_x, y + note_y, tick_f_x, y + note_y ); } } tick_marker += sequence_length; } } } } }
bool Widget_Timeslider::redraw(bool /*doublebuffer*/) { Glib::RefPtr<Gdk::Window> window = get_window(); if(!window) return false; Glib::RefPtr<Gdk::GC> gc = Gdk::GC::create(window); if(!gc) return false; //synfig::info("Drawing Timeslider"); //clear and update to current values //invalidated = false; //update_times(); //draw grey rectangle Gdk::Color c("#7f7f7f"); gc->set_rgb_fg_color(c); gc->set_background(c); //Get the data for the window and the params to draw it... int w = get_width(), h = get_height(); window->draw_rectangle(gc,true,0,0,w,h); const double EPSILON = 1e-6; if(!adj_timescale || w == 0) return true; //Get the time information since we now know it's valid double start = adj_timescale->get_lower(), end = adj_timescale->get_upper(), current = adj_timescale->get_value(); if(end-start < EPSILON) return true; //synfig::info("Drawing Lines"); //draw all the time stuff double dtdp = (end - start)/get_width(); double dpdt = 1/dtdp; //lines //Draw the time line... double tpx = (current-start)*dpdt; gc->set_rgb_fg_color(Gdk::Color("#ffaf00")); window->draw_line(gc,round_to_int(tpx),0,round_to_int(tpx),fullheight); //normal line/text color gc->set_rgb_fg_color(Gdk::Color("#333333")); int ifps = round_to_int(fps); if (ifps < 1) ifps = 1; std::vector<double> ranges; unsigned int pos = 0; // build a list of all the factors of the frame rate for (int i = 1; i*i <= ifps; i++) if ((ifps%i) == 0) { ranges.insert(ranges.begin()+pos, i/fps); if (i*i != ifps) ranges.insert(ranges.begin()+pos+1, ifps/i/fps); pos++; } // fill in any gaps where one factor is more than 2 times the previous std::vector<double>::iterator iter, next; pos = 0; for (pos = 0; pos < ranges.size()-1; pos++) { iter = ranges.begin()+pos; next = iter+1; if (*iter*2 < *next) ranges.insert(next, *iter*2); } double more_ranges[] = { 2, 3, 5, 10, 20, 30, 60, 90, 120, 180, 300, 600, 1200, 1800, 2700, 3600, 3600*2, 3600*4, 3600*8, 3600*16, 3600*32, 3600*64, 3600*128, 3600*256, 3600*512, 3600*1024 }; ranges.insert(ranges.end(), more_ranges, more_ranges + sizeof(more_ranges)/sizeof(double)); double lowerrange = dtdp*140, upperrange = dtdp*280; double midrange = (lowerrange + upperrange)/2; //find most ideal scale double scale; next = binary_find(ranges.begin(), ranges.end(), midrange); iter = next++; if (iter == ranges.end()) iter--; if (next == ranges.end()) next--; if (abs(*next - midrange) < abs(*iter - midrange)) iter = next; scale = *iter; // subdivide into this many tick marks (8 or less) int subdiv = round_to_int(scale * ifps); if (subdiv > 8) { const int ideal = subdiv; // find a number of tick marks that nicely divides the scale // (5 minutes divided by 6 is 50s, but that's not 'nice' - // 5 ticks of 1m each is much simpler than 6 ticks of 50s) for (subdiv = 8; subdiv > 0; subdiv--) if ((ideal <= ifps*2 && (ideal % (subdiv )) == 0) || (ideal <= ifps*2*60 && (ideal % (subdiv*ifps )) == 0) || (ideal <= ifps*2*60*60 && (ideal % (subdiv*ifps*60 )) == 0) || (true && (ideal % (subdiv*ifps*60*60)) == 0)) break; // if we didn't find anything, use 4 ticks if (!subdiv) subdiv = 4; } time_per_tickmark = scale / subdiv; //get first valid line and its position in pixel space double time = 0; double pixel = 0; int sdindex = 0; double subr = scale / subdiv; //get its position inside... time = ceil(start/subr)*subr - start; pixel = time*dpdt; //absolute time of the line to be drawn time += start; { //inside the big'n double t = (time/scale - floor(time/scale))*subdiv; // the difference from the big mark in 0:1 //sdindex = (int)floor(t + 0.5); //get how far through the range it is... sdindex = round_to_int(t); //get how far through the range it is... if (sdindex == subdiv) sdindex = 0; //synfig::info("Extracted fr %.2lf -> %d", t, sdindex); } //synfig::info("Initial values: %.4lf t, %.1lf pixels, %d i", time,pixel,sdindex); //loop to draw const int heightbig = 12; const int heightsmall = 4; int width = get_width(); while( pixel < width ) { int xpx = round_to_int(pixel); //draw big if(sdindex == 0) { window->draw_line(gc,xpx,0,xpx,heightbig); //round the time to nearest frame and draw the text Time tm((double)time); if(get_global_fps()) tm.round(get_global_fps()); Glib::ustring timecode(tm.get_string(get_global_fps(),App::get_time_format())); //gc->set_rgb_fg_color(Gdk::Color("#000000")); layout->set_text(timecode); Pango::AttrList attr_list; // Aproximately a font size of 8 pixels. // Pango::SCALE = 1024 // create_attr_size waits a number in 1000th of pixels. // Should be user customizable in the future. Now it is fixed to 10 Pango::AttrInt pango_size(Pango::Attribute::create_attr_size(Pango::SCALE*10)); pango_size.set_start_index(0); pango_size.set_end_index(64); attr_list.change(pango_size); layout->set_attributes(attr_list); window->draw_layout(gc,xpx+2,0,layout); }else { window->draw_line(gc,xpx,0,xpx,heightsmall); } //increment time and position pixel += subr / dtdp; time += subr; //increment index if(++sdindex >= subdiv) sdindex -= subdiv; } return true; }
void perfroll::draw_sequence_on( Glib::RefPtr<Gdk::Drawable> a_draw, int a_sequence ) { long tick_on; long tick_off; long offset; bool selected; long tick_offset = m_4bar_offset * c_ppqn * 16; long x_offset = tick_offset / m_perf_scale_x; if ( a_sequence < c_total_seqs ) { if ( m_mainperf->is_active( a_sequence )) { m_sequence_active[a_sequence] = true; sequence *seq = m_mainperf->get_sequence( a_sequence ); seq->reset_draw_trigger_marker(); a_sequence -= m_sequence_offset; long sequence_length = seq->get_length(); int length_w = sequence_length / m_perf_scale_x; while ( seq->get_next_trigger( &tick_on, &tick_off, &selected, &offset )) { if ( tick_off > 0 ) { long x_on = tick_on / m_perf_scale_x; long x_off = tick_off / m_perf_scale_x; int w = x_off - x_on + 1; int x = x_on; int y = c_names_y * a_sequence + 1; // + 2 int h = c_names_y - 2; // - 4 // adjust to screen corrids x = x - x_offset; if ( selected ) m_gc->set_foreground(m_grey); else m_gc->set_foreground(m_white); /* main trigger box */ a_draw->draw_rectangle(m_gc,true, x, y, w, h ); /* trigger outline */ m_gc->set_foreground(m_black); a_draw->draw_rectangle(m_gc,false, x, y, w, h ); /* little seq grab handle - left hand side */ m_gc->set_foreground(m_black); a_draw->draw_rectangle(m_gc,false, x, y, c_perfroll_size_box_w, c_perfroll_size_box_w ); /* seq grab handle - right side */ a_draw->draw_rectangle(m_gc,false, x+w-c_perfroll_size_box_w, y+h-c_perfroll_size_box_w, c_perfroll_size_box_w, c_perfroll_size_box_w ); m_gc->set_foreground(m_black); long length_marker_first_tick = ( tick_on - (tick_on % sequence_length) + (offset % sequence_length) - sequence_length); long tick_marker = length_marker_first_tick; while ( tick_marker < tick_off ) { long tick_marker_x = (tick_marker / m_perf_scale_x) - x_offset; if ( tick_marker > tick_on ) { m_gc->set_foreground(m_lt_grey); a_draw->draw_rectangle(m_gc,true, tick_marker_x, y+4, 1, h-8 ); } int lowest_note = seq->get_lowest_note_event( ); int highest_note = seq->get_highest_note_event( ); int height = highest_note - lowest_note; height += 2; int length = seq->get_length( ); long tick_s; long tick_f; int note; bool selected; int velocity; draw_type dt; seq->reset_draw_marker(); m_gc->set_foreground(m_black); while ( (dt = seq->get_next_note_event( &tick_s, &tick_f, ¬e, &selected, &velocity )) != DRAW_FIN ) { int note_y = ((c_names_y-6) - ((c_names_y-6) * (note - lowest_note)) / height) + 1; int tick_s_x = ((tick_s * length_w) / length) + tick_marker_x; int tick_f_x = ((tick_f * length_w) / length) + tick_marker_x; if ( dt == DRAW_NOTE_ON || dt == DRAW_NOTE_OFF ) tick_f_x = tick_s_x + 1; if ( tick_f_x <= tick_s_x ) tick_f_x = tick_s_x + 1; if ( tick_s_x < x ) { tick_s_x = x; } if ( tick_f_x > x + w ) { tick_f_x = x + w; } /* [ ] ----------- --------- ---------------- ------ ------ */ if ( tick_f_x >= x && tick_s_x <= x+w ) m_pixmap->draw_line(m_gc, tick_s_x, y + note_y, tick_f_x, y + note_y ); } tick_marker += sequence_length; } } } } } }
bool GammaPattern::redraw(GdkEventExpose */*bleh*/) { //!Check if the window we want draw is ready Glib::RefPtr<Gdk::Window> window = get_window(); if(!window) return true; static const char hlines[] = { 3, 0 }; Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(window)); int i; Gdk::Color trueblack("#000000"); // 50% Pattern for(i=0;i<4;i++) { gc->set_rgb_fg_color(black[i]); window->draw_rectangle(gc, true, i*tile_w, 0, tile_w, tile_h); gc->set_stipple(Gdk::Bitmap::create(hlines,2,2)); gc->set_fill(Gdk::STIPPLED); gc->set_rgb_fg_color(white[i]); window->draw_rectangle(gc, true, i*tile_w, 0, tile_w, tile_h); gc->set_fill(Gdk::SOLID); gc->set_rgb_fg_color(gray50[i]); window->draw_rectangle(gc, true, i*tile_w+tile_w/4, tile_h/4, tile_w-tile_w/2, tile_h-tile_h/2); } // 25% Pattern for(i=0;i<4;i++) { gc->set_rgb_fg_color(black[i]); window->draw_rectangle(gc, true, i*tile_w, tile_h, tile_w, tile_h); gc->set_stipple(Gdk::Bitmap::create(hlines,2,2)); gc->set_fill(Gdk::STIPPLED); gc->set_rgb_fg_color(gray50[i]); window->draw_rectangle(gc, true, i*tile_w, tile_h, tile_w, tile_h); gc->set_fill(Gdk::SOLID); gc->set_rgb_fg_color(gray25[i]); window->draw_rectangle(gc, true, i*tile_w+tile_w/4, tile_h+tile_h/4, tile_w-tile_w/2, tile_h-tile_h/2); } // Black-level Pattern gc->set_rgb_fg_color(trueblack); window->draw_rectangle(gc, true, 0, tile_h*2, tile_w*4, tile_h); gc->set_fill(Gdk::SOLID); for(i=0;i<4;i++) { gc->set_rgb_fg_color(black[i]); window->draw_rectangle(gc, true, i*tile_w+tile_w/4, tile_h*2+tile_h/4, tile_w-tile_w/2, tile_h-tile_h/2); } return true; }
bool DimRegionChooser::on_expose_event(GdkEventExpose* event) { if (!region) return true; // This is where we draw on the window Glib::RefPtr<Gdk::Window> window = get_window(); Glib::RefPtr<Pango::Context> context = get_pango_context(); Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create(context); window->clear(); // draw labels on the left (reflecting the dimension type) int y = 0; double maxwidth = 0; for (int i = 0 ; i < region->Dimensions ; i++) { int nbZones = region->pDimensionDefinitions[i].zones; if (nbZones) { const char* dstr; char dstrbuf[10]; switch (region->pDimensionDefinitions[i].dimension) { case gig::dimension_none: dstr="none"; break; case gig::dimension_samplechannel: dstr="samplechannel"; break; case gig::dimension_layer: dstr="layer"; break; case gig::dimension_velocity: dstr="velocity"; break; case gig::dimension_channelaftertouch: dstr="channelaftertouch"; break; case gig::dimension_releasetrigger: dstr="releasetrigger"; break; case gig::dimension_keyboard: dstr="keyboard"; break; case gig::dimension_roundrobin: dstr="roundrobin"; break; case gig::dimension_random: dstr="random"; break; case gig::dimension_smartmidi: dstr="smartmidi"; break; case gig::dimension_roundrobinkeyboard: dstr="roundrobinkeyboard"; break; case gig::dimension_modwheel: dstr="modwheel"; break; case gig::dimension_breath: dstr="breath"; break; case gig::dimension_foot: dstr="foot"; break; case gig::dimension_portamentotime: dstr="portamentotime"; break; case gig::dimension_effect1: dstr="effect1"; break; case gig::dimension_effect2: dstr="effect2"; break; case gig::dimension_genpurpose1: dstr="genpurpose1"; break; case gig::dimension_genpurpose2: dstr="genpurpose2"; break; case gig::dimension_genpurpose3: dstr="genpurpose3"; break; case gig::dimension_genpurpose4: dstr="genpurpose4"; break; case gig::dimension_sustainpedal: dstr="sustainpedal"; break; case gig::dimension_portamento: dstr="portamento"; break; case gig::dimension_sostenutopedal: dstr="sostenutopedal"; break; case gig::dimension_softpedal: dstr="softpedal"; break; case gig::dimension_genpurpose5: dstr="genpurpose5"; break; case gig::dimension_genpurpose6: dstr="genpurpose6"; break; case gig::dimension_genpurpose7: dstr="genpurpose7"; break; case gig::dimension_genpurpose8: dstr="genpurpose8"; break; case gig::dimension_effect1depth: dstr="effect1depth"; break; case gig::dimension_effect2depth: dstr="effect2depth"; break; case gig::dimension_effect3depth: dstr="effect3depth"; break; case gig::dimension_effect4depth: dstr="effect4depth"; break; case gig::dimension_effect5depth: dstr="effect5depth"; break; default: sprintf(dstrbuf, "%d", region->pDimensionDefinitions[i].dimension); dstr = dstrbuf; break; } layout->set_text(dstr); Pango::Rectangle rectangle = layout->get_logical_extents(); double text_w = double(rectangle.get_width()) / Pango::SCALE; if (text_w > maxwidth) maxwidth = text_w; double text_h = double(rectangle.get_height()) / Pango::SCALE; Glib::RefPtr<const Gdk::GC> fg = get_style()->get_fg_gc(get_state()); window->draw_layout(fg, 4, int(y + (h - text_h) / 2 + 0.5), layout); } y += h; } // draw dimensions' zones areas y = 0; int bitpos = 0; label_width = int(maxwidth + 10); for (int i = 0 ; i < region->Dimensions ; i++) { int nbZones = region->pDimensionDefinitions[i].zones; if (nbZones) { // draw focus rectangle around dimension's label and zones if (has_focus() && focus_line == i) { Gdk::Rectangle farea(0, y, 150, 20); get_style()->paint_focus(window, get_state(), farea, *this, "", 0, y, label_width, 20); } Glib::RefPtr<const Gdk::GC> black = get_style()->get_black_gc(); // draw top and bottom lines of dimension's zones window->draw_line(black, label_width, y, w - 1, y); window->draw_line(black, w - 1, y + h - 1, label_width, y + h - 1); // erase whole dimension's zones area window->draw_rectangle(get_style()->get_white_gc(), true, label_width + 1, y + 1, (w - label_width - 2), h - 2); int c = 0; if (dimregno >= 0) { int mask = ~(((1 << region->pDimensionDefinitions[i].bits) - 1) << bitpos); c = dimregno & mask; // mask away this dimension } bool customsplits = ((region->pDimensionDefinitions[i].split_type == gig::split_type_normal && region->pDimensionRegions[c]->DimensionUpperLimits[i]) || (region->pDimensionDefinitions[i].dimension == gig::dimension_velocity && region->pDimensionRegions[c]->VelocityUpperLimit)); // draw dimension's zone borders if (customsplits) { window->draw_line(black, label_width, y + 1, label_width, y + h - 2); for (int j = 0 ; j < nbZones ; j++) { gig::DimensionRegion *d = region->pDimensionRegions[c + (j << bitpos)]; int upperLimit = d->DimensionUpperLimits[i]; if (!upperLimit) upperLimit = d->VelocityUpperLimit; int v = upperLimit + 1; int x = int((w - label_width - 1) * v / 128.0 + 0.5); window->draw_line(black, label_width + x, y + 1, label_width + x, y + h - 2); } } else { for (int j = 0 ; j <= nbZones ; j++) { int x = int((w - label_width - 1) * j / double(nbZones) + 0.5); window->draw_line(black, label_width + x, y + 1, label_width + x, y + h - 2); } } // draw fill for currently selected zone if (dimregno >= 0) { gc->set_foreground(red); int dr = (dimregno >> bitpos) & ((1 << region->pDimensionDefinitions[i].bits) - 1); if (customsplits) { int x1 = 0; for (int j = 0 ; j < nbZones ; j++) { gig::DimensionRegion *d = region->pDimensionRegions[c + (j << bitpos)]; int upperLimit = d->DimensionUpperLimits[i]; if (!upperLimit) upperLimit = d->VelocityUpperLimit; int v = upperLimit + 1; int x2 = int((w - label_width - 1) * v / 128.0 + 0.5); if (j == dr && x1 < x2) { window->draw_rectangle(gc, true, label_width + x1 + 1, y + 1, (x2 - x1) - 1, h - 2); break; } x1 = x2; } } else { if (dr < nbZones) { int x1 = int((w - label_width - 1) * dr / double(nbZones) + 0.5); int x2 = int((w - label_width - 1) * (dr + 1) / double(nbZones) + 0.5); window->draw_rectangle(gc, true, label_width + x1 + 1, y + 1, (x2 - x1) - 1, h - 2); } } } y += h; } bitpos += region->pDimensionDefinitions[i].bits; }
/*! \fn Widget_Keyframe_List::redraw() ** \brief Redraw event. Should draw all the keyframes + the selected + the dragged + disabled ** connected on signal_expose_event() */ bool Widget_Keyframe_List::redraw() { //!Check if the window we want draw is ready Glib::RefPtr<Gdk::Window> window = get_window(); if(!window) return true; const int h(get_height()); const int w(get_width()); //!Boundaries of the drawing area in time units. synfig::Time top(adj_timescale->get_upper()); synfig::Time bottom(adj_timescale->get_lower()); //! The graphic context Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(window)); //! A rectangle that defines the drawing area. Gdk::Rectangle area(0,0,w,h); //! draw a background gc->set_rgb_fg_color(Gdk::Color("#9d9d9d")); window->draw_rectangle(gc, true, 0, 0, w, h); if(!editable_) { return true; //needs fixing! } //!Returns if there are not keyframes to draw. if (kf_list_->empty()) return false; //!Loop all the keyframes synfig::KeyframeList::iterator iter,selected_iter; bool show_selected(false); for(iter=kf_list_->begin();iter!=kf_list_->end();iter++) { //!do not draw keyframes out of the widget boundaries if (iter->get_time()>top || iter->get_time()<bottom) continue; //! If the keyframe is not the selected one if(*iter!=selected_kf) { const int x((int)((float)(iter->get_time()-bottom) * (w/(top-bottom)) ) ); // Change shape for disabled keyframe if (iter->active()) get_style()->paint_arrow(window, Gtk::STATE_NORMAL, Gtk::SHADOW_OUT, area, *this, " ", Gtk::ARROW_DOWN, 1, x-h/2+1, 0, h, h ); else get_style()->paint_arrow(window, Gtk::STATE_INSENSITIVE, Gtk::SHADOW_OUT, area, *this, " ", Gtk::ARROW_RIGHT, 1, x-h/2+1, 0, h, h ); } else { selected_iter=iter; show_selected=true; } } // we do this so that we can be sure that // the selected keyframe is shown on top if(show_selected) { // If not dragging just show the selected keyframe if (!dragging_) { int x((int)((float)(selected_iter->get_time()-bottom) * (w/(top-bottom)) ) ); // Change shape for disabled keyframe if (selected_iter->active()) get_style()->paint_arrow(window, Gtk::STATE_NORMAL, Gtk::SHADOW_OUT, area, *this, " ", Gtk::ARROW_DOWN, 1, x-h/2+1, 0, h, h ); else get_style()->paint_arrow(window, Gtk::STATE_NORMAL, Gtk::SHADOW_OUT, area, *this, " ", Gtk::ARROW_RIGHT, 1, x-h/2+1, 0, h, h ); } // If dragging then show the selected as insensitive and the // dragged as selected else { int x((int)((float)(selected_iter->get_time()-bottom) * (w/(top-bottom)) ) ); get_style()->paint_arrow(window, Gtk::STATE_INSENSITIVE, Gtk::SHADOW_OUT, area, *this, " ", Gtk::ARROW_DOWN, 1, x-h/2, 0, h, h ); x=(int)((float)(dragging_kf_time-bottom) * (w/(top-bottom)) ) ; get_style()->paint_arrow(window, Gtk::STATE_SELECTED, Gtk::SHADOW_OUT, area, *this, " ", Gtk::ARROW_DOWN, 1, x-h/2+1, 0, h, h ); } } return true; }
void draw_rectangle (int x, int y, int lx, int ly, bool fill = true) { m_window->draw_rectangle(m_gc, fill, x, y, lx, ly); }