View Full Version : my current GUI-project
ReneMiner
19-07-2014, 18:35
Just to keep it interesting here I post some preview of my current project... maybe someone's nosy and has the passion to browse it for ideas...
Its a GUI for TBGL where the TBGL-Window becomes an "MDI-Window" - means, user has a few little "windows" (i call them just "t_CTRL_Box") to move around inside client-area. Most useful for TBGL-editor-apps without the need of "UI" and resulting win32-contamination of your code ;)
Its not done yet and just contains a few basic controls as the base-boxes (no "common dialogs" yet) , buttons, labels, checkboxes, option-buttons, scrollbars and all the menustuff.
The philosophy behind it is a little vb6-alike, every control gets a name (optional index if more controls with this name) and the user has only to care about which controls to create and has to write only the code for the events that occur on those controls.
It contains an emptyProject.tBasic - a template to start with and some testProject01.tBasic which shows a few of the current possibilities and explains how to setup controls and how to read the events.
Basically every user-defined sub to each control starts with the name that has been given to the control. Every sub has to have
Sub myControlName_MyEvent( Byval Index as Long [,...] )
so with the index you might identify which control currently had that event.
Ignore Index if you have none assigned (=0)... but the subs have to have this parameter.
To request the exact control that caused the event you might place an absolute variable onto it to access its properties and methods.
Therefor my GUI has a function that will create the fitting variable, so you send the name and the index of the control where to place a layover and it will create the layover of the fitting type at the heap where the controls data is store.
The heap makes it possible to attach any different new Type that Extends the t_CTRL_Basetype to the GUI, so its dynamically expandeable (for example with additional user-defined controls that are not invented yet) and you can omit to include unneeded controls to your project later to save on memory.
The download contains a lot of files and the first time you start one of the *.tBasic files you'll get prompted to select your local keyboard-layout, so just enter the number (currently 1 to 4) of your layout. If yours is not listed feel free to create one (I'll tell how on demand since its too much for this post) - anyway- there's no keyboard-input (except esc-key) since there are no controls to enter values nor strings yet.
Have a look at the testproject01.tBasic-code and run it, move the boxes around inside the TBGL-window and enlarge the inner client by doing so. try out menus, (open additional "windows" from menu). Compare the stuff in both *.tBasic-files: the emptyProject consists of a skeleton to start with. All additional code in the second (testproject01) - mostly subs - is the code the user will write later to create controls and handle them.
Very undone yet... and some things might change or get improved. But I think its a very good example of the opportunities the latest to tB implemented features offer.
PS. ByPtr-functionality is implemented but not in use. Currently I prefer the way of pre-overlay to make use of great Extends-features which allow to sort out
EDIT: updated version attached
#MinVersion 1.9.12.0
Petr Schreiber
19-07-2014, 20:07
The demo itself is great, but what made me even more impressed was the look into code.
Really nicely structured, well done Rene!
Petr
P.S. Little issue found - when moving the window really fast, the anchor point of drag can change.
ReneMiner
19-07-2014, 20:26
Ok, that issue can be solved by dragging them boxes slower :D
Anyway- i think there is "first-time-usage" of some stuff that were never possible before, especially through extended types- really a great feature (can't stop to ballyhoo for it) - I found some small core-issue concerning optional parameters & Call_IfExists <composing function name here> - need some more experiments into that direction... but I think there's some bug.
I hope for some miracle to fire up some passion in a certain direction...
ReneMiner
01-08-2014, 19:44
just to keep the nosy ones up to date - I have another snoop-in here... now already a few more controls, currently I'm creating some variable-bound listfield, i.e. grid (check out the testproject window 5 from menu - just start the script, hit "w" followed by "5")
Another hopefully interesting one you'll find in testbox (window) 4 - its on the way to become an editeable textfield... yes and all the others, just try out type in keys or check out what you can do with your mouse to certain controls, see easy approach to get modal messageboxes to work and all the other stuff - and be sure it won't be done before 2015...
Still no textures yet. But the keyboard-unit is in use now so if you start the first time you'll be asked to enter the number for your local keyboard-layout.
I like to abuse the forum for online-backups of my scripts :D
Petr Schreiber
01-08-2014, 22:14
This will sound weird, but... please feel free to abuse this forum Rene :D
The updated example is truly fantastic, highly recommended for anyone to try out!
Not only the visuals are impressive, but the GUI API design as well.
Highly recommended, without exaggeration this is the best TBGL based GUI demo up to date!
Petr
ReneMiner
06-08-2014, 06:49
Eros can be really proud of his works and all of you can just be flabbergasted about what it makes possible- it's really unbelieveable.
Await an update near the weekend. :D
ErosOlmi
06-08-2014, 09:56
This will sound weird, but... please feel free to abuse this forum Rene :D
The updated example is truly fantastic, highly recommended for anyone to try out!
Not only the visuals are impressive, but the GUI API design as well.
Highly recommended, without exaggeration this is the best TBGL based GUI demo up to date!
Petr
I cannot agree more.
Code produced by Renι is always so clear and well organized, but at the same time it has that kind of complexity to be a great source of inspiration for new native ThinBASIC features.
Renι, I will spend my holidays in reading back all your requests and see if I can add few of them.
Ciao
Eros
ReneMiner
06-08-2014, 16:44
yeah - since Eros replied and I know he had a look at it I now can not leave it like that until weekend- i probably have not time then because we have a big party here. So i uploaded a little polished and more functional version today, just to name a few
- remember Extends makes it possible to create an extension of any existing control on top of it- and also its very simple to combine different controls to new ones.:) -
the controls I already have:
standard-menubar that gets displayed on top of screen, with it come popups and menuitems that are ordered from top to bottom, all of them behave as common popups & menus, so popups can be attached to controls directly to popup on right-click, also tooltip can be attached - multiline of course...
an infinite client-area where still can a 3D-Scene be rendered in the background or while all GUI-stuff is collapsed and where the following can be placed in
boxes - so to say little windows, that are containers for all below
simple buttons
simple, one-lined labels
multiline-labels
horizontal scrollbars that can control other controls or be bound to variables
vertical scrollbars (as above)
checkboxes
option-buttons
progressbar
editeable one-line-textboxes that can be bound to variables
simple multiline text-display
editeable multiline text-display
simple listbox, only for check, select and display
choicebox - combination of a button & a listbox where user just can pick one of some predefined choices
and a listfield, an editeable multiline-data-grid that has to be bound to some udt to be of use...
almost forgot, of course timers too...
There's only a handful of Global variables - most of them are related to Input so you have all Key(%VK_...).Current-states available and have them classified - I used .categorie for this - but i think its a wrong written german word ;)
Also there are a few for the Mouse as there were
Long MousePosX, MousePosY ' tell current position on window-surface
Long MouseDeltaX, MouseDeltaY ' tell current movement
Long MouseWheel ' current wheel-turn
DWord MouseOver ' holds pointer to control where the mouse is over
DWord MouseDrags ' holds pointer to control that gets dragged
' if you need the control the mouse is over its as easy as - err- like that:
Local lCtrl Like Heap_Get(Peek( DWord, MouseOver)) At MouseOver
'...
All of these should be considered read-only so all the frame works with the same values. Anyway you might delete or change them if you know what you're doing. Check genericInput.tBasicU for more information about that.
The other 4 globals are for fonts, Screen, the Win and the GUI. All of the GUI is noded to the GUI and hidden in the depth of heap-memory somewhere. And because that were really complicated to handle all that heap gets names and indexes which the user can work with. All readeable names, controls with same name get indexed automatic meanwhile too, a couple of functions of the GUI that find pointers and type-names and help to perform common tasks to save the user having to create local overlays
No further documentation yet- I made a lot of comments inside- but probably not enough...
As first you should probably run the testproject and try out on that "always here"-box a little, explore menus & window-popup at the menubar- there you'll get access to all the little boxes that show a lot of the controls so one can try out and play around a little, click and turn wheel anywhere, also shift buttons (Shift,Ctrl, Alt/Menu) often increase by default the size of some change- whatever it is...
Still no use of textures yet- i put more effort in polishing and finishing the base-works before i include that unit.
Anyway,
#MinVersion 1.9.12.0
have fun
Edit: Small bug in GUI.GetFreeIndex regarding timers, please pass indexes on create for timers with same names for the meantime...
+ another small missing parenthesis in Sub MenuFile_Save_Click() in the testproject-file...
ReneMiner
06-08-2014, 20:32
...
Renι, I will spend my holidays in reading back all your requests and see if I can add few of them.
Ciao
Eros
Ok, Eros. I think my most urgent request was to call type-functions on a pointer... still very cool feature that could be added - but it will of course not be possible using extends-behavior but just calling straight on a type directly... yes would be great. In the meantime I've found a workaround that you'll discover if you follow the .Render-Functions into the deeper universes: The Window renders first 3d-stuff (if some) and finally calls GUI to render/draw on top.
The GUI.Render creates a local overlay of the basetype so it can loop through all controls in zOrder without to care about the type.
Then GUI calls .Render() on the basetype and there in the BaseType-Function the overlay to the real type is created and .Render() gets called on it ( the real type ) eventually. So this a lot of passing forward but I won't complain, as -err- like you see it works.
:D
More important than that were Petrs request to have udt_elements to be private - so can only be read/set through Me / in a type function of the parenting type. That would make code-units to real "objects" then...
A request (?) an idea were to make heap a vartype - but the first native built-in type that has functions.... have a look at the by accident shipped "console.tBasic" to get the idea. Its a little- but not much different than dynamic strings. Those could be "typed" later on- so all the current core-string functions will work on all of type string by appendig it with a dot like Len(myString) becomes myString.Len...
And one more- Heap_AllocByStr(s) should not allocate memory if StrPtrLen(Strptr(s)) = 0 !
ReneMiner
07-08-2014, 16:04
Just because it reads so nice & short... and not to interfere with already occupied keyword private...
i would appreciate if tB would go its Own way instead of following others rules in the own backyard - compatibility is not a reason since tB is smart enough to differ own and foreign...
Type t_Type
A As Long
Own B As Byte
C As Function
End Type
... B now only accessable inside t_Type.C() - and other functions of that type.... how to achieve this... im certain it's quite cumbersome to flag all variables from within a tB-script... but if there were a flag deeper below like some unused far left bit in the vartypes-table...
...however I'm in party-mode now... on the way to get loaded... this is the last backup before the big black-out :drink:
ps. a few functions added to GUI for getting lbound and ubound of "control-arrays" , fixed timer-indexing etc. added a filelistbox (start testproject, hit "w" followed by "7" and click a file... or change the filter) + a little polishing, new mousepointer... more to come... on try out remember to hold shift-keys (shift, ctrl, menu/alt) when wheeling something...
(as usual just for backup-purposes since my HD is short on space :D )
I'm just doing it because I'm having fun doing it
may i invite you to listen a GREAT TRACK: that's what i listen while i'm coding (https://soundcloud.com/excision/excision-datsik-calypso?in=reneminer/sets/hardnloud)
Petr Schreiber
07-08-2014, 20:05
Hi Rene,
thanks for the updates and the music tip as well! I wrote BASICally complete StringBuilder module when listening to:
TRUE (http://www.youtube.com/watch?v=d6Qkm0PfGqQ)
Checkout RDio.com for tons of music...
The addition Eros made in 1.9.13.0 will make incredible things possible...
Petr
ReneMiner
07-08-2014, 20:16
i'm screwed- the video is not available in germany because the german government wants to have money before i can listen to this - it's a shame and it's only possible in germany .... you still can pay... viva le capitalism...
Petr Schreiber
07-08-2014, 20:48
No problem, try to register at rdio.com:
http://www.rdio.com/
It is perfectly legal, no user content, just official releases. Seek for "Avicii - True".
This is somehow not very intelectually challenging album, but it is fantastic for coding...
I have an account there, we can share coding music if you want.
Petr
ReneMiner
08-08-2014, 11:11
something else :offtopic: here might be an idea...
currently we do this:
' assume heap hPtrs holds pointers, created alike
Dword hPtrs = Heap_allocbyStr( MKDWD$( ptr1, ptr2, ptr3, ptr4,...) )
' create local pointer-array on this
Local lPtr(Heap_Size(hPtrs)/4) As Dword At hPtrs
'now it comes, lets say all those pointers point some data of type t_myType
Local lData As t_myType At 0
' until this line my function works pretty well without any real local variables.
' ( hPtrs in reality is noded to some other structure )
' now I need to push the lData-mask forward and place it to the pointers in a loop
' like this
Local i As Long
For i = 1 To Ubound(lPtr)
SetAt(lData, lPtr(i) )
' do something with data...
Next
in many cases i don't need the value of "i" and loop through all elements of Array lPtr anyway and thought about something like this:
For Array lPtr
' from now on lPtr is an overlay at the "current" element of Array lPtr()
SetAt(lData, lPtr)
' do something with data...
Next
... until here still understandeable ... this does it too- without the need of any real variables, assume hPtrs would be read out somewhere and this were inside some function:
Uses "console"
DWord hPtrs = HEAP_AllocByStr( MKDWD$ ( _
HEAP_AllocByStr("This is a test"), _
HEAP_AllocByStr("only try out"), _
HEAP_AllocByStr("if it were possible"), _
HEAP_AllocByStr("to bind a few different"), _
HEAP_AllocByStr("sized amounts of data"), _
HEAP_AllocByStr("to just one DWord") _
) )
Dim lPtr As DWord At hPtrs ' this only a virtual surfer
While VarPtr(lPtr) <= hPtrs + HEAP_Size(hPtrs) - SizeOf(DWord)
PrintL HEAP_Get(lPtr) ' usually would SetAt( lData, lPtr ) here...
SetAt(lPtr, VarPtr(lPtr) + SizeOf(DWord))
Wend
PrintL $CRLF & Repeat$(42, "*")
PrintL $CRLF & "Any key to end"
WaitKey
still easy, just when it comes to multidimensional storage it becomes hard to read when you try to avoid real variables
check this:
Uses "console"
' exxagerate a little bit now
' all noded to one dword:
DWord hPtrs = HEAP_AllocByStr( MKDWD$ ( _
HEAP_AllocByStr( MKDWD$( _
HEAP_AllocByStr("Name"), _
HEAP_AllocByStr("Mail"), _
HEAP_AllocByStr("System" & $CRLF ) _
) ), _
HEAP_AllocByStr( MKDWD$( _
HEAP_AllocByStr("Eros"), _
HEAP_AllocByStr("@Olmi"), _
HEAP_AllocByStr("Intel i7 M620") _
) ), _
HEAP_AllocByStr( MKDWD$( _
HEAP_AllocByStr("Petr"), _
HEAP_AllocByStr("@PSch"), _
HEAP_AllocByStr("Intel Core i5-3350P") _
) ), _
HEAP_AllocByStr( MKDWD$( _
HEAP_AllocByStr("Rene"), _
HEAP_AllocByStr("@home"), _
HEAP_AllocByStr("Intel Core i5-3330") _
) ) ) )
' not any real variables used to read out :D
Dim lPtrLine As DWord At hPtrs
Dim lPtrColumn As DWord At lPtrLine
While VarPtr(lPtrLine) <= hPtrs + HEAP_Size(hPtrs) - SizeOf(DWord)
While VarPtr(lPtrColumn) <= lPtrLine + HEAP_Size(lPtrLine) - SizeOf(DWord)
Print HEAP_Get(lPtrColumn) & $TAB
SetAt(lPtrColumn, VarPtr(lPtrColumn) + SizeOf(DWord))
Wend
PrintL
SetAt(lPtrLine, VarPtr(lPtrLine) + SizeOf(DWord))
SetAt(lPtrColumn, lPtrLine)
Wend
PrintL $CRLF & Repeat$(42, "*")
PrintL $CRLF & "Any key to end"
WaitKey
barely readeable in the end. the same in future syntax if the world were a perfect place...
Dim lPtrLine(Heap_Size(hPtrs)/4) As Dword At hPtrs
Dim lPtrColumn() As Dword At 0
For Array lPtrLine
Redim lPtrColumn(Heap_Size(lPtrLine)/4) At lPtrLine
For Array lPtrColumn
Print Heap_Get( lPtrColumn ) & $TAB
Next
PrintL
Next
Listen to this (https://soundcloud.com/reneminer/sets/hardnloud) while thinking about the above...
ReneMiner
03-09-2014, 09:44
i ran into some issue regarding negative coordinates when printing TBGL_PrintFont2D.
Attached image shows twice the same TBGL-window and within you see a box captioned "GUI.tBasicu" on the left with some text inside.
On the right image i dragged the box a little left so it starts outside left of the visible TBGL-window-client. Drawing the box from negative coords is no problem as you see but it won't print the text
:(
Now do I have to render the text onto a texture or cumbersome calculate the very left visible char or use some viewport?
Any simple suggest anyone?
Petr Schreiber
04-09-2014, 17:04
Dear Rene,
thank you for your question - this is sadly a behavior of the OpenGL implementation when working with this kind of fonts. It is very annoying, but I found no way around it.
But there is a light at the end of tunnel - you may render the text to texture. How?
You just clear the frame, render the text into positive coordinates, copy the graphical output to texture via TBGL_RenderToTexture and then you map this texture to your window.
I hope this will help you, I will investigate options how to avoid this limitation of Windows OpenGL.
Petr
P.S. I am leaving to Slovakia till Sunday, so I might not be able to reply in that time.
ReneMiner
05-09-2014, 10:45
i was anxious to get an answer like that because it means to re-think about the mechanics of my gui. perhaps in general it could be better to have no window-alike boxes that just get drawn as now - but each box (i.e. "window") just is a textured quad. would use up quite a few texture-slots but will certainly draw faster if the surface-template of a box/window gets only drawn again if it changes and else use the existing texture again...
the final "printed" font would look better too (automatic anti-aliased) due the usage as texture.
...but...
i'm not sure about sizes, imagine we have a box 100 * 200 pixels, i would need to use a texture of 128 * 256 ( the next power of two) for it to be on the safe side ? that would occupy a lot of unused memory on the graphics-hardware if it were this way...
My other idea was that maybe TBGL_PrintFont2d can be changed in behaviour when negative x-value is passed? I planned to create a function alike that:
TBGL_SetActiveFont 1
PrintFont "Hello", X, Y, Align1, Align2, MaxWidth
Function PrintFont( ByVal sText As String, _
ByVal X As Long, _
ByVal Y As Long, _
Optional ByVal sAlign As Long, _
ByVal aAlign As Long, _
ByVal maxW As Long )
Local i, lW, lH As Long
While X < 0
If i >= StrPtrLen(StrPtr(sText)) Then Exit While
TBGL_GetFontTextSize( Memory_Get(StrPtr(sText)+i,1), lW, lH )
X += lW
' totalTextwidth += lW ' >>> startX for maxWidth-calculation !
i += 1
Wend
Select Case i
Case StrPtrLen(StrPtr(sText))
Exit Function
Case 0
Nop
Case Else
sText = Memory_Get(StrPtr(sText)+i, StrPtrLen(StrPtr(sText))-i)
End Select
' don't bother actual alignement nor passing maxWidth for this example
' this approach only works for left-aligned, else much more complicated
TBGL_PrintFont2D sText, X, Y, sAlign, aAlign, maxW ' - totalTextwidth
End Function
Petr Schreiber
08-09-2014, 22:18
Stay tuned Rene,
I am investigating ;)
Petr
Petr Schreiber
13-09-2014, 10:12
Haha! I think I got it!
Let me know, if tbgl_PrintFont and tbgl_PrintFont2D works for you as expected now :dance1:
If yes, I will update help file and binaries for next ThinBASIC...
Petr
Attachement removed.
ReneMiner
13-09-2014, 11:50
sadly does not print any text at all now :(
attached latest version - Attention, needs thinCore.dll (http://www.thinbasic.com/community/showthread.php?12459-ARRAY-ideas&p=91468#post91468) from other thread, use version of september 10th !
Petr Schreiber
13-09-2014, 13:13
Hi Rene,
okay, I will check. In the meantime, can you verify that this script gives you graphical output in the attachement?
Uses "TBGL"
Function TBMain()
Local hWnd As DWord
Local FrameRate As Double
' -- Create and show window
hWnd = TBGL_CreateWindowEx("Testing clipping - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
' -- Resets status of all keys
TBGL_ResetKeyState()
Dim hFont As DWord = TBGL_FontHandle("Courier New", 64)
TBGL_BuildFont( hFont )
' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
TBGL_RenderMatrix2D
TBGL_ClearFrame
TBGL_PrintFont "ThinBASIC", -175,230
TBGL_PrintFont "ThinBASIC", 460,230
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
Wend
TBGL_DestroyWindow
End Function
Petr
ReneMiner
13-09-2014, 13:51
your script does print - but as soon as you change line 21 to its correct syntax
TBGL_RenderMatrix2D( 0, 480, 640, 0)
the text vanishes...
Petr Schreiber
13-09-2014, 14:50
I have tweaked the code further, please check, if you have a minute :)
Petr
ReneMiner
13-09-2014, 15:07
great- works :)
Petr Schreiber
13-09-2014, 15:57
Great, will be part of thinBasic 1.9.14.0 :)
Sorry it took so long. The official advice for OpenGL with glBitmap sounded silly to me, so it took some time to get around it with some matrix magic :D
Petr