sGUI

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Post Reply
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

Bug founded - 'MessagesBox' !
When length of titletext is bigger then longestline of messagetext >> Title is out of msg. box area.

Solved !
changes in "MessagesBox.bas":

Code: Select all

'...
    ll=t->GetLongestLine
    if len(TitleText)>ll then ll=len(TitleText)		'my
    boxw=ll*8 + 16
'...    
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

Bug founded - 'ToggleGadget'
Too long gadget text is printed off setted gad's area.
Preferred solution is enlarging gad length by text and printing it all to see, howto change/cut down that text.

Fixed now.
Changed in "ToggleGadget.bas"

Code: Select all

'...
function AddToggleGadget (event as EventHandle ptr,PosX as integer,PosY as integer,GadWidth as integer,GadHeight as integer,s as integer,txt as string,RLCprintStyle as string) as Gadget ptr
'...
    gad->posy=PosY
		'my - enlarged
    if len(txt)*8+16>GadWidth then gad->gadw=len(txt)*8+16 else gad->gadw=GadWidth		
    gad->gadh=GadHeight
'...
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

'SimpleGadget' correction ;)
The same problem as 'ToggleGadget' had.Longer text then gadheight is printed out of box.
Due missing priority rule (text or height we need to keep) gadbox is enlarged to see this problem; all passed text is printed inside the box.
Problem solved
"SimpleGadget.bas"

Code: Select all

'...    
  gad->gadh=GadHeight
'my
    if len(Text)*8+16>GadWidth then
    	? "SimpleGad enlarged ";gad->gadw;" > ";
    	gad->gadw=len(Text)*8+16
    	? gad->gadw
	end if	
  gad->caption=Text
'...
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

I use comfort way to fill text for MessageBox via MultilineEditor in designer plugin
(semifinal stage, last 3 things to fix); and there is a problem:
editor uses Chr(13,10) as line separator, while MessageBox uses char "|" & doesn't affect
Chr(13,10) as line separator, so text is printed in one line - which is wrong.
I'll fix it with conversion routine - Chr(13,10) to "|".

Q #1 - Do you plan to enhance MessageBox to standard parsing methods from this disproportion,
or keep "|" as one and only separator ?



Second problem & question founded - for 'movable' feature of created gadgets preview I don't know to identify,
which kind of gadget is hovered >> which kind of macro to select for recaltulating its position.
This is caused due gadget's construction (not from one point derived everything in hidden way).
My old idea was to use ctrl(15) as flag, but some gadgets use it already; IIRC as I saw.

Q #2 - Better would be to add new gadget parameter 'gadgetKind' as integer, or does exist here another way to find out
which kind of gadget is it ??

Solved
MessageBox - only added new lineseparator as parameter.Founded all needed - was built-in.Super.
Q2 - added new gadget parameter 'gadgetKind
Last edited by petan on Dec 03, 2014 4:27, edited 1 time in total.
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

2 new changes
A/ 'FileRequester' ... corrected layout after tuning
"FileRequester.bas"

Code: Select all

function FileRequester(posx as integer,posy as integer,BtnText as string,Path as string, File as string="",FExistMode as integer=0) as string
'...
  labelp  =AddLabel(event,posx+5, posy+28,phrase_path & ":",TextColor)
  'strpath =AddStringGadget(event,posx+52,posy+25,38,Path,,,1)		'orig
  strpath =AddStringGadget(event,posx+50,posy+25,38,Path,,,1)		'my
  contlist=AddListBox(event,posx+5,posy+54,46,rows)
  labelf  =AddLabel(event,posx+5, posy+245,phrase_file & ":",TextColor)
  strfile =AddStringGadget(event,posx+62,posy+242,29,File,,,1)
  doit    =AddSimpleGadget(event,posx+309,posy+242,85,23,BtnText)
  cancel  =AddSimpleGadget(event,posx+309,posy+271,85,23,phrase_cancel)
  'cdparent=AddSimpleGadget(event,posx+370,posy+25,24,23,"..")		'orig
  cdparent=AddSimpleGadget(event,posx+362,posy+25,32,23,"..")		'my
'...
B/ 'Messagebox' ... added custom lineseparator

Usage:
Messagebox - lineseparator "|" in passed string

Code: Select all

MessageBoxMove(100,80,"copy and paste code| into your source file","created ...",MBType_OK,"|")
Messagebox - created via MultilineEditor - lineseparator ODOA default

Code: Select all

MessageBoxMove(100,80,"copy and paste code| into your source file","created ...",MBType_OK)
"MessageBox.bas"

Code: Select all

'...
'new
declare function MessageBoxMove(byref PosX as integer,byref PosY as integer,MsgText as string="",TitleText as string="",MsgType as integer=1,byval lineSep as string=chr(13,10)) as integer
'...
function MessageBoxMove(byref PosX as integer,byref PosY as integer,MsgText as string="",TitleText as string="",MsgType as integer=1,byval lineSep as string=chr(13,10)) as integer
'...
  t=new TextObject

  if t then
    't->SetText(MsgText,"|")		'orig
    t->SetText(MsgText,lineSep)		 'my  use custom lineseparator
    l =t->GetLines
'...
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

Q - what about 'resizeable' feature for 'FileRequester' & 'MultilineEditor',
is it possible ?
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

Q - is 'FileRequester' able to select drive or folder ?

edit:
Yes, tuned.
So now already it needs 'movable' feature too.
'movable' enabled ;)
Last edited by petan on Dec 10, 2014 13:01, edited 2 times in total.
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

3 hours playing today with 'FileRequesterD', 'coz I want to select files AND folders.
Bug founded, this line NEVER happened on my system (Puppy linux)
because curdir doesn't return slash ! (other OS do what ?)

Code: Select all

if right(Path,1)<> sep then			'orig  - NEVER happened !!
After laboring I got it to work; my fixgap is

Code: Select all

'...
'on all places 3x! change Path
              Path=UImport(curdir)                        'Setze aktuellen Pfad
				if right(Path,1)<>sep then Path+=sep		'my
'...
        case doit	',strfile
          File=GetString(strfile)
          if File<>"" then
            'if right(Path,1)<> sep then			'orig  - NEVER happened !!
            if instr(entry,"<DIR> ") then				'my
              'full=UExport(Path) & sep & UExport(File)		'orig
              full=UExport(Path)						'my
              File=GoToFolder		'my
            else
              full=UExport(Path) & UExport(File)		
            end if
'...            
but still yet it doesn't like me.

Better would be to rebuild 'FileRequester' to 'OpenTargetDialog' gadget to be able:
-select Drive
-select Folder
-select File/s
and add there gadget for selecting 'FileMask' as optional parameter.
This feature would be excellent, Muttonhead, what do you say ?

Here is enhanced "Demo_FileRequeste.bas" to see/understand target AND fullpathedTarget

Code: Select all

'Compileroption -s gui
#include "sGUI\sGUI.bas"
'#include once "sGUI\FileRequester.bas"
#include once "sGUI\FileRequesterD.bas"'german version to show("convert") german umlauts
using sGUI
screen 20,32
InitGFX 0
? "curdir= ";curdir
?
dim as string openfile,aFile=""
openfile=FileRequester(600,100,"Open",curdir,"",1)
	? "openfile= ";openfile
	? "aFile- ";aFile," =empty - not passed to gadget !"	
 ? ,"press a key ...":sleep
?:? "NOW passed to gadget !"
aFile=""
openfile=FileRequester(600,100,"Open",curdir,aFile,1)
	? "openfile= ";openfile
	? "aFile- ";aFile
 ? ,"press a key ...":sleep
end
S'shotImage
Muttonhead
Posts: 143
Joined: May 28, 2009 20:07

Re: sGUI

Post by Muttonhead »

Windows only:

Code: Select all

chdir "c:\"
print curdir
sleep
in this case curdir returns´"c:\", and here is your separator at end ;)
the origin code runs under linux too, so i decide to make no difference

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

Re: sGUI

Post by petan »

Wildy ..
Well, so I'll try to rewrite it completely tonight and test it on 3 tuxes and XP.

edit:
Solved.
Last edited by petan on Dec 10, 2014 4:06, edited 1 time in total.
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

This one likes me more ;)
And movable!
Image
Named as 'FileRequestere2' temporary..
Adding to WizDizzy 0.3b in a next days I hope due swapped macros, other mechanism for flickerfree & designer bugfix (Dim groups output).

Code: Select all

declare function FileRequester2(PosX as integer,PosY as integer,akcion as string,Path as string, File as string="",FExistMode as integer=0) as string
declare sub FindContent(gad as Gadget ptr,t as string )
#macro rrrActionSelector()	
'rearrange ActionSelector FileRequester...
	mbX+=difX:mbY+=difY
rem	stayInScene()
	rrrLTGad(labelp)
	rrrLTGad(labelf)
	rrrLTGad(lablMask)
	rrrComboGad(doit)
	rrrComboGad(aFileMask)
	rrrStringGad(strpath)
	rrrStringGad(strfile)
	rrrListBoxGad(contlist)
	rrrLTGad(gogo)
	rrrLTGad(cancel)
	rrrLTGad(cdparent)
#endmacro		
	'strictly action
'function FileRequester(posx as integer,posy as integer,BtnText as string,Path as string, File as string="",FExistMode as integer=0) as string
	'selectable action
function FileRequester2(PosX as integer,PosY as integer,akcion as string,Path as string, File as string="",FExistMode as integer=0) as string
  function=""
  dim as integer i,boxw,boxh
  dim as string noCh=string(10,219)
  dim as integer scrW, scrH,mbX,mbY,difX,difY,msgBoxMove=0		
  ScreenInfo scrW, scrH			
  dim as string akce(1 to 5)={phrase_open,phrase_save,phrase_edit,phrase_search,phrase_delete}
  'Sichern des vom Requester bedeckten Hintergrundes
  dim as FB.Image ptr gfxbackup,messBoxBackup
  boxw=400: boxh=300
  gfxbackup=imagecreate(boxw,boxh)
  messBoxBackup=imagecreate(boxw,boxh)	
    mbX=PosX:mbY=PosY						
    stayInScene()		'correction if needed
    PosX=mbX:PosY=mbY	'calling coord corrected 
  
  get (mbX,mbY)-(mbX+boxw-1,mbY+boxh-1),gfxbackup
  
  FillA(PosX,PosY,400,300,GadgetColor,0)
  FrameB(PosX+2,PosY+21,396,277,1)
  ClearBox(PosX+3,PosY+22,394,275)
  draw string (mbX+8,mbY+3),akce(1) & "...",TextColor		'synchronize dialog action title
  draw string (mbX+80,mbY+3)," action ",TextColor  
  if messBoxBackup then	
		get (mbX,mbY)-(mbX+boxw-1,mbY+boxh-1),messBoxBackup		
  end if	
  
  
  dim as string sep,drive,originpath=curdir
  'Windows Variante
  #ifdef __fb_win32__
    sep="\"
  #endif
  'Tux Variante
  #ifdef __FB_LINUX__
    sep="/"
  #endif

  dim as integer rows
  if fontheight=8  then rows=22
  if fontheight=14 then rows=12
  if fontheight=16 then rows=11

  dim as string entry,GoToFolder,full
  GoToFolder=""
  entry=""
  chdir Path
  Path=curdir
   if right(Path,1)<>sep then Path+=sep		'fix path slash if missing
  drive=left(Path,1)	'win
  'drive=	'lin !! different
 dim as EventHandle ptr event=new EventHandle
 dim as Gadget ptr labelp,labelf,doit,cancel,strpath,strfile,contlist,cdparent,aFileMask,lablMask,gogo
  labelp  =AddLabel(event,PosX+5, PosY+28,phrase_path & ":",TextColor)
  strpath =AddStringGadget(event,PosX+50,PosY+25,38,Path,,,1)	
  contlist=AddListBox(event,PosX+5,PosY+54,46,rows)
  labelf  =AddLabel(event,PosX+5, PosY+245,phrase_file & ":",TextColor)
  lablMask=AddLabel(event,PosX+5, PosY+271,phrase_mask & ":",TextColor)
  'doit    =AddSimpleGadget(event,PosX+309,PosY+242,85,23,akcion)	'strictly passed action only
  doit    =AddComboBox (event,PosX+230,PosY+271,7,5)	'select action
	for i=1 to ubound(akce)
		TO_AppendLine(doit,akce(i))
	next i
	 SetComboBoxVal(doit,1)

  gogo    =AddSimpleGadget(event,PosX+325,PosY+242,70,23,akce(1))
  cancel  =AddSimpleGadget(event,PosX+325,PosY+271,70,23,phrase_cancel)
  
  strfile =AddStringGadget(event,PosX+50,PosY+242,31,File,,,1)
  aFileMask=AddComboBox (event,PosX+50,PosY+271,10,4)
   TO_AppendLine(aFileMask,"*.*")
   TO_AppendLine(aFileMask,"*.audio")
   TO_AppendLine(aFileMask,"*.video")
   TO_AppendLine(aFileMask,"*.text")
    SetComboBoxVal(aFileMask,1)
  cdparent=AddSimpleGadget(event,PosX+362,PosY+25,32,23,"..")		

  TO_ClearText(contlist)
  FindContent(contlist,"D")
  FindContent(contlist,"F")
  UpdateGadget(contlist)

  GadgetOn(labelp,cdparent)
  do
    event->xSleep(1,0)
    if event->GADGETMESSAGE then
      select case event->GADGETMESSAGE

        'Pfadeingabe
        case strpath
          chdir GetString(strpath)           'Wechsel ins Directory
          Path=curdir                        'Setze aktuellen Pfad
           if right(Path,1)<>sep then Path+=sep		'fix path slash if missing
           
          TO_ClearText(contlist)
          FindContent(contlist,"D")
          FindContent(contlist,"F")
          UpdateGadget(contlist)

          SetString(strpath,Path)                     'Aktualisiere die Pfadanzeige

        case contlist
          entry=TO_GetLineContent(contlist,GetListBoxVal(contlist))

          if entry<>"" then
            if left(entry,6)="<DIR> " then                'wenn entry ein Directory
              GadgetSleep(aFileMask)
              GoToFolder=right(entry,len(entry)-6)
              chdir GoToFolder                   'Wechsel ins Directory
              Path=curdir                        'Setze aktuellen Pfad
			   if right(Path,1)<>sep then Path+=sep		'fix path slash if missing

              TO_ClearText(contlist)
              FindContent(contlist,"D")
              FindContent(contlist,"F")
              UpdateGadget(contlist)
              SetString(strpath,Path)                     'Aktualisiere die Pfadanzeige
			else                     'non-directory
				GadgetOn(aFileMask)
            end if
              File=entry
              SetString(strfile,File)
          end if

        case cdparent
          chdir ".."                                  'Wechsel ins übergeordnete Directory
          Path=curdir                        'Setze aktuellen Pfad
           if right(Path,1)<>sep then Path+=sep		'fix path slash if missing
          
          TO_ClearText(contlist)
          FindContent(contlist,"D")
          FindContent(contlist,"F")
          UpdateGadget(contlist)
           SetString(strpath,Path)                     'Aktualisiere die Pfadanzeige        

				'Beenden und Rückabe eines Strings
        case doit
			if akce(GetComboBoxVal(doit))<>akcion then 
				akcion=akce(GetComboBoxVal(doit))
				draw string (mbX+5,mbY+3),noCh,GadgetColor		
				draw string (mbX+8,mbY+3),akcion & "...",TextColor		'synchronize dialog action title
				SetCaption(gogo,akcion)
			end if
			
        case gogo	
          File=GetString(strfile)
          if File<>"" then
             if instr(entry,"<DIR> ") then				
              full=Path						
              File=GoToFolder		
            else
              full=Path & File
            end if           
            
            if FExistMode then
              if fileexists(full) then
                function=full
                event->EXITEVENT=1
              else
                GadgetSleep(labelp,cdparent)
                MessageBoxMove(PosX+20,PosY+100,phrase_fileaccessdenied,phrase_error,MBType_OK)
                RestoreActivation(labelp,cdparent)
              end if
            else
              function=full
              event->EXITEVENT=1
            end if
          end if

        'Abbruch des FileRequesters
        case cancel
          event->EXITEVENT=1
          function=""

      end select
    end if
    'moving
		if LMB=HOLD and (MOUSEX>=mbX) and (MOUSEX<mbX+boxw) and (MOUSEY>=mbY) and (MOUSEY<mbY+30) and msgBoxMove=0 then 		
			msgBoxMove=1
			sGS(labelp,cdparent,2)		'gadsShot
			GadgetOff(labelp,cdparent)
		end if
		
		if LMB=HOLD and msgBoxMove=1 and mouseMoved=1 then
                    screenlock
			put (mbX,mbY),gfxbackup,pset
		  if MOUSEX>-1 and MOUSEY>-1 then
			difX=MOUSEX-OLDMOUSEX:difY=MOUSEY-OLDMOUSEY
			rrrActionSelector()
			'cls? flickering
		  end if
			get (mbX,mbY)-(mbX+boxw-1,mbY+boxh-1),gfxbackup		
			put (mbX,mbY),messBoxBackup,pset
                  screenunlock
		end if
		
		if LMB=RELEASED and msgBoxMove=1 then
			msgBoxMove=0
			put (mbX,mbY),gfxbackup,pset
		  if MOUSEX>-1 and MOUSEY>-1 then			
			difX=MOUSEX-OLDMOUSEX:difY=MOUSEY-OLDMOUSEY
			rrrActionSelector()
		  end if
			put (mbX,mbY),messBoxBackup,pset
			rGS(labelp,cdparent,2)		'restore gadsShot
		end if    
  loop until event->EXITEVENT
  delete event
  chdir originpath
   put (mbX,mbY),gfxbackup,pset
   imagedestroy gfxbackup
   imagedestroy messBoxBackup
end function
Last edited by petan on Dec 11, 2014 4:47, edited 2 times in total.
RockTheSchock
Posts: 252
Joined: Mar 12, 2006 16:25

Re: sGUI

Post by RockTheSchock »

http://www.freebasic-portal.de/porticul ... -1783.html

Maybe this could be intersting for you. It plots strings with utf-8 characters to screen.
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

Thx for this tip, I 'll test it if time permit.

'FileRequester' updated.Even better, no OK btn ;)

Thinking on 'resizingBox' feature.Seems the best would be to expand three lines - diagonal,vert+horizontal line from mouse and not whole picture, due speed&flickering.
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

sGUI - Error messages

Post by petan »

Error messages:
139 Segmentation fault - where - 'Menu(off)' - why - missing 'Menu(on)',
the same as this

Code: Select all

    
'...
Menu(on)
Menu(off)
Menu(off)
'...

Status - Fixed. (sub MenuOn/Off enhanced)
petan
Posts: 683
Joined: Feb 16, 2010 15:34
Location: Europe
Contact:

Re: sGUI

Post by petan »

Bug in 'Menu' founded,
reason - missing state solver/Johnson

Fixed (assuming only 1 menu existing).
"Menu.bas"

Code: Select all

    
sub MenuOn(event as EventHandle ptr)
 '? "MenuOn",event->GetMenuStatus
 if event->GetMenuStatus=0 then
  dim as integer scrw
  dim as integer ptr buffer
  screeninfo(scrw)
  buffer=imagecreate(scrw,fontheight+4)
  get (0,0)-(scrw-1,fontheight+3),buffer
  event->SetMenuBarBuffer(buffer)
  event->MenuSwitch(1)
  DrawAllMenuHeaders(event)
 else
	? "bug Menuon"
 end if
' ? "MenuOn",event->GetMenuStatus
end sub
sub MenuOff(event as EventHandle ptr)
'? "MenuOff",event->GetMenuStatus
 if event->GetMenuStatus=1 then
  dim as integer scrw
  dim as integer ptr buffer
  screeninfo(scrw)
  put (0,0),event->GetMenuBarBuffer,pset
  imagedestroy event->GetMenuBarBuffer
  event->SetMenuBarBuffer(0)
  event->MenuSwitch(0)
  else
	? "bug Menuoff"
 end if
 '? "MenuOff",event->GetMenuStatus
end sub
Post Reply