I'm trying to display one form relative to a Button on a control below it.
But Button.top is relative to the titlebar of the bottom form, and the top form will be relative to the screen.
So, to compensate for that I need to now how tall the titlebar is.
I've used Form.height-Form.ScalehHeight but ScaleHeight doesn't include the title bar or the border so Scaleheight is inflated slightly.
Anyone know how to calculate the height of just the title bar?
You need to use the GetSystemMetrics API call to get the height of the titlebar.
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Const SM_CYCAPTION = 4
Property Get TitleBarHeight() as Long
TitleBarHeight = GetSystemMetrics(SM_CYCAPTION)
End Property
Note: This will return the height in pixels. If you need twips you will have to convert using a form's ScaleY method like so: Me.ScaleY(TitleBarHeight(), vbPixels, vbTwips)
Subtract it back out:
(Form.height-Form.ScaleHeight) - (Form.Width-Form.ScaleWidth) / 2
"Recursive's" answer above is not quite correct. It subtracts twice the border width - there is a border on the left and one on the right!
We get the best results with this:
(Form.Height-Form.ScaleHeight) - (Form.Width-Form.ScaleWidth)/2
' For completeness:
Public Const SM_CYCAPTION = 4
Public Const SM_CYBORDER = 6
Public Const SM_CYFRAME = 33
' in Pixels
Property Get NonClinetHeight()
FrameH = GetSystemMetrics(SM_CYFRAME) ' Total height, Top + Bottom
CaptionH = GetSystemMetrics(SM_CYCAPTION)
BorderH = GetSystemMetrics(SM_CYBORDER) ' Border around Client area
NonClinetHeight = FrameH + CaptionH + (BorderH * 2)
End Property
You'll probably need to make a Win32 API call to GetSystemMetrics()
You can use the ClientToScreen() windows API function to convert a point from client coordinates to screen coordinates:
Dim Position As Point
Position.x = 0
Position.y = 0
ClientToScreen Me.hWnd, Position
FormTop = Position.y
If you want to skip this and go direct to the button, you can use the button's position (in pixels):
Position.x = This.ScaleX(Button.Left, this.ScaleMode, vbPixels)
Position.Y = This.ScaleY(Button.Top, this.ScaleMode, vbPixels)
...
Or just get the buttons position using GetWindowRect()
Dim Position2 As Rect
GetClientRect Button.hWnd, Position2
Position.x = Position2.left
Position.y = Position2.top
...
Related
I there a way, at runtime, other than using styles, to change the background color of a TListBox? Can I use the OnPaint event?
Because the TListbox doesn't have a property to change the background color, I can only think of the following, which is based on combining two components, of which one (the TListBox) uses a built-in style. Note however, that this is not depending on TStyleBook nor any of the style files supplied with Delphi Firemonkey.
Place a TRectangle as a background for the TListBox. Set its Fill - Color property to a color you like. (I used "Cornsilk" in the example).
Place the TListBox on the rectangle as a child of the rectangle. In the "Object Inspector" locate the StyleLookup property and change its value to transparentlistboxstyle. This makes the listbox transparent and the rectangle and its fill color to shine through.
If you make the TListBox one pixel smaller than the rectangle on each side, you can use the Sides property to provide a thin frame around the listbox. Or you can choose to make them equally sized and not show any frame.
My test result looks like this:
The TRectangle and the TListbox properties from the .fmx file:
object Rectangle1: TRectangle
Anchors = [akLeft, akTop, akBottom]
Fill.Color = claCornsilk
Position.X = 7.000000000000000000
Position.Y = 40.000000000000000000
Size.Width = 361.000000000000000000
Size.Height = 219.000000000000000000
Size.PlatformDefault = False
object ListBox1: TListBox
Anchors = [akLeft, akTop, akRight, akBottom]
Position.X = 1.000000000000000000
Position.Y = 1.000000000000000000
Size.Width = 359.000000000000000000
Size.Height = 217.000000000000000000
Size.PlatformDefault = False
StyleLookup = 'transparentlistboxstyle'
TabOrder = 0
ParentShowHint = False
ShowHint = False
DisableFocusEffect = True
ItemHeight = 48.000000000000000000
DefaultItemStyles.ItemStyle = 'listboxitemrightdetail'
DefaultItemStyles.GroupHeaderStyle = ''
DefaultItemStyles.GroupFooterStyle = ''
Viewport.Width = 359.000000000000000000
Viewport.Height = 217.000000000000000000
end
end
To change the color of ListBox1, you actually change the color of the TRectangle:
procedure TForm5.ColorListBox1ItemClick(const Sender: TCustomListBox;
const Item: TListBoxItem);
begin
Rectangle1.Fill.Color := TColorListBox(Sender).Color;
end;
rect = Sprite::create();
rect->setTextureRect(Rect(0, 0, 180, 80));
rect->setPosition(Point(visibleSize.width / 2 + origin.x, visibleSize.height + 80));
auto grad = LayerGradient::create(arr[randSayi][0], arr[randSayi][1]);
grad->changeHeight(rect->getContentSize().height);
grad->changeWidth(rect->getContentSize().width);
label = Label::createWithTTF(arrRenk[randRenk], "fonts/font.ttf", 54);
label->setPosition(rect->getContentSize().width / 2, rect->getContentSize().height / 2);
label->setColor(/*(Color3B)arr[randSayi][0]*/Color3B(arr[randSayi][0]));
grad->addChild(label);
rect->setTag(i);
rect->addChild(grad);
This is how i crete a rectangular sprite with a gradient color and a label added on top of it. My problem is that i can't set font color properly.
label->setColor(/*(Color3B)arr[randSayi][0]*/Color3B(arr[randSayi][0]));
arr[][] is an array of colors Color4B. I both tried casting and the uncommented out but the result is:
Which means color isn't set. Can anybody identify the problem?
i tried in my code, both setColor and setTextColor work for me
my cocos2dx engine version is v3.2
you may take a try with setTextColor
Newbie here! :P
I'm trying to create a game in Corona where animals falls from the top of the screen and keep bouncing. When you touch an animal it disappears.
I've drawn all the animals like circles, then, I added a circular physics body to it. The images are PNG with transparency.
The problem is, some details of the animals, such as ears and paws, they are outside of the physics body (what I want, because it seems a better collision this way). Moreover, when I touch outside the animal image sometimes it is pressed on the alpha region of my image and it is counted as a tap, but I have not actually tapped in the animal.
I would like to it disappear when i click only on its physical body region.
Anyone knows how to handle this? Is there a way to add a touch handler for the physics body? (The collision works pretty fine, it's just the touch that is related to the image instead of the physics body).
local rect = display.newImage("img/Animals/cow_a1.png");
rect.x = 60 + math.random( 160 )
rect.y = -100
physics.addBody( rect, { density=9, friction=0.3, bounce=0.3,radius=27} )
function rect:touch(e)
-- Remove the animals from screen and memory
removeAnimal(self);
end
-- Add event listener to the cow
rect:addEventListener("touch", rect);
This is because of the rectangular image space. try using MASK on your animal objet with HIT TEST option on (true):
try this link for masking images
here is an example:
local displayGroupTmp = display.newGroup( )
displayGroupTmp.id = id + 1
-- creating a slice
local circleSize = Constants.screenX*3.8/4 - 20
local background = display.newImageRect( displayGroupTmp, "images/slice.png", circleSize/2, circleSize*1.5/2 )
background.anchorX = 0
background.anchorY = 0.66
background.x = Constants.screenX/2 + deltaX
background.y = Constants.screenY/2 + deltaY
background:setFillColor( color[1], color[2], color[3] )
-- setting mask of an object to identify the true bounding of the background
local mask = graphics.newMask( "images/sliceMask.png" )
-- mask.anchorX = 0
background.maskX = background.x
background.maskY = background.y
background:setMask( mask )
background.maskScaleX, background.maskScaleY = 0.38,0.38
background.isHitTestMasked = true
I am trying to make a Matlab GUI that has a panel with scrolling content inside of a larger figure. I am having a problem hiding the overflow content when it scrolls out of the subpanel.
I got the code for the scrollbar from this SO post: Adding scroll bar in subplots within GUI
Try the code below. I have a figure, an outer panel (smaller than the figure, child to the figure), a scrolling panel (with a height greater than the figure, child to outer panel), a scroll bar, and a text field to appear in the scrolling pane (child to the scrolling panel).
When you try the code you will see the text string, which is just the alphabet repeated, scrolls up and down the whole length of the figure, but the scrolling panel stops at the edge of the limits of the outer panel.
How can I correct this problem. Thanks.
function guitest
scrsz = get(0,'ScreenSize');
height = scrsz(4)*7/8;
width = scrsz(3)*2/3;
leftmargin = 10;
rightmargin = 10;
% figure
handles.hFig = figure('Visible','on',...
'Position', [scrsz(3)/8 scrsz(4)/10 width height],...
'Name', 'Tap Toolbar Report',...
'NumberTitle', 'off',...
'Color', [0.75 0.75 0.75],...
'ToolBar','none',...
'MenuBar','none',...
'Resize','off');
% subpanel in the figure for scrolling
handles.hOut = uipanel('Parent',handles.hFig,...
'BackgroundColor', [0.85 0.85 0.85],...
'BorderWidth', 0,...
'Units', 'pixels',...
'Position',[leftmargin 100 width-2*leftmargin height-200]);
hPanheight = 2000;
handles.hPan = uipanel('Parent',handles.hOut,...
'BackgroundColor', [0.85 0.85 0.85],...
'BorderWidth', 0,...
'Units', 'pixels',...
'Position',[0 0 width-2*leftmargin-19 hPanheight]);
str = sprintf('a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nx\ny\nz\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nx\ny\nz\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nx\ny\nz\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nx\ny\nz\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nx\ny\nz\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nx\ny\nz\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nx\ny\nz\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nx\ny\nz');
uicontrol('Parent', handles.hPan,'Style','text','String',str,'FontSize', 10,'FontWeight','bold', 'HorizontalAlignment', 'left',...
'Position',[10 20 20 1960],'BackgroundColor', [0.85 0.85 0.85]);
handles.hSld = uicontrol('Style', 'slider',...
'BackgroundColor', [0.8 0.8 0.8], ...
'Position', [width-leftmargin-20 101 19 height-202],...
'Callback', {#onSlide,handles.hPan,handles.hOut});
set(handles.hSld,'Value',1);
onSlide(handles.hSld,'',handles.hPan,handles.hOut)
end
function onSlide(hSld,~,hPan,hOut)
%# slider value
offset = get(hSld,'Value');
%# update panel position
p = get(hPan, 'Position'); %# panel current position
ph = get(hOut, 'Position');
set(hPan, 'Position',[p(1) -offset*(p(4)-ph(4)) p(3) p(4)])
end
I would use a container object that has scroll capability built-in. Take a look at:
help uitable
help uitree
Could anyone could point me to some code/give me ideas on how to create a smooth scrolling vertical marquee for VFP 8 or 9?
Any help is appreciated.
Here's a quick program that will scroll messages. Put the following in a prg file and run it.
I'd make a containerScrollArea a class that encapsulates the timer, labels, and scrolling code. Give it GetNextMessage method that you can override to retrieve the messages.
* Put a container on the screen to hold our scroller
_screen.AddObject("containerScrollArea", "container")
WITH _Screen.containerScrollArea
* Size it
.Visible = .t.
.Width = 100
.Height = 100
* Add two labels, one to hold each scrolling message
.AddObject("labelScroll1", "Label")
.AddObject("labelScroll2", "Label")
* This timer will move the labels to scroll them
.AddObject("timerScroller", "ScrollTimer")
ENDWITH
WITH _Screen.containerScrollArea.labelScroll1
* The labels are positioned below the margin of the container, so they're not initially visible
.Top = 101
.Height = 100
.Visible = .t.
.WordWrap = .t.
.BackStyle= 0
.Caption = "This is the first scrolling text, which is scrolling."
ENDWITH
WITH _Screen.containerScrollArea.labelScroll2
* The labels are positioned below the margin of the container, so they're not initially visible
.Top = 200
.Height = 100
.Visible = .t.
.WordWrap = .t.
.BackStyle= 0
.Caption = "This is the second scrolling text, which is scrolling."
ENDWITH
* Start the timer, which scrolls the labels
_Screen.containerScrollArea.timerScroller.Interval = 100
DEFINE CLASS ScrollTimer AS Timer
PROCEDURE Timer
* If the first label is still in view, move it by one pixel
IF This.Parent.labelScroll1.Top > -100
This.Parent.labelScroll1.Top = This.Parent.labelScroll1.Top - 1
ELSE
* If the first label has scrolled out of view on the top of the container, move it back to the bottom.
This.Parent.labelScroll1.Top = 101
* Load some new text here
ENDIF
IF This.Parent.labelScroll2.Top > -100
* If the second label is still in view, move it by one pixel
This.Parent.labelScroll2.Top = This.Parent.labelScroll2.Top - 1
ELSE
* If the second label has scrolled out of view on the top of the container, move it back to the bottom.
This.Parent.labelScroll2.Top = 101
* Load some new text here
ENDIF
ENDPROC
ENDDEFINE
You can use Scrollable Container
Unfortunately the nature of my work leaves me no time for fooling around with graphics, however if I did I would look into using GDI+ with VFP. Here is an article to get you started