I want a fullscreen GUI with a gutter net of 96x96 pixels and a small gutter border (maybe a pixel). The GUI should be a transparent overlay (just the gutter net should be displayed).
Why? I often work with sprite-sheet images (create, resize or rearrange them). I do not have software which supports gutter lines as help view. It would be great to have for a quick accurate adjustment.
I use a fullscreen GUI as $WS_POPUP (borderless) window. The gutter is a label with specific background color. I have to manually create these so I hope you have a better idea.
My code so far:
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
$iGuiW = #DesktopWidth
$iGuiH = #DesktopHeight
$iGuiGutterSize = 96
$hColor = 0x00FF00
$hGui = GUICreate("", #DesktopWidth, #DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
; From left to right.
GUICtrlCreateLabel("", 0, 0, $iGuiW, 1)
GUICtrlSetBkColor(-1, $hColor)
GUICtrlCreateLabel("", 0, $iGuiGutterSize, $iGuiW, 1)
GUICtrlSetBkColor(-1, $hColor)
GUICtrlCreateLabel("", 0, $iGuiGutterSize * 2, $iGuiW, 1)
GUICtrlSetBkColor(-1, $hColor)
GUICtrlCreateLabel("", 0, $iGuiGutterSize * 3, $iGuiW, 1)
GUICtrlSetBkColor(-1, $hColor)
; From top to bottom.
GUICtrlCreateLabel("", 0, 0, 1, $iGuiH)
GUICtrlSetBkColor(-1, $hColor)
GUICtrlCreateLabel("", $iGuiGutterSize, 0, 1, $iGuiH)
GUICtrlSetBkColor(-1, $hColor)
GUICtrlCreateLabel("", $iGuiGutterSize * 2, 0, 1, $iGuiH)
GUICtrlSetBkColor(-1, $hColor)
GUICtrlCreateLabel("", $iGuiGutterSize * 3, 0, 1, $iGuiH)
GUICtrlSetBkColor(-1, $hColor)
GUISetState( #SW_SHOW, $hGui )
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
GUIDelete($hGui)
Exit
EndSwitch
WEnd
How to get the GUI to be transparent except the gutter lines?
How can I do it without manually setting label by label for each line (row and column)?
Yes it's like a grid design but just the borders as lines.
Notice:
It's a bit unclear that my suggestion fits your imaginations, but I guess you mean something like a grid design. As you mentioned the GUI is like a overlay (transparent) and just the grid lines are visible.
The solution is in the _createGridStructure() function which uses some WinAPI functions to provide such a grid (rectangle design). I extracted your GUIDelete($hGui) and Exit in a separat function _disposeAndExit(). I also extracted the GUI creation part in a function to be a bit more flexible.
Approach:
#include-once
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Global $iGuiWidth = #DesktopWidth
Global $iGuiHeight = #DesktopHeight
Global $iGridSize = 96 ; change the size if you want
Global $vGridColor = 0x00FF00 ; change the grid line color if you want
Global $hMainGui
Func _createGui()
$hMainGui = GUICreate( '', $iGuiWidth, $iGuiHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST )
GUISetBkColor( $vGridColor )
GUISetState( #SW_SHOW, $hMainGui )
EndFunc
Func _createGridStructure()
Local $iGridLinesX = Floor( $iGuiWidth / $iGridSize )
Local $iGridLinesY = Floor( $iGuiHeight / $iGridSize )
Local $hMainRegion = _WinAPI_CreateRectRgn( 0, 0, 0, 0 )
For $i = 0 To $iGridLinesX Step 1
$hRegion = _WinAPI_CreateRectRgn( $i * $iGridSize, 0, ( $i * $iGridSize ) + 1, $iGuiHeight )
_WinAPI_CombineRgn( $hMainRegion, $hRegion, $hMainRegion, 2 )
_WinAPI_DeleteObject( $hRegion )
Next
For $i = 0 To $iGridLinesY Step 1
$hRegion = _WinAPI_CreateRectRgn( 0, $i * $iGridSize, $iGuiWidth, ( $i * $iGridSize ) + 1 )
_WinAPI_CombineRgn( $hMainRegion, $hRegion, $hMainRegion, 2 )
_WinAPI_DeleteObject( $hRegion )
Next
_WinAPI_SetWindowRgn( $hMainGui, $hMainRegion )
EndFunc
Func _disposeAndExit()
GUIDelete( $hMainGui )
Exit
EndFunc
_createGui()
_createGridStructure()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
_disposeAndExit()
EndSwitch
WEnd
Now you don't have to manually adjust the grid lines if you switch the monitor resolution.
Related
I need to check the orientation of a div with Cypress.
This is the test:
cy
.get('data-test="vertical"')
.should('have.css', 'transform', 'translate(-100%, 0) rotate(270deg)')
The div behaviour is standard in a scenario, or it's rotated with css transform: translate(-100%, 0) rotate(270deg); in the other scenario.
I need a way to check the orientation, but transform is difficult to check, because for example in Cypress test what happens is:
when I expect transform: rotateX(180deg) I actually receive transform: matrix3d(1, 0, 0, 0, 0, -1, 1.22465e-16, 0, 0, -1.22465e-16, -1, 0, 0, 0, 0, 1).
I need to find a smart way to detect the orientation. Suggestions? Tips?
Issue is solved like this, with the creation of a command:
const getTransformRotationAngle = (cssTransformMatrix, absoluteValue) => {
const cssTransformMatrixIndexes = cssTransformMatrix
.split('(')[1]
.split(')')[0]
.split(',')
const cssTransformScale = Math.sqrt(
cssTransformMatrixIndexes[0] * cssTransformMatrixIndexes[0] +
cssTransformMatrixIndexes[1] * cssTransformMatrixIndexes[1]
)
const cssTransformSin = cssTransformMatrixIndexes[1] / cssTransformScale
const cssTransformAngle = Math.round(
Math.asin(cssTransformSin) * (180 / Math.PI)
)
return absoluteValue ? Math.abs(cssTransformAngle) : cssTransformAngle
}
Cypress.Commands.add('getTransformRotationAngle', getTransformRotationAngle)
and its use in the test:
cy
.get('data-test="vertical"')
.invoke('css', 'transform')
.then(cssTransform => {
cy.getTransformRotationAngle(cssTransform, true).should(
'eq',
90 || 270
)
})
I have a 3x3 Convolution Function defined like this
conv(x, y) = 0;
conv(x, y) += kernel(r.x, r.y) * in(x + r.x - 1, y + r.y - 1);
Size of the input buffer is 16 x 16
If I want to execute it with padding I can directly do
in = Halide::BoundaryConditions::constant_exterior(in_buffer, 0, 0, 16, 0, 16)
But I have to execute without padding and so I am trying to manually set the bounds on the function like this
conv.bound(x, 1, 14);
conv.bound(y, 1, 14);
This returns an error message
Error:
Bounds given for convolution in y (from 1 to 14) do not cover required region (from 0 to 15)
What should I do to set bounds on a Var in Func?
I think you need not to manually set the bounds using the *.bound function. Try this one:
Halide::Func conv("conv"), kernelF("kernel"), in("in");
Halide::Var x("x"), y("y");
Halide::RDom r(0, 3, 0, 3,"r");
in = Halide::BoundaryConditions::constant_exterior(in_buffer, 0,
0, 16, 0, 16);
kernelF = Halide::BoundaryConditions::constant_exterior(kernel_buffer, 0,
0, 3, 0, 3);
conv(x, y) = 0.0f;
conv(x, y) += kernelF(r.x, r.y) * in(x + r.x, y + r.y);
//conv.print_loop_nest();
Halide::Buffer<float_t> outputBuf = conv.realize(14, 14);
Look, we can set the bounds directly in *.realize() arguments, i.e. 14=16-3+1; Also, note that the convolution anchors are at the top-left of kernels.
I have some code that positions windows to screen quadrants. It works fine on Windows XP, 7, and 8/8.1. However, on Windows 10, there is a weird gap between windows. The extra space surrounds the window on all 4 sides. I presume it has something to do with window borders, but can't figure out how to correct the problem. Any input would be highly appreciated. The code is as follows:
// Get monitor info
HMONITOR hm = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
MONITORINFO mi;
mi.cbSize = sizeof(mi);
GetMonitorInfo(hm, &mi);
// Set screen coordinates and dimensions of monitor's work area
DWORD x = mi.rcWork.left;
DWORD y = mi.rcWork.top;
DWORD w = mi.rcWork.right - x;
DWORD h = mi.rcWork.bottom - y;
switch (corner) {
case 0: // Left top
SetWindowPos(hWnd, HWND_TOP, x, y, w / 2, h / 2, SWP_NOZORDER);
break;
case 1: // Right top
SetWindowPos(hWnd, HWND_TOP, x + w / 2, y, w / 2, h / 2, SWP_NOZORDER);
break;
case 2: // Right bottom
SetWindowPos(hWnd, HWND_TOP, x + w / 2, y + h / 2, w / 2, h / 2, SWP_NOZORDER);
break;
case 3: // Left bottom
SetWindowPos(hWnd, HWND_TOP, x, y + h / 2, w / 2, h / 2, SWP_NOZORDER);
break;
}
I managed to correct this effect by inflating target rectangle by a calculated margin like this:
static RECT GetSystemMargin(IntPtr handle) {
HResult success = DwmGetWindowAttribute(handle, DwmApi.DWMWINDOWATTRIBUTE.DWMWA_EXTENDED_FRAME_BOUNDS,
out var withMargin, Marshal.SizeOf<RECT>());
if (!success.Succeeded) {
Debug.WriteLine($"DwmGetWindowAttribute: {success.GetException()}");
return new RECT();
}
if (!GetWindowRect(handle, out var noMargin)) {
Debug.WriteLine($"GetWindowRect: {new Win32Exception()}");
return new RECT();
}
return new RECT {
left = withMargin.left - noMargin.left,
top = withMargin.top - noMargin.top,
right = noMargin.right - withMargin.right,
bottom = noMargin.bottom - withMargin.bottom,
};
}
And then doing
RECT systemMargin = GetSystemMargin(this.Handle);
targetBounds.X -= systemMargin.left;
targetBounds.Y -= systemMargin.top;
targetBounds.Width += systemMargin.left + systemMargin.right;
targetBounds.Height += systemMargin.top + systemMargin.bottom;
That worked for all windows I could test it with, except Explorer windows, which I hardcoded to exclude. If I'd do that expansion on Explorer near the screen edge, window ends up spilling a large area past it to the adjacent monitor.
The default font size of windows XP/7/8/8.1 is 100%, but in windows 10 the default is to display text and items in 125%. That affects directly all the window sizes.
Go to settings, display and you will find a scroller, move it to 100% and everything should display the same way as it did in Windows 8/7/XP
I am trying to get a uint8_t[] of a portion of the screen. The xy coordinates of the top left is 2,3 and of bottom right is 17,18.
This is the top 30x30 pixels of my screen with regular screenshot and photoshop crop:
And this is what 2,3 to 17,18 screenshot should look like via regular screenshot and Photoshop crop:
This is what I am getting as a result of my code:
My code is in js-ctypes but there is no ctypes errors. This is a winapi thing. So I didn't tag this with ctypes as they would be confused. This is the simplified code I am using, the error checks etc have been removed:
c1 = {x:2, y:3} // top left corner
c2 = {x:17, y:18} // bottom right corner
CreateDC('DISPLAY', null, null, null);
nBPP = GetDeviceCaps(hdcScreen, BITSPIXEL);
w = c2.x - c1.x; // width = 15
h = c2.y - c1.y; // height = 15
hdcMemoryDC = CreateCompatibleDC(hdcScreen);
bmi = BITMAPINFO();
bmi.bmiHeader.biSize = BITMAPINFOHEADER.size;
bmi.bmiHeader.biWidth = w;
bmi.bmiHeader.biHeight = -1 * h;
bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = nBPP; // nBPP is 32
bmi.bmiHeader.biCompression = BI_RGB;
hbmp = CreateDIBSection(hdcScreen, &bmi, DIB_RGB_COLORS, (void**)&pixelBuffer, null, 0);
SelectObject(hdcMemoryDC, hbmp);
BitBlt(hdcMemoryDC, 0, 0, w, h, hdcScreen, c1.x, c1.y, SRCCOPY);
Why portion of screen bits come out wrong? If I do a full screen shot it works fine.
OSX 10.8.3, Python, PyOpenGL.
I'm trying to put together a basic terrain-drawing function in PyOpenGL using VBOs. Having a couple of problems I don't know how to resolve, mostly because I don't fully understand the way VBOs work. This is a basic test sandbox I started when I had too much difficulty changing my project over to VBOs, so it's sloppy in places (see: frame counter).
I've hardcoded a basic 3x3 terrain array and corresponding index array, but it seems to be only drawing two of three rows (it does the y=0 row and y=0.5 but not y=2.0). I'm not entirely comfortable with numpy, so that might be the cause.
The contents of the colour array have only erratic bearing on the final colours: assigning numpy.zeros() to the array produces a black screen, assigning numpy.ones() produces green and purple stripes rather than the white surface I'm expecting. Was initially using random colours but that didn't do anything different from ones(). I don't really understand how OpenGL is supposed to determine that this is a color VBO rather than anything else.
The triangle-drawing algorithm will be problematic, when I get to it - I don't know how best to draw multiple rows without using GL_PRIMITIVE_RESTART, which isn't available in GLUT (I'd rather only change to GLFW or similar as a last resort). Right now, I'm not too concerned about it. Drawing in strips like this isn't quite what I want: http:// www.matrix44.net/cms/notes/opengl-3d-graphics/understanding-gl_triangle_strip (sorry, don't have 10 reputation)
How it currently looks, when rotating: http://i.imgur.com/4Db4qYJ.png
Have been using http://www.mbsoftworks.sk/index.php?page=tutorials&series=1&tutorial=8 as my most successful guide.
I'd really appreciate some guidance with this - no single resource I've found on the web has explained it all, and this isn't exactly a complex topic.
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.arrays import vbo
from math import sin, cos, tan, radians, sqrt
from numpy import *
from random import random
hWindow = 0
frameno = 0
sr2 = sqrt(0.75)
def InitGL( nWidth, nHeight ):
glClearColor( 0.0, 0.0, 0.0, 0.0 )
glClearDepth( 1.0 )
glDepthFunc( GL_LESS )
glEnable( GL_DEPTH_TEST )
glShadeModel( GL_SMOOTH )
print str(glGetString( GL_VERSION ))
global terrain_vbo, index_vbo, color_vbo
# these two will produce a working (huge) triangle
#terrain_array = array([[ 0,0,0 ], [ 9,0,0 ], [ 0,9,0 ], [ 0,0,9 ]], dtype=float32)
#index_array = array([ 0,1, 0,2, 0,3, 2,3, 2,1],dtype=ubyte)
terrain_array = array([ [[0,0,0], [0,0,1], [0,0,2]],
[[1,0.5,0], [1,0.5,1], [1,0.5,2]],
[[2,2,0], [2,2,1], [2,2,2]] ], dtype=float32)
index_array = array([ 0, 3, 1, 4, 2, 5,
8, 4, 7, 3, 6 ], dtype=ubyte )
color_array = zeros( (9, 3) )
for i in range(9):
color_array[i] += (1.0, 1.0, 1.0)
'''
color_array[0] = [1.0, 0.0, 0.0]
color_array[1] = [0.0, 1.0, 0.0]
color_array[2] = [0.0, 0.0, 1.0]
color_array[3] = [1.0, 1.0, 1.0]
color_array[4] = [1.0, 1.0, 0.0]
'''
#for i in range(len(terrain_array)):
#index_array[i][0] = i
for i in range(len(terrain_array)):
print terrain_array[i]
terrain_vbo = vbo.VBO(terrain_array)
#index_vbo = vbo.VBO( zeros((1,3)), target=GL_ELEMENT_ARRAY_BUFFER )
index_vbo = vbo.VBO(index_array, target=GL_ELEMENT_ARRAY_BUFFER)
color_vbo = vbo.VBO(color_array)
ResizeGLScene( nWidth, nHeight )
def ResizeGLScene( nWidth, nHeight ):
# prevent a divide-by-zero error if the window is too small
if nHeight == 0:
nHeight = 1
# reset the current viewport and recalculate the perspective transformation
# for the projection matrix
glViewport( 0, 0, nWidth, nHeight )
glMatrixMode( GL_PROJECTION )
glLoadIdentity( )
gluPerspective( 45.0, float( nWidth )/float( nHeight ), 0.1, 100.0 )
# return to the modelview matrix mode
glMatrixMode( GL_MODELVIEW )
#
# Draw the scene.
#
def DrawGLScene( ):
# clear the screen and depth buffer
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
# reset the matrix stack with the identity matrix
glLoadIdentity( )
global frameno
frameno = frameno + 1
glTranslatef( 0.0, -0.2, -2.0 )
glRotatef( frameno/6, 0.0, sr2, 0.0 )
# draw code
#glTranslatef( 0.0, 0.0, -3.0 )
glScalef( 0.5, 0.5, 0.5 )
glColor3f( 1.0, 1.0, 1.0 )
global index_vbo, terrain_vbo, color_vbo
color_vbo.bind()
glEnableClientState( GL_COLOR_ARRAY )
glColorPointer( 3, GL_FLOAT, 0, color_vbo )
terrain_vbo.bind()
glEnableClientState(GL_VERTEX_ARRAY)
glVertexPointer( 3, GL_FLOAT, 0, None )
index_vbo.bind()
glDrawElements(GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_BYTE,None)
glDisableClientState( GL_COLOR_ARRAY )
glDisableClientState( GL_VERTEX_ARRAY )
index_vbo.unbind()
terrain_vbo.unbind()
color_vbo.unbind()
glutSwapBuffers( )
def KeyPressed( key, x, y ):
key = ord(key)
if key == 27:
glutDestroyWindow( hWindow )
sys.exit( )
def main( ):
global hWindow
# initialise GLUT and a few other things
glutInit( "" )
glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH )
glutInitWindowSize( 640, 480 )
glutInitWindowPosition( 0, 0 )
# create our window
hWindow = glutCreateWindow( "VBO testing" )
# setup the display function callback
glutDisplayFunc( DrawGLScene )
# go full-screen if we want to
glutFullScreen( )
# setup the idle function callback -- if we idle, we just want to keep
# drawing the screen
glutIdleFunc( DrawGLScene )
# setup the window resize callback -- this is only needed if we arent going
# full-screen
glutReshapeFunc( ResizeGLScene )
# setup the keyboard function callback to handle key presses
glutKeyboardFunc( KeyPressed )
# call our init function
InitGL( 640, 480 )
# enter the window's main loop to set things rolling
glutMainLoop( )
print "Hit ESC key to quit."
main( )