How to center the main Application Window in MOTIF in the middle of the computer screen? - motif

How to center the main application window of a MOTIF Widget in the center of the computer screen ? for example a form Widget here.
The code is ready and working but the window appears on the left upper side on the screen.
#include <Xm/Form.h>
#include <Xm/Label.h>
#include <Xm/PushB.h>
void main ( int argc, char ** argv )
{
Widget shell, form, label, button;
XtAppContext app;
int i;
shell = XtAppInitialize ( &app, "Formtest", NULL, 0,
&argc, argv, NULL, NULL, 0 );
form = XtCreateManagedWidget ( "form", xmFormWidgetClass,
shell, NULL, 0 );
XtVaSetValues ( form,
XmNwidth, 500,
XmNheight, 300,
NULL );
label = XtVaCreateManagedWidget ( "label", xmLabelWidgetClass,
form, NULL, 0 );
button = XtVaCreateManagedWidget ( "button", xmPushButtonWidgetClass,
form,
XmNbottomAttachment, XmATTACH_FORM,
0 );
XtVaSetValues ( button,
XmNwidth, 100,
XmNheight, 50,
NULL );
XtRealizeWidget ( shell );
XtAppMainLoop ( app );
}`````
This MOTIF Windows is working correct already.
The only thing i want to do is to position it in the middle of the computerscreen.
It has something to do with the command Xtscreen.

Get the Screen height and width and do your adjustments.
Try the following:
#include <Xm/Form.h>
#include <Xm/Label.h>
#include <Xm/PushB.h>
int main ( int argc, char ** argv )
{
Widget shell, form, label, button;
XtAppContext app;
int i;
shell = XtAppInitialize ( &app, "Formtest", NULL, 0,
&argc, argv, NULL, NULL, 0 );
Screen * s = XtScreen(shell);
int dw = WidthOfScreen(s);
int dh = HeightOfScreen( s );
Dimension px = (dw-500)/2;
Dimension py = (dh-300)/2;
XtVaSetValues ( shell,
XmNwidth, 500,
XmNheight, 300,
XmNx, px,
XmNy, py,
NULL );
form = XtCreateManagedWidget ( "form", xmFormWidgetClass,
shell, NULL, 0 );
label = XtVaCreateManagedWidget ( "label", xmLabelWidgetClass,
form, NULL, 0 );
button = XtVaCreateManagedWidget ( "button", xmPushButtonWidgetClass,
form,
XmNbottomAttachment, XmATTACH_FORM,
0 );
XtVaSetValues ( button,
XmNwidth, 100,
XmNheight, 50,
NULL );
XtRealizeWidget ( shell );
XtAppMainLoop ( app );
}

Related

Is there a way to let the printer handling multiple copies when printing using gdi plus?

I'm printing using the hDC I get from the print dialog and was wondering if there's a way to let the printer/printer driver/OS handle multiple copies and collation settings? I can of course print the pages multiple times, but that doesn't feel like the right way to go about this...
This is roughly what my code looks like now:
ULONG_PTR gdiplusToken = 0;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup( &gdiplusToken, &gdiplusStartupInput, NULL );
DOCINFO documentInfo;
memset( &documentInfo, 0, sizeof( documentInfo ) );
documentInfo.cbSize = sizeof( documentInfo );
theDocumentInfo.lpszDocName = mDocumentName;
HDC printerHDC = printDialogData.hDC; // printDialogData is PRINTDLG struct from PrintDlg
::StartDoc( printerHDC, &documentInfo );
for( int page = 0; page < numberOfPages; ++ page )
{
::StartPage( printerHDC );
// print the page
::EndPage( printerHDC );
}
::EndDoc( printerHDC );
::DeleteDC( printerHDC );
Gdiplus::GdiplusShutdown( gdiplusToken );

How can I create Direct3d 11 renderer using SDL 2.0.9

In my project I must use SDL_BLENDOPERATION_MAXIMUM via SDL_ComposeCustomBlendMode() which is supported in SDL 2.0.9 by direct3d11 renderer only. I have Windows 8.1 and GeForce GTX750 Ti with updated drivers. My system should support DirectX 11 renderending.
Changing defines in SDL_config.h or SDL_config_windows.h (SDL_VIDEO_RENDER_D3D11 to 1 and SDL_VIDEO_RENDER_D3D to 0) doesn't help.
I tried to fill preprocessor difinitions with defines SDL_VIDEO_RENDER_D3D11 or WINRT according to SDL source code. But it doesn't help.
What should I do to activate direct3d11 renderer so I can use blend mode max?
My test code:
#include "SDL.h"
#include "SDL_image.h"
#include <string>
using namespace std;
int main( int argc, char *argv[] ) {
SDL_Init( SDL_INIT_VIDEO );
IMG_Init( IMG_INIT_PNG );
SDL_SetHintWithPriority( SDL_HINT_RENDER_DRIVER, "direct3d11", SDL_HINT_OVERRIDE );
SDL_Window *window = SDL_CreateWindow( "Testing", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
1200, 600, SDL_WINDOW_RESIZABLE );
SDL_Renderer *renderer = SDL_CreateRenderer( window, -1, SDL_RENDERER_ACCELERATED );
SDL_RendererInfo *rendererInfo = new SDL_RendererInfo();
SDL_RendererInfo *driverInfo = new SDL_RendererInfo();
SDL_GetRendererInfo( renderer, rendererInfo );
int drivers = SDL_GetNumRenderDrivers();
string availableDrivers = " (";
for ( int i = 0; i < drivers; ++i ) {
SDL_GetRenderDriverInfo( i, driverInfo );
string driverName = driverInfo->name;
if ( i == drivers - 1 ) {
availableDrivers += driverName;
}
else {
availableDrivers += driverName + ", ";
}
}
availableDrivers += ")";
string path = SDL_GetBasePath();
SDL_Surface *surfRed = IMG_Load( (path + "\\Red.png").c_str() );
SDL_Texture *textRed = SDL_CreateTextureFromSurface( renderer, surfRed );
SDL_FreeSurface( surfRed );
SDL_Surface *surfBlue = IMG_Load( ( path + "\\Blue.png" ).c_str() );
SDL_Texture *textBlue = SDL_CreateTextureFromSurface( renderer, surfBlue );
SDL_FreeSurface( surfBlue );
SDL_Rect destRed, destBlue;
destRed.x = 128;
destRed.y = 128;
destBlue.x = 196;
destBlue.y = 196;
SDL_QueryTexture( textRed, NULL, NULL, &destRed.w, &destRed.h );
SDL_QueryTexture( textBlue, NULL, NULL, &destBlue.w, &destBlue.h );
SDL_BlendMode blendMode = SDL_ComposeCustomBlendMode( SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_MAXIMUM,
SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_MAXIMUM );
SDL_SetTextureBlendMode( textRed, blendMode );
SDL_SetTextureBlendMode( textBlue, blendMode );
// SDL_SetRenderDrawBlendMode( renderer, blendMode );
string info = rendererInfo->name + availableDrivers + " " + SDL_GetError();
SDL_SetWindowTitle( window, info.c_str() );
SDL_SetRenderDrawColor( renderer, 0, 0, 0, 255 );
SDL_Event event;
bool isRunning = true;
while ( isRunning ) {
if ( SDL_PollEvent( &event ) ) {
if ( event.type == SDL_QUIT ) {
isRunning = false;
}
}
SDL_RenderClear( renderer );
SDL_RenderCopy( renderer, textRed, NULL, &destRed );
SDL_RenderCopy( renderer, textBlue, NULL, &destBlue );
SDL_RenderPresent( renderer );
}
delete driverInfo;
delete rendererInfo;
SDL_DestroyTexture( textRed );
SDL_DestroyTexture( textBlue );
SDL_DestroyRenderer( renderer );
SDL_DestroyWindow( window );
IMG_Quit();
SDL_Quit();
return 0;
}
Window title is "direct3d (direct3d, opengl, opengles2, software) This operration is not supported". It works fine when I change to SDL_BLENDOPERATION_ADD, but it's not what I want. If I uncomment renderer blend mode it doesn't help too.
Enumerate the supported renderer backends via SDL_GetNumRenderDrivers() and SDL_GetRenderDriverInfo().
Note the index of the direct3d11 driver, if it exists.
Pass index into SDL_CreateRenderer().
All together:
SDL_Init( SDL_INIT_VIDEO );
SDL_Window* window = SDL_CreateWindow( "SDL2", 0, 0, 640, 480, SDL_WINDOW_SHOWN );
SDL_Renderer* renderer = nullptr;
for( int i = 0; i < SDL_GetNumRenderDrivers(); ++i )
{
SDL_RendererInfo rendererInfo = {};
SDL_GetRenderDriverInfo( i, &rendererInfo );
if( rendererInfo.name != std::string( "direct3d11" ) )
{
continue;
}
renderer = SDL_CreateRenderer( window, i, 0 );
break;
}
Note that what you are setting with SDL_VIDEO_RENDER_D3D and friends are compile time definitions for building SDL with D3D support.
To do this at runtime:
Sometime after SDL_Init() and before creating your window/renderer set a hint for it.
// returns true on success or false on failure
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "direct3d11");
However, this will only work on Windows, and I believe d3d is already the default renderer for windows. If your version of windows supports d3d11 that is what SDL should use. I strongly suspect you already have a d3d11 renderer and your problem is with how you instantiate or use your custom blend mode.
To verify you have a d3d11 renderer:
SDL_RendererInfo info;
SDL_GetRendererInfo(renderer, &info);
printf("%s", info.name);
To create a custom blend mode with SDL_BLENDOPERATION_MAXIMUM
SDL_BlendMode blender = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA, // change this to suit your needs
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, // change this to suit your needs
SDL_BLENDOPERATION_MAXIMUM,
SDL_BLENDFACTOR_ONE, // change this to suit your needs
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, // change this to suit your needs
SDL_BLENDOPERATION_MAXIMUM);
SDL_SetTextureBlendMode(texture, blender); // blender is your custom mode
SDL_SetRenderDrawBlendMode(renderer, blender); // blender is your custom mode
I cant imagine the above blender is actually the combination of factors/operations you want, but you didn't post your actual code to work off.

Error with VAO on Nexus 4 device only

I've got a strange error on my nexus 4 with OpenGL ES2 when I use vertex array objects.
Here is some informations:
Everything work when I don't use VAO
Everything work on others device and on an Ipad 2 with and without VAO
glGetError() didn't return error
Due to the error some glitch appear in the game (some elements take another apparence)
My VBO are dynamics (I update them with glBufferData)
Here is the error:
Adreno-ES20(16818): : validate_vertex_attrib_state: No vertex attrib is enabled in a draw call!
And here is my code:
void Renderer::setVertexBuffer( Uint32 stream, const Base* vertexBuffer, std::size_t stride, Uint32 startVertex, Uint32 endVertex )
{
static const bool VAOSupported = this->isExtensionPresent(VertexArrayObject);
if( VAOSupported )
{
if( vertexBuffer->vao.isReady() == false )
{
// Bind VAO.
glBindVertexArrayOES( vertexBuffer->vao.getId() );
// Bind filled VBO.
glCheck( glBindBuffer( GL_ARRAY_BUFFER, vertexBuffer->getId() ) );
// Set attributs with vertex format.
this->applyVertexFormat( startVertex, endVertex );
// Unbind buffer and VAO.
glBindVertexArrayOES(0);
vertexBuffer->vao.isReady(true);
}
glBindVertexArrayOES( vertexBuffer->vao.getId() );
}
else
{
glBindVertexArrayOES(0);
glCheck( glBindBuffer( GL_ARRAY_BUFFER, vertexBuffer->getId() ) );
this->applyVertexFormat( startVertex, endVertex );
}
}
////////////////////////////////////////////////////////////
void Renderer::setIndexBuffer( const Buffer* indexBuffer, std::size_t stride )
{
glCheck( glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBuffer->getId() ) );
this->usedIndexBufferStride = stride;
}
////////////////////////////////////////////////////////////
void Renderer::applyVertexFormat( Uint32 startVertex, Uint32 endVertex )
{
const Uint32 stride = this->vertexFormat->getStride();
for( Uint32 i = 0; i < this->vertexFormat->getAttributCount(); i++ )
{
const VertexElement& element = this->vertexFormat->getAttribut(i);
glCheck( glEnableVertexAttribArray( element.usage ) );
glCheck( glVertexAttribPointer( element.usage,
element.type,
element.type,
element.normalize,
stride,
BUFFER_OFFSET(element.offset + startVertex * stride ) ) );
}
}
And here is how I use it :
renderer->setFormat(geometry->getFormat()); // Only save a pointer to the format to use in apply method.
renderer->setVertexBuffer(geometry->getVertexBuffer());
renderer->setIndexBuffer(geometry->getIndexBuffer());
renderer->draw(GL_TRIANGLES, geometry->indiceCount);
Are you sure usage is an appropriate name for the field that defines which attribute array to associate the pointer with? Buffer objects already have a property called usage (e.g. GL_DYNAMIC_DRAW). location might make more sense.
You have a much more serious issue in your code, however:
element.type cannot be both the type of your data and the number of components. glVertexAttribPointer (...) only accepts 1, 2, 3 or 4 components, an enumerant like GL_FLOAT has a value much larger than 4.
Assuming glCheck( ... ) correctly wraps glGetError (...), this situation should be indicating GL_INVALID_VALUE.
This leads me to believe that your loop in void Renderer::applyVertexFormat( Uint32 startVertex, Uint32 endVertex ) is never triggered.

how to make a gtkwindow transparent on windows backend

I'm trying to make my GtkWindow transparent on windows backend but the programm failed. I use gtk+ 3.6.1 it seems that the gdk_window_set_opacity() function is not working so is there another solution? here is my code:
#include <stdio.h>
#include <stdlib.h>
#include "gtk/gtk.h"
int main( int argc, char *argv[] )
{
gboolean user_func( GtkWidget *wid,
cairo_t *cr,
gpointer user_data );
gtk_init( &argc, &argv );
GtkWidget *win = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_window_set_title( GTK_WINDOW( win ), "Translucent window");
g_signal_connect( G_OBJECT( win ), "draw", G_CALLBACK( user_func ), NULL );
gtk_widget_show( win );
gtk_main();
return 0;
}
gboolean user_func( GtkWidget *wid,
cairo_t *cr,
gpointer user_data )
{
GdkWindow *window = gtk_widget_get_window( wid );
printf("bbbb\n"); // for debuging purpose
gdk_window_set_opacity( window, 0.5 );
printf("bonjour\n"); // for debuging purpose
cairo_set_source_rgba( cr, 0.0, 0.0, 1.0, 0.5 );
cairo_paint( cr );
GTK_WIDGET_GET_CLASS( wid )->draw( wid, cr );
return TRUE;
}
best regards.

Notification icon tooltip not showing despite properly setting szTip

I am trying to make a small system tray program with only a context menu as its GUI.
However, I cannot get the tooltip to work. I properly setup NOTIFYICONDATA's szTip and everything else seems to work...what is preventing the tooltip from showing on mouseover?
void main()
{
int result;
hinst = GetModuleHandle( NULL );
memset( &wnd, 0, sizeof( wnd ) );
wnd.cbSize = sizeof( wnd );
wnd.lpszClassName = "MainWClass";
wnd.lpfnWndProc = MainWProc;
wnd.hInstance = hinst;
result = RegisterClassEx( &wnd );
hwnd = CreateWindowEx
(
0, //extended styles
wnd.lpszClassName, //class name
"Main Window", //window name
WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL | WS_MINIMIZEBOX, //style tags
CW_USEDEFAULT, //horizontal position
CW_USEDEFAULT, //vertical position
CW_USEDEFAULT, //width
CW_USEDEFAULT, //height
(HWND) NULL, //parent window
(HMENU) NULL, //class menu
(HINSTANCE) wnd.hInstance, //some HINSTANCE pointer
NULL //Create Window Data?
);
nid.cbSize = sizeof( nid );
nid.hWnd = hwnd;
nid.uID = 1;
nid.uVersion = NOTIFYICON_VERSION_4;
nid.uCallbackMessage = WM_CONTEXTMENU;
nid.hIcon = LoadIcon( hinst, MAKEINTRESOURCE( IDI_ICON1 ) );
strcpy( nid.szTip, "My Tooltip!" );
nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
if( ! Shell_NotifyIcon( NIM_ADD, &nid ) )
{
printf("Shell_NotifyIcon( NIM_ADD, &nid ) failed.\r\n");
Sleep( INFINITE );
}
if( ! Shell_NotifyIcon( NIM_SETVERSION, &nid ) )
{
printf("Shell_NotifyIcon( NIM_SETVERSION, &nid ) failed.\r\n");
Sleep( INFINITE );
}
UpdateWindow( hwnd );
while( true )
{
//Dispatch for main window
if( PeekMessage( &msg, hwnd, NULL, NULL, PM_REMOVE ) )
{
DispatchMessage( &msg );
}
}
}
try adding the NIF_SHOWTIP flag, according to MSDN, NOTIFYICON_VERSION_4 requires that the tooltip be userdrawn.

Resources