diff options
author | Antony Kellermann | 2018-09-27 13:43:33 -0400 |
---|---|---|
committer | Antony Kellermann | 2018-09-27 13:43:33 -0400 |
commit | 36396f7507f188a8b087718fbee654d66266721b (patch) | |
tree | eb39c4e59252853b9279eb5a092c13371518a1a6 | |
parent | 75fedaba7430389a8491332153123f35c53f39d9 (diff) | |
download | aur-36396f7507f188a8b087718fbee654d66266721b.tar.gz |
Implemented getting info on peers in gtk
-rw-r--r-- | gtk_win.c | 42 | ||||
-rw-r--r-- | gtk_win.h | 3 | ||||
-rw-r--r-- | window_main.glade | 25 |
3 files changed, 46 insertions, 24 deletions
diff --git a/gtk_win.c b/gtk_win.c index b0267222caa9..a948b18da4d1 100644 --- a/gtk_win.c +++ b/gtk_win.c @@ -416,19 +416,26 @@ gboolean on_info_graph_drawing_area_draw(GtkWidget* widget, cairo_t* cr) { if (trading_days - app.focused->num_points > 0) info_chart_fill_empty(app.focused, trading_days); - double max = app.focused->points[0], min = app.focused->points[0]; - for (int i = 1; i < app.focused->num_points; i++) { - if (app.focused->points[i] > max) - max = app.focused->points[i]; - if (app.focused->points[i] < min) - min = app.focused->points[i]; + double max = EMPTY, min = DBL_MAX; + int first_non_empty = EMPTY; + for (int i = 0; i < app.focused->num_points; i++) { + if (app.focused->points[i] != EMPTY) { + if (app.focused->points[i] > max) + max = app.focused->points[i]; + if (app.focused->points[i] < min) + min = app.focused->points[i]; + + if (first_non_empty == EMPTY) + first_non_empty = i; + } } + double line_diff = (max - min) / graph_max_y, day_close; cairo_set_line_width(cr, 1.0); - cairo_move_to(cr, 0.0, 0.0); + cairo_move_to(cr, first_non_empty * (graph_max_x / trading_days), + (app.focused->points[first_non_empty] - min) / line_diff); - double line_diff = (max - min) / graph_max_y, day_close; - for (gdouble i = 0, y; i < graph_max_x; i++) { + for (gdouble i = first_non_empty * (graph_max_x / trading_days), y; i < graph_max_x; i++) { day_close = app.focused->points[(int) ((double) i * app.focused->num_points / graph_max_x)]; y = (day_close - min) / line_diff; cairo_line_to(cr, i, y); @@ -438,12 +445,12 @@ gboolean on_info_graph_drawing_area_draw(GtkWidget* widget, cairo_t* cr) { cairo_set_line_width(cr, 0.3); int square_side_length = 20; - for (gdouble x = 0; x < graph_max_x; x += square_side_length) { + for (gdouble x = 0; x < graph_max_x; x += square_side_length) { // Vertical squares cairo_move_to(cr, x, 0.0); cairo_line_to(cr, x, graph_max_y); } - for (gdouble y = 0; y < graph_max_y; y += square_side_length) { + for (gdouble y = 0; y < graph_max_y; y += square_side_length) { // Horizontal squares cairo_move_to(cr, 0.0, y); cairo_line_to(cr, graph_max_x, y); } @@ -479,6 +486,17 @@ gboolean on_info_graph_drawing_area_draw(GtkWidget* widget, cairo_t* cr) { return FALSE; } +void on_info_peers_tree_view_row_activated(GtkTreeView* tree_view, GtkTreePath* path, + GtkTreeViewColumn* column) { + GtkTreeIter iter; + GtkTreeModel* model = GTK_TREE_MODEL(GET_OBJECT("peers_list")); + gtk_tree_model_get_iter(model, &iter, path); + gchar* symbol; + gtk_tree_model_get(model, &iter, 0, &symbol, -1); + symbol_show_info(symbol); + g_free(symbol); +} + void symbol_show_info(const char* symbol) { Info* pInfo = info_array_find_symbol_recursive(app.portfolio_data, symbol); if (pInfo == NULL) @@ -505,7 +523,7 @@ void symbol_show_info(const char* symbol) { app.focused = pInfo; info_pane_populate_all(pInfo); GtkContainer* window = GTK_CONTAINER(GET_OBJECT("check_window")); - gtk_container_remove(window, GTK_WIDGET(GET_OBJECT("check_pane"))); + gtk_container_remove(window, gtk_bin_get_child(GTK_BIN(window))); // Remove child gtk_container_add(window, GTK_WIDGET(GET_OBJECT("info_pane"))); } diff --git a/gtk_win.h b/gtk_win.h index 92362e375960..50025ed059f1 100644 --- a/gtk_win.h +++ b/gtk_win.h @@ -183,6 +183,9 @@ void on_search_entry_focus_in_event(GtkWidget* search_entry, GdkEvent* event); void on_search_entry_activate(GtkEntry* entry); +void on_info_peers_tree_view_row_activated(GtkTreeView* tree_view, GtkTreePath* path, + GtkTreeViewColumn* column); + void symbol_show_info(const char* symbol); /** UTILS **/ diff --git a/window_main.glade b/window_main.glade index 9f1e17d1d57a..c90817a9e0c2 100644 --- a/window_main.glade +++ b/window_main.glade @@ -62,6 +62,18 @@ https://github.com/aokellermann/ <column type="gchararray"/> </columns> </object> + <object class="GtkListStore" id="peers_list"> + <columns> + <!-- column-name Symbol --> + <column type="gchararray"/> + <!-- column-name 24H% --> + <column type="gchararray"/> + <!-- column-name 7D% --> + <column type="gchararray"/> + <!-- column-name 30D% --> + <column type="gchararray"/> + </columns> + </object> <object class="GtkPaned" id="info_pane"> <property name="visible">True</property> <property name="can_focus">True</property> @@ -798,6 +810,7 @@ https://github.com/aokellermann/ <property name="search_column">0</property> <property name="show_expanders">False</property> <property name="enable_grid_lines">both</property> + <signal name="row-activated" handler="on_info_peers_tree_view_row_activated" swapped="no"/> <child internal-child="selection"> <object class="GtkTreeSelection"/> </child> @@ -948,18 +961,6 @@ https://github.com/aokellermann/ </packing> </child> </object> - <object class="GtkListStore" id="peers_list"> - <columns> - <!-- column-name Symbol --> - <column type="gchararray"/> - <!-- column-name 24H% --> - <column type="gchararray"/> - <!-- column-name 7D% --> - <column type="gchararray"/> - <!-- column-name 30D% --> - <column type="gchararray"/> - </columns> - </object> <object class="GtkListStore" id="search_entry_completion_store"> <columns> <!-- column-name Symbol --> |