FLTK 1.3.x C Wrapper (obsolete)

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
nimdays
Posts: 219
Joined: May 29, 2014 22:01
Location: ID

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby nimdays » Jul 20, 2015 0:57

D.J.Peters wrote:@nimdays
The taskbar or info panel is the part of the desktop manager you are using (KDE, GNOME, XFCE, ...)

Joshy


Ok then :)

Right now i want to create a small calculator with Fl_Float_Input , how to align the text to the right and maybe uneditable from keyboard input ?
D.J.Peters
Posts: 7694
Joined: May 28, 2005 3:28

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » Jul 20, 2015 2:12

@nimdays if you will only shown numbers you entered via buttons
why do you use an input widget witch is of course editable via keyboard ?

Looks like you need only a text output widget
Fl_Box or FL_Output or Fl_Text_Display ...

Alignment can be set via Fl_WidgetSetAlign() there are more
search in fltk-c.bi for "Fl_Align"

Joshy
Last edited by D.J.Peters on Jul 20, 2015 13:25, edited 1 time in total.
enform
Posts: 173
Joined: Apr 24, 2011 12:57
Location: France

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby enform » Jul 20, 2015 10:30

Hello ,

I want to highlight 1 line of text in Fl_Editor , but with this code 2 clicks are needed .
Is it possible with 1 click ? Thank you .

Compile with console

Edit : with the first click only , Fl_Text_DisplayGetInsertPosition does not give the right position .

Code: Select all

#include once "fltk-c.bi"

'test of:
' HighLight in editor

Namespace ns
   Dim As Any Ptr edt,buf
End Namespace   

Function wineventsCB Cdecl(win As Any Ptr ,event as Fl_Event) As Integer
    If Fl_EventInside(ns.edt) > 0 And event = FL_EVENT_PUSH Then
       Var cursor = Fl_Text_DisplayGetInsertPosition(ns.edt)
 ? cursor
       Var startl = Fl_Text_DisplayLineStart(ns.edt,cursor)
       Var endl = Fl_Text_DisplayLineEnd(ns.edt,cursor,1)
       Fl_Text_BufferSetHighlight(ns.buf,startl,endl)
    EndIf
   Return Fl_WindowExHandleBase(win,event)
End Function


'
' main
'
var win = Fl_WindowExNew(640,480, "Fl_Text_Editor")
Fl_WindowExSetHandleCB(win,@wineventsCB)
ns.buf = Fl_Text_BufferNew()
ns.edt = Fl_Text_EditorNew(10,10,Fl_WidgetGetW(win)-20,Fl_WidgetGetH(win)-20)
Fl_Text_DisplaySetBuffer ns.edt,ns.buf

Fl_Text_BufferAppend ns.buf,"012345" + Chr(10)
Fl_Text_BufferAppend ns.buf,"012345" + Chr(10)
Fl_Text_BufferAppend ns.buf,"012345" + Chr(10)
Fl_Text_BufferAppend ns.buf,"012345" + Chr(10)
Fl_Text_BufferAppend ns.buf,"012345" + Chr(10)

Fl_GroupSetResizable win,ns.edt
Fl_WindowShow win
Fl_Run
D.J.Peters
Posts: 7694
Joined: May 28, 2005 3:28

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » Jul 20, 2015 11:25

@nimdays here are:

how to use a Fl_Box as text output
how to align text inside a label
how to send different numbers to one Button callback
...
Joshy

Code: Select all

#include once "fltk-c.bi"

enum
  DOT = 10
  CLR
  PLUS
  MINUS
  MULT
  DIVI
  CALC
end enum


sub ButtonCB cdecl (button as Fl_Widget ptr,number as long)
  static as double     a,b
  static as string * 1 op
  static as integer    c,u,n
  dim as Fl_Window ptr win = Fl_WidgetWindow(button)
  dim as Fl_Box    ptr box = Fl_WidgetGetUserData(win)
  var txt = *Fl_WidgetGetLabel(box)
  select case as const number
  case 0 to 9
    if c then txt="" : c=0 ' clear flag
    if u then txt="-": u=0 ' unary flag
    txt &= number
    if op="" then
      n=1:a=val(txt)
    else
      n=2:b=val(txt)
    end if
  case DOT   : if instr(txt,".")=0 then txt &="."
  case CLR   : c=1:op=""
  case MINUS : if n=1 and op="" then
                 op="-":c=1
               elseif op="" then
                 u=1
               end if
  case PLUS  : if n=1 and op="" then op="+":c=1
  case MULT  : if n=1 and op="" then op="*":c=1
  case DIVI  : if n=1 and op="" then op="/":c=1
  case CALC  : if n=2 then
                 txt=""
                 select case op
                 case "-" :a-=b
                 case "+" :a+=b
                 case "*" :a*=b
                 case "/"
                   if b<>0 then
                     a/=b
                   else
                     txt="err"
                   end if
                 end select
                 if txt="" then txt=str(a)
                 c=1:op=""
               end if
  end select
  Fl_WidgetCopyLabel(box,txt)
end sub
#define COL(x) 10+x*30
#define ROW(y) 44+y*30
#define BTN Fl_WidgetSetCallback1Arg Fl_ButtonNew

'
' main
'
var win = Fl_WindowNew(160,160,"")
var box = Fl_BoxNew(5,5,150,32)
Fl_WidgetSetUserData   win,box
Fl_WidgetSetBox        box,BoxType(FL_PLASTIC_DOWN_BOX)
Fl_WidgetSetAlign      box,Fl_ALIGN_RIGHT or Fl_ALIGN_INSIDE
Fl_WidgetSetLabelColor box,FL_BLUE
Fl_WidgetSetLabelFont  box,Fl_COURIER_BOLD
Fl_WidgetSetLabelSize  box,22

BTN(COL(0),ROW(0),24,24,"1"),@ButtonCB,1
BTN(COL(1),ROW(0),24,24,"2"),@ButtonCB,2
BTN(COL(2),ROW(0),24,24,"3"),@ButtonCB,3
BTN(COL(3),ROW(0),54,24,"C"),@ButtonCB,CLR
BTN(COL(0),ROW(1),24,24,"4"),@ButtonCB,4
BTN(COL(1),ROW(1),24,24,"5"),@ButtonCB,5
BTN(COL(2),ROW(1),24,24,"6"),@ButtonCB,6
BTN(COL(3),ROW(1),24,24,"+"),@ButtonCB,PLUS
BTN(COL(4),ROW(1),24,24,"-"),@ButtonCB,MINUS
BTN(COL(0),ROW(2),24,24,"7"),@ButtonCB,7
BTN(COL(1),ROW(2),24,24,"8"),@ButtonCB,8
BTN(COL(2),ROW(2),24,24,"9"),@ButtonCB,9
BTN(COL(3),ROW(2),24,24,"*"),@ButtonCB,MULT
BTN(COL(4),ROW(2),24,24,"/"),@ButtonCB,DIVI
BTN(COL(0),ROW(3),24,24,"0"),@ButtonCB,0
BTN(COL(1),ROW(3),24,24,"."),@ButtonCB,DOT
BTN(COL(3),ROW(3),54,24,"="),@ButtonCB,CALC

Fl_WindowShow win
Fl_Run
Last edited by D.J.Peters on Jul 21, 2015 6:06, edited 1 time in total.
D.J.Peters
Posts: 7694
Joined: May 28, 2005 3:28

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » Jul 20, 2015 12:14

enform wrote:but with this code 2 clicks are needed
In your case looks like the first event goes to the parent Fl_Window and the second to the child Fl_Text_Editor.

firstly:
I'm not sure what you mean.
1) Select a single editor line for editing (delete,copy,paste,search ... default color is dark blue)
or
2) Syntax highlighting a single line of text ?

secondly:
Why you extend the parent window of the widget and not the text editor widget self ?

Tip for free:
If you create a resizable window you should use a flicker free double buffered window.
(use a Fl_Double_Window instead of a Fl_Window)

By the way don't use integer (it's 8 byte on 64bit) and won't compile.
FLTK used 32 bit (long) for all callbacks.
(take a lock at fltk-c.bi there isn't any integer)

Joshy

Code: Select all

#include once "fltk-c.bi"

function HandleCB cdecl(me as any ptr ,event as Fl_Event) as long ' !!! use long not integer !!!
  if event = FL_EVENT_RELEASE then
    var cursor = Fl_Text_DisplayGetInsertPosition(me)
    var sLine  = Fl_Text_DisplayLineStart(me,cursor)
    var eLine  = Fl_Text_DisplayLineEnd(me,cursor,1)
    var buf    = Fl_Text_DisplayGetBuffer(me)
    Fl_Text_BufferSetHighlight(buf,sLine,eLine)
  end if
  return Fl_Text_EditorExHandleBase(me,event)
end function

'
' main
'
var win = Fl_Double_WindowNew(640,480, "Fl_Text_EditorEx")
var edt = Fl_Text_EditorExNew(10,10,Fl_WidgetGetW(win)-20,Fl_WidgetGetH(win)-20)
Fl_Text_EditorExSetHandleCB edt,@HandleCB
var buf = Fl_Text_BufferNew()
for i as long = 1 to 10
  Fl_Text_BufferAppend buf,"line " & i & Chr(10)
next
Fl_Text_DisplaySetBuffer edt,buf
Fl_GroupSetResizable win,edt
Fl_WindowShow win

Fl_Run
Last edited by D.J.Peters on Jul 27, 2015 22:05, edited 2 times in total.
nimdays
Posts: 219
Joined: May 29, 2014 22:01
Location: ID

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby nimdays » Jul 21, 2015 1:20

@D.J.Peters
Thanks a lot Man
D.J.Peters
Posts: 7694
Joined: May 28, 2005 3:28

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » Jul 21, 2015 5:53

nimdays wrote:Thanks a lot Man
No problem.

My question are not answered.
What is your reason for highlight a single line ?

Currently I build a retro home computer with only parts from the late 70' and early 80' but with my knowledge from now. ;-)

The most IC's are MOTOROLA 6800 8-bit family (Freescale this days).
I wrote a 6803 assembler /disassembler from ground up.
I need it to create my own operating system (ROM).
Later a C compiler and linker will follow.

How ever I think about a cycle accurate simulation of some integrated circuits with FLTK.
I would like to have the current execution line of source code highlight.
(the complete row from first left to right most visible pixel, not only the length of text in the row)
Same for a step by step debuger.

So far I know only a Fl_Browser can highlight a complete row.
(should be enough I don't need to edit the executed line)

Joshy
BasicCoder2
Posts: 3358
Joined: Jan 01, 2009 7:03

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby BasicCoder2 » Jul 23, 2015 1:10

D.J.Peters wrote:Currently I build a retro home computer with only parts from the late 70' and early 80' but with my knowledge from now. ;-)
...
How ever I think about a cycle accurate simulation of some integrated circuits with FLTK.
I would like to have the current execution line of source code highlight...


Little confused where your retro computer and FLTK come together?
Can FLTK be used on your 6803 based retro computer using C?
Are you going to have a web page for your project's progress?
D.J.Peters
Posts: 7694
Joined: May 28, 2005 3:28

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » Jul 23, 2015 11:10

BasicCoder2 wrote:Little confused where your retro computer and FLTK come together?
Before you get a working home build computer running you have to build minimal OS.
(the OS must be burned in a ROM chip after power on the MCU will run from reset vector at $FFFE)
So first step are writing an assembler on PC for your target MCU/CPU.
Of course I found 2 old motorola assemblers but they are for DOS and closed source.
The advantage (if you are write your own assembler) is you get a pro of the target CPU in short time.

I combine a lot of old ICs: (I know all IC by name in my mind)
MC6803 (MCU)
MC6874 (CRT video)
MC1372 (TV)
2xMC6821 (PORT I/O)
2xSN76489 (complex sound gererator)
2xYAMAHA YM2612 (FM synth)
AD574 (ADC)
AD667 (DAC)
of course many 74's (OR,NAND,XOR ...) and 8-bit bus/line drivers
the only one modern IC are the PAM8403 a tiny 5V stereo amplifier 2*3W

I emulated a C64 and TRS-80 in the past
so my idea are to create a simulator with FLTK
than I can play with the IC's before I solder it.

In theory you can compile FLTK for an 8 bit computer too.
The problem are a the missing C++ compiler for 8 bit CPUs

I will inform you if I made a web page of my old school computer project.
(or if I upload stuff on youtube)

Joshy
marcov
Posts: 2752
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby marcov » Jul 23, 2015 11:50

D.J.Peters wrote:In theory you can compile FLTK for an 8 bit computer too.
The problem are a the missing C++ compiler for 8 bit CPUs


Many 8-bitters can't have structured types (read: arrays) larger than 256 bytes. So compiling arbitrary software without heavy modifications is out of the question.

Even 16-bit targets suffer from this (but the 64kb limit is already a bit more palpable).
BasicCoder2
Posts: 3358
Joined: Jan 01, 2009 7:03

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby BasicCoder2 » Jul 23, 2015 12:01

I see the 6800 instruction set looks like the 6502 instruction set except there is no IY index register. I remember writing a simple 6502 assembler for the C64. I was into retro stuff back when it wasn't retro :) but it is so long ago I forget most of it. The C64 was a lot of fun.
Amundo
Posts: 56
Joined: Feb 26, 2007 0:25

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby Amundo » Jul 24, 2015 3:39

BasicCoder2 wrote:I see the 6800 instruction set looks like the 6502 instruction set


Getting WAY off-topic here, but the 6502 was MOS Technologies simplified, cut-down, sped-up version of Motorola's 6800.
enform
Posts: 173
Joined: Apr 24, 2011 12:57
Location: France

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby enform » Jul 24, 2015 16:57

Hi D.J.Peters,

I'm not sure what you mean.
1) Select a single editor line for editing (delete,copy,paste,search ... default color is dark blue)
or
2) Syntax highlighting a single line of text ?

i don't see well the difference : once the line is highlighted , it can be edited , no ? Highlighting is the first phase ?

Why you extend the parent window of the widget and not the text editor widget self ?

The easy work with copy-paste ... and yes i forgot all the possible extends , listed in a separate place in fltk-c.bi ( how many
functions 2250 ? ... )

If you create a resizable window you should use a flicker free double buffered window .

I know that feature .

By the way don't use integer (it's 8 byte on 64bit) and won't compile.

64 bits , ok i see .
Thank you for the details in your ( edited ) answer ... ;-)
D.J.Peters
Posts: 7694
Joined: May 28, 2005 3:28

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby D.J.Peters » Jul 27, 2015 22:08

Last version I added some missing DeclareEx() and tested with fbc 1.04.0 (07-25-2015)

Joshy
nimdays
Posts: 219
Joined: May 29, 2014 22:01
Location: ID

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Postby nimdays » Aug 01, 2015 19:50

Hello , what is the correct way to load url by Fl_Help_ViewLoad
From the manual :This method loads the specified file or URL
But when i tried that , transfered to firefox
Thanks

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 1 guest