コード例 #1
1
ファイル: main_template.cpp プロジェクト: EQ4/axLib
int main(int argc, char** argv)
{
	// Create display.
	Display* dpy = CreateDisplay();
	int screen = XDefaultScreen(dpy);
	int depth = XDefaultDepth(dpy, screen);
	Window root_win = XDefaultRootWindow(dpy);
	int numScreens = 1;
	Drawable screens[] = { root_win };
	axRect dpy_rect = axRect(0, 0, XDisplayWidth(dpy, screen),
                   			 XDisplayHeight(dpy, screen));

	// Setup GLX.
	XVisualInfo* v_info = GetGLXVisualInfo(dpy);
	Visual* visual = v_info->visual;

	Colormap colormap = XCreateColormap(dpy, root_win, visual, AllocNone);
	glEnable(GL_TEXTURE_2D);

	// Create window.
	axRect window_rect(0, 0, 500, 500);
	
	Window win = CreateWindow(dpy, window_rect, root_win, colormap, v_info);
	
	// Pixmap back_buffer = XCreatePixmap(dpy, win,
 //                                       window_rect.size.x, window_rect.size.y,
 //                                       screen);
	
	GLXContext glx_context = glXCreateContext(dpy, v_info, NULL, GL_TRUE);
	//GC gc;
	glXMakeCurrent(dpy, win, glx_context);
	//glXMakeCurrent( AX_GLOBAL_DISPLAY, win, gc->GetGLX_GC() );

	//Window win = XCreateSimpleWindow(dpy, RootWindow(dpy, s), 10, 10, 660, 200, 1,
	//                               BlackPixel(dpy, s), WhitePixel(dpy, s));

    XSelectInput(dpy, win,
             	 StructureNotifyMask |
             	 ExposureMask        |
             	 ButtonPressMask     |
             	 ButtonReleaseMask   |
             	 PointerMotionMask   |
             	 EnterWindowMask     |
             	 LeaveWindowMask     |
             	 FocusChangeMask );

    // Show window.
    XMapWindow(dpy, win);
    //XFlush(dpy);

	XStoreName(dpy, win, "axLib");


  //XSelectInput(dpy, win, ExposureMask | KeyPressMask);
  //XMapWindow(dpy, win);
 
// #if defined(__APPLE_CC__)  
//   XStoreName(dpy, win, "Geeks3D.com - X11 window under Mac OS X (Lion)");
// #else
//   XStoreName(dpy, win, "Geeks3D.com - X11 window under Linux (Mint 10)");
// #endif  
 
  
 
  MainLoop(dpy, win, window_rect);
 
  XDestroyWindow(dpy, win);
  XCloseDisplay(dpy);
  return 0;
}
コード例 #2
0
ファイル: menu_item_widget.cpp プロジェクト: basisbit/neogfx
	point menu_item_widget::sub_menu_position() const
	{
		if (iMenu.type() == i_menu::MenuBar)
			return window_rect().bottom_left() + surface().surface_position();
		else
			return window_rect().top_right() + surface().surface_position();
	}
コード例 #3
0
ファイル: window_test_gtk.cpp プロジェクト: Archlizz/javacef
void SetPos(CefWindowHandle handle, int x, int y, int width, int height) {
  GtkWindow* window = GetWindow(handle);
  GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(window));

  // Make sure the window isn't minimized or maximized.
  if (IsMaximized(window))
    gtk_window_unmaximize(window);
  else
    gtk_window_present(window);

  // Retrieve information about the display that contains the window.
  GdkScreen* screen = gdk_screen_get_default();
  gint monitor = gdk_screen_get_monitor_at_window(screen, gdk_window);
  GdkRectangle rect;
  gdk_screen_get_monitor_geometry(screen, monitor, &rect);

  // Make sure the window is inside the display.
  CefRect display_rect(rect.x, rect.y, rect.width, rect.height);
  CefRect window_rect(x, y, width, height);
  ModifyBounds(display_rect, window_rect);

  gdk_window_move_resize(gdk_window, window_rect.x, window_rect.y,
                         window_rect.width, window_rect.height);
}
コード例 #4
0
void CPrint::OnPaint() 
{
	if(m_bRepaintPreview){
		CWnd* item = GetDlgItem(IDC_PREVIEW_FRAME);
		CRect prerect;
		item->GetWindowRect(prerect);
		ScreenToClient(prerect);
		
		int obase = m_Calculator->m_base;
		m_Calculator->m_base = 10;
		
		UpdateData();
		CDC print_dc;
		print_dc.Attach(m_PrintDlg.GetPrinterDC());         // Attach a printer DC
		
		CPaintDC dc(this); // device context for painting
		CPoint ul(prerect.left + 10, prerect.top + 19);
		CRect print_rect(0,0, print_dc.GetDeviceCaps(HORZRES), print_dc.GetDeviceCaps(VERTRES));
		CRect window_rect(0,0,prerect.Width() - 20, prerect.Height() - 25);
		double scale_factor;
		
		TRACE("print_rect.Width=%d print_rect.Height=%d\n", print_rect.Width(), print_rect.Height());
		
		if((double(print_rect.Width())/double(print_rect.Height())) >
			(double(window_rect.Width())/double(window_rect.Height())))
			scale_factor = double(window_rect.Width()) / double(print_rect.Width());
		else
			scale_factor = double(window_rect.Height()) / double(print_rect.Height());
		
		CPoint start;
		start.x = ul.x + (double(window_rect.Width() - (print_rect.Width() * scale_factor)) / 2.0);
		start.y = ul.y + (double(window_rect.Height() - (print_rect.Height() * scale_factor)) / 2.0);
		
		//////////// DRAW PAPER
		CBrush brush(RGB(255,255,255)), *pOldBrush;
		pOldBrush = dc.SelectObject(&brush);
		CPen penBlack;
		penBlack.CreatePen(PS_SOLID, 0, RGB(0,0,0));
		CPen* pOldPen = dc.SelectObject(&penBlack);
		
		dc.Rectangle(start.x - 3, start.y - 3, 
			start.x + (print_rect.Width() * scale_factor) + 3, 
			start.y + (print_rect.Height() * scale_factor) + 3);
		dc.SelectObject(pOldPen);
		//////////// END DRAW PAPER
		
		//////////// Calculate width and height
		long double w, h;
		
		if(m_iPageSize == 1){
			double scale;
			if((double(print_rect.Width()) / double(m_graph_width)) > 
				(double(print_rect.Height()) / double(m_graph_height)))
				scale = (double(print_rect.Height()) / 2.0) / double(m_graph_height);
			else
				scale = (double(print_rect.Width()) / 2.0) / double(m_graph_width);
			
			h = (double(m_graph_height)/double(print_dc.GetDeviceCaps(LOGPIXELSY))) * scale;
			w = (double(m_graph_width)/double(print_dc.GetDeviceCaps(LOGPIXELSX))) * scale;
		}
		else if(m_iPageSize == 0){
			w = double(print_rect.Width()) / double(print_dc.GetDeviceCaps(LOGPIXELSX));
			h = double(print_rect.Height()) / double(print_dc.GetDeviceCaps(LOGPIXELSY));
		}
		else{
			m_Calculator->StringToDecimal(m_sWidth, 10, w);
			m_Calculator->StringToDecimal(m_sHeight, 10, h);
			w = m_Calculator->abs(w);
			h = m_Calculator->abs(h);
			// convert width
			if(m_sWUnits == "cm")
				w *= 0.39370078740157;
			// convert height
			if(m_sHUnits == "cm")
				h *= 0.39370078740157;
		}
		
		// I now have desired width and height in inches
		CPoint gstart(start.x, start.y);
		
		double max_h((double(print_rect.Height()) / double(print_dc.GetDeviceCaps(LOGPIXELSY))));
		double max_w((double(print_rect.Width()) / double(print_dc.GetDeviceCaps(LOGPIXELSX))));
		
		// resize max height based on printing options
		if(m_bTitleOn){
			max_h -= (0.25 + 0.125);
			gstart.y += ((0.25 + 0.125) * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor);
		}
		if(m_bEquations)
			max_h -= (1.5 + 0.125);
		
		// error check for desired size too large too large
		if(w > (max_w + 0.0001)){
			w = max_w;
			m_Calculator->DecimalToString(m_sWidth, w);
			if(m_iPageSize == 2)
				SetDimensionsW(w);
		}
		if(h > (max_h + 0.0001)){
			h = max_h;
			m_Calculator->DecimalToString(m_sHeight, h);
			if(m_iPageSize == 2)
				SetDimensionsH(h);
		}
		
		// now convert inches into device units (ie device pixels)
		w *= print_dc.GetDeviceCaps(LOGPIXELSX) * scale_factor;			// scale w for window
		h *= print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor;			// scale h for window
		//////////// END Calculate width and height
		
		//////////// Draw Graph Rectangle
		CBrush gray(RGB(128,128,128));
		dc.SelectObject(&gray);
		
		if(m_bCenter){
			gstart.x += ((print_rect.Width() * scale_factor) / 2.0) - (w / 2.0);
			
			double th(h);
			if(m_bTitleOn)
				th += ((0.25 + 0.125) * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor);
			if(m_bEquations)
				th += ((1.5 + 0.125) * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor);
			
			gstart.y += (double(print_rect.Height() * scale_factor) / 2.0) - (double(th) / 2.0);
		}
		dc.Rectangle(gstart.x, 
			gstart.y, 
			gstart.x + w, 
			gstart.y + h);
		//////////// END Draw Graph Rectangle
		
		if(m_bEquations){
			//////////// Draw Equations List
			CPoint estart(gstart.x, gstart.y + h +(0.125 * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor));
			CPoint eend(gstart.x + w, gstart.y + h + (1.625 * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor));
			
			int ew(w);
			
			if(ew < (5 * print_dc.GetDeviceCaps(LOGPIXELSX) * scale_factor)) // check for min eqs list size
				ew = (5 * print_dc.GetDeviceCaps(LOGPIXELSX) * scale_factor);
			
			if(ew > (max_w * print_dc.GetDeviceCaps(LOGPIXELSX) * scale_factor))
				ew = max_w;
			if((eend.y - estart.y) > (max_h * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor))
				eend.y = estart.y + max_h;
			
			estart.x = (gstart.x + (double(w) / 2.0)) - (double(ew) / 2.0);
			if(estart.x < start.x)
				estart.x = start.x;
			
			eend.x = estart.x + ew;
			
			dc.SelectObject(&brush);
			dc.Rectangle(estart.x, estart.y, eend.x, eend.y);
			//////////// END Draw Equations List
		}
		
		if(m_bTitleOn){
			//////////// Draw Title Rectangle
			dc.SelectObject(&brush);
			dc.Rectangle(start.x, 
				start.y, 
				start.x + (print_rect.Width() * scale_factor), 
				start.y + (0.25 * print_dc.GetDeviceCaps(LOGPIXELSY) * scale_factor));
			//////////// END Draw Title Rectangle
		}
		
		dc.SelectObject(pOldBrush);
		print_dc.Detach();
		UpdateData(true);
		
		m_Calculator->m_base = obase;
	}
	
}
コード例 #5
0
bool create_texture_mipmaps(dds_texture &work_tex, const crn_comp_params &params, const crn_mipmap_params &mipmap_params, bool generate_mipmaps)
{
    crn_comp_params new_params(params);

    bool generate_new_mips = false;

    switch (mipmap_params.m_mode)
    {
    case cCRNMipModeUseSourceOrGenerateMips:
    {
        if (work_tex.get_num_levels() == 1)
            generate_new_mips = true;
        break;
    }
    case cCRNMipModeUseSourceMips:
    {
        break;
    }
    case cCRNMipModeGenerateMips:
    {
        generate_new_mips = true;
        break;
    }
    case cCRNMipModeNoMips:
    {
        work_tex.discard_mipmaps();
        break;
    }
    default:
    {
        CRNLIB_ASSERT(0);
        break;
    }
    }

    rect window_rect(mipmap_params.m_window_left, mipmap_params.m_window_top, mipmap_params.m_window_right, mipmap_params.m_window_bottom);

    if (!window_rect.is_empty())
    {
        if (work_tex.get_num_faces() > 1)
        {
            console::warning(L"Can't crop cubemap textures");
        }
        else
        {
            console::info(L"Cropping input texture from window (%ux%u)-(%ux%u)", window_rect.get_left(), window_rect.get_top(), window_rect.get_right(), window_rect.get_bottom());

            if (!work_tex.crop(window_rect.get_left(), window_rect.get_top(), window_rect.get_width(), window_rect.get_height()))
                console::warning(L"Failed cropping window rect");
        }
    }

    int new_width = work_tex.get_width();
    int new_height = work_tex.get_height();

    if ((mipmap_params.m_clamp_width) && (mipmap_params.m_clamp_height))
    {
        if ((new_width > (int)mipmap_params.m_clamp_width) || (new_height > (int)mipmap_params.m_clamp_height))
        {
            if (!mipmap_params.m_clamp_scale)
            {
                if (work_tex.get_num_faces() > 1)
                {
                    console::warning(L"Can't crop cubemap textures");
                }
                else
                {
                    new_width = math::minimum<uint>(mipmap_params.m_clamp_width, new_width);
                    new_height = math::minimum<uint>(mipmap_params.m_clamp_height, new_height);
                    console::info(L"Clamping input texture to %ux%u", new_width, new_height);
                    work_tex.crop(0, 0, new_width, new_height);
                }
            }
        }
    }

    if (mipmap_params.m_scale_mode != cCRNSMDisabled)
    {
        bool is_pow2 = math::is_power_of_2((uint32)new_width) && math::is_power_of_2((uint32)new_height);

        switch (mipmap_params.m_scale_mode)
        {
        case cCRNSMAbsolute:
        {
            new_width = (uint)mipmap_params.m_scale_x;
            new_height = (uint)mipmap_params.m_scale_y;
            break;
        }
        case cCRNSMRelative:
        {
            new_width = (uint)(mipmap_params.m_scale_x * new_width + .5f);
            new_height = (uint)(mipmap_params.m_scale_y * new_height + .5f);
            break;
        }
        case cCRNSMLowerPow2:
        {
            if (!is_pow2)
                math::compute_lower_pow2_dim(new_width, new_height);
            break;
        }
        case cCRNSMNearestPow2:
        {
            if (!is_pow2)
            {
                int lwidth = new_width;
                int lheight = new_height;
                math::compute_lower_pow2_dim(lwidth, lheight);

                int uwidth = new_width;
                int uheight = new_height;
                math::compute_upper_pow2_dim(uwidth, uheight);

                if (labs(new_width - lwidth) < labs(new_width - uwidth))
                    new_width = lwidth;
                else
                    new_width = uwidth;

                if (labs(new_height - lheight) < labs(new_height - uheight))
                    new_height = lheight;
                else
                    new_height = uheight;
            }
            break;
        }
        case cCRNSMNextPow2:
        {
            if (!is_pow2)
                math::compute_upper_pow2_dim(new_width, new_height);
            break;
        }
        default:
            break;
        }
    }

    if ((mipmap_params.m_clamp_width) && (mipmap_params.m_clamp_height))
    {
        if ((new_width > (int)mipmap_params.m_clamp_width) || (new_height > (int)mipmap_params.m_clamp_height))
        {
            if (mipmap_params.m_clamp_scale)
            {
                new_width = math::minimum<uint>(mipmap_params.m_clamp_width, new_width);
                new_height = math::minimum<uint>(mipmap_params.m_clamp_height, new_height);
            }
        }
    }

    new_width = math::clamp<int>(new_width, 1, cCRNMaxLevelResolution);
    new_height = math::clamp<int>(new_height, 1, cCRNMaxLevelResolution);

    if ((new_width != (int)work_tex.get_width()) || (new_height != (int)work_tex.get_height()))
    {
        console::info(L"Resampling input texture to %ux%u", new_width, new_height);

        const char* pFilter = crn_get_mip_filter_name(mipmap_params.m_filter);

        bool srgb = mipmap_params.m_gamma_filtering != 0;

        dds_texture::resample_params res_params;
        res_params.m_pFilter = pFilter;
        res_params.m_wrapping = mipmap_params.m_tiled != 0;
        if (work_tex.get_num_faces())
            res_params.m_wrapping = false;
        res_params.m_renormalize = mipmap_params.m_renormalize != 0;
        res_params.m_filter_scale = 1.0f;
        res_params.m_gamma = mipmap_params.m_gamma;
        res_params.m_srgb = srgb;
        res_params.m_multithreaded = (params.m_num_helper_threads > 0);

        if (!work_tex.resize(new_width, new_height, res_params))
        {
            console::error(L"Failed resizing texture!");
            return false;
        }
    }

    if ((generate_new_mips) && (generate_mipmaps))
    {
        bool srgb = mipmap_params.m_gamma_filtering != 0;

        const char* pFilter = crn_get_mip_filter_name(mipmap_params.m_filter);

        dds_texture::generate_mipmap_params gen_params;
        gen_params.m_pFilter = pFilter;
        gen_params.m_wrapping = mipmap_params.m_tiled != 0;
        gen_params.m_renormalize = mipmap_params.m_renormalize != 0;
        gen_params.m_filter_scale = mipmap_params.m_blurriness;
        gen_params.m_gamma = mipmap_params.m_gamma;
        gen_params.m_srgb = srgb;
        gen_params.m_multithreaded = params.m_num_helper_threads > 0;
        gen_params.m_max_mips = mipmap_params.m_max_levels;
        gen_params.m_min_mip_size = mipmap_params.m_min_mip_size;

        console::info(L"Generating mipmaps using filter \"%S\"", pFilter);

        timer tm;
        tm.start();
        if (!work_tex.generate_mipmaps(gen_params, true))
        {
            console::error(L"Failed generating mipmaps!");
            return false;
        }
        double t = tm.get_elapsed_secs();

        console::info(L"Generated %u mipmap levels in %3.3fs", work_tex.get_num_levels() - 1, t);
    }

    return true;
}