Exemple #1
0
 void rectangle(const Point& point1, const Point& point2, const Color& color, bool filled)
 {
     if (filled)
         gdImageFilledRectangle(im_, SCALEX(point1.x), SCALEY(point1.y), SCALEX(point2.x), SCALEY(point2.y), color2gd(color));
     else    
         gdImageRectangle(im_, SCALEX(point1.x), SCALEY(point1.y), SCALEX(point2.x), SCALEY(point2.y), color2gd(color));
 }
Exemple #2
0
 void circle(const Point& center, int radius, const Color& color, bool filled)
 {
     if (filled)
         gdImageFilledEllipse(im_, SCALEX(center.x), SCALEY(center.y), SCALER(radius*2), SCALER(radius*2), color2gd(color)); 
     else    
         gdImageArc(im_, SCALEX(center.x), SCALEY(center.y), SCALER(radius*2), SCALER(radius*2), 0, 360, color2gd(color)); 
 }
Exemple #3
0
BOOL CBrowseDlg::OnInitDialog() {
	CCeDialog::OnInitDialog();
	LocalizeDialog(GetSafeHwnd(), IDD);

	// make extension list
	int nStart = 0;
	int nSemiCol = m_strExts.Find(';');
	while (nSemiCol != -1) {
		m_arExts.Add(m_strExts.Mid(nStart, nSemiCol - nStart));
		nStart = nSemiCol + 1;
		nSemiCol = m_strExts.Find(';', nStart);
	}
	m_arExts.Add(m_strExts.Mid(nStart));

	CDC *pDC = GetDC();
	if (pDC->GetDeviceCaps(LOGPIXELSX) > 130)
		m_oImageList.Create(IDB_DIRS_HI, SCALEX(16), 10, RGB(255, 0, 255));
	else
		m_oImageList.Create(IDB_DIRS, SCALEX(16), 10, RGB(255, 0, 255));
	ReleaseDC(pDC);

	// menu bar
	BOOL fSuccess;
	SHMENUBARINFO mbi = { 0 };

	mbi.cbSize = sizeof(mbi);
	mbi.dwFlags = SHCMBF_HMENU;
	mbi.nToolBarId = m_nMenuID; //m_bNewFolderBtn ? IDR_BROWSE : IDR_CANCEL;
	mbi.hInstRes = AfxGetInstanceHandle();
	mbi.hwndParent = GetSafeHwnd();

	fSuccess = SHCreateMenuBar(&mbi);
	m_hwndCmdBar = mbi.hwndMB;

	LocalizeMenubar(m_hwndCmdBar);


	SHFILEINFO sfi = { 0 };
	// folder
	ZeroMemory(&sfi, sizeof(sfi));
	SHGetFileInfo(_T("\\"), 0, &sfi, sizeof(sfi), SHGFI_ICON | SHGFI_SMALLICON);
	m_oImageList.Add(sfi.hIcon);

	m_ctlDirs.SetImageList(&m_oImageList, TVSIL_NORMAL);

//	m_ctlCaption.SetTitle(m_strCaption);

	// sanitize path
	if (m_strPath.Right(1).CompareNoCase(_T("\\")) != 0)
		m_strPath += _T("\\");

	FillMe();
	SelectPath(m_strPath);

	SetForegroundWindow();
//	SESSION_RESTORE;

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
/**
 * gimp_display_shell_transform_segments:
 * @shell:       a #GimpDisplayShell
 * @src_segs:    array of segments in image coordinates
 * @dest_segs:   returns the corresponding segments in display coordinates
 * @n_segs:      number of segments
 *
 * Transforms from image coordinates to display coordinates, so that
 * objects can be rendered at the correct points on the display.
 **/
void
gimp_display_shell_transform_segments (const GimpDisplayShell *shell,
                                       const GimpBoundSeg     *src_segs,
                                       GimpSegment            *dest_segs,
                                       gint                    n_segs,
                                       gdouble                 offset_x,
                                       gdouble                 offset_y)
{
    gint i;

    g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

    for (i = 0; i < n_segs ; i++)
    {
        gdouble x1, x2;
        gdouble y1, y2;

        x1 = src_segs[i].x1 + offset_x;
        x2 = src_segs[i].x2 + offset_x;
        y1 = src_segs[i].y1 + offset_y;
        y2 = src_segs[i].y2 + offset_y;

        dest_segs[i].x1 = SCALEX (shell, x1) - shell->offset_x;
        dest_segs[i].x2 = SCALEX (shell, x2) - shell->offset_x;
        dest_segs[i].y1 = SCALEY (shell, y1) - shell->offset_y;
        dest_segs[i].y2 = SCALEY (shell, y2) - shell->offset_y;
    }
}
Exemple #5
0
void CTextProgressCtrl::OnPaint() {
	CPaintDC dc(this); // device context for painting

	int saveDC = dc.SaveDC();

	CRect rcClient;
	GetClientRect(&rcClient);

	CBrush brHollow;
	brHollow.Attach(::GetStockObject(NULL_BRUSH));
	dc.SelectObject(&brHollow);

	// frame
	CPen pen(PS_SOLID, SCALEX(1), ::GetSysColor(COLOR_WINDOWFRAME));
	dc.SelectObject(&pen);
	HIDPI_BorderRectangle(dc.GetSafeHdc(), rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);

	// inside
	rcClient.DeflateRect(SCALEX(1), SCALEY(1));

	int nWd = (Hi - Lo);
	double pos = (double) Pos / nWd;

	// bar
	int nPhysPos = (int) (rcClient.Width() * pos);
	COLORREF clrBar = ::GetSysColor(COLOR_HIGHLIGHT);
	CRect rcBar(rcClient.left, rcClient.top, rcClient.left + nPhysPos, rcClient.bottom);
	dc.FillSolidRect(&rcBar, clrBar);

	COLORREF clrBkgnd = ::GetSysColor(COLOR_3DSHADOW);
	CRect rcBack(rcClient.left + nPhysPos, rcClient.top, rcClient.right, rcClient.bottom);
	dc.FillSolidRect(&rcBack, clrBkgnd);

	// draw text over the progress bar
	rcClient.DeflateRect(SCALEX(4), -1, SCALEX(4), 1);

	dc.SetBkMode(TRANSPARENT);
	dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));

	CRect rcSize(0, 0, 0, 0);
	if (!m_strSize.IsEmpty()) {
		dc.SelectObject(&m_fntSize);
		rcSize = rcClient;
		dc.DrawText(m_strSize, rcSize, DT_RIGHT | DT_BOTTOM | DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
		dc.DrawText(m_strSize, rcClient, DT_RIGHT | DT_BOTTOM | DT_SINGLELINE | DT_NOPREFIX);
	}

	dc.SelectObject(&m_fntText);
	CRect rcProgress = rcClient;
	rcProgress.right -= rcSize.Width() - SCALEX(6);
	DrawTextEndEllipsis(dc, m_strText, rcProgress, DT_LEFT | DT_BOTTOM | DT_SINGLELINE | DT_NOPREFIX);

	// validate
	GetClientRect(&rcClient);
	ValidateRect(rcClient);

	dc.RestoreDC(saveDC);
}
static void
gimp_display_shell_size_changed_detailed_handler (GimpImage        *image,
        gint              previous_origin_x,
        gint              previous_origin_y,
        gint              previous_width,
        gint              previous_height,
        GimpDisplayShell *shell)
{
    if (shell->display->config->resize_windows_on_resize)
    {
        GimpImageWindow *window = gimp_display_shell_get_window (shell);

        if (window && gimp_image_window_get_active_shell (window) == shell)
        {
            /* If the window is resized just center the image in it when it
             * has change size
             */
            gimp_image_window_shrink_wrap (window, FALSE);
        }
    }
    else
    {
        GimpImage *image                    = gimp_display_get_image (shell->display);
        gint       new_width                = gimp_image_get_width  (image);
        gint       new_height               = gimp_image_get_height (image);
        gint       scaled_previous_origin_x = SCALEX (shell, previous_origin_x);
        gint       scaled_previous_origin_y = SCALEY (shell, previous_origin_y);
        gboolean   horizontally;
        gboolean   vertically;

        horizontally = (SCALEX (shell, previous_width)  >  shell->disp_width  &&
                        SCALEX (shell, new_width)       <= shell->disp_width);
        vertically   = (SCALEY (shell, previous_height) >  shell->disp_height &&
                        SCALEY (shell, new_height)      <= shell->disp_height);

        gimp_display_shell_scroll_set_offset (shell,
                                              shell->offset_x + scaled_previous_origin_x,
                                              shell->offset_y + scaled_previous_origin_y);

        gimp_display_shell_scroll_center_image (shell, horizontally, vertically);

        /* The above calls might not lead to a call to
         * gimp_display_shell_scroll_clamp_and_update() in all cases we
         * need it to be called, so simply call it explicitly here at
         * the end
         */
        gimp_display_shell_scroll_clamp_and_update (shell);

        gimp_display_shell_expose_full (shell);
    }
}
Exemple #7
0
CPlayListDlg::CPlayListDlg()
{
	m_hWnd = NULL;
	m_hwndMB = NULL;
	m_fCtrlKey = FALSE;
	
	m_hImageList = ImageList_Create(SCALEX(16), SCALEY(16), ILC_COLOR | ILC_MASK, 2, 2);
	HICON hIcon = LoadIcon(GetInst(), LPCTSTR(IDI_FILE_S));
	ImageList_AddIcon(m_hImageList, hIcon);
	DestroyIcon(hIcon);
	hIcon = (HICON)LoadImage(GetInst(), (LPCTSTR)IDI_PLAY_S, IMAGE_ICON, SCALEX(16), SCALEY(16), 0);
	ImageList_AddIcon(m_hImageList, hIcon);
	DestroyIcon(hIcon);
}
Exemple #8
0
 void pixel(const Point& point, const Color& color)
 {
     if (scaled_) // might actually need more than one pixel
     {
         // gd rectangle is inclusive, so find scaled pixel just outside and back off
         Point p1(SCALEX(point.x),SCALEY(point.y));
         Point p2(SCALEX(point.x+1),SCALEY(point.y+1)); // far edge of rectangle of 1x1 logical pixels
         if (p2.x > p1.x)
             p2.x--;
         if (p2.y > p1.y)
             p2.y--;
         gdImageFilledRectangle(im_,p1.x,p1.y,p2.x,p2.y,color2gd(color));
     }
     else
         gdImageSetPixel(im_, point.x, point.y, color2gd(color));
 }
Exemple #9
0
void CFolderDlg::OnInitDialog(HWND hDlg)
{
	CTempStr str(IDS_ROOT_FOLDER_NAME);
	ShellInitDialog(hDlg);
	HWND hTreeView = GetDlgItem(hDlg, IDC_TREE_FOLDER);

	m_bRefresh = FALSE;
	m_hImageList = NULL;
	HICON hIcon;

	//イメージリスト作成
	m_hImageList = ImageList_Create(SCALEX(16), SCALEY(16), ILC_COLOR|ILC_MASK, 1, 2);

	hIcon = (HICON)LoadImage(GetInst(), (LPCTSTR)IDI_ROOT, IMAGE_ICON, SCALEX(16), SCALEY(16), 0);
	ImageList_AddIcon(m_hImageList, hIcon);
	DeleteObject(hIcon);

	SHFILEINFO shfi;
	SHGetFileInfo(_T("\\Windows"), NULL, &shfi, sizeof(shfi), SHGFI_SMALLICON | SHGFI_ICON);
	ImageList_AddIcon(m_hImageList, shfi.hIcon);

	TreeView_SetImageList(hTreeView, m_hImageList, TVSIL_NORMAL);
	SetWindowLong(hTreeView, GWL_STYLE, GetWindowLong(hTreeView, GWL_STYLE)|TVS_HASBUTTONS|TVS_HASLINES|TVS_SHOWSELALWAYS);
	
	//フォルダ読み込み
	HCURSOR hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));

	TVINSERTSTRUCT tvis;
	tvis.hParent = NULL;
	tvis.hInsertAfter = TVI_SORT;
	tvis.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN;
	tvis.item.pszText = str;
	tvis.item.iImage = 0;
	tvis.item.iSelectedImage = 0;
	tvis.item.cChildren = 1;
	HTREEITEM hRoot = TreeView_InsertItem(hTreeView, &tvis);
	TreeView_Expand(hTreeView, hRoot, TVE_EXPAND);

	//カレントフォルダをセット
	SetCurrentFolder(hTreeView, m_pszPath);

	if (m_bSubFolder)
		SendMessage(GetDlgItem(hDlg, IDC_CHECK_SUBFOLDER), BM_SETCHECK, 1, 0);

	SetCursor(hCursor);
}
/**
 * gimp_display_shell_transform_xy_f:
 * @shell: a #GimpDisplayShell
 * @x:     image x coordinate of point
 * @y:     image y coordinate of point
 * @nx:    returned shell canvas x coordinate
 * @ny:    returned shell canvas y coordinate
 *
 * Transforms from image coordinates to display shell canvas
 * coordinates.
 **/
void
gimp_display_shell_transform_xy_f  (const GimpDisplayShell *shell,
                                    gdouble                 x,
                                    gdouble                 y,
                                    gdouble                *nx,
                                    gdouble                *ny)
{
    g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
    g_return_if_fail (nx != NULL);
    g_return_if_fail (ny != NULL);

    *nx = SCALEX (shell, x) - shell->offset_x;
    *ny = SCALEY (shell, y) - shell->offset_y;
}
Exemple #11
0
BOOL DefDlgPaintProc(HWND hDlg, WPARAM wParam, LPARAM lParam)
{
#if defined(_WIN32_WCE_PPC) && !defined(_WIN32_WCE_SP)
    if (IsLandscape())
        return FALSE;

    PAINTSTRUCT ps;
    HDC hDC = BeginPaint(hDlg, &ps);
    POINT pt[2] = {{0, SCALEY(24)},{SCALEX(GetSystemMetrics(SM_CXSCREEN)), SCALEY(24)}};
    Polyline(hDC, pt, sizeof(pt)/sizeof(POINT));
    EndPaint(hDlg, &ps);
    return TRUE;
#else
    return FALSE;
#endif
}
/**
 * gimp_display_shell_transform_coords:
 * @shell:          a #GimpDisplayShell
 * @image_coords:   image coordinates
 * @display_coords: returns the corresponding display coordinates
 *
 * Transforms from image coordinates to display coordinates, so that
 * objects can be rendered at the correct points on the display.
 **/
void
gimp_display_shell_transform_coords (const GimpDisplayShell *shell,
                                     const GimpCoords       *image_coords,
                                     GimpCoords             *display_coords)
{
    g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
    g_return_if_fail (image_coords != NULL);
    g_return_if_fail (display_coords != NULL);

    *display_coords = *image_coords;

    display_coords->x = SCALEX (shell, image_coords->x);
    display_coords->y = SCALEY (shell, image_coords->y);

    display_coords->x -= shell->offset_x;
    display_coords->y -= shell->offset_y;
}
Exemple #13
0
static gboolean
gimp_tool_check_click_distance (GimpTool         *tool,
                                const GimpCoords *coords,
                                guint32           time,
                                GimpDisplay      *display)
{
  GimpDisplayShell *shell;
  gint              double_click_time;
  gint              double_click_distance;

  if (! tool->in_click_distance)
    return FALSE;

  shell = gimp_display_get_shell (display);

  g_object_get (gtk_widget_get_settings (GTK_WIDGET (shell)),
                "gtk-double-click-time",     &double_click_time,
                "gtk-double-click-distance", &double_click_distance,
                NULL);

  if ((time - tool->button_press_time) > double_click_time)
    {
      tool->in_click_distance = FALSE;
    }
  else
    {
      GimpDisplayShell *shell = gimp_display_get_shell (display);
      gdouble           dx;
      gdouble           dy;

      dx = SCALEX (shell, tool->button_press_coords.x - coords->x);
      dy = SCALEY (shell, tool->button_press_coords.y - coords->y);

      if ((SQR (dx) + SQR (dy)) > SQR (double_click_distance))
        {
          tool->in_click_distance = FALSE;
        }
    }

  return tool->in_click_distance;
}
Exemple #14
0
    void stringUp(const std::string& text, const Point& point, const Color& color, Size size, int align)
    {
        // copy text into gd-friendly (unsigned char) buffer

        vector<unsigned char> buffer;
        copy(text.begin(), text.end(), back_inserter(buffer));
        buffer.push_back('\0');

        // choose font 

        gdFontPtr font;
        switch (size)
        {
            case Tiny: font = gdFontGetTiny(); break;
            case Small: font = gdFontGetSmall(); break;
            case MediumBold: font = gdFontGetMediumBold(); break;
            case Large: font = gdFontGetLarge(); break;
            case Giant: font = gdFontGetGiant(); break;
            default: throw runtime_error("[ImageImpl::string()] This isn't happening.");
        }

        // calculate position

        Point position(SCALEX(point.x),SCALEY(point.y));
        int length = (int)text.size() * font->w;
        int height = font->h;
        
        if (align & CenterX) position.x -= height/2;
        else if (align & Right) position.x -= height;
            
        if (align & CenterY) position.y -= length/2;
        else if (align & Bottom) position.y -= length;

        // draw the string vertically
            
        gdImageStringUp(im_, font, position.x, position.y, &buffer[0], color2gd(color)); 
    }
void
gimp_display_shell_canvas_size_allocate (GtkWidget        *widget,
                                         GtkAllocation    *allocation,
                                         GimpDisplayShell *shell)
{
  /*  are we in destruction?  */
  if (! shell->display || ! gimp_display_get_shell (shell->display))
    return;

  if ((shell->disp_width  != allocation->width) ||
      (shell->disp_height != allocation->height))
    {
      if (shell->zoom_on_resize   &&
          shell->disp_width  > 64 &&
          shell->disp_height > 64 &&
          allocation->width  > 64 &&
          allocation->height > 64)
        {
          gdouble scale = gimp_zoom_model_get_factor (shell->zoom);
          gint    offset_x;
          gint    offset_y;

          /* FIXME: The code is a bit of a mess */

          /*  multiply the zoom_factor with the ratio of the new and
           *  old canvas diagonals
           */
          scale *= (sqrt (SQR (allocation->width) +
                          SQR (allocation->height)) /
                    sqrt (SQR (shell->disp_width) +
                          SQR (shell->disp_height)));

          offset_x = UNSCALEX (shell, shell->offset_x);
          offset_y = UNSCALEX (shell, shell->offset_y);

          gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO, scale);

          shell->offset_x = SCALEX (shell, offset_x);
          shell->offset_y = SCALEY (shell, offset_y);
        }

      shell->disp_width  = allocation->width;
      shell->disp_height = allocation->height;

      /* When we size-allocate due to resize of the top level window,
       * we want some additional logic. Don't apply it on
       * zoom_on_resize though.
       */
      if (shell->size_allocate_from_configure_event &&
          ! shell->zoom_on_resize)
        {
          gboolean center_horizontally;
          gboolean center_vertically;
          gint     target_offset_x;
          gint     target_offset_y;
          gint     sw;
          gint     sh;

          gimp_display_shell_scale_get_image_size (shell, &sw, &sh);

          center_horizontally = sw <= shell->disp_width;
          center_vertically   = sh <= shell->disp_height;

          gimp_display_shell_scroll_center_image (shell,
                                                  center_horizontally,
                                                  center_vertically);

          /* This is basically the best we can do before we get an
           * API for storing the image offset at the start of an
           * image window resize using the mouse
           */
          target_offset_x = shell->offset_x;
          target_offset_y = shell->offset_y;

          if (! center_horizontally)
            {
              target_offset_x = MAX (shell->offset_x, 0);
            }

          if (! center_vertically)
            {
              target_offset_y = MAX (shell->offset_y, 0);
            }

          gimp_display_shell_scroll_set_offset (shell,
                                                target_offset_x,
                                                target_offset_y);
        }

      gimp_display_shell_scroll_clamp_and_update (shell);
      gimp_display_shell_scaled (shell);

      /* Reset */
      shell->size_allocate_from_configure_event = FALSE;
    }
}
Exemple #16
0
// Creates and populates the file operations list.
bool CProgressDialog::CreateFileOpsList(void)
{
	LVCOLUMN iconcolumn;
	POSITION pos;
	LVITEM  itemdata;
	RECT FileQueueRect;

	itemdata.mask =  LVIF_IMAGE | LVIF_STATE;
	itemdata.iImage = 3;
	itemdata.state  = 0;
	itemdata.stateMask = 0;
	itemdata.iSubItem = 0;
	itemdata.iItem = 0;

	// Create image list of folder icons
	m_FileOpImageList.Create(16, 16, ILC_COLOR8, 6, 5);

	// Add folder icons.
	m_FileOpImageList.Add(AfxGetApp()->LoadIcon(IDI_CHECKMARK));
	m_FileOpImageList.Add(AfxGetApp()->LoadIcon(IDI_RIGHTARROW));
	m_FileOpImageList.Add(AfxGetApp()->LoadIcon(IDI_REDX));
	m_FileOpImageList.Add(AfxGetApp()->LoadIcon(IDI_DOT));
	m_FileOpImageList.Add(AfxGetApp()->LoadIcon(IDI_PAUSE));
	m_FileOpImageList.Add(AfxGetApp()->LoadIcon(IDI_BLANK));
	lstQueuedFiles.SetImageList(&m_FileOpImageList, LVSIL_SMALL);

	iconcolumn.pszText = "";
	iconcolumn.cchTextMax = 1;
	iconcolumn.cx = SCALEX(22);
	iconcolumn.fmt = LVCFMT_CENTER;
	iconcolumn.iImage = 0;
	iconcolumn.iOrder = 0;
	iconcolumn.iSubItem = 0;
	iconcolumn.mask = LVCF_TEXT| LVCF_WIDTH| LVCF_SUBITEM | LVCF_FMT;

	lstQueuedFiles.GetClientRect(&FileQueueRect);

	lstQueuedFiles.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
	lstQueuedFiles.InsertColumn(0, &iconcolumn);
	lstQueuedFiles.InsertColumn(1, "Operation", LVCFMT_LEFT, FileQueueRect.right - SCALEX(70) - SCALEX(22) - SCALEX(20), 1);
	lstQueuedFiles.InsertColumn(2, "Complete", LVCFMT_CENTER, SCALEX(70), 1);

	for( pos = m_pApp->pFileList->GetHeadPosition(); pos != NULL; )
	{
		CDBFile* dbfile = (CDBFile*)m_pApp->pFileList->GetNext( pos );

		if (dbfile->bSelected)
		{
			itemdata.iItem = lstQueuedFiles.GetItemCount();
			itemdata.iItem = lstQueuedFiles.InsertItem(&itemdata);
			lstQueuedFiles.SetItem(itemdata.iItem, 1, LVIF_TEXT, "Download " + dbfile->GetFileNameOnly(dbfile->szSrcFileName), 0, 0, 0, 0, 0);
			lstQueuedFiles.SetItem(itemdata.iItem, 2, LVIF_TEXT, "0%", 0, 0, 0, 0, 0);
		}

	}

	for( pos = m_pApp->pFileList->GetHeadPosition(); pos != NULL; )
	{
		CDBFile* dbfile = (CDBFile*)m_pApp->pFileList->GetNext( pos );

		if (dbfile->bSelected&& (dbfile->szSrcFileName.Right(4).MakeUpper() == ".EXE" || 
			dbfile->szSrcFileName.Right(4).MakeUpper() == ".BAT"))
		{
			itemdata.iItem = lstQueuedFiles.GetItemCount();
			itemdata.iItem = lstQueuedFiles.InsertItem(&itemdata);
			lstQueuedFiles.SetItem(itemdata.iItem, 1, LVIF_TEXT, "Extract " + dbfile->GetFileNameOnly(dbfile->szSrcFileName), 0, 0, 0, 0, 0);
			lstQueuedFiles.SetItem(itemdata.iItem, 2, LVIF_TEXT, "0%", 0, 0, 0, 0, 0);
		}
	}

	m_nCurrentQueueIndex = 0;

	return true;
}
Exemple #17
0
static void OnPaint(HWND hWnd) {
	PAINTSTRUCT ps;
	HDC hDC = BeginPaint(hWnd, &ps);

	RECT rc;
	GetClientRect(hWnd, &rc);

	HBRUSH brHilight = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
	HBRUSH brBkgnd = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
	HPEN penBkgnd = CreatePen(PS_NULL, 0, 0);

	int maxTasks = (TaskCount > MAX_TASKS) ? MAX_TASKS : TaskCount;
	int half = maxTasks / 2;
	int firstTask = (AltTabPrgIdx + TaskCount - half) % TaskCount;

	for (int i = 0; i < maxTasks; i++) {
		int act = (firstTask + i) % TaskCount;
		CProgramItem *pi = TaskList[act];

		RECT rcItem;
		rcItem.left = rc.left;
		rcItem.top = rc.top + (i * SCALEY(20));
		rcItem.right = rc.right;
		rcItem.bottom = rc.top + ((i + 1) * SCALEY(20));

		HGDIOBJ hOrigBrush;
		if (act == AltTabPrgIdx) hOrigBrush = SelectObject(hDC, brHilight);
		else hOrigBrush = SelectObject(hDC, brBkgnd);
		HGDIOBJ hOrigPen = SelectObject(hDC, penBkgnd);

		Rectangle(hDC, rcItem.left, rcItem.top, rcItem.right, rcItem.bottom);

		SelectObject(hDC, hOrigPen);
		SelectObject(hDC, hOrigBrush);

		// icon for progs
		TCHAR pathFileName[MAX_PATH];
		GetProcessPathFileName(pi, pathFileName);

		SHFILEINFO sfi = { 0 };
		DWORD imageList;
		imageList = SHGetFileInfo(pathFileName, 0, &sfi, sizeof(sfi), SHGFI_ICON | SHGFI_SYSICONINDEX | SHGFI_SMALLICON);

		if (imageList != 0) {
			ImageList_DrawEx((HIMAGELIST) imageList, sfi.iIcon, hDC,
				rcItem.left + SCALEX(7), rcItem.top + SCALEY(1), SCALEX(16), SCALEY(16), CLR_NONE, CLR_NONE, ILD_NORMAL);
		}

		// font
		HGDIOBJ hOrigFont = SelectObject(hDC, HBoldFont);
		RECT rcText = rcItem;
		rcText.left += SCALEX(25);
		rcText.right -= SCALEX(25);
		if (act == AltTabPrgIdx) SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
		else SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT));
		int oldMode = SetBkMode(hDC, TRANSPARENT);

		UINT uFmt = DT_LEFT | DT_VCENTER | DT_SINGLELINE;
		if (pi->ProcessId != 0) uFmt |= DT_NOPREFIX;		// we don not want to interpret & as mark of hot key

		DrawTextEndEllipsis(hDC, pi->Name, lstrlen(pi->Name), &rcText, uFmt);
		SetBkMode(hDC, oldMode);
		SelectObject(hDC, hOrigFont);

	}

	DeleteObject(brBkgnd);
	DeleteObject(penBkgnd);

	EndPaint(hWnd, &ps);
}
Exemple #18
0
 void clip(const Point& point1, const Point& point2)
 {
     gdImageSetClip(im_, SCALEX(point1.x), SCALEY(point1.y), SCALEX(point2.x), SCALEY(point2.y));
 }
Exemple #19
0
 void line(const Point& point1, const Point& point2, const Color& color)
 {
     gdImageLine(im_, SCALEX(point1.x), SCALEY(point1.y), SCALEX(point2.x), SCALEY(point2.y), color2gd(color));
 }
void
gimp_display_shell_scroll_clamp_offsets (GimpDisplayShell *shell)
{
  GimpImage *image;

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  image = gimp_display_get_image (shell->display);

  if (image)
    {
      gint sw, sh;
      gint min_offset_x;
      gint max_offset_x;
      gint min_offset_y;
      gint max_offset_y;

      sw = SCALEX (shell, gimp_image_get_width  (image));
      sh = SCALEY (shell, gimp_image_get_height (image));

      if (shell->disp_width < sw)
        {
          min_offset_x = 0  - shell->disp_width * OVERPAN_FACTOR;
          max_offset_x = sw - shell->disp_width * (1.0 - OVERPAN_FACTOR);
        }
      else
        {
          gint overpan_amount;

          overpan_amount = shell->disp_width - sw * (1.0 - OVERPAN_FACTOR);

          min_offset_x = 0  - overpan_amount;
          max_offset_x = sw + overpan_amount - shell->disp_width;
        }

      if (shell->disp_height < sh)
        {
          min_offset_y = 0  - shell->disp_height * OVERPAN_FACTOR;
          max_offset_y = sh - shell->disp_height * (1.0 - OVERPAN_FACTOR);
        }
      else
        {
          gint overpan_amount;

          overpan_amount = shell->disp_height - sh * (1.0 - OVERPAN_FACTOR);

          min_offset_y = 0  - overpan_amount;
          max_offset_y = sh + overpan_amount - shell->disp_height;
        }


      /* Handle scrollbar stepper sensitiity */

      gtk_range_set_lower_stepper_sensitivity (GTK_RANGE (shell->hsb),
                                               min_offset_x < shell->offset_x ?
                                               GTK_SENSITIVITY_ON :
                                               GTK_SENSITIVITY_OFF);

      gtk_range_set_upper_stepper_sensitivity (GTK_RANGE (shell->hsb),
                                               max_offset_x > shell->offset_x ?
                                               GTK_SENSITIVITY_ON :
                                               GTK_SENSITIVITY_OFF);

      gtk_range_set_lower_stepper_sensitivity (GTK_RANGE (shell->vsb),
                                               min_offset_y < shell->offset_y ?
                                               GTK_SENSITIVITY_ON :
                                               GTK_SENSITIVITY_OFF);

      gtk_range_set_upper_stepper_sensitivity (GTK_RANGE (shell->vsb),
                                               max_offset_y > shell->offset_y ?
                                               GTK_SENSITIVITY_ON :
                                               GTK_SENSITIVITY_OFF);


      /* Clamp */

      shell->offset_x = CLAMP (shell->offset_x, min_offset_x, max_offset_x);
      shell->offset_y = CLAMP (shell->offset_y, min_offset_y, max_offset_y);
    }
  else
    {
      shell->offset_x = 0;
      shell->offset_y = 0;
    }
}
void
gimp_display_shell_set_initial_scale (GimpDisplayShell *shell,
                                      gdouble           scale,
                                      gint             *display_width,
                                      gint             *display_height)
{
  GimpImage *image;
  GdkScreen *screen;
  gint       image_width;
  gint       image_height;
  gint       shell_width;
  gint       shell_height;
  gint       screen_width;
  gint       screen_height;

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  image = gimp_display_get_image (shell->display);

  screen = gtk_widget_get_screen (GTK_WIDGET (shell));

  image_width  = gimp_image_get_width  (image);
  image_height = gimp_image_get_height (image);

  screen_width  = gdk_screen_get_width (screen)  * 0.75;
  screen_height = gdk_screen_get_height (screen) * 0.75;

  /* We need to zoom before we use SCALE[XY] */
  gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO, scale);

  shell_width  = SCALEX (shell, image_width);
  shell_height = SCALEY (shell, image_height);

  if (shell->display->config->initial_zoom_to_fit)
    {
      /*  Limit to the size of the screen...  */
      if (shell_width > screen_width || shell_height > screen_height)
        {
          gdouble new_scale;
          gdouble current = gimp_zoom_model_get_factor (shell->zoom);

          new_scale = current * MIN (((gdouble) screen_height) / shell_height,
                                     ((gdouble) screen_width)  / shell_width);

          new_scale = gimp_zoom_model_zoom_step (GIMP_ZOOM_OUT, new_scale);

          /*  Since zooming out might skip a zoom step we zoom in
           *  again and test if we are small enough.
           */
          gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO,
                                gimp_zoom_model_zoom_step (GIMP_ZOOM_IN,
                                                           new_scale));

          if (SCALEX (shell, image_width) > screen_width ||
              SCALEY (shell, image_height) > screen_height)
            gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO, new_scale);

          shell_width  = SCALEX (shell, image_width);
          shell_height = SCALEY (shell, image_height);
        }
    }
  else
    {
      /*  Set up size like above, but do not zoom to fit. Useful when
       *  working on large images.
       */
      if (shell_width > screen_width)
        shell_width = screen_width;

      if (shell_height > screen_height)
        shell_height = screen_height;
    }

  if (display_width)
    *display_width = shell_width;

  if (display_height)
    *display_height = shell_height;
}
Exemple #22
0
// Based on the user's font size setting, move and size the controls 
// relative to the splashscreen which is not proportional
void CProgressDialog::MoveAndSizeControls(void)
{
	CRect DialogRect, SplashRect, FileTallyRect, OptionsRect, PauseRect, AbortRect,
		CancelDlgRect, FileQueueRect, FileQueueDialogRect, SplashDlgRect, 
		CurrentFileRect, CurrentFileDialogRect, DownloadStatisticsRect, DownloadStatsDlgRect, CancelRect,
		OKRect, OKDlgRect, OptionsGrpDlgRect, FileInDLRect, ProgressRect;

	int	nLabelWidths = 100, nFromTop = 20, nValuePaddingFromRight = 28;

	GetClientRect(&DialogRect);
	picGenMAPPSplash.GetClientRect(&SplashRect);
	labFileTally.GetClientRect(&FileTallyRect);
	grpOptions.GetClientRect(&OptionsRect);
	btnPause.GetClientRect(&PauseRect);
	btnAbort.GetClientRect(&AbortRect);
	lstQueuedFiles.GetClientRect(&FileQueueRect);
	grpCurrentFile.GetClientRect(&CurrentFileRect);
	grpDownloadStatistics.GetClientRect(&DownloadStatisticsRect);
	btnCancel.GetClientRect(&CancelRect);
	labFileInDL.GetClientRect(&FileInDLRect);
	OverallProgress.GetClientRect(&ProgressRect);
	btnOK.GetClientRect(&OKRect);
	

	// Splashscreen
	::MoveWindow(picGenMAPPSplash.GetSafeHwnd(), DialogRect.right  - SplashRect.right - SCALEX(7), SCALEY(7), SplashRect.right, SplashRect.bottom, true);


	// File Queue List Box
	SplashDlgRect = AdjustToDlgCoordinates(&picGenMAPPSplash);
	::MoveWindow(lstQueuedFiles.GetSafeHwnd(), SCALEX(7), SCALEY(10), SplashDlgRect.left - SCALEX(17), SplashDlgRect.bottom - SCALEY(15), true);
	
	// Maximize width of the "Operation" column using list box width - Percent column width - icon colum width - vert. scroll bar witdh
	lstQueuedFiles.GetClientRect(&FileQueueRect);
	lstQueuedFiles.SetColumnWidth(1, FileQueueRect.right - SCALEX(70) - SCALEX(22) - SCALEX(20));

	
	// Current File group
	// Note that FileTally.bottom represents the label height of all labels
	FileQueueDialogRect = AdjustToDlgCoordinates(&lstQueuedFiles);
	::MoveWindow(grpCurrentFile.GetSafeHwnd(), DialogRect.right - (LONG)(DialogRect.right * .50), FileQueueDialogRect.bottom + SCALEY(7), (int)(DialogRect.right * .50) - SCALEX(7), SCALEY(150), true);
	CurrentFileDialogRect = AdjustToDlgCoordinates(&grpCurrentFile);
	::MoveWindow(lblFileNameKey.GetSafeHwnd(), CurrentFileDialogRect.left + SCALEX(15), CurrentFileDialogRect.top + SCALEY(nFromTop), SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(lblFileName.GetSafeHwnd(), CurrentFileDialogRect.left + SCALEX(15) + SCALEX(nLabelWidths), CurrentFileDialogRect.top + SCALEY(nFromTop), CurrentFileDialogRect.right - CurrentFileDialogRect.left - SCALEX(nValuePaddingFromRight) - SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(lblServerNameKey.GetSafeHwnd(), CurrentFileDialogRect.left + SCALEX(15), CurrentFileDialogRect.top + SCALEY(nFromTop) + FileTallyRect.bottom, SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(lblServerName.GetSafeHwnd(), CurrentFileDialogRect.left + SCALEX(15) + SCALEX(nLabelWidths), CurrentFileDialogRect.top + SCALEY(nFromTop) + FileTallyRect.bottom, CurrentFileDialogRect.right - CurrentFileDialogRect.left - SCALEX(nValuePaddingFromRight) - SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(lblLocationKey.GetSafeHwnd(), CurrentFileDialogRect.left + SCALEX(15), CurrentFileDialogRect.top + SCALEY(nFromTop) + (FileTallyRect.bottom * 2), SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(lblLocation.GetSafeHwnd(), CurrentFileDialogRect.left + SCALEX(15) + SCALEX(nLabelWidths), CurrentFileDialogRect.top + SCALEY(nFromTop) + (FileTallyRect.bottom * 2), CurrentFileDialogRect.right - CurrentFileDialogRect.left - SCALEX(nValuePaddingFromRight) - SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(lblFileBytesDLKey.GetSafeHwnd(), CurrentFileDialogRect.left + SCALEX(15), CurrentFileDialogRect.top + SCALEY(nFromTop) + (FileTallyRect.bottom * 3), SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(lblFileBytesDownloaded.GetSafeHwnd(), CurrentFileDialogRect.left + SCALEX(15) + SCALEX(nLabelWidths), CurrentFileDialogRect.top + SCALEY(nFromTop) + (FileTallyRect.bottom * 3), CurrentFileDialogRect.right - CurrentFileDialogRect.left - SCALEX(nValuePaddingFromRight) - SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(lblNetTransKey.GetSafeHwnd(), CurrentFileDialogRect.left + SCALEX(15), CurrentFileDialogRect.top + SCALEY(nFromTop) + (FileTallyRect.bottom * 4), SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(lblTransport.GetSafeHwnd(), CurrentFileDialogRect.left + SCALEX(15) + SCALEX(nLabelWidths), CurrentFileDialogRect.top + SCALEY(nFromTop) + (FileTallyRect.bottom * 4), CurrentFileDialogRect.right - CurrentFileDialogRect.left - SCALEX(nValuePaddingFromRight) - SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(lblFileTypeKey.GetSafeHwnd(), CurrentFileDialogRect.left + SCALEX(15), CurrentFileDialogRect.top + SCALEY(nFromTop) + (FileTallyRect.bottom * 5), SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(lblFileType.GetSafeHwnd(), CurrentFileDialogRect.left + SCALEX(15) + SCALEX(nLabelWidths), CurrentFileDialogRect.top + SCALEY(nFromTop) + (FileTallyRect.bottom * 5), CurrentFileDialogRect.right - CurrentFileDialogRect.left - SCALEX(nValuePaddingFromRight) - SCALEX(nLabelWidths), FileTallyRect.bottom, true);


	// Download statistics group
	::MoveWindow(grpDownloadStatistics.GetSafeHwnd(), SCALEX(7), FileQueueDialogRect.bottom + SCALEY(7), CurrentFileDialogRect.left - SCALEX(17), SCALEY(150), true);
	DownloadStatsDlgRect = AdjustToDlgCoordinates(&grpDownloadStatistics);
	::MoveWindow(lblFileTallyKey.GetSafeHwnd(), DownloadStatsDlgRect.left + SCALEX(15), DownloadStatsDlgRect.top + SCALEY(nFromTop), SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(labFileTally.GetSafeHwnd(), DownloadStatsDlgRect.left + SCALEX(15) + SCALEX(nLabelWidths), DownloadStatsDlgRect.top + SCALEY(nFromTop), DownloadStatsDlgRect.right - DownloadStatsDlgRect.left - SCALEX(nValuePaddingFromRight) - SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(lblTotalBytesDLKey.GetSafeHwnd(), DownloadStatsDlgRect.left + SCALEX(15), DownloadStatsDlgRect.top + SCALEY(nFromTop) + FileTallyRect.bottom, SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(lblByteTotals.GetSafeHwnd(), DownloadStatsDlgRect.left + SCALEX(15) + SCALEX(nLabelWidths), DownloadStatsDlgRect.top + SCALEY(nFromTop) + FileTallyRect.bottom, DownloadStatsDlgRect.right - DownloadStatsDlgRect.left - SCALEX(nValuePaddingFromRight) - SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(lblDLSpeedKey.GetSafeHwnd(), DownloadStatsDlgRect.left + SCALEX(15), DownloadStatsDlgRect.top + SCALEY(nFromTop) + (FileTallyRect.bottom * 2), SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(lblDownloadSpeed.GetSafeHwnd(), DownloadStatsDlgRect.left + SCALEX(15) + SCALEX(nLabelWidths), DownloadStatsDlgRect.top + SCALEY(nFromTop) + (FileTallyRect.bottom * 2), DownloadStatsDlgRect.right - DownloadStatsDlgRect.left - SCALEX(nValuePaddingFromRight) - SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(lblRemainingTimeKey.GetSafeHwnd(), DownloadStatsDlgRect.left + SCALEX(15), DownloadStatsDlgRect.top + SCALEY(nFromTop) + (FileTallyRect.bottom * 3), SCALEX(nLabelWidths), FileTallyRect.bottom, true);
	::MoveWindow(lblRemainingTime.GetSafeHwnd(), DownloadStatsDlgRect.left + SCALEX(15) + SCALEX(nLabelWidths), DownloadStatsDlgRect.top + SCALEY(nFromTop) + (FileTallyRect.bottom * 3), DownloadStatsDlgRect.right - DownloadStatsDlgRect.left - SCALEX(nValuePaddingFromRight) - SCALEX(nLabelWidths), FileTallyRect.bottom, true);


	// OK and Cancel
	::MoveWindow(btnOK.GetSafeHwnd(), DialogRect.right - OKRect.right - SCALEX(7), DialogRect.bottom - OKRect.bottom - SCALEY(7), OKRect.right, OKRect.bottom, true);
	OKDlgRect = AdjustToDlgCoordinates(&btnOK);
	::MoveWindow(btnCancel.GetSafeHwnd(), OKDlgRect.left - CancelRect.right - SCALEX(15), DialogRect.bottom - CancelRect.bottom - SCALEY(7), CancelRect.right, CancelRect.bottom, true);

	
	// Options group
	CancelDlgRect = AdjustToDlgCoordinates(&btnCancel);
	::MoveWindow(grpOptions.GetSafeHwnd(), CancelDlgRect.left - (int)(PauseRect.right * 2.7) - SCALEX(15), CancelDlgRect.bottom - (PauseRect.bottom * 2) - SCALEY(7), (int)(PauseRect.right * 2.7), (PauseRect.bottom * 2) + SCALEY(4), true);
	OptionsGrpDlgRect = AdjustToDlgCoordinates(&grpOptions);
	::MoveWindow(btnAbort.GetSafeHwnd(), OptionsGrpDlgRect.left + (int)(PauseRect.right * .2), OptionsGrpDlgRect.top + SCALEY(15), AbortRect.right, AbortRect.bottom, true);
	::MoveWindow(btnPause.GetSafeHwnd(), OptionsGrpDlgRect.left + PauseRect.right + SCALEX(22), OptionsGrpDlgRect.top + SCALEY(15), PauseRect.right, PauseRect.bottom, true);

	// Progress bar and status message
	// Bottom of statistics + (Height between statistics and options buttons / 2) - (Height of both controls / 2)
	::MoveWindow(labFileInDL.GetSafeHwnd(), (DialogRect.right / 2) - (int)(DialogRect.right * .45),
		DownloadStatsDlgRect.bottom + ((OptionsGrpDlgRect.top - DownloadStatsDlgRect.bottom) / 2) - ((FileInDLRect.bottom + ProgressRect.bottom) / 2), 
		(int)(DialogRect.right * .9), FileInDLRect.bottom, true);
	::MoveWindow(OverallProgress.GetSafeHwnd(), (DialogRect.right / 2) - (int)(DialogRect.right * .45),
		DownloadStatsDlgRect.bottom + ((OptionsGrpDlgRect.top - DownloadStatsDlgRect.bottom) / 2) - ((FileInDLRect.bottom + ProgressRect.bottom) / 2) + FileInDLRect.bottom, 
		(int)(DialogRect.right * .9), SCALEY(25), true);

	InvalidateRect(NULL);
	UpdateWindow();

}
void
gimp_display_shell_set_initial_scale (GimpDisplayShell *shell,
                                      gdouble           scale,
                                      gint             *display_width,
                                      gint             *display_height)
{
  GimpImage    *image;
  GdkRectangle  workarea;
  gint          image_width;
  gint          image_height;
  gint          monitor_width;
  gint          monitor_height;
  gint          shell_width;
  gint          shell_height;

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  image = gimp_display_get_image (shell->display);

  gdk_monitor_get_workarea (shell->initial_monitor, &workarea);

  image_width  = gimp_image_get_width  (image);
  image_height = gimp_image_get_height (image);

  monitor_width  = workarea.width  * 0.75;
  monitor_height = workarea.height * 0.75;

  /* We need to zoom before we use SCALE[XY] */
  gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO, scale);

  shell_width  = SCALEX (shell, image_width);
  shell_height = SCALEY (shell, image_height);

  if (shell->display->config->initial_zoom_to_fit)
    {
      /*  Limit to the size of the monitor...  */
      if (shell_width > monitor_width || shell_height > monitor_height)
        {
          gdouble new_scale;
          gdouble current = gimp_zoom_model_get_factor (shell->zoom);

          new_scale = current * MIN (((gdouble) monitor_height) / shell_height,
                                     ((gdouble) monitor_width)  / shell_width);

          new_scale = gimp_zoom_model_zoom_step (GIMP_ZOOM_OUT, new_scale, 0.0);

          /*  Since zooming out might skip a zoom step we zoom in
           *  again and test if we are small enough.
           */
          gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO,
                                gimp_zoom_model_zoom_step (GIMP_ZOOM_IN,
                                                           new_scale, 0.0));

          if (SCALEX (shell, image_width)  > monitor_width ||
              SCALEY (shell, image_height) > monitor_height)
            gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO, new_scale);

          shell_width  = SCALEX (shell, image_width);
          shell_height = SCALEY (shell, image_height);
        }
    }
  else
    {
      /*  Set up size like above, but do not zoom to fit. Useful when
       *  working on large images.
       */
      shell_width  = MIN (shell_width,  monitor_width);
      shell_height = MIN (shell_height, monitor_height);
    }

  if (display_width)  *display_width  = shell_width;
  if (display_height) *display_height = shell_height;
}
static void
gimp_display_shell_size_changed_detailed_handler (GimpImage        *image,
                                                  gint              previous_origin_x,
                                                  gint              previous_origin_y,
                                                  gint              previous_width,
                                                  gint              previous_height,
                                                  GimpDisplayShell *shell)
{
  GimpDisplayConfig *config = shell->display->config;
  gboolean           resize_window;

  /* Resize windows only in multi-window mode */
  resize_window = (config->resize_windows_on_resize &&
                   ! GIMP_GUI_CONFIG (config)->single_window_mode);

  if (resize_window)
    {
      GimpImageWindow *window = gimp_display_shell_get_window (shell);

      if (window && gimp_image_window_get_active_shell (window) == shell)
        {
          /* If the window is resized just center the image in it when it
           * has change size
           */
          gimp_image_window_shrink_wrap (window, FALSE);
        }
    }
  else
    {
      GimpImage *image      = gimp_display_get_image (shell->display);
      gint       new_width  = gimp_image_get_width  (image);
      gint       new_height = gimp_image_get_height (image);
      gint       scaled_previous_origin_x;
      gint       scaled_previous_origin_y;
      gboolean   horizontally;
      gboolean   vertically;

      scaled_previous_origin_x = SCALEX (shell, previous_origin_x);
      scaled_previous_origin_y = SCALEY (shell, previous_origin_y);

      horizontally = (SCALEX (shell, previous_width)  >  shell->disp_width  &&
                      SCALEX (shell, new_width)       <= shell->disp_width);
      vertically   = (SCALEY (shell, previous_height) >  shell->disp_height &&
                      SCALEY (shell, new_height)      <= shell->disp_height);

      gimp_display_shell_scroll_set_offset (shell,
                                            shell->offset_x + scaled_previous_origin_x,
                                            shell->offset_y + scaled_previous_origin_y);

      gimp_display_shell_scroll_center_image (shell, horizontally, vertically);

      /* The above calls might not lead to a call to
       * gimp_display_shell_scroll_clamp_and_update() and
       * gimp_display_shell_expose_full() in all cases because when
       * scaling the old and new scroll offset might be the same.
       *
       * We need them to be called in all cases, so simply call them
       * explicitly here at the end
       */
      gimp_display_shell_scroll_clamp_and_update (shell);

      gimp_display_shell_expose_full (shell);
    }
}
/**
 * gimp_display_shell_scale_to_rectangle:
 * @shell:         the #GimpDisplayShell
 * @zoom_type:     whether to zoom in or out
 * @x:             retangle's x in image coordinates
 * @y:             retangle's y in image coordinates
 * @width:         retangle's width in image coordinates
 * @height:        retangle's height in image coordinates
 * @resize_window: whether the display window should be resized
 *
 * Scales and scrolls to a specific image rectangle
 **/
void
gimp_display_shell_scale_to_rectangle (GimpDisplayShell *shell,
                                       GimpZoomType      zoom_type,
                                       gdouble           x,
                                       gdouble           y,
                                       gdouble           width,
                                       gdouble           height,
                                       gboolean          resize_window)
{
  GimpImage *image;
  gdouble    current_scale;
  gdouble    new_scale;
  gdouble    display_width;
  gdouble    display_height;
  gdouble    factor   = 1.0;
  gint       offset_x = 0;
  gint       offset_y = 0;
  gdouble    xres;
  gdouble    yres;
  gdouble    screen_xres;
  gdouble    screen_yres;

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  image = gimp_display_get_image (shell->display);

  width  = MAX (1.0, width);
  height = MAX (1.0, height);

  current_scale = gimp_zoom_model_get_factor (shell->zoom);

  display_width  = FUNSCALEX (shell, shell->disp_width);
  display_height = FUNSCALEY (shell, shell->disp_height);

  switch (zoom_type)
    {
    case GIMP_ZOOM_IN:
      factor = MIN ((display_width  / width),
                    (display_height / height));
      break;

    case GIMP_ZOOM_OUT:
      factor = MAX ((width  / display_width),
                    (height / display_height));
      break;

    default:
      g_return_if_reached ();
      break;
    }

  new_scale = current_scale * factor;

  gimp_image_get_resolution (image, &xres, &yres);
  gimp_display_shell_scale_get_screen_resolution (shell,
                                                  &screen_xres, &screen_yres);

  switch (zoom_type)
    {
    case GIMP_ZOOM_IN:
      /*  move the center of the rectangle to the center of the
       *  viewport:
       *
       *  new_offset = center of rectangle in new scale screen coords
       *               including offset
       *               -
       *               center of viewport in screen coords without
       *               offset
       */
      offset_x = RINT (new_scale * (x + width / 2.0) *
                       screen_xres / xres -
                       (shell->disp_width / 2.0));

      offset_y = RINT (new_scale * (y + height / 2.0) *
                       screen_yres / yres -
                       (shell->disp_height / 2.0));
      break;

    case GIMP_ZOOM_OUT:
      /*  move the center of the viewport to the center of the
       *  rectangle:
       *
       *  new_offset = center of viewport in new scale screen coords
       *               including offset
       *               -
       *               center of rectangle in screen coords without
       *               offset
       */
      offset_x = RINT (new_scale * UNSCALEX (shell,
                                             shell->offset_x +
                                             shell->disp_width / 2.0) *
                       screen_xres / xres -
                       (SCALEX (shell, x + width / 2.0) -
                        shell->offset_x));

      offset_y = RINT (new_scale * UNSCALEY (shell,
                                             shell->offset_y +
                                             shell->disp_height / 2.0) *
                       screen_yres / yres -
                       (SCALEY (shell, y + height / 2.0) -
                        shell->offset_y));
      break;

    default:
      break;
    }

  if (new_scale != current_scale   ||
      offset_x  != shell->offset_x ||
      offset_y  != shell->offset_y)
    {
      gimp_display_shell_scale_by_values (shell,
                                          new_scale,
                                          offset_x, offset_y,
                                          resize_window);
    }
}
Exemple #26
0
GimpCanvasItem *
gimp_brush_tool_create_outline (GimpBrushTool *brush_tool,
                                GimpDisplay   *display,
                                gdouble        x,
                                gdouble        y)
{
  GimpBrushCore        *brush_core;
  GimpPaintOptions     *options;
  GimpDisplayShell     *shell;
  const GimpBezierDesc *boundary = NULL;
  gint                  width    = 0;
  gint                  height   = 0;

  g_return_val_if_fail (GIMP_IS_BRUSH_TOOL (brush_tool), NULL);
  g_return_val_if_fail (GIMP_IS_DISPLAY (display), NULL);

  if (! GIMP_PAINT_TOOL (brush_tool)->draw_brush)
    return NULL;

  brush_core = GIMP_BRUSH_CORE (GIMP_PAINT_TOOL (brush_tool)->core);
  options    = GIMP_PAINT_TOOL_GET_OPTIONS (brush_tool);
  shell      = gimp_display_get_shell (display);

  if (! brush_core->main_brush || ! brush_core->dynamics)
    return NULL;

  if (brush_core->scale > 0.0)
    boundary = gimp_brush_transform_boundary (brush_core->main_brush,
                                              brush_core->scale,
                                              brush_core->aspect_ratio,
                                              brush_core->angle,
                                              brush_core->hardness,
                                              &width,
                                              &height);

  /*  don't draw the boundary if it becomes too small  */
  if (boundary                   &&
      SCALEX (shell, width)  > 4 &&
      SCALEY (shell, height) > 4)
    {
      x -= width  / 2.0;
      y -= height / 2.0;

      if (gimp_paint_options_get_brush_mode (options) == GIMP_BRUSH_HARD)
        {
#define EPSILON 0.000001
          /*  Add EPSILON before rounding since e.g.
           *  (5.0 - 0.5) may end up at (4.499999999....)
           *  due to floating point fnords
           */
          x = RINT (x + EPSILON);
          y = RINT (y + EPSILON);
#undef EPSILON
        }

      return gimp_canvas_path_new (shell, boundary, x, y, FALSE,
                                   GIMP_PATH_STYLE_OUTLINE);
    }

  return NULL;
}