PDA

View Full Version : Trying to Implement Control Resizing



Bidmaron
November 21st, 2017, 12:35
OK, what I am trying to achieve is to create what I call a dragline control that, when you hover over it or you drag it, the frame changes from a horizontal line to a horizontal line with double arrow vertical drag indicators spaced along the plain horizontal line. When you release the mouse, it is supposed to resize the preprocessor control by the amount you dragged the line up or down.

The problem I am having is that when you hover over the control, the frame does not change, and you cannot drag it.

The graphics I am using are the standard CoreRPG textline (which is 100 x 20 with the one pixel wide horizontal line at the 15th pixel [1-relative] down from the top) and the textline modified with a double-headed vertical arrow (5 pixels from left). Here are the two graphics:

TextLine:
21545

Dragline:
21546

Here are my frame definitions (quiescentdragline intended to be state at rest, dragline the state when hovering over control or dragging it):

<framedef name="dragline">
<bitmap file="dragline.png" />
<middle rect="0,11,40,9" />
</framedef>
<framedef name="quiescentdragline">
<bitmap file="textline.png" />
<middle rect="0,11,40,9" />
</framedef>


Here is what my window looks like with the preprocessor control being the one with all the text in it, and my dragline control right under it:
21547

Unfortunately, it looks the same when I try to hover over and drag the dragline control.

Here is my layered window definition with all these controls:

<windowclass name="table_main" merge="join">
<sheetdata merge="join">

<basicstring name="preprocessor">
<empty textres="generator_emptyforward" />
<anchored position="insidetop" offset="-5" height="60"/>
<invisible />
<multilinespacing>20</multilinespacing>
</basicstring>

<genericcontrol name="drag_line">
<anchored height="9">
<top parent="preprocessor" anchor="bottom" relation="absolute" offset="0,0" />
<left />
<right />
</anchored>
<frame name="quiescentdragline" />
<pressed name="dragline">
<nobaseframe />
</pressed>
<hover name="dragline">
<nobaseframe />
</hover>
<script>
local nYStart;
function onDragStart(button, x, y, dragdata)
nYStart=y;
end
function onDragEnd(button, x, y, dragdata)
local _,nOldHeight=preprocessor.getSize();
preprocessor.setAnchoredHeight(nOldHeight+y-nYStart);
nOldHeight=tabletoplabelanchor.getSize();
tabletoplabelanchor.setAnchoredHeight(nOldHeight+y-nYStart);
end
</script>
</genericcontrol>

<line_column name="divider3" />

<string_column_full name="postprocessor">
<empty textres="generator_emptyafterward" />
<invisible />
</string_column_full>

</sheetdata>
<script>
function onInit()
if TableManager.isGenerator(getDatabaseNode()) then
preprocessor.setAnchor("top","divider","bottom","absolute",5);
preprocessor.setVisible(true);
postprocessor.setVisible(true);
tabletoplabelanchor.setAnchor("top","columnanchor","bottom","relative",90);
else
divider3.setVisible(false);
dragline.setVisible(false);
end
super.onInit();
end
</script>
</windowclass>


The windowclass code is designed to make the window look like the normal table (TableManager.isGenerator returns false) or the enhanced Generators window (if it returns true). That all works just fine.

The script for the dragline control is supposed to save the y position at start of drag and then at end of drag adjust the height of the preprocessor control by the amount of the drag and to also make the same adjustment to the anchor that all of the legacy table controls are tied to.

Bidmaron
November 22nd, 2017, 15:36
I just cannot get dragging to work. Is there some tag you have to set in order to enable a control for dragging?

Bidmaron
November 23rd, 2017, 01:27
Bump please

damned
November 23rd, 2017, 02:38
I dont know the answer. I do see <nodrag /> tags in plenty of places - although these are mainly for data. You could possibly try <drag />.
The other one i see is <resize> which is used for dragging frames bigger/smaller.
I couldnt find anything specifically for what you are attempting.

Are you anchoring the bottom of the text field to the dragline? Are you doing this so you can expand the edit field as required?
One thing you might notice is that when you lock the sheet that field will autosize to the contents.

Bidmaron
November 23rd, 2017, 04:45
Well I am mainly doing this to help minty. But I have to figure this out eventually because I want tables to have resizable columns. The text box is not anchored to the line. When you drag the line (which I cannot get to work), it has event code that will resize the text box and move the anchor the table is based upon

Moon Wizard
November 23rd, 2017, 07:16
The physical relocation of a control is not supported in any of the FG client code, or the current Lua code. If you want to be able to drag a control on the screen, you'll need to capture the onDragStart, onDrag and onDragEnd events for that control; then actually move the control using setPosition / setSize functions.

Regards,
JPG

Bidmaron
November 23rd, 2017, 12:25
MW, I know what you are saying, and if you look at the code I posted, you will see that I am capturing those events (but not onDrag yet because my first implementation was just proof-of-concept and was going to simply look at the delta between drag start and drag end.

I have a debug in onDragStart, and it is never getting called for the control that I have posted above. That is why I concluded that there must be some kind of tag that requires setting to turn on drag-ability. However, I cannot see such a tag in the inheritance tree of any control that currently supports conventional drag-and-drop.

Also, after I posted that code, I changed it to below, and it still never gets called:


function onDragStart(button, x, y, dragdata)
nYStart=y;
Debug.chat("in drag start");
return true;
end

pindercarl
November 23rd, 2017, 15:27
You can try simplifying the situation. Add an onClickDown function and see if that fires. I can't think of any particular reason that onDragStart wouldn't work on a generic control, but onClickDown will help you verify that the control is receiving mouse interaction.

Bidmaron
November 23rd, 2017, 15:33
Thanks. I overlooked that one. I currently in my test version am looking at onHover and onHoverUpdate. Those are firing just fine.

BTW, there is a bug with Input.getMouseButtonState. The documentation on that says:


getMouseButtonState


function getMouseButtonState( button )
Get the state of the specified mouse button.

Parameters

button (number)
This value specifies the mouse button whose state is being queried and should be 1 for the left mouse button, 2 for the middle button and 3 for the right button
Return values

(boolean)
Returns true if the button is pressed and false if it is not


In fact, to get the left button status, you have to pass in 3, not 1. I have no idea what any other values of the button parameter do, but the button parameter documentation is not correct.

I know that because in my onHoverUpdate, I can get the status of the left button if I make that call with a 3 parameter.

I will give onClickDown event a try. I can brute-force the drag operation.

Bidmaron
November 26th, 2017, 06:58
I got a horizontal dragline resized working. If anyone is interested I can post the template for it somewhere. It operates in three modes:
1. The control above and below are both dynamically resized when you drag the dragline vertically.
2. The control above the dragline gets resized, but the control below simply is anchored to the dragline and slides vertically.
3. The control above the dragline gets resized, and there is another anchor that must be moved in order for the other controls below the dragline in the window to slide to the proper vertical orientation below the dragline. For most of the record windows, this would probably be useful because you can be minimally invasive in your extension and leave the original window intact and only use windowclass join merging to add in your new resizable control(s). I am using this in my Generators extension so that I can leave the original tables functionality untouched and share the same underlying window definition. Hopefully, this will make my code more resistant to future FG upgrades.

I could not think of an application for the fourth case you might wonder about: that is, the case where the resizable control is below the dragline and the stuff above is anchored to the dragline, but if someone is interested in the template for the dragline and needs this use case, I would modify it accordingly.

Minty, I think this will help you in your search extension.

Minty23185Fresh
November 29th, 2017, 04:38
Sorry I have been doing other less fun things and have been away for a while.

This is fantastic. If only I was as far along as I wished I was to utilize it. I am totally interested in seeing this in action.

Bidmaron
November 29th, 2017, 04:41
OK, I need to write it up with some screen shots of the code in action. Let me finish some testing I am doing on the Generator itself, and I'll write it up. It is fairly easy to use, I think.