void calculateDotterExonViewHeight(GtkWidget *exonView) { ExonViewProperties *properties = exonViewGetProperties(exonView); DotterContext *dc = properties->dc; /* Calculate the height based on how many exon lines will actually be drawn */ int numExons = 0; int maxExons = properties->bumped ? UNSET_INT : 1; /* unset means no limit */ /* Loop through all sequences */ GList *seqItem = dc->seqList; for ( ; seqItem; seqItem = seqItem->next) { /* Loop through all msps */ const BlxSequence *seq = (BlxSequence*)(seqItem->data); GList *mspItem = seq->mspList; for ( ; mspItem; mspItem = mspItem->next) { const MSP *msp = (const MSP*)(mspItem->data); if ((mspIsExon(msp) || mspIsIntron(msp)) && mspGetRefStrand(msp) == properties->strand && rangesOverlap(&msp->qRange, properties->qRange)) { ++numExons; break; /* break inner loop and move to next sequence */ } } /* Break after we've found the maximum number of lines, if a max is specified */ if (maxExons != UNSET_INT && numExons >= maxExons) { break; } } if (properties->horizontal) { properties->exonViewRect.height = (numExons * (properties->exonHeight + 2 * properties->yPad)) + (2 * properties->yPad); gtk_widget_set_size_request(exonView, -1, properties->exonViewRect.height); gtk_layout_set_size(GTK_LAYOUT(exonView), exonView->allocation.width, properties->exonViewRect.height); } else { properties->exonViewRect.width = (numExons * (properties->exonHeight + 2 * properties->yPad)) + (2 * properties->yPad); gtk_widget_set_size_request(exonView, properties->exonViewRect.width, -1); gtk_layout_set_size(GTK_LAYOUT(exonView), properties->exonViewRect.width, exonView->allocation.height); } }
/* Handle a size allocation by re-laying-out each paragraph to * the new width, setting the new size for the layout and * then queing a redraw */ void size_allocate (GtkWidget *layout, GtkAllocation *allocation) { GList *tmp_list; guint height = 0; PangoDirection base_dir = pango_context_get_base_dir (context); tmp_list = paragraphs; while (tmp_list) { Paragraph *para = tmp_list->data; PangoRectangle logical_rect; tmp_list = tmp_list->next; pango_layout_set_alignment (para->layout, base_dir == PANGO_DIRECTION_LTR ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT); pango_layout_set_width (para->layout, layout->allocation.width * PANGO_SCALE); pango_layout_get_extents (para->layout, NULL, &logical_rect); para->height = PANGO_PIXELS (logical_rect.height); height += para->height; } gtk_layout_set_size (GTK_LAYOUT (layout), allocation->width, height); if (GTK_LAYOUT (layout)->yoffset + allocation->height > height) gtk_adjustment_set_value (GTK_LAYOUT (layout)->vadjustment, (float)(height - allocation->height)); }
int main(int argc, char *argv[]) { gtk_init(&argc, &argv); GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL); GtkWidget *table = gtk_table_new(2, 2, FALSE); gtk_container_add(GTK_CONTAINER(window), table); GtkWidget *layout = gtk_layout_new(NULL, NULL); gtk_layout_set_size(GTK_LAYOUT(layout), 2000, 800); gtk_table_attach(GTK_TABLE(table), layout, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); GtkAdjustment *vadjustment = gtk_layout_get_vadjustment(GTK_LAYOUT(layout)); GtkAdjustment *hadjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(layout)); GtkWidget *vscrollbar = gtk_vscrollbar_new(vadjustment); gtk_table_attach(GTK_TABLE(table), vscrollbar, 1, 2, 0, 1, GTK_SHRINK, GTK_FILL | GTK_EXPAND, 0, 0); GtkWidget *hscrollbar = gtk_hscrollbar_new(hadjustment); gtk_table_attach(GTK_TABLE(table), hscrollbar, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0); gtk_widget_show_all(window); gtk_main(); return 0; }
/* Create the rectangle area that displays the gradient */ static GtkWidget* createGradientRect(GtkWidget *greyramp, GdkRectangle *rect) { /* Put it in a frame with a border */ GtkWidget *frame = gtk_frame_new(NULL); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN); gtk_container_set_border_width(GTK_CONTAINER(frame), GRADIENT_RECT_FRAME_PADDING); /* Get the total size of the gradient area, including markers and padding */ const int totalWidth = GRADIENT_RECT_WIDTH + (2 * GRADIENT_RECT_X_PADDING) ; const int totalHeight = GRADIENT_RECT_HEIGHT + (2 * (GRADIENT_RECT_MARKER_HEIGHT + GRADIENT_RECT_Y_PADDING)); /* We'll draw the gradient and the child markers onto a layout */ GtkWidget *layout = gtk_layout_new(NULL, NULL); gtk_layout_set_size(GTK_LAYOUT(layout), totalWidth, totalHeight); gtk_widget_set_size_request(layout, totalWidth, totalHeight); gtk_container_add(GTK_CONTAINER(frame), layout); gtk_widget_add_events(layout, GDK_BUTTON_PRESS_MASK); gtk_widget_add_events(layout, GDK_BUTTON_RELEASE_MASK); gtk_widget_add_events(layout, GDK_POINTER_MOTION_MASK); g_signal_connect(G_OBJECT(layout), "expose-event", G_CALLBACK(onExposeGradient), greyramp); g_signal_connect(G_OBJECT(layout), "button-press-event", G_CALLBACK(onButtonPressGradient), greyramp); g_signal_connect(G_OBJECT(layout), "button-release-event", G_CALLBACK(onButtonReleaseGradient), greyramp); g_signal_connect(G_OBJECT(layout), "motion-notify-event", G_CALLBACK(onMouseMoveGradient), greyramp); /* Set the size of the gradient rectangle to be drawn */ rect->x = GRADIENT_RECT_X_PADDING; rect->y = GRADIENT_RECT_MARKER_HEIGHT + GRADIENT_RECT_Y_PADDING; rect->width = GRADIENT_RECT_WIDTH; rect->height = GRADIENT_RECT_HEIGHT; return frame; }
void tbo_drawing_adjust_scroll (TboDrawing *self) { if (!self->comic) return; gtk_layout_set_size (GTK_LAYOUT (self), self->comic->width*self->zoom, self->comic->height*self->zoom); tbo_drawing_update (self); }
static void gui_window_update_extent(struct gui_window *g) { int w, h; if (browser_window_get_extents(g->bw, true, &w, &h) == NSERROR_OK) { gtk_layout_set_size(g->layout, w, h); } }
void gui_window_update_extent(struct gui_window *g) { if (!g->bw->current_content) return; gtk_layout_set_size(g->layout, content_get_width(g->bw->current_content) * g->bw->scale, content_get_height(g->bw->current_content) * g->bw->scale); }
GtkWidget * tbo_drawing_new_with_params (Comic *comic) { GtkWidget *drawing = tbo_drawing_new (); TBO_DRAWING (drawing)->comic = comic; gtk_layout_set_size (GTK_LAYOUT (drawing), comic->width+2, comic->height+2); return drawing; }
void preview_set_size(signal_user_data_t *ud, int width, int height) { GtkWidget *widget; widget = GHB_WIDGET (ud->builder, "preview_image"); gtk_widget_set_size_request(widget, width, height); gtk_layout_set_size(GTK_LAYOUT(widget), width, height); widget = GHB_WIDGET (ud->builder, "preview_hud_box"); gtk_widget_set_size_request(widget, width, height); ud->preview->width = width; ud->preview->height = height; }
int clip_GTK_LAYOUTSETSIZE(ClipMachine * cm) { C_widget *clay = _fetch_cw_arg(cm); guint width = _clip_parni(cm, 2); guint height = _clip_parni(cm, 3); CHECKCWID(clay,GTK_IS_LAYOUT); CHECKOPT(2,NUMERIC_t); CHECKOPT(3, NUMERIC_t); gtk_layout_set_size(GTK_LAYOUT(clay->widget), width, height); return 0; err: return 1; }
static void update_layout_size (SoliPrintPreview *preview) { gint tile_width; gint tile_height; get_tile_size (preview, &tile_width, &tile_height); /* force size of the drawing area to make the scrolled window work */ gtk_layout_set_size (preview->layout, tile_width * preview->n_columns, tile_height); gtk_widget_queue_draw (GTK_WIDGET (preview->layout)); }
void gnc_header_reconfigure (GncHeader *header) { GnucashSheet *sheet; SheetBlockStyle *old_style; int w, h; g_return_if_fail (header != NULL); g_return_if_fail (GNC_IS_HEADER (header)); sheet = GNUCASH_SHEET(header->sheet); old_style = header->style; header->style = gnucash_sheet_get_style_from_cursor (sheet, header->cursor_name); if (header->style == NULL) return; sheet->width = header->style->dimensions->width; w = header->style->dimensions->width; h = header->style->dimensions->height; h *= header->num_phys_rows; h /= header->style->nrows; h += 2; if (header->height != h || header->width != w || header->style != old_style) { header->height = h; header->width = w; gtk_layout_set_size(GTK_LAYOUT(header), w, h); gtk_widget_set_size_request(GTK_WIDGET(header), -1, h); gnc_header_request_redraw (header); } }
static void icon_scroll_size_allocate_cb(GtkWidget *widget, GtkAllocation *size, MimeView *mimeview) { GtkAllocation *mainbox_size; GtkAllocation *vbox_size; GtkAllocation *layout_size; GtkAdjustment *adj; adj = gtk_layout_get_vadjustment(GTK_LAYOUT(mimeview->icon_scroll)); mainbox_size = &mimeview->icon_mainbox->allocation; vbox_size = &mimeview->icon_vbox->allocation; layout_size = &mimeview->icon_scroll->allocation; /* centralise the vbox */ gtk_layout_move(GTK_LAYOUT(mimeview->icon_scroll), mimeview->icon_vbox, (mainbox_size->width - vbox_size->width)/2, 0); gtk_layout_set_size(GTK_LAYOUT(mimeview->icon_scroll), GTK_LAYOUT(mimeview->icon_scroll)->width, MAX(vbox_size->height, layout_size->height)); adj->step_increment = 5; }
void calculateDotterExonViewBorders(GtkWidget *exonView, const int width, const int height) { DEBUG_ENTER("calculateDotterExonViewBorders(width=%d, height=%d)", width, height); ExonViewProperties *properties = exonViewGetProperties(exonView); /* Calculate the area where the exon view will be drawn */ if (properties->horizontal) { properties->exonViewRect.x = properties->dc->scaleWidth + properties->dc->charHeight; /* use same left border as dotplot */ properties->exonViewRect.y = 0; properties->exonViewRect.width = width; properties->exonViewRect.height = properties->exonHeight + (2 * properties->yPad); } else { properties->exonViewRect.x = 0; properties->exonViewRect.y = properties->dc->scaleHeight + properties->dc->charHeight; /* use same top border as dotplot */ properties->exonViewRect.width = properties->exonHeight + (2 * properties->yPad); properties->exonViewRect.height = height; } gtk_layout_set_size(GTK_LAYOUT(exonView), properties->exonViewRect.x + properties->exonViewRect.width, properties->exonViewRect.y + properties->exonViewRect.height); gtk_widget_set_size_request(exonView, properties->exonViewRect.x + properties->exonViewRect.width, properties->exonViewRect.y + properties->exonViewRect.height); /* If the display is bumped, we need to do more work to determine the height * because it depends on the number of exons that are visible */ if (properties->bumped) calculateDotterExonViewHeight(exonView); widgetClearCachedDrawable(exonView, NULL); gtk_widget_queue_draw(exonView); DEBUG_OUT("seq horizontal=%d, x=%d, y=%d, w=%d, h=%d\n", properties->horizontal, properties->exonViewRect.x, properties->exonViewRect.y, properties->exonViewRect.width, properties->exonViewRect.height); DEBUG_EXIT("calculateDotterExonViewBorders returning "); }
static void app_resizer_size_allocate (GtkWidget * widget, GtkAllocation * allocation) { /* printf("ENTER - app_resizer_size_allocate\n"); */ AppResizer *resizer = APP_RESIZER (widget); GtkWidget *child = GTK_WIDGET (APP_RESIZER (resizer)->child); GtkAllocation widget_allocation; GtkRequisition child_requisition; static gboolean first_time = TRUE; gint new_num_cols; gint useable_area; gtk_widget_get_allocation (child, &widget_allocation); if (first_time) { /* we are letting the first show be the "natural" size of the child widget so do nothing. */ if (GTK_WIDGET_CLASS (app_resizer_parent_class)->size_allocate) (*GTK_WIDGET_CLASS (app_resizer_parent_class)->size_allocate) (widget, allocation); first_time = FALSE; gtk_layout_set_size (GTK_LAYOUT (resizer), widget_allocation.width, widget_allocation.height); return; } #if GTK_CHECK_VERSION (3, 0, 0) gtk_widget_get_preferred_size (child, &child_requisition, NULL); #else child_requisition = child->requisition; #endif if (!resizer->cached_tables_list) /* if everthing is currently filtered out - just return */ { GtkAllocation child_allocation; if (GTK_WIDGET_CLASS (app_resizer_parent_class)->size_allocate) (*GTK_WIDGET_CLASS (app_resizer_parent_class)->size_allocate) (widget, allocation); /* We want the message to center itself and only scroll if it's bigger than the available real size. */ child_allocation.x = 0; child_allocation.y = 0; child_allocation.width = MAX (allocation->width, child_requisition.width); child_allocation.height = MAX (allocation->height, child_requisition.height); gtk_widget_size_allocate (child, &child_allocation); gtk_layout_set_size (GTK_LAYOUT (resizer), child_allocation.width, child_allocation.height); return; } GtkRequisition other_requisiton; #if GTK_CHECK_VERSION (3, 0, 0) gtk_widget_get_preferred_size (GTK_WIDGET (resizer->cached_tables_list->data), &other_requisiton, NULL); #else other_requisiton = GTK_WIDGET (resizer->cached_tables_list->data)->requisition; #endif useable_area = allocation->width - (child_requisition.width - other_requisiton.width); new_num_cols = relayout_tables_if_needed (APP_RESIZER (resizer), useable_area, resizer->cur_num_cols); if (resizer->cur_num_cols != new_num_cols) { GtkRequisition req; /* Have to do this so that it requests, and thus gets allocated, new amount */ gtk_widget_size_request (child, &req); resizer->cur_num_cols = new_num_cols; } if (GTK_WIDGET_CLASS (app_resizer_parent_class)->size_allocate) (*GTK_WIDGET_CLASS (app_resizer_parent_class)->size_allocate) (widget, allocation); gtk_layout_set_size (GTK_LAYOUT (resizer), widget_allocation.width, widget_allocation.height); }
static void create_layout (GtkWidget *vbox) { GtkAdjustment *hadjustment, *vadjustment; GtkLayout *layout; GtkWidget *layout_widget; GtkWidget *scrolledwindow; GtkWidget *button; gchar buf[16]; gint i, j; scrolledwindow = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_SHADOW_IN); gtk_scrolled_window_set_placement (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_CORNER_TOP_RIGHT); gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0); layout_widget = gtk_layout_new (NULL, NULL); layout = GTK_LAYOUT (layout_widget); gtk_container_add (GTK_CONTAINER (scrolledwindow), layout_widget); /* We set step sizes here since GtkLayout does not set * them itself. */ hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (layout)); vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (layout)); gtk_adjustment_set_step_increment (hadjustment, 10.0); gtk_adjustment_set_step_increment (vadjustment, 10.0); gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (layout), hadjustment); gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (layout), vadjustment); gtk_widget_set_events (layout_widget, GDK_EXPOSURE_MASK); g_signal_connect (layout, "draw", G_CALLBACK (layout_draw_handler), NULL); gtk_layout_set_size (layout, 1600, 128000); for (i = 0 ; i < 16 ; i++) for (j = 0 ; j < 16 ; j++) { g_snprintf (buf, sizeof (buf), "Button %d, %d", i, j); if ((i + j) % 2) button = gtk_button_new_with_label (buf); else button = gtk_label_new (buf); gtk_layout_put (layout, button, j * 100, i * 100); } for (i = 16; i < 1280; i++) { g_snprintf (buf, sizeof (buf), "Button %d, %d", i, 0); if (i % 2) button = gtk_button_new_with_label (buf); else button = gtk_label_new (buf); gtk_layout_put (layout, button, 0, i * 100); } layout_timeout = g_timeout_add (1000, scroll_layout, layout); }
int main (int argc, char *argv[]) { r.x=0; r.y=0; r.width=510; r.height = 400; // ************************** Thread scheduling **************************88 // Use round-robin scheduling on a low latency linux kernel. // Set application's threads to priority 50. // Set data collection thread to priority 99 // Looks solid on Netbook pthread_attr_init(&tattr); pthread_attr_setschedpolicy(&tattr,SCHED_FIFO); pMyHound = new CMySignalHound(); if(pMyHound->Initialize()) return -5; double myTemp = pMyHound->ReadTemperature(); sprintf(debugstr,"Temp %.2f",myTemp); pMyHound->SetupForSweep(); //Set up for initial sweep pthread_create(&sweepThread, &tattr,ThreadFunc,NULL); //Begin initial sweep /* Initialize GTK+ */ g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL); gtk_init (&argc, &argv); g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL); /* Create the main window */ win = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_container_set_border_width (GTK_CONTAINER (win), 8); gtk_window_set_title (GTK_WINDOW (win), "Signal Hound"); gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER); gtk_widget_realize (win); g_signal_connect (win, "destroy", gtk_main_quit, NULL); /* Create a layout box with buttons */ layout = (GtkLayout *) gtk_layout_new (NULL,NULL); gtk_layout_set_size(layout,640,410); gtk_container_add (GTK_CONTAINER (win), (GtkWidget *) layout); graticule = (GtkDrawingArea *) gtk_drawing_area_new(); gtk_widget_set_size_request((GtkWidget *)graticule,510,400); gtk_layout_put ( layout, (GtkWidget *)graticule, 2, 2); gtk_signal_connect (GTK_OBJECT (graticule), "expose_event", (GtkSignalFunc) expose_event, NULL); gtk_signal_connect (GTK_OBJECT(graticule),"configure_event", (GtkSignalFunc) configure_event, NULL); gtk_widget_set_events ((GtkWidget *)graticule, GDK_EXPOSURE_MASK); gtk_widget_set_size_request(win,640,410); button = gtk_button_new_with_label("FREQ+"); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (freqplus), (gpointer) win); gtk_layout_put ( layout, button, 520, 10); button = gtk_button_new_with_label("FREQ-"); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (freqminus), (gpointer) win); gtk_layout_put ( layout, button, 572, 10); button = gtk_button_new_with_label("SPAN+"); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (spanplus), (gpointer) win); gtk_layout_put ( layout, button, 520, 110); button = gtk_button_new_with_label("SPAN-"); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (spanminus), (gpointer) win); gtk_layout_put ( layout, button, 572, 110); button = gtk_button_new_with_label("REF+"); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (refplus), (gpointer) win); gtk_layout_put ( layout, button, 520, 210); button = gtk_button_new_with_label("REF-"); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (refminus), (gpointer) win); gtk_layout_put ( layout, button, 572, 210); fbuf = gtk_text_buffer_new(NULL); rbuf = gtk_text_buffer_new(NULL); sbuf = gtk_text_buffer_new(NULL); bbuf = gtk_text_buffer_new(NULL); dbuf = gtk_text_buffer_new(NULL); textfreq = gtk_text_view_new(); textspan = gtk_text_view_new(); textreflvl = gtk_text_view_new(); textRBW = gtk_text_view_new(); textdebug = gtk_text_view_new(); UpdateStrings(); gtk_text_view_set_buffer((GtkTextView *)textfreq,fbuf); gtk_text_view_set_buffer((GtkTextView *)textspan,sbuf); gtk_text_view_set_buffer((GtkTextView *)textreflvl,rbuf); gtk_text_view_set_buffer((GtkTextView *)textRBW,bbuf); gtk_text_view_set_buffer((GtkTextView *)textdebug,dbuf); gtk_layout_put ( layout, textfreq, 520, 60); gtk_layout_put ( layout, textspan, 520, 160); gtk_layout_put ( layout, textreflvl, 520, 260); gtk_layout_put ( layout, textRBW, 520, 310); gtk_layout_put ( layout, textdebug, 520, 360); // pMyHound->m_settings.m_suppressImage = false; // if you want image rejection off... g_timeout_add(25,(GSourceFunc) TimerFunc,NULL); /* Enter the main loop */ gtk_widget_show_all (win); gtk_main (); delete pMyHound; return 0; }
void refreshConnectDialog() { /* Create the GtkTable */ static GtkWidget *rootTable = NULL; if(rootTable != NULL) { gtk_widget_destroy(rootTable); } rootTable = gtk_table_new( g_robotManager->numEntries()*3, 10, FALSE); /* For each Mobot entry, we need to compose a set of child widgets and attach * them to the right places on the grid */ int32_t i; // i is passed to signal handlers, so may be at most 32 bits GtkWidget *w; for(i = 0; i < g_robotManager->numEntries(); i++) { /* Make a new label for the entry */ w = gtk_label_new(g_robotManager->getEntry(i)); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 0, 1, //columns i*3, (i*3)+2, //rows GTK_FILL, GTK_FILL, 2, 2); /* Add connect/connecting/disconnect button */ recordMobot_t* mobot; if(mobot = g_robotManager->getMobotIndex(i)) { switch(mobot->connectStatus) { case RMOBOT_NOT_CONNECTED: w = gtk_button_new_with_label("Connect"); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 2, 3, i*3, (i*3)+2, GTK_FILL, GTK_FILL, 2, 2); /* Attach the connect/disconnect button signal handler */ g_signal_connect(G_OBJECT(w), "clicked", G_CALLBACK(on_button_Connect_clicked), GINT_TO_POINTER(i)); /* Add an image denoting connection status for each one */ w = gtk_image_new_from_stock(GTK_STOCK_NO, GTK_ICON_SIZE_BUTTON); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 1, 2, i*3, (i*3)+2, GTK_FILL, GTK_FILL, 2, 2); break; case RMOBOT_CONNECTING: w = gtk_button_new_with_label("Connecting..."); gtk_widget_show(w); gtk_widget_set_sensitive(w, FALSE); gtk_table_attach( GTK_TABLE(rootTable), w, 2, 3, i*3, (i*3)+2, GTK_FILL, GTK_FILL, 2, 2); /* Add an image denoting connection status for each one */ w = gtk_image_new_from_stock(GTK_STOCK_NO, GTK_ICON_SIZE_BUTTON); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 1, 2, i*3, (i*3)+2, GTK_FILL, GTK_FILL, 2, 2); break; case RMOBOT_CONNECTED: w = gtk_button_new_with_label("Disconnect"); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 2, 3, i*3, (i*3)+2, GTK_FILL, GTK_FILL, 2, 2); /* Attach the connect/disconnect button signal handler */ g_signal_connect(G_OBJECT(w), "clicked", G_CALLBACK(on_button_Disconnect_clicked), GINT_TO_POINTER(i)); /* Add an image denoting connection status for each one */ w = gtk_image_new_from_stock(GTK_STOCK_YES, GTK_ICON_SIZE_BUTTON); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 1, 2, i*3, (i*3)+2, GTK_FILL, GTK_FILL, 2, 2); break; default: w = gtk_button_new_with_label("Meh?"); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 2, 3, i*3, (i*3)+2, GTK_FILL, GTK_FILL, 2, 2); break; } } else { w = gtk_button_new_with_label("Connect"); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 2, 3, i*3, (i*3)+2, GTK_FILL, GTK_FILL, 2, 2); /* Attach the connect/disconnect button signal handler */ g_signal_connect(G_OBJECT(w), "clicked", G_CALLBACK(on_button_Connect_clicked), GINT_TO_POINTER(i)); /* Add an image denoting connection status for each one */ w = gtk_image_new_from_stock(GTK_STOCK_NO, GTK_ICON_SIZE_BUTTON); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 1, 2, i*3, (i*3)+2, GTK_FILL, GTK_FILL, 2, 2); } /* Add remove button */ w = gtk_button_new_with_label("Remove"); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 3, 4, i*3, (i*3)+2, GTK_FILL, GTK_FILL, 2, 2); g_signal_connect(G_OBJECT(w), "clicked", G_CALLBACK(on_button_Remove_clicked), GINT_TO_POINTER(i)); /* Add move-up button */ w = gtk_button_new_from_stock(GTK_STOCK_GO_UP); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 4, 5, i*3, (i*3)+1, GTK_FILL, GTK_FILL, 2, 2); g_signal_connect(G_OBJECT(w), "clicked", G_CALLBACK(on_button_MoveUp_clicked), GINT_TO_POINTER(i)); /* Add move-down button */ w = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 4, 5, (i*3)+1, (i*3)+2, GTK_FILL, GTK_FILL, 2, 2); g_signal_connect(G_OBJECT(w), "clicked", G_CALLBACK(on_button_MoveDown_clicked), GINT_TO_POINTER(i)); /* Maybe add a color and beep buttons */ int form; if( (g_robotManager->getMobotIndex(i) != NULL ) && (g_robotManager->getMobotIndex(i)->connectStatus == RMOBOT_CONNECTED) ) { if(!Mobot_getFormFactor((mobot_t*)g_robotManager->getMobotIndex(i), &form)) { if( (form == MOBOTFORM_I) || (form == MOBOTFORM_L) || (form == MOBOTFORM_T) ) { int r, g, b; int _r, _g, _b; char buf[16]; if(g_robotManager->getMobotIndex(i)->dirty) { if(!Mobot_getColorRGB((mobot_t*)g_robotManager->getMobotIndex(i), &r, &g, &b)) { g_robotManager->getMobotIndex(i)->rgb[0] = r; g_robotManager->getMobotIndex(i)->rgb[1] = g; g_robotManager->getMobotIndex(i)->rgb[2] = b; sprintf(buf, "#%02X%02X%02X", r, g, b); GdkColor color; gdk_color_parse(buf, &color); w = gtk_color_button_new_with_color(&color); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 5, 6, i*3, (i*3)+2, GTK_FILL, GTK_FILL, 2, 2); g_signal_connect( G_OBJECT(w), "color-set", G_CALLBACK(on_colorDialog_color_set), (void*)g_robotManager->getMobotIndex(i) ); } } else { sprintf(buf, "#%02X%02X%02X", g_robotManager->getMobotIndex(i)->rgb[0], g_robotManager->getMobotIndex(i)->rgb[1], g_robotManager->getMobotIndex(i)->rgb[2]); GdkColor color; gdk_color_parse(buf, &color); w = gtk_color_button_new_with_color(&color); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 5, 6, i*3, (i*3)+2, GTK_FILL, GTK_FILL, 2, 2); g_signal_connect( G_OBJECT(w), "color-set", G_CALLBACK(on_colorDialog_color_set), (void*)g_robotManager->getMobotIndex(i) ); } w = gtk_button_new_with_label("Beep!"); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 6, 7, i*3, (i*3)+2, GTK_FILL, GTK_FILL, 2, 2); g_signal_connect( G_OBJECT(w), "pressed", G_CALLBACK(on_beep_button_pressed), (void*)g_robotManager->getMobotIndex(i) ); g_signal_connect( G_OBJECT(w), "released", G_CALLBACK(on_beep_button_released), (void*)g_robotManager->getMobotIndex(i) ); } } } /* Maybe add an "Upgrade Firmware" button */ if( (g_robotManager->getMobotIndex(i) != NULL) && (g_robotManager->getMobotIndex(i)->connectStatus == RMOBOT_CONNECTED) && (g_robotManager->getMobotIndex(i)->firmwareVersion < Mobot_protocolVersion()) ) { int form=0; Mobot_getFormFactor((mobot_t*)g_robotManager->getMobotIndex(i), &form); GdkColor color; gdk_color_parse("yellow", &color); w = gtk_button_new_with_label("Upgrade\nFirmware"); gtk_widget_modify_bg(w, GTK_STATE_NORMAL, &color); gdk_color_parse("#FFFF22", &color); gtk_widget_modify_bg(w, GTK_STATE_PRELIGHT, &color); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 7, 8, i*3, (i*3)+2, GTK_FILL, GTK_FILL, 2, 2); g_signal_connect(G_OBJECT(w), "clicked", G_CALLBACK(on_button_updateFirmware_clicked), GINT_TO_POINTER(i)); } /* Add an "Info" button */ if( (g_robotManager->getMobotIndex(i) != NULL) && (g_robotManager->getMobotIndex(i)->connectStatus == RMOBOT_CONNECTED) ) { w = gtk_button_new_with_label("Info"); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 8, 9, i*3, (i*3)+2, GTK_FILL, GTK_FILL, 2, 2); g_signal_connect(G_OBJECT(w), "clicked", G_CALLBACK(on_button_robotInfo_clicked), GINT_TO_POINTER(i)); } /* Add a horizontal separator */ w = gtk_hseparator_new(); gtk_widget_show(w); gtk_table_attach( GTK_TABLE(rootTable), w, 0, 9, i*3+2, (i*3)+3, GTK_FILL, GTK_FILL, 2, 2); } GtkRequisition sizeRequest; gtk_widget_size_request(rootTable, &sizeRequest); GtkWidget *layout = GTK_WIDGET(gtk_builder_get_object(g_builder, "layout_connectDialog")); gtk_layout_set_size(GTK_LAYOUT(layout), sizeRequest.width, sizeRequest.height); gtk_layout_put(GTK_LAYOUT(layout), rootTable, 0, 0); gtk_widget_show(rootTable); /* Refresh the list stores, etc. */ static GtkListStore* liststore_available = GTK_LIST_STORE( gtk_builder_get_object(g_builder, "liststore_availableRobots")); static GtkListStore* liststore_connected = GTK_LIST_STORE( gtk_builder_get_object(g_builder, "liststore_connectedRobots")); g_dndConnect = false; /* Clear the widgets */ gtk_list_store_clear(liststore_available); gtk_list_store_clear(liststore_connected); /* Populate the widgets */ GtkTreeIter iter; GtkTreeIter connectedIter; for(i = 0; i < g_robotManager->numEntries(); i++) { gtk_list_store_append(liststore_available, &iter); if( (g_robotManager->getMobotIndex(i) != NULL) && (g_robotManager->getMobotIndex(i)->connectStatus == RMOBOT_CONNECTED) ) { /* Add it to the liststore of connected bots */ gtk_list_store_append(liststore_connected, &connectedIter); gtk_list_store_set(liststore_connected, &connectedIter, 0, g_robotManager->getEntry(i), -1); /* Set the blinky light icon to green */ gtk_list_store_set(liststore_available, &iter, 0, g_robotManager->getEntry(i), 1, GTK_STOCK_YES, -1 ); /* Set the update progress bar data */ //printf("%d:%d\n", g_robotManager->getMobotIndex(i)->firmwareVersion, Mobot_protocolVersion()); if(g_robotManager->getMobotIndex(i)->firmwareVersion < Mobot_protocolVersion()) { gtk_list_store_set(liststore_available, &iter, 2, TRUE, 3, 0, -1); } else { gtk_list_store_set(liststore_available, &iter, 2, FALSE, 3, 0, -1); } } else { gtk_list_store_set(liststore_available, &iter, 0, g_robotManager->getEntry(i), 1, GTK_STOCK_DISCONNECT, -1 ); } } /* If there is only one entry, set that entry as active in the "Control * Robot" dialog. */ /* if(g_robotManager->numConnected() == 1) { GtkWidget *w; w = GTK_WIDGET(gtk_builder_get_object(g_builder, "combobox_connectedRobots")); gtk_combo_box_set_active(GTK_COMBO_BOX(w), 0); } */ g_dndConnect = true; }
int main(int argc, char *argv[]){ GtkWidget *window1; GtkWidget *vbox1; GtkWidget *scrollw1; GtkWidget *active_plot; GdkColor color; gint page_width, page_height; gfloat scale = 1.; page_width = GTK_PLOT_LETTER_W * scale; page_height = GTK_PLOT_LETTER_H * scale; gtk_init(&argc,&argv); window1=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window1), "GtkPlot Real Time Demo"); gtk_widget_set_usize(window1,550,600); gtk_container_border_width(GTK_CONTAINER(window1),0); gtk_signal_connect (GTK_OBJECT (window1), "destroy", GTK_SIGNAL_FUNC (quit), NULL); vbox1=gtk_vbox_new(FALSE,0); gtk_container_add(GTK_CONTAINER(window1),vbox1); gtk_widget_show(vbox1); scrollw1=gtk_scrolled_window_new(NULL, NULL); gtk_container_border_width(GTK_CONTAINER(scrollw1),0); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollw1), GTK_POLICY_ALWAYS,GTK_POLICY_ALWAYS); gtk_box_pack_start(GTK_BOX(vbox1),scrollw1, TRUE, TRUE,0); gtk_widget_show(scrollw1); canvas = gtk_plot_canvas_new(page_width, page_height); GTK_PLOT_CANVAS_UNSET_FLAGS(GTK_PLOT_CANVAS(canvas), GTK_PLOT_CANVAS_DND_FLAGS); layout = canvas; gtk_container_add(GTK_CONTAINER(scrollw1),layout); gtk_layout_set_size(GTK_LAYOUT(layout), page_width, page_height); GTK_LAYOUT(layout)->hadjustment->step_increment = 5; GTK_LAYOUT(layout)->vadjustment->step_increment = 5; gdk_color_parse("light blue", &color); gdk_color_alloc(gtk_widget_get_colormap(layout), &color); gtk_plot_layout_set_background(GTK_PLOT_LAYOUT(layout), color); gtk_widget_show(layout); active_plot = new_layer(layout); gdk_color_parse("light yellow", &color); gdk_color_alloc(gtk_widget_get_colormap(active_plot), &color); gtk_plot_set_background(GTK_PLOT(active_plot), color); gdk_color_parse("white", &color); gdk_color_alloc(gtk_widget_get_colormap(layout), &color); gtk_plot_legends_set_attributes(GTK_PLOT(active_plot), NULL, 0, NULL, &color); gtk_plot_set_range(GTK_PLOT(active_plot), 0. ,20., 0., 1.); gtk_plot_axis_set_ticks(GTK_PLOT(active_plot), 0, 2, 1); gtk_plot_axis_set_ticks(GTK_PLOT(active_plot), 1, .1, .05); gtk_plot_axis_labels_set_numbers(GTK_PLOT(active_plot), 2, 0, 0); gtk_plot_axis_labels_set_numbers(GTK_PLOT(active_plot), 3, 0, 0); gtk_plot_axis_set_visible(GTK_PLOT(active_plot), GTK_PLOT_AXIS_TOP, TRUE); gtk_plot_axis_set_visible(GTK_PLOT(active_plot), GTK_PLOT_AXIS_RIGHT, TRUE); gtk_plot_set_grids_visible(GTK_PLOT(active_plot), TRUE, TRUE, TRUE, TRUE); gtk_plot_canvas_add_plot(GTK_PLOT_CANVAS(canvas), GTK_PLOT(active_plot), .15, .15); gtk_plot_axis_hide_title(GTK_PLOT(active_plot), GTK_PLOT_AXIS_TOP); gtk_plot_axis_hide_title(GTK_PLOT(active_plot), GTK_PLOT_AXIS_RIGHT); gtk_plot_axis_set_title(GTK_PLOT(active_plot), GTK_PLOT_AXIS_LEFT, "Intensity"); gtk_plot_axis_set_title(GTK_PLOT(active_plot), GTK_PLOT_AXIS_BOTTOM, "Time (s)"); gtk_plot_show_legends_border(GTK_PLOT(active_plot), TRUE, 3); gtk_plot_legends_move(GTK_PLOT(active_plot), .60, .10); gtk_widget_show(active_plot); gtk_widget_show(window1); gtk_plot_layout_put_text(GTK_PLOT_LAYOUT(canvas), .45, .05, 0, "Times-BoldItalic", 20, NULL, NULL, GTK_JUSTIFY_CENTER, "Real Time Demo"); dataset = gtk_plot_dataset_new(GTK_PLOT(active_plot)); gtk_plot_add_dataset(GTK_PLOT(active_plot), dataset); gdk_color_parse("red", &color); gdk_color_alloc(gdk_colormap_get_system(), &color); gtk_plot_dataset_set_legend(dataset, "Random pulse"); gtk_plot_dataset_set_symbol(dataset, GTK_PLOT_SYMBOL_DIAMOND, GTK_PLOT_SYMBOL_OPAQUE, 10, 2, color); gtk_plot_dataset_set_line_attributes(dataset, GTK_PLOT_LINE_SOLID, 1, color); timer = gtk_timeout_add(1000, update, active_plot); gtk_main(); return(0); }
/* * Calculate the size of the scrolled area and allocate the top-level * widget. This function is called when the top-level Dw widget has * changed its size etc. */ void Dw_gtk_viewport_calc_size (GtkDwViewport *viewport) { GtkWidget *widget; GtkScrolledWindow *scrolled; DwRequisition child_requisition; DwAllocation child_allocation; gint border_width, space; GtkRequisition bar_requisition; gint max_width, max_height, bar_width_diff, bar_height_diff, child_height; if (viewport->calc_size_blocked) return; viewport->calc_size_blocked = TRUE; if (viewport->child) { /* * Determine the size hints for the Dw widget. This is a bit * tricky, because you must know if scrollbars are visible or * not, which depends on the size of the Dw widget, which then * depends on the hints. The idea is to test several * configurations, there are four of them, from combining the * cases horizontal/vertical scrollbar visible/invisible. * * For optimization, the horizontal scrollbar is currently not * regarded, the height hint is always the same, as if the * scrollbar was allways visible. In future, this may be * implemented correctly, by using the minimal width to optimize * most cases. (Minimal widths will also be used by tables.) * * Furthermore, the last result (vertical scrollbar visible or * not) is stored in the viewport, and tested first. This will * make a second test only necessary when the visibility * switches, which normally happens only once when filling the * page with text. (Actually, this assumes that the page size is * always *growing*, but this is nevertheless true in dillo.) */ widget = GTK_WIDGET (viewport); scrolled = GTK_SCROLLED_WINDOW (widget->parent->parent); space = GTK_SCROLLED_WINDOW_CLASS(GTK_OBJECT(scrolled)->klass) ->scrollbar_spacing; border_width = GTK_CONTAINER(viewport)->border_width; gtk_widget_size_request (scrolled->vscrollbar, &bar_requisition); bar_width_diff = bar_requisition.width + space; max_width = widget->allocation.width - 2 * border_width; if (scrolled->vscrollbar_visible) max_width += bar_width_diff; gtk_widget_size_request (scrolled->hscrollbar, &bar_requisition); bar_height_diff = bar_requisition.height + space; max_height = widget->allocation.height - 2 * border_width; if (scrolled->hscrollbar_visible) max_height += bar_height_diff; DEBUG_MSG (2, "------------------------------------------------->\n"); DEBUG_MSG (2, "Dw_gtk_viewport_calc_size: %d x %d (%c/%c) -> %d x %d\n", widget->allocation.width, widget->allocation.height, scrolled->vscrollbar_visible ? 't' : 'f', scrolled->hscrollbar_visible ? 't' : 'f', max_width, max_height); if (scrolled->vscrollbar_policy == GTK_POLICY_NEVER) child_height = max_height; else child_height = max_height - bar_height_diff; switch (scrolled->vscrollbar_policy) { case GTK_POLICY_ALWAYS: Dw_gtk_viewport_calc_child_size (viewport, max_width - bar_width_diff, child_height, &child_requisition); break; case GTK_POLICY_AUTOMATIC: if (viewport->vscrollbar_used) { DEBUG_MSG (2, "Testing with vertical scrollbar ...\n"); Dw_gtk_viewport_calc_child_size (viewport, max_width - bar_width_diff, child_height, &child_requisition); if (child_requisition.ascent + child_requisition.descent <= child_height) { DEBUG_MSG (2, " failed!\n"); Dw_gtk_viewport_calc_child_size (viewport, max_width, child_height, &child_requisition); viewport->vscrollbar_used = TRUE; } } else { DEBUG_MSG (2, "Testing without vertical scrollbar ...\n"); Dw_gtk_viewport_calc_child_size (viewport, max_width, child_height, &child_requisition); /* todo: see above */ if (child_requisition.ascent + child_requisition.descent > child_height) { DEBUG_MSG (2, " failed!\n"); Dw_gtk_viewport_calc_child_size (viewport, max_width - bar_width_diff, child_height, &child_requisition); viewport->vscrollbar_used = TRUE; } } break; case GTK_POLICY_NEVER: Dw_gtk_viewport_calc_child_size (viewport, max_width, child_height, &child_requisition); } child_allocation.x = border_width; child_allocation.y = border_width; child_allocation.width = child_requisition.width; child_allocation.ascent = child_requisition.ascent; child_allocation.descent = child_requisition.descent; p_Dw_widget_size_allocate (viewport->child, &child_allocation); gtk_layout_set_size (GTK_LAYOUT (viewport), child_requisition.width + 2 * border_width, child_requisition.ascent + child_requisition.descent + 2 * border_width); DEBUG_MSG (1, "Setting size to %d x %d\n", child_requisition.width + 2 * border_width, child_requisition.ascent + child_requisition.descent + 2 * border_width); DEBUG_MSG (2, "<-------------------------------------------------\n"); } else { gtk_layout_set_size (GTK_LAYOUT (viewport), 1, 1); viewport->hscrollbar_used = FALSE; viewport->vscrollbar_used = FALSE; } Dw_gtk_viewport_update_anchor (viewport); gtk_widget_queue_draw (GTK_WIDGET (viewport)); viewport->calc_size_blocked = FALSE; }
/* Draw the exon view */ static void drawExonView(GtkWidget *exonView, GdkDrawable *drawable) { GtkWidget *blxWindow = exonViewGetBlxWindow(exonView); BlxViewContext *bc = blxWindowGetContext(blxWindow); ExonViewProperties *properties = exonViewGetProperties(exonView); const IntRange* const displayRange = bigPictureGetDisplayRange(properties->bigPicture); /* First, highlight any assembly gaps */ /* Get the display range in dna coords */ IntRange bpRange; convertDisplayRangeToDnaRange(displayRange, bc->seqType, bc->numFrames, bc->displayRev, &bc->refSeqRange, &bpRange); GdkColor *gapColor = getGdkColor(BLXCOLOR_ASSEMBLY_GAP, bc->defaultColors, FALSE, bc->usePrintColors); drawAssemblyGaps(exonView, drawable, gapColor, bc->displayRev, &properties->exonViewRect, &bpRange, bc->featureLists[BLXMSP_GAP]); /* Set a clip rectangle for drawing the exons and introns (because they are drawn "over the * edges" to make sure intron lines have the correct slope etc.) */ GdkGC *gc = gdk_gc_new(drawable); gdk_gc_set_clip_origin(gc, 0, 0); gdk_gc_set_clip_rectangle(gc, &properties->exonViewRect); /* Draw the exons and introns. Since we could have a lot of them in the loop, extract all the * info we need now and pass it around so we don't have to look for this stuff each time. */ DrawData drawData = { drawable, gc, &properties->exonViewRect, blxWindow, bc, properties->currentStrand, displayRange, &bc->refSeqRange, bc->displayRev, bc->numFrames, bc->seqType, properties->expanded, FALSE, properties->yPad, properties->exonViewRect.y, properties->exonHeight }; /* If the view is compressed (i.e. exons will overlap each other), then * only draw "normal" MSPs the first time round, and draw grouped/selected * MSPs afterwards, so that they appear on top. If the view is expanded, * we can draw them all in a single loop, because they will not overlap. */ drawData.normalOnly = !properties->expanded; /* Loop through all sequences, drawing all msps that are exons/introns */ GList *seqList = blxWindowGetAllMatchSeqs(blxWindow); g_list_foreach(seqList, drawExonIntronItem, &drawData); if (!properties->expanded) { drawData.normalOnly = FALSE; /* Draw all selected msps */ g_list_foreach(bc->selectedSeqs, drawExonIntronItem, &drawData); /* Increment the y value when finished, because we calculate the view height based on this */ drawData.y += drawData.height + drawData.yPad; } /* Set the height based on the height of the exons that were actually drawn */ const int newHeight = drawData.y - properties->exonViewRect.y + drawData.yPad; gtk_layout_set_size(GTK_LAYOUT(exonView), exonView->allocation.width, newHeight); g_object_unref(gc); }