TinyDialog a simple Windows and Linux user interface.

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: TinyDialog a simple Windows and Linux user interface.

Post by TJF »

I cannot test (no more m$ OS in this house), but I think your issues are due to a missing CDECL

Code: Select all

' TinyDialog.bi
#IFNDEF __TINYDIALOG_BI__
#DEFINE __TINYDIALOG_BI__

#INCLUDE ONCE "crt.bi"  ??? MODIFICATION full path necessary TO avoid 'not found ...' compile error ??? check your installation !!!

TYPE TinyDialog
...
...
PRIVATE:
...
...
  AS ShowDialog AS FUNCTION CDECL(AS ZSTRING PTR, AS ZSTRING PTR, AS INTEGER, AS INTEGER, AS ANY PTR) AS INTEGER
  AS ANY PTR hLib
END TYPE

CONSTRUCTOR TinyDialog (BYREF sTitle AS STRING)
  strTitle = TRIM(sTitle)
  IF LEN(strTitle) = 0 THEN strTitle = "tiny dialog"
  strOk = "OK" : strCancel = "Cancel"

#IF __FB_UNIX__
  CONST ddl_n = "TinyDialog.so"
#ELSE
  CONST ddl_n = "TinyDialog.dll"
#ENDIF

  hLib = DYLIBLOAD(dll_n)
  IF hLib THEN
    ShowDialog = DYLIBSYMBOL(hLib,"SHOWDIALOG")
    IF @ShowDialog = 0 THEN
      ? "error: can't locate 'ShowDialog()' in '" & dll_n & "' !"
    END IF
  ELSE
    ? "error: can't load '" & dll_n & "' !"
  ENDIF
END CONSTRUCTOR

DESTRUCTOR TinyDialog()
  this.Clear
  IF hLib THEN DYLIBFREE(hLib)
END DESTRUCTOR

...
#ENDIF
[Edit]Typo[/Edit]
Last edited by TJF on Mar 19, 2014 10:58, edited 5 times in total.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: TinyDialog a simple Windows and Linux user interface.

Post by MrSwiss »

Thanks a lot TJF,

I'll try later and report the outcome, as soon as I've the time... .
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

New feature request

Post by petan »

Feature request/upgrade library

Hi, Joshy.

Is possible to add a color into some dialogs ?
/ as additional parameter RGB - e.g. global color variable of program /
I mean colorized dialog window's border or background color of dialog window or
color background of text - for VISUAL WARNING about actually doing action.
For dangerous actions ( deleting mid-data & similar ) I use additional sound warning, but this is insufficient.
Colorized warning is highly needed there.

Thx.
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Quickly done for now

Post by petan »

Temporary solution

Code: Select all

Pseudocode
'remember actual screenpage as origPage
'change screenpage to unused
' CLS
' paint with red color/load warning background
'  run warning dialog
'go back to screenpage origPage
Not elegant, but quick
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

red warning background..

Post by petan »

'working example - red warning background for danger things
' sufficient effects for me
'change it for your preferred ..
file "RedBell.bas"

Code: Select all

#Include "fbgfx.bi"
#include "TinyDialog.bi"		    'original
'#include "TinyDialog_patched.bi"   'patched 
	'=== shared matrices  ===
dim shared as integer X_size, Y_size, Sdepth 
dim shared as integer wokno
	'=== Colors  ===
const cGold=rgb(128,128,0)
const cRed=rgb(255,0,0)		
const cBlack=rgb(0,0,0)
	'ok shared matrices  ===
	'===   Subs Func  declarations  ===
declare function finishD() as integer
	'ok Subs Func  declarations  ===

ScreenRes 1024,704,32,7,FB.GFX_windowed	
Width 128,44
WindowTitle "  Example on linux .."	
wokno=0
ScreenSet wokno,wokno		'0 page
Screeninfo X_size, Y_size, Sdepth 	
Window (0,0)-(X_size, Y_size)

label10:
 color cGold,cBlack
 cls
 ? "videopage 0 .. main"

scope
 dim as TinyDialog dlg1
 dlg1.Title  = "   Main menu   "
var List1 = dlg1.addList("sports:","Tennis| Handball|  Baseball|   Soccer",0,"tip: some item")
 dlg1.addSeperator ""
var Bool0 = dlg1.addBoolean("T h e  END",0,"no","yes","boolean!")
 dlg1.show()
	
if dlg1.GetInteger(Bool0)=1 then	'check end
 wokno=4
  ScreenSet wokno,wokno		'4 page 
  color cGold,cBlack
   cls
    paint (10,10),cBlack

   ' Draw checkered background
For y As Integer = 0 To Y_size
    For x As Integer = 0 To X_size
       PSet (x, y), IIf((x Shr 2 Xor y Shr 2) And 1,cBlack,cRed)
    Next x
Next y

For y As Integer = 0 To Y_size
	 line (0,y) - (X_size,y),rgb(255,0+y,0+y)	'red milk GRADIENT
Next y	 
? "videopage 4 .."
	'check ending
 if finishD()=1 then
  wokno=0
   ScreenSet wokno,wokno		'0 page
   goto label10
 else
   end	'ende
 end if 
end if 

 select case dlg1.GetInteger(List1)+1
	case 1
		'action 1
	case 2
		'action 2
	case 3
		'action 3
	case 4
		'action 4
 end select
end scope
 goto label10
end
	' ========  Subs Func   ==================
function finishD() as integer

'start-TinyDialog window
 dim as TinyDialog dlg
 dlg.Title  = "Finishing..."
 dlg.addSeperator "^    Warning !"
 var Bool0 = dlg.addBoolean("E X I T   of program:",0,"yes","no","boolean!")
 dlg.addSeperator "Are you sure ?"
 dlg.show()
 return dlg.GetInteger(Bool0)
end function
	'ok Subs Func  ==================
Image
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Problem founded

Post by petan »

Something went wrong; for list of longer strings I obtained uncorrect output.
Not all items are displayed in the list.
Why ? Is this a bug ??
(Looks like internal constant buffersize.)

Code: Select all

#Include "fbgfx.bi"
#include once "TinyDialog.bi"
screen 19
dim as string s,cd
dim as string *91 wws(200)
dim as integer i
 s=""
 cd=""	
do
	cd+="Sometext"
loop until len(cd)>85
	? "len(cd)= ";len(cd)
for i as integer=1 to 200
	wws(i)=cd+STR(i)
	s+=wws(i)+"|"
next
? s
?
? "Problem; Only first 44 items is in list... ??? (from 200)"
dim as TinyDialog dlg
 dlg.Title  = "See a problem.."
 var List1 = dlg.addList("preview:",s,1,"tip: some letter")
 dlg.show()
i=dlg.GetInteger(List1)+1
'   ended-TinyDialog window #1 Letters

? "item ";i,wws(i)
? "Press a key.."
sleep
end
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: TinyDialog a simple Windows and Linux user interface.

Post by D.J.Peters »

A list box should select any item from short labels but you use the listbox for large text content.

If you will show large text use a multiline widget.

Joshy

here are a list with 400 selectable items.

Code: Select all

#include once "TinyDialog.bi"

const MAX_ITEMS=400
dim as string s
dim as string items(MAX_ITEMS-1)
dim as string item = "Sometext Sometext Sometext Sometext Sometext Sometext Sometext Sometext Sometext Sometext Sometext"
for i as integer=0 to MAX_ITEMS-1
  print "add item " & i+1
  items(i)= "" & i & " " & item
  s & ="item " & i & "|"
next

dim as TinyDialog dlg
var List1 = dlg.addList("a list of items:",s,0)
print "show dialog"
if dlg.show() then
  var index = dlg.GetInteger(List1)
  dlg.clear
  dlg.addString("item[" & index & "]=",items(index))
  dlg.show()
else
  print "dialog was cancled ..."
  sleep
end if
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Problem solved

Post by petan »

Good hint, Joshy; thank you ! It pointed me to a bit bigger laboring yesterday.
Because still founded problems - even with 'multiline', solving it by trial&error.
I didn't discover yet how increase buffersize for 'addString' function, so summary string is divided into a few substrings and then 'Lists' also.
Using 'addMultiline' function shows only 112 lines with original "TinyDialog.bi" file..
Then changed value of buffersize in line 349 of file "TinyDialog.bi" - from 10240 to 20480.
Now it works for me as needed. See on both screenshots.
Great !
But with using 'multiline' I cannot select item directly, it needs second 'addList' function for selection.
Here is not a problem to select "Item nr.XY" - this is easy.
Here is the problem to select directly long VISIBLE contents of line XY from RAW text data,
without any corrections&filtering..
I'll try to use both ways in my program to see, which way is better and speedy.
By actual laboring I have a suggestion for increasing both buffers,IMO, to be able displaying e.g. string array(300 lines)* 95 chars long each.
Again, thanks a tons..

Screenshots here:
http://www.4shared.com/photo/CVqm5a8dce/items200-3.html
http://www.4shared.com/photo/OgIdr15jce/items200.html
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: TinyDialog a simple Windows and Linux user interface.

Post by D.J.Peters »

Why not using FLTK ?

Joshy
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: TinyDialog a simple Windows and Linux user interface.

Post by petan »

Yeppiie!

Here is working example
"LongString_SelectMultiline.bas"
for selecting one string from 1500 ones, each 93 chars in length.
Solution with multiline is much speedier than divided string, espetially in long arrays.

"TinyDialog.bi" must be tuned; next change there is
old line "return AddItem(sLabel,ParamTypes.m,"",sToolTip,AllocCString(sText,10240))"
new line "return AddItem(sLabel,ParamTypes.m,"",sToolTip,AllocCString(sText,138393))"
somewhere around 349 line, sorry I have this file more commented.

Enjoy !

"LongString_SelectMultiline.bas"

Code: Select all

#Include "fbgfx.bi"
#include once "TinyDialog.bi"		'original
'#include once "TinyDialog_patched.bi"	'patched
screen 19
windowtitle "Solution #2 for selection in long strings/text/arrays"
?
? ,"For max job speed & selection in long lists use multiline widget MAXIMIZED;"
? " by double-clicking on upper bar of widget.."
?
? ,"Press a key.."
sleep

dim as string s,cd
dim as integer i,MaxItems
MaxItems=1500
dim as string *93 wws(MaxItems)
 s=""
 cd=""	
do 
	cd+="Sometxt_"
loop until len(cd)>85
 ? "len(cd)= ";len(cd)
 windowtitle "s creation.."

for i as integer=1 to MaxItems
	wws(i)=cd+STR(i)+!"\n"
	s+=wws(i)
next
? s;"=s"
? "len(s)= ";len(s)
?
? ,"Press a key.."
sleep:
'   TinyDialog window 
dim as TinyDialog dlg
 dlg.Title  = "Solution with 'multiline'"
 var String22 = dlg.addMultiLine("Preview of items: Select index ..",s,"tip: Maximize me")
  dlg.addseperator "All items = "+str(MaxItems)
  var Int2 = dlg.addIntegerMinMax("Select item:",1,0,MaxItems)
  dlg.addseperator "Note - item 0 is empty string (unprinted)"
 dlg.show()
i=dlg.GetInteger(Int2)
'   ended-TinyDialog window 

? "Selected item nr. ";i
? "Text of item =";wws(i)
? ,"Press a key..to END"
sleep
end
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: TinyDialog a simple Windows and Linux user interface.

Post by petan »

Having short test of FLTK, but bad interactio/flow with fbgfx window founded; not sured what is wrong...
I'll report that problem in FLTK thread..
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: TinyDialog a simple Windows and Linux user interface.

Post by petan »

Finishing my next full-app with TDialogs only ;)
what I see as small good tip is setting screen mouse position prior calling
TD show.
Saving my time from unproductive up-down moving mouse on the screen.
Seems TD windows have internal flag "Centered", so good choice is moving mouse to mid-point of display
Xsize\2 and Ysize\2.

Code: Select all

rem +- fine adjust to awaited action
setmouse 550,350     
dlg.show
JohnK
Posts: 279
Joined: Sep 01, 2005 5:20
Location: Earth, usually
Contact:

Re: TinyDialog a simple Windows and Linux user interface.

Post by JohnK »

Hello DJ --- if you still exist...

This library is based only on IUP library?
If so, why IUP instead of FLTK? Was it easier to interface since FLTK is C++ ??
The download does not include source code for DLL, will you release it?

Thanks Sir
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: TinyDialog a simple Windows and Linux user interface.

Post by D.J.Peters »

JohnK wrote:This library is based only on IUP library?
YES
JohnK wrote:If so, why IUP instead of FLTK?
6 years ago I don't know FLTK
JohnK wrote:The download does not include source code for DLL, will you release it?[
No I can't find it :-(
But you can create it self look for IUPGetParamV at http://webserver2.tecgraf.puc-rio.br/iu ... param.html

Joshy
JohnK
Posts: 279
Joined: Sep 01, 2005 5:20
Location: Earth, usually
Contact:

Re: TinyDialog a simple Windows and Linux user interface.

Post by JohnK »

Thanks Joshy for the info.
Btw, if you didn't read the gui thread, don't bother. I still think FLTK and this lib are the best choice for FB.
Post Reply