⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hxbandwidthgraph.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                    /* This shouldn't happen -- we should be drawing r->l in this                       case, which would make this percentage negative. */                    time_percent_graph = 1.0;                }                y2 = (gint)((1.0 - bandwidth_percent_graph) * height);                if(draw_left_to_right)                {                    x2 = (gint)(time_percent_graph * width);                }                else                {                    /* time_percent_graph is negative */                    x2 = (gint)((1.0 + time_percent_graph) * width);                    if(x2 < 0 && (x1 >= 0 && y1 >= 0 && y2 >= 0))                    {                        /* extrapolate back to 0 */                        gdouble m;                                                m = (y2 - y1) / (x2 - x1);                        x2 = 0;                        y2 = (gint)(y1 - m * x1);                    }                    if(x2 <= 0)                    {                        done = TRUE;                    }                }                                if(x1 >= 0 && y1 >= 0 && x2 >= 0 && y2 >= 0)                {                                        gdk_draw_line (graph->pixmap,                                   graph->gc,                                   x1, y1,                                   x2, y2);                }                x1 = x2;                y1 = y2;                                    if(draw_left_to_right)                {                    iter = g_list_next(iter);                }                else                {                    iter = g_list_previous(iter);                }            }                    /* Step 4: Remove trailing points older than 2 * the size of our graph. */            gdouble delete_cutoff = b->time - 2 * graph_time;                    iter = first;            while(iter)            {                point = (HXBandwidthData*) iter->data;                if(point->time < delete_cutoff)                {                    GList* link = iter;                    iter = g_list_next(iter);                    g_free(point);                    graph->points = g_list_delete_link(graph->points, link);                }                else                {                    iter = g_list_next(iter);                }            }        }    }        /* Invalidate widget */    gtk_widget_queue_draw_area(widget,                               0,                               0,                               widget->allocation.width,                               widget->allocation.height);}static gbooleanhx_bandwidth_graph_expose (GtkWidget*      widget,                           GdkEventExpose* event){    HXBandwidthGraph* graph;        g_return_val_if_fail(widget != NULL, FALSE);     g_return_val_if_fail(HX_IS_BANDWIDTH_GRAPH(widget), FALSE);         graph = HX_BANDWIDTH_GRAPH(widget);         if (GTK_WIDGET_DRAWABLE (widget))    {        if(graph->pixmap)        {                    gdk_draw_drawable(widget->window,                              widget->style->fg_gc[GTK_WIDGET_STATE(widget)],                              graph->pixmap,                                                        event->area.x,                              event->area.y,                              event->area.x,                              event->area.y,                              event->area.width,                              event->area.height);        }    }    return FALSE;}static voidhx_bandwidth_graph_realize (GtkWidget *widget){    HXBandwidthGraph *graph;    GdkWindowAttr attributes;    gint attributes_mask;        g_return_if_fail (widget != NULL);    g_return_if_fail (HX_BANDWIDTH_GRAPH (widget));    GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);    graph = HX_BANDWIDTH_GRAPH (widget);    attributes.x = widget->allocation.x;    attributes.y = widget->allocation.y;    attributes.width = widget->allocation.width;    attributes.height = widget->allocation.height;    attributes.wclass = GDK_INPUT_OUTPUT;    attributes.window_type = GDK_WINDOW_CHILD;    attributes.event_mask = gtk_widget_get_events (widget) |                             GDK_EXPOSURE_MASK;        attributes.visual = gtk_widget_get_visual (widget);    attributes.colormap = gtk_widget_get_colormap (widget);    attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;    widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask);    widget->style = gtk_style_attach (widget->style, widget->window);    gdk_window_set_user_data (widget->window, widget);    gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE);    /* Create the gc */    GdkColormap* colormap;    gboolean result;    GdkGCValues values;    GdkGCValuesMask mask;                        gdk_color_parse ("darkgreen", &graph->grid_color);        gdk_color_parse ("black", &graph->background_color);        gdk_color_parse ("green", &graph->line_color);        colormap = gtk_widget_get_colormap(widget);    result = gdk_colormap_alloc_color(colormap,                                      &graph->grid_color,                                      FALSE,                                      TRUE);                g_return_if_fail (result);    result = gdk_colormap_alloc_color(colormap,                                      &graph->background_color,                                      FALSE,                                      TRUE);                g_return_if_fail (result);    result = gdk_colormap_alloc_color(colormap,                                      &graph->line_color,                                      FALSE,                                      TRUE);                g_return_if_fail (result);    values.function = GDK_COPY;    values.line_width = 1;    values.join_style = GDK_JOIN_ROUND;    values.cap_style = GDK_CAP_ROUND;    mask = (GdkGCValuesMask)(GDK_GC_FUNCTION |                             GDK_GC_LINE_WIDTH |                             GDK_GC_CAP_STYLE |                             GDK_GC_JOIN_STYLE);        graph->gc = gdk_gc_new_with_values(widget->window, &values, mask);                    hx_bandwidth_graph_draw(graph);}static voidhx_bandwidth_graph_unrealize (GtkWidget *widget){    HXBandwidthGraph *graph;    g_return_if_fail (widget != NULL);    g_return_if_fail (HX_BANDWIDTH_GRAPH (widget));    graph = HX_BANDWIDTH_GRAPH (widget);    if(graph->gc)    {        g_object_unref(graph->gc);        graph->gc = NULL;    }    if (GTK_WIDGET_CLASS (parent_class)->unrealize)    {        (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);    }}static voidhx_bandwidth_graph_size_allocate (GtkWidget*     widget,                                  GtkAllocation* allocation){    HXBandwidthGraph* graph;        g_return_if_fail (widget != NULL);    g_return_if_fail (HX_IS_BANDWIDTH_GRAPH (widget));    g_return_if_fail (allocation != NULL);    graph = HX_BANDWIDTH_GRAPH(widget);        widget->allocation = *allocation;    if (GTK_WIDGET_REALIZED (widget))    {        if(graph->pixmap)        {            g_object_unref(graph->pixmap);            graph->pixmap = NULL;        }                gdk_window_move_resize (widget->window,                                allocation->x, allocation->y,                                allocation->width, allocation->height);        hx_bandwidth_graph_draw(graph);    }}static void hx_bandwidth_graph_size_request (GtkWidget*      /* widget */,                                 GtkRequisition* requisition){    requisition->width = 1;    requisition->height = 1;}voidhx_bandwidth_graph_add_value(HXBandwidthGraph* graph,                             guint             bandwidth){    HXBandwidthData* point;    GTimeVal time_val;        g_return_if_fail(graph != NULL);    point = g_new0(HXBandwidthData, 1);    g_get_current_time(&time_val);    if(graph->ideal_bandwidth)    {        point->percent = (gdouble)bandwidth / (gdouble)graph->ideal_bandwidth;    }    else    {        point->percent = 0;    }    point->time = (gdouble)time_val.tv_sec + (gdouble)time_val.tv_sec / 1e6;    graph->points = g_list_append(graph->points, point);}voidhx_bandwidth_graph_update(HXBandwidthGraph* graph){    GList* item;        g_return_if_fail(graph != NULL);        item = g_list_last(graph->points);    if(item)    {        HXBandwidthData* point;                point = (HXBandwidthData*)item->data;        graph->cutoff_time = point->time;        hx_bandwidth_graph_draw(graph);    }}voidhx_bandwidth_graph_set_ideal_bandwidth(HXBandwidthGraph* graph,                                       guint             bandwidth){    g_return_if_fail(graph != NULL);    graph->ideal_bandwidth = bandwidth;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -