int DrawScreenBitmap2(HDC hdc_screen_save, HDC hdc_screen, HDC hdc_screen_memory, int *arr, int arr_count, int split_width, int width, int height, double accelerate, HBRUSH hbr_background) { int i, count = 0; UNREFERENCED_PARAMETER(hbr_background); for (i = 0; i < arr_count; i++) { if (arr[i] > 0) { int old_offset = RoundToInt(CalcOffset(arr[i] - 1, accelerate)); int new_offset = RoundToInt(CalcOffset(arr[i], accelerate)); if (new_offset > height) { new_offset = height; count++; } if (new_offset > old_offset) { BitBlt(hdc_screen_memory, i * split_width, 0, split_width, new_offset, hdc_screen_save, i * split_width, height - new_offset, SRCCOPY); } } } BitBlt(hdc_screen, 0, 0, width, height, hdc_screen_memory, 0, 0, SRCCOPY); return count; }
void ImgMaskCreator::DrawLine(TPoint2D<long> point0, TPoint2D<long> point1) { if(m_img.IsNull()) return; //╬биоие long dx = point1.x() - point0.x(); long dy = point1.y() - point0.y(); long t = max(abs(dx), abs(dy)); if(t>0) { double ddx = dx*1.0/t; double ddy = dy*1.0/t; double x = point0.x(); double y = point0.y(); m_img.SetPixel(point0.x(), point0.y(), m_boundLineVal); while(t>=0) { --t; x = x+ddx; y = y+ddy; int x0 = RoundToInt (x); int y0 = RoundToInt (y); m_img.SetPixel(x0, y0, m_boundLineVal); } m_img.SetPixel(point1.x(), point1.y(), m_boundLineVal); } }
int DrawScreenBitmap1(HDC hdc_screen_save, HDC hdc_screen, HDC hdc_screen_memory, int *arr, int arr_count, int split_width, int width, int height, double accelerate, HBRUSH hbr_background) { static RECT rect; int i, count = 0; for (i = 0; i < arr_count; i++) { if (arr[i] > 0) { int old_offset = RoundToInt(CalcOffset(arr[i] - 1, accelerate)); int new_offset = RoundToInt(CalcOffset(arr[i], accelerate)); if (new_offset > height) { new_offset = height; count++; } if (new_offset > old_offset) { rect.left = i * split_width; rect.top = old_offset; rect.right = rect.left + split_width; rect.bottom = new_offset; FillRect(hdc_screen_memory, &rect, hbr_background); BitBlt(hdc_screen_memory, rect.left, new_offset, split_width, height - new_offset, hdc_screen_save, rect.left, 0, SRCCOPY); } } } BitBlt(hdc_screen, 0, 0, width, height, hdc_screen_memory, 0, 0, SRCCOPY); return count; }
PelLab24 CSoftWareConfig::GetStdHue(const std::vector<PelLab24>& hueVect) { bool success = !hueVect.empty(); PelLab24 lab; if(success) { int size = hueVect.size(); int sum_a = 0, sum_b = 0; for(int i=0; i<size; ++i) { sum_a += hueVect[i].a; sum_b += hueVect[i].b; } lab.a = RoundToInt(1.0*sum_a / size); lab.b = RoundToInt(1.0*sum_b / size); sum_a = sum_b = 0; for(int j=0; j<size; ++j) { sum_a += (hueVect[j].a - lab.a) * (hueVect[j].a - lab.a); sum_b += (hueVect[j].b - lab.b) * (hueVect[j].b - lab.b); } double sqrtRoot_a = sqrt(1.0*sum_a/size); double sqrtRoot_b = sqrt(1.0*sum_b/size); double aqrtRoot_ab = sqrt(sqrtRoot_a*sqrtRoot_a + sqrtRoot_b*sqrtRoot_b); lab.L = static_cast<char>( 1 + CeilToInt( 3.0*aqrtRoot_ab)); } return lab; }
CapsuleParam CSoftWareConfig::GetStdDim(const std::vector<CapsuleParam>& dimVect) { bool success = !dimVect.empty(); CapsuleParam dim; if(success) { int size = dimVect.size(); int sum_w = 0; int sum_h = 0; for(int i=0; i<size; ++i) { sum_w += dimVect[i].capsuleDim.width; sum_h += dimVect[i].capsuleDim.height; } dim.capsuleDim.width = RoundToInt(1.0*sum_w / size); dim.capsuleDim.height = RoundToInt(1.0*sum_h / size); sum_w = sum_h = 0; for(int j=0; j<size; ++j) { sum_w += (dimVect[j].capsuleDim.width - dim.capsuleDim.width ) * (dimVect[j].capsuleDim.width - dim.capsuleDim.width); sum_h += (dimVect[j].capsuleDim.height - dim.capsuleDim.height) * (dimVect[j].capsuleDim.height - dim.capsuleDim.height) ; } double sqrtRoot_w = sqrt ( 1.0*sum_w/size); double sqrtRoot_h = sqrt ( 1.0*sum_h/size); dim.capsuleDim.tolerance = CeilToInt ( 2.0*sqrtRoot_h); int sum_body = 0; int sum_cap = 0; for(int i = 0; i < size; ++i) { sum_body += dimVect[i].bodyLength; sum_cap += dimVect[i].capLength; } dim.bodyLength = RoundToInt(1.0*sum_body / size); dim.capLength = RoundToInt(1.0*sum_cap / size); sum_body = sum_cap = 0; for(int j=0; j<size; ++j) { sum_body += (dimVect[j].bodyLength - dim.bodyLength ) * (dimVect[j].bodyLength - dim.bodyLength); sum_cap += (dimVect[j].capLength - dim.capLength) * (dimVect[j].capLength - dim.capLength) ; } double sqrtRoot_body = sqrt ( 1.0*sum_body/size); double sqrtRoot_cap = sqrt ( 1.0*sum_cap/size); double maxRoot = sqrtRoot_body > sqrtRoot_cap?sqrtRoot_body:sqrtRoot_cap; dim.partTolerance = CeilToInt ( 2.0 * maxRoot); } return dim; }
bool PlatformGraphicsContext::setupPaintStroke(SkPaint* paint, SkRect* rect, bool isHLine) { this->setupPaintCommon(paint); paint->setColor(m_state->applyAlpha(m_state->strokeColor)); paint->setShader(m_state->strokeShader); float width = m_state->strokeThickness; // This allows dashing and dotting to work properly for hairline strokes // FIXME: Should we only do this for dashed and dotted strokes? if (!width) width = 1; paint->setStyle(SkPaint::kStroke_Style); paint->setStrokeWidth(SkFloatToScalar(width)); paint->setStrokeCap(m_state->lineCap); paint->setStrokeJoin(m_state->lineJoin); paint->setStrokeMiter(SkFloatToScalar(m_state->miterLimit)); if (rect && (RoundToInt(width) & 1)) rect->inset(-SK_ScalarHalf, -SK_ScalarHalf); SkPathEffect* pe = m_state->pathEffect; if (pe) { paint->setPathEffect(pe); return false; } switch (m_state->strokeStyle) { case NoStroke: case SolidStroke: width = 0; break; case DashedStroke: width = m_state->dashRatio * width; break; // No break case DottedStroke: break; } if (width > 0) { // Return true if we're basically a dotted dash of squares bool justSqrs = RoundToInt(width) == RoundToInt(paint->getStrokeWidth()); /// M: apply dash effect to DashedStroke and DottedStroke if (justSqrs || m_state->strokeStyle == DashedStroke) { // this is slow enough that we just skip it for now // see http://b/issue?id=4163023 SkScalar intervals[] = { width, width }; pe = new SkDashPathEffect(intervals, 2, 0); paint->setPathEffect(pe)->unref(); } return justSqrs; } return false; }
GVector2D<INT32> GGraph::PositionAtValue(UINT32 in_iValueIndex, REAL32 in_fValue, bool& out_bClipped) { if( (in_iValueIndex < m_iOffset) || (in_iValueIndex >= m_iNbValues + m_iOffset) ) { out_bClipped = true; } else { out_bClipped = false; } return GVector2D<INT32>( RoundToInt( ( (REAL32) (in_iValueIndex - m_iOffset) * m_pTransform->Size().X / (REAL32) m_iNbValues) ), RoundToInt( m_pTransform->Size().Y * (1 - ( (in_fValue - m_fMinValue) / (m_fMaxValue - m_fMinValue) ) ) ) ); }
// // Open preview in standalone window // void CPreview::ShowFileModal(void) { GdkRectangle rc; char buf[FILENAME_MAX+128]; GtkWindow *pParent = GTK_WINDOW(GetTopLevel()); if (m_FileType!=TYPE_IMAGE && m_FileType!=TYPE_CAT && m_FileType!=TYPE_PHOT && m_FileType!=TYPE_TABLE) return; // Dialog with buttons GtkWidget *pDlg = gtk_dialog_new_with_buttons("", pParent, (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); gtk_dialog_widget_standard_tooltips(GTK_DIALOG(pDlg)); // Dialog size GdkScreen *scr = gtk_window_get_screen(pParent); int mon = gdk_screen_get_monitor_at_window(scr, GTK_WIDGET(pParent)->window); gdk_screen_get_monitor_geometry(scr, mon, &rc); if (rc.width>0 && rc.height>0) gtk_window_set_default_size(GTK_WINDOW(pDlg), RoundToInt(0.7*rc.width), RoundToInt(0.7*rc.height)); // Dialog icon char *icon = get_icon_file("preview"); gtk_window_set_icon(GTK_WINDOW(pDlg), gdk_pixbuf_new_from_file(icon, NULL)); g_free(icon); // Preview widget GtkWidget *preview = cmpack_preview_new_with_model(m_Data); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pDlg)->vbox), preview, TRUE, TRUE, 0); if (m_FileType == TYPE_TABLE) { cmpack_preview_set_x_axis(CMPACK_PREVIEW(preview), FALSE, FALSE, m_MinX, m_MaxX, m_EpsX); cmpack_preview_set_y_axis(CMPACK_PREVIEW(preview), FALSE, m_ReverseY, m_MinY, m_MaxY, m_EpsY); } bool chart_invert = CConfig::GetBool(CConfig::NEGATIVE_CHARTS); cmpack_preview_set_negative(CMPACK_PREVIEW(preview), chart_invert); bool rows_upward = CConfig::GetBool(CConfig::ROWS_UPWARD); cmpack_preview_set_image_orientation(CMPACK_PREVIEW(preview), rows_upward ? CMPACK_ROWS_UPWARDS : CMPACK_ROWS_DOWNWARDS); // Display the preview dialog gchar *basename = g_path_get_basename(m_Path); sprintf(buf, "%s - %s", basename, g_AppTitle); g_free(basename); gtk_window_set_title(GTK_WINDOW(pDlg), buf); gtk_widget_show_all(pDlg); gtk_dialog_run(GTK_DIALOG(pDlg)); gtk_widget_destroy(pDlg); }
SkColor PlatformGraphicsContext::State::applyAlpha(SkColor c) const { int s = RoundToInt(alpha * 256); if (s >= 256) return c; if (s < 0) return 0; int a = SkAlphaMul(SkColorGetA(c), s); return (c & 0x00FFFFFF) | (a << 24); }
CMessagesDlg::CMessagesDlg(GtkWindow *pParent) { GtkWidget *text_view, *scrolled_window; GdkRectangle rc; // Dialog with buttons m_pDlg = gtk_dialog_new_with_buttons("Message log", pParent, (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, GTK_STOCK_HELP, GTK_RESPONSE_HELP, NULL); gtk_dialog_widget_standard_tooltips(GTK_DIALOG(m_pDlg)); g_signal_connect(G_OBJECT(m_pDlg), "response", G_CALLBACK(response_dialog), this); // Dialog size GdkScreen *scr = gtk_window_get_screen(pParent); int mon = gdk_screen_get_monitor_at_window(scr, GTK_WIDGET(pParent)->window); gdk_screen_get_monitor_geometry(scr, mon, &rc); if (rc.width>0 && rc.height>0) gtk_window_set_default_size(GTK_WINDOW(m_pDlg), RoundToInt(0.7*rc.width), RoundToInt(0.7*rc.height)); // Dialog icon gchar *icon = get_icon_file("messagelog"); gtk_window_set_icon(GTK_WINDOW(m_pDlg), gdk_pixbuf_new_from_file(icon, NULL)); g_free(icon); // List box text_view = gtk_text_view_new_with_buffer(ms_Buffer); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_view), GTK_WRAP_WORD_CHAR); gtk_text_view_set_editable(GTK_TEXT_VIEW(text_view), false); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text_view), false); scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_ETCHED_IN); gtk_container_add(GTK_CONTAINER(scrolled_window), text_view); gtk_widget_set_size_request(scrolled_window, 640, 480); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(m_pDlg)->vbox), scrolled_window, TRUE, TRUE, 0); gtk_widget_show_all(GTK_DIALOG(m_pDlg)->vbox); }
void Text::UpdateCharLocations() { // Remember the font face to see if it's still valid when it's time to render FontFace* face = font_ ? font_->GetFace(fontSize_) : nullptr; if (!face) return; fontFace_ = face; auto rowHeight = RoundToInt(rowSpacing_ * rowHeight_); // Store position & size of each character, and locations per texture page unsigned numChars = unicodeText_.size(); charLocations_.resize(numChars + 1); pageGlyphLocations_.resize(face->GetTextures().size()); for (unsigned i = 0; i < pageGlyphLocations_.size(); ++i) pageGlyphLocations_[i].clear(); IntVector2 offset = font_->GetTotalGlyphOffset(fontSize_); unsigned rowIndex = 0; unsigned lastFilled = 0; float x = Round(GetRowStartPosition(rowIndex) + offset.x_); float y = Round(offset.y_); for (unsigned i = 0; i < printText_.size(); ++i) { CharLocation loc; loc.position_ = Vector2(x, y); unsigned c = printText_[i]; if (c != '\n') { const FontGlyph* glyph = face->GetGlyph(c); loc.size_ = Vector2(glyph ? glyph->advanceX_ : 0, rowHeight_); if (glyph) { // Store glyph's location for rendering. Verify that glyph page is valid if (glyph->page_ < pageGlyphLocations_.size()) pageGlyphLocations_[glyph->page_].push_back(GlyphLocation(x, y, glyph)); x += glyph->advanceX_; if (i < printText_.size() - 1) x += face->GetKerning(c, printText_[i + 1]); } } else { loc.size_ = Vector2::ZERO; x = GetRowStartPosition(++rowIndex); y += rowHeight; } if (lastFilled > printToText_[i]) lastFilled = printToText_[i]; // Fill gaps in case characters were skipped from printing for (unsigned j = lastFilled; j <= printToText_[i]; ++j) charLocations_[j] = loc; lastFilled = printToText_[i] + 1; } // Store the ending position charLocations_[numChars].position_ = Vector2(x, y); charLocations_[numChars].size_ = Vector2::ZERO; charLocationsDirty_ = false; }
void Text::UpdateText(bool onResize) { rowWidths_.clear(); printText_.clear(); if (font_) { FontFace* face = font_->GetFace(fontSize_); if (!face) return; rowHeight_ = face->GetRowHeight(); int width = 0; int height = 0; int rowWidth = 0; auto rowHeight = RoundToInt(rowSpacing_ * rowHeight_); // First see if the text must be split up if (!wordWrap_) { printText_ = unicodeText_; printToText_.resize(printText_.size()); for (unsigned i = 0; i < printText_.size(); ++i) printToText_[i] = i; } else { int maxWidth = GetWidth(); unsigned nextBreak = 0; unsigned lineStart = 0; printToText_.clear(); for (unsigned i = 0; i < unicodeText_.size(); ++i) { unsigned j; unsigned c = unicodeText_[i]; if (c != '\n') { bool ok = true; if (nextBreak <= i) { int futureRowWidth = rowWidth; for (j = i; j < unicodeText_.size(); ++j) { unsigned d = unicodeText_[j]; if (d == ' ' || d == '\n') { nextBreak = j; break; } const FontGlyph* glyph = face->GetGlyph(d); if (glyph) { futureRowWidth += glyph->advanceX_; if (j < unicodeText_.size() - 1) futureRowWidth += face->GetKerning(d, unicodeText_[j + 1]); } if (d == '-' && futureRowWidth <= maxWidth) { nextBreak = j + 1; break; } if (futureRowWidth > maxWidth) { ok = false; break; } } } if (!ok) { // If did not find any breaks on the line, copy until j, or at least 1 char, to prevent infinite loop if (nextBreak == lineStart) { while (i < j) { printText_.push_back(unicodeText_[i]); printToText_.push_back(i); ++i; } } // Eliminate spaces that have been copied before the forced break while (printText_.size() && printText_.back() == ' ') { printText_.pop_back(); printToText_.pop_back(); } printText_.push_back('\n'); printToText_.push_back(Min(i, unicodeText_.size() - 1)); rowWidth = 0; nextBreak = lineStart = i; } if (i < unicodeText_.size()) { // When copying a space, position is allowed to be over row width c = unicodeText_[i]; const FontGlyph* glyph = face->GetGlyph(c); if (glyph) { rowWidth += glyph->advanceX_; if (i < unicodeText_.size() - 1) rowWidth += face->GetKerning(c, unicodeText_[i + 1]); } if (rowWidth <= maxWidth) { printText_.push_back(c); printToText_.push_back(i); } } } else { printText_.push_back('\n'); printToText_.push_back(Min(i, unicodeText_.size() - 1)); rowWidth = 0; nextBreak = lineStart = i; } } } rowWidth = 0; for (unsigned i = 0; i < printText_.size(); ++i) { unsigned c = printText_[i]; if (c != '\n') { const FontGlyph* glyph = face->GetGlyph(c); if (glyph) { rowWidth += glyph->advanceX_; if (i < printText_.size() - 1) rowWidth += face->GetKerning(c, printText_[i + 1]); } } else { width = Max(width, rowWidth); height += rowHeight; rowWidths_.push_back(rowWidth); rowWidth = 0; } } if (rowWidth) { width = Max(width, rowWidth); height += rowHeight; rowWidths_.push_back(rowWidth); } // Set at least one row height even if text is empty if (!height) height = rowHeight; // Set minimum and current size according to the text size, but respect fixed width if set if (!IsFixedWidth()) { if (wordWrap_) SetMinWidth(0); else { SetMinWidth(width); SetWidth(width); } } SetFixedHeight(height); charLocationsDirty_ = true; } else { // No font, nothing to render pageGlyphLocations_.clear(); } // If wordwrap is on, parent may need layout update to correct for overshoot in size. However, do not do this when the // update is a response to resize, as that could cause infinite recursion if (wordWrap_ && !onResize) { UIElement* parent = GetParent(); if (parent && parent->GetLayoutMode() != LM_FREE) parent->UpdateLayout(); } }
CMatchingDlg::CMatchingDlg(GtkWindow *pParent):m_pParent(pParent), m_FileList(NULL), m_FrameCols(NULL), m_CatalogCols(NULL), m_ChartData(NULL), m_ImageData(NULL), m_CatFile(NULL), m_SelectionName(NULL), m_Updating(false) { int i, w, width, mon; GtkWidget *tbox, *tbar, *frame, *hbox; GdkRectangle rc; GSList *group; m_Negative = CConfig::GetBool(CConfig::NEGATIVE_CHARTS); m_RowsUpward = CConfig::GetBool(CConfig::ROWS_UPWARD); // Dialog with buttons m_pDlg = gtk_dialog_new_with_buttons("Match stars", pParent, (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_HELP, GTK_RESPONSE_HELP, NULL); gtk_dialog_widget_standard_tooltips(GTK_DIALOG(m_pDlg)); gtk_dialog_set_tooltip_by_response(GTK_DIALOG(m_pDlg), GTK_RESPONSE_ACCEPT, "Start the process"); g_signal_connect(G_OBJECT(m_pDlg), "response", G_CALLBACK(response_dialog), this); // Dialog icon gchar *icon = get_icon_file("matchstars"); gtk_window_set_icon(GTK_WINDOW(m_pDlg), gdk_pixbuf_new_from_file(icon, NULL)); g_free(icon); // Dialog layout GtkWidget *vbox = gtk_vbox_new(FALSE, 4); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(m_pDlg)->vbox), vbox, TRUE, TRUE, 0); gtk_container_set_border_width(GTK_CONTAINER(vbox), 8); // Dialog size GdkScreen *scr = gtk_window_get_screen(pParent); mon = gdk_screen_get_monitor_at_window(scr, GTK_WIDGET(pParent)->window); gdk_screen_get_monitor_geometry(scr, mon, &rc); if (rc.width>0 && rc.height>0) gtk_window_set_default_size(GTK_WINDOW(m_pDlg), RoundToInt(0.7*rc.width), RoundToInt(0.7*rc.height)); // Initial state m_SelectMode = (tSelectMode)g_Project->GetInt("MatchingDlg", "Select", REFERENCE_FRAME); m_DMFrame = (tDisplayMode)g_Project->GetInt("MatchingDlg", "Display", DISPLAY_CHART); m_DMCatalog = (tDisplayMode)g_Project->GetInt("MatchingDlg", "Display2", DISPLAY_CHART); m_FrameSort = g_Project->GetInt("MatchingDlg", "Sort", FCOL_STARS); // List of frames m_Frames = gtk_list_store_new(FNCOLS, G_TYPE_INT, G_TYPE_INT, G_TYPE_DOUBLE, G_TYPE_INT); // List of catalog files m_Catalogs = gtk_list_store_new(CNCOLS, G_TYPE_STRING, G_TYPE_STRING); // Reference frame or catalog file? m_UseFrame = gtk_vbox_new(TRUE, 4); gtk_box_pack_start(GTK_BOX(vbox), m_UseFrame, FALSE, TRUE, 0); GtkWidget *label = gtk_label_new(NULL); gtk_label_set_markup(GTK_LABEL(label), "<b>As a reference file, use:</b>"); gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); gtk_box_pack_start(GTK_BOX(m_UseFrame), label, FALSE, TRUE, 0); m_FrameBtn = gtk_radio_button_new_with_label(NULL, "a frame from the current project"); gtk_widget_set_tooltip_text(m_FrameBtn, "Use one of the source frames as a reference frame"); g_signal_connect(G_OBJECT(m_FrameBtn), "toggled", G_CALLBACK(button_clicked), this); gtk_box_pack_start(GTK_BOX(m_UseFrame), m_FrameBtn, TRUE, TRUE, 0); group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(m_FrameBtn)); m_CatalogBtn = gtk_radio_button_new_with_label(group, "a catalog file from the disk"); gtk_widget_set_tooltip_text(m_CatalogBtn, "Use a catalog file as a reference frame"); g_signal_connect(G_OBJECT(m_CatalogBtn), "toggled", G_CALLBACK(button_clicked), this); gtk_box_pack_start(GTK_BOX(m_UseFrame), m_CatalogBtn, TRUE, TRUE, 0); // Separator gtk_box_pack_start(GTK_BOX(m_UseFrame), gtk_label_new(NULL), FALSE, TRUE, 0); m_SelLabel = gtk_label_new(NULL); gtk_misc_set_alignment(GTK_MISC(m_SelLabel), 0.0, 0.5); gtk_box_pack_start(GTK_BOX(vbox), m_SelLabel, FALSE, TRUE, 0); tbox = gtk_table_new(2, 3, FALSE); gtk_table_set_col_spacings(GTK_TABLE(tbox), 0); gtk_table_set_col_spacing(GTK_TABLE(tbox), 1, 8); gtk_table_set_row_spacings(GTK_TABLE(tbox), 0); gtk_table_set_row_spacing(GTK_TABLE(tbox), 1, 8); gtk_box_pack_start(GTK_BOX(vbox), tbox, TRUE, TRUE, 0); // List of reference frames m_FrameView = gtk_tree_view_new(); width = 8; for (i=0; FrameColumns[i].caption!=NULL; i++) { GtkTreeViewColumn *col = gtk_tree_view_column_new(); // Set column name and alignment gtk_tree_view_column_set_title(col, FrameColumns[i].caption); gtk_tree_view_append_column(GTK_TREE_VIEW(m_FrameView), col); // Add text renderer GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(col, renderer, TRUE); g_object_set(renderer, "xalign", FrameColumns[i].align, NULL); if (FrameColumns[i].datafn) gtk_tree_view_column_set_cell_data_func(col, renderer, FrameColumns[i].datafn, NULL, NULL); else gtk_tree_view_column_add_attribute(col, renderer, "text", FrameColumns[i].column); g_signal_connect(G_OBJECT(col), "clicked", G_CALLBACK(frame_column_clicked), this); tColData *data = (tColData*)g_malloc(sizeof(tColData)); data->col = col; data->data = &FrameColumns[i]; m_FrameCols = g_slist_append(m_FrameCols, data); if (FrameColumns[i].maxtext) w = text_width(m_FrameView, FrameColumns[i].maxtext); else w = text_width(m_FrameView, FrameColumns[i].caption); width += w + 24; } gtk_tree_view_set_model(GTK_TREE_VIEW(m_FrameView), GTK_TREE_MODEL(m_Frames)); gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(m_FrameView), true); gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_FrameView)), GTK_SELECTION_SINGLE); m_FrameBox = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(m_FrameBox), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(m_FrameBox), GTK_SHADOW_ETCHED_IN); gtk_container_add(GTK_CONTAINER(m_FrameBox), m_FrameView); gtk_widget_set_size_request(m_FrameView, width, -1); gtk_table_attach(GTK_TABLE(tbox), m_FrameBox, 0, 1, 0, 2, GTK_FILL, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), 0, 0); // Register callback for selection change GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(m_FrameView)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE); g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(selection_changed), this); // Catalog files m_CatalogView = gtk_tree_view_new(); for (i=0; CatalogColumns[i].caption!=NULL; i++) { GtkTreeViewColumn *col = gtk_tree_view_column_new(); // Set column name and alignment gtk_tree_view_column_set_title(col, CatalogColumns[i].caption); gtk_tree_view_append_column(GTK_TREE_VIEW(m_CatalogView), col); // Add text renderer GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(col, renderer, TRUE); g_object_set(renderer, "xalign", CatalogColumns[i].align, NULL); if (CatalogColumns[i].datafn) gtk_tree_view_column_set_cell_data_func(col, renderer, CatalogColumns[i].datafn, NULL, NULL); else gtk_tree_view_column_add_attribute(col, renderer, "text", CatalogColumns[i].column); tColData *data = (tColData*)g_malloc(sizeof(tColData)); data->col = col; data->data = &CatalogColumns[i]; m_CatalogCols = g_slist_append(m_CatalogCols, data); } gtk_tree_view_set_model(GTK_TREE_VIEW(m_CatalogView), GTK_TREE_MODEL(m_Catalogs)); gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(m_CatalogView), true); m_CatalogBox = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(m_CatalogBox), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(m_CatalogBox), GTK_SHADOW_ETCHED_IN); gtk_container_add(GTK_CONTAINER(m_CatalogBox), m_CatalogView); gtk_widget_set_size_request(m_CatalogView, width, -1); gtk_table_attach(GTK_TABLE(tbox), m_CatalogBox, 1, 2, 0, 2, GTK_FILL, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), 0, 0); // Register callback for selection change selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(m_CatalogView)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE); g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(selection_changed), this); // Toolbox tbar = gtk_toolbar_new(); gtk_toolbar_set_style(GTK_TOOLBAR(tbar), GTK_TOOLBAR_TEXT); m_ShowChart = toolbar_new_radio_button(tbar, NULL, "Chart", "Display objects on a flat background"); g_signal_connect(G_OBJECT(m_ShowChart), "toggled", G_CALLBACK(button_clicked), this); m_ShowImage = toolbar_new_radio_button(tbar, m_ShowChart, "Image", "Display an image only"); g_signal_connect(G_OBJECT(m_ShowImage), "toggled", G_CALLBACK(button_clicked), this); gtk_table_attach(GTK_TABLE(tbox), tbar, 2, 3, 0, 1, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), GTK_FILL, 0, 0); // Frame preview frame = gtk_frame_new(NULL); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); m_Preview = cmpack_chart_view_new(); gtk_container_add(GTK_CONTAINER(frame), m_Preview); gtk_widget_set_size_request(frame, 160, 120); gtk_table_attach_defaults(GTK_TABLE(tbox), frame, 2, 3, 1, 2); // Bottom toolbox hbox = gtk_hbox_new(FALSE, 8); m_OptionsBtn = gtk_button_new_with_label("Options"); gtk_widget_set_tooltip_text(m_OptionsBtn, "Edit project settings"); gtk_box_pack_start(GTK_BOX(hbox), m_OptionsBtn, 0, 0, 0); g_signal_connect(G_OBJECT(m_OptionsBtn), "clicked", G_CALLBACK(button_clicked), this); m_PathLabel = gtk_label_new("Search path:"); gtk_box_pack_start(GTK_BOX(hbox), m_PathLabel, FALSE, TRUE, 0); m_PathEntry = gtk_entry_new(); gtk_widget_set_tooltip_text(m_PathEntry, "Path to the folder with catalog files"); gtk_editable_set_editable(GTK_EDITABLE(m_PathEntry), false); gtk_box_pack_start(GTK_BOX(hbox), m_PathEntry, TRUE, TRUE, 0); m_PathBtn = gtk_button_new_with_label("Change folder"); gtk_widget_set_tooltip_text(m_PathBtn, "Change folder with catalog files"); g_signal_connect(G_OBJECT(m_PathBtn), "clicked", G_CALLBACK(button_clicked), this); gtk_box_pack_start(GTK_BOX(hbox), m_PathBtn, FALSE, TRUE, 0); gtk_table_attach(GTK_TABLE(tbox), hbox, 0, 3, 2, 3, GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show_all(GTK_DIALOG(m_pDlg)->vbox); }
CChooseApertureDlg::CChooseApertureDlg(GtkWindow *pParent):m_FrameSet(NULL), m_Table(NULL), m_GraphData(NULL), m_ApertureIndex(-1), m_Row(-1), m_Column(-1) { GdkRectangle rc; GtkWidget *hbox, *vbox, *scrwnd; GtkTreeViewColumn *col; GtkCellRenderer *renderer; GtkTreeSelection *selection; // Dialog with buttons m_pDlg = gtk_dialog_new_with_buttons("Choose aperture", pParent, (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_HELP, GTK_RESPONSE_HELP, NULL); gtk_dialog_widget_standard_tooltips(GTK_DIALOG(m_pDlg)); g_signal_connect(G_OBJECT(m_pDlg), "response", G_CALLBACK(response_dialog), this); // Dialog size GdkScreen *scr = gdk_screen_get_default(); gdk_screen_get_monitor_geometry(scr, 0, &rc); if (rc.width>0 && rc.height>0) gtk_window_set_default_size(GTK_WINDOW(m_pDlg), RoundToInt(0.6*rc.width), RoundToInt(0.5*rc.height)); // Dialog icon gchar *icon = get_icon_file("muniwin"); gtk_window_set_icon(GTK_WINDOW(m_pDlg), gdk_pixbuf_new_from_file(icon, NULL)); g_free(icon); // Preview box hbox = gtk_hbox_new(FALSE, 8); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(m_pDlg)->vbox), hbox, TRUE, TRUE, 0); vbox = gtk_vbox_new(FALSE, 8); gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, TRUE, 0); // List of apertures m_Apertures = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING); m_AperView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(m_Apertures)); gtk_widget_set_tooltip_text(m_AperView, "Click on a item to select an aperture"); col = gtk_tree_view_column_new(); gtk_tree_view_column_set_title(col, "Apertures"); gtk_tree_view_append_column(GTK_TREE_VIEW(m_AperView), col); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(col, renderer, FALSE); gtk_tree_view_column_add_attribute(col, renderer, "text", 1); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(m_AperView)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE); g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(selection_changed), this); scrwnd = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrwnd), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrwnd), GTK_SHADOW_ETCHED_IN); gtk_container_add(GTK_CONTAINER(scrwnd), m_AperView); gtk_box_pack_start(GTK_BOX(vbox), scrwnd, FALSE, TRUE, 0); gtk_widget_set_size_request(scrwnd, 140, 300); // List of data columns m_Channels = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING); m_DataView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(m_Channels)); col = gtk_tree_view_column_new(); gtk_tree_view_column_set_title(col, "Data sets"); gtk_tree_view_append_column(GTK_TREE_VIEW(m_DataView), col); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(col, renderer, TRUE); gtk_tree_view_column_add_attribute(col, renderer, "text", 1); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(m_DataView)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE); g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(selection_changed), this); scrwnd = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrwnd), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrwnd), GTK_SHADOW_ETCHED_IN); gtk_container_add(GTK_CONTAINER(scrwnd), m_DataView); gtk_box_pack_start(GTK_BOX(vbox), scrwnd, TRUE, TRUE, 0); gtk_widget_set_size_request(scrwnd, -1, 120); // Graph m_GraphView = cmpack_graph_view_new_with_model(NULL); gtk_widget_set_tooltip_text(m_GraphView, "Click on a point to select an aperture"); cmpack_graph_view_set_mouse_control(CMPACK_GRAPH_VIEW(m_GraphView), FALSE); cmpack_graph_view_set_scales(CMPACK_GRAPH_VIEW(m_GraphView), TRUE, TRUE); cmpack_graph_view_set_activation_mode(CMPACK_GRAPH_VIEW(m_GraphView), CMPACK_ACTIVATION_CLICK); g_signal_connect(G_OBJECT(m_GraphView), "item-activated", G_CALLBACK(item_activated), this); gtk_widget_set_size_request(m_GraphView, 200, -1); gtk_box_pack_start(GTK_BOX(hbox), m_GraphView, TRUE, TRUE, 0); gtk_widget_show_all(hbox); }
CChartDlg::CChartDlg(GtkWindow *pParent):m_pParent(pParent), m_ChartData(NULL), m_ImageData(NULL) { GtkWidget *scrwnd, *tbox; GdkRectangle rc; m_DisplayMode = (tDisplayMode)g_Project->GetInt("ChartDlg", "Mode", DISPLAY_IMAGE, 0, DISPLAY_FULL); m_Negative = CConfig::GetBool(CConfig::NEGATIVE_CHARTS); m_RowsUpward = CConfig::GetBool(CConfig::ROWS_UPWARD); // Dialog with buttons m_pDlg = gtk_dialog_new_with_buttons("Chart", pParent, (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, GTK_STOCK_SAVE, GTK_RESPONSE_NONE, GTK_STOCK_HELP, GTK_RESPONSE_HELP, NULL); gtk_dialog_widget_standard_tooltips(GTK_DIALOG(m_pDlg)); gtk_dialog_set_tooltip_by_response(GTK_DIALOG(m_pDlg), GTK_RESPONSE_NONE, "Export the chart to a file"); g_signal_connect(G_OBJECT(m_pDlg), "response", G_CALLBACK(response_dialog), this); // Dialog icon gchar *icon = get_icon_file("muniwin"); gtk_window_set_icon(GTK_WINDOW(m_pDlg), gdk_pixbuf_new_from_file(icon, NULL)); g_free(icon); // Dialog size GdkScreen *scr = gtk_window_get_screen(pParent); int mon = gdk_screen_get_monitor_at_window(scr, GTK_WIDGET(pParent)->window); gdk_screen_get_monitor_geometry(scr, mon, &rc); if (rc.width>0 && rc.height>0) gtk_window_set_default_size(GTK_WINDOW(m_pDlg), RoundToInt(0.7*rc.width), RoundToInt(0.7*rc.height)); // Toolbar tbox = gtk_toolbar_new(); gtk_toolbar_set_style(GTK_TOOLBAR(tbox), GTK_TOOLBAR_ICONS); gtk_toolbar_set_orientation(GTK_TOOLBAR(tbox), GTK_ORIENTATION_HORIZONTAL); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(m_pDlg)->vbox), tbox, FALSE, FALSE, 0); m_ViewLabel = toolbar_new_label(tbox, "View"); m_ShowImage = toolbar_new_radio_button(tbox, NULL, "Image", "Display an image only"); g_signal_connect(G_OBJECT(m_ShowImage), "toggled", G_CALLBACK(button_clicked), this); m_ShowChart = toolbar_new_radio_button(tbox, m_ShowImage, "Chart", "Display objects on a flat background"); g_signal_connect(G_OBJECT(m_ShowChart), "toggled", G_CALLBACK(button_clicked), this); m_ShowMixed = toolbar_new_radio_button(tbox, m_ShowImage, "Mixed", "Display objects over an image"); g_signal_connect(G_OBJECT(m_ShowMixed), "toggled", G_CALLBACK(button_clicked), this); toolbar_new_separator(tbox); toolbar_new_label(tbox, "Zoom"); m_ZoomFit = toolbar_new_button_from_stock(tbox, GTK_STOCK_ZOOM_FIT, "Fit the frame to the window"); g_signal_connect(G_OBJECT(m_ZoomFit), "clicked", G_CALLBACK(button_clicked), this); m_ZoomOut = toolbar_new_button_from_stock(tbox, GTK_STOCK_ZOOM_OUT, "Zoom out"); g_signal_connect(G_OBJECT(m_ZoomOut), "clicked", G_CALLBACK(button_clicked), this); m_ZoomIn = toolbar_new_button_from_stock(tbox, GTK_STOCK_ZOOM_IN, "Zoom in"); g_signal_connect(G_OBJECT(m_ZoomIn), "clicked", G_CALLBACK(button_clicked), this); // Chart m_Chart = cmpack_chart_view_new(); scrwnd = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrwnd), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrwnd), GTK_SHADOW_ETCHED_IN); gtk_container_add(GTK_CONTAINER(scrwnd), m_Chart); gtk_widget_set_size_request(m_Chart, 300, 200); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(m_pDlg)->vbox), scrwnd, TRUE, TRUE, 0); gtk_widget_show_all(GTK_DIALOG(m_pDlg)->vbox); }
IntVector2 Font::GetTotalGlyphOffset(float pointSize) const { Vector2 multipliedOffset = pointSize * scaledOffset_; return absoluteOffset_ + IntVector2(RoundToInt(multipliedOffset.x_), RoundToInt(multipliedOffset.y_)); }