FLTK 1.3.x C Wrapper (obsolete)

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
D.J.Peters
Posts: 8121
Joined: May 28, 2005 3:28
Contact:

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

Postby D.J.Peters » Jun 06, 2015 22:42

@badidea why not using VAR it's much simpler as writing all class pointer types.

Joshy

Code: Select all

#include once "fltk-c.bi"

sub ChoiceCB cdecl (byval self as Fl_Widget ptr,byval Choice as any ptr)
  print *Fl_Menu_GetMenu(Choice)[Fl_ChoiceGetValue(Choice)].text
end sub

sub CheckCB cdecl (byval self as Fl_Widget ptr, byval CheckButton as any ptr)
  print *Fl_WidgetGetLabel(self) & "[" & Fl_ButtonGetValue(CheckButton) & "]"
end sub

'
' main
'
var win = Fl_WindowNew(320, 200, "Window title!")
var chc = Fl_ChoiceNew(10, 10, 200, 25)
var cbn = Fl_Check_ButtonNew(10, 40, 200, 25, "Check this")

Fl_Menu_Add Chc, "Random text here"
Fl_Menu_Add Chc, "Even more nonsense"
Fl_WidgetSetCallbackArg chc, @ChoiceCB, chc
Fl_WidgetSetCallbackArg cbn, @CheckCB , cbn

Fl_WindowShow Win
Fl_Run
badidea
Posts: 2120
Joined: May 24, 2007 22:10
Location: The Netherlands

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

Postby badidea » Jun 07, 2015 0:04

Naming and typing all the class names makes it more clear for me to understand what I am doing (I hope). But maybe I should use var now, getting more and more variables.

Basic GUI layout done, now to link with actual code...

Code: Select all

#include once "fltk-c.bi"

sub ChoiceCB cdecl (byval self as Fl_Widget ptr,byval pChoice as any ptr)
   print *Fl_Menu_GetMenu(pChoice)[Fl_ChoiceGetValue(pChoice)].text
end sub

sub CheckCB cdecl (byval self as Fl_Widget ptr, byval pButton as any ptr)
   print Fl_ButtonGetValue(pButton)
end sub

sub ButtonCB cdecl (byval self as Fl_Widget ptr, byval pButton as any ptr)
   print Fl_ButtonGetValue(pButton)
end sub

dim as integer i

'Window
dim as Fl_Window ptr pWin
pWin = Fl_WindowNew(590, 600, "Settler Online Battle Simulator / 2015-06-07")

'Label
dim as Fl_Box ptr pBoxGens, pBoxUnits
pBoxGens = Fl_BoxNew2(BoxType(FL_ENGRAVED_BOX), 10, 10, 100, 25, "Generalen")
pBoxUnits = Fl_BoxNew2(BoxType(FL_ENGRAVED_BOX), 120, 10, 100, 25, "Eenheden")

'Checkbox
const as integer NUM_GEN_TYPES = 6
const as integer NUM_UNIT_TYPES = 9
dim as string genAbrStr(NUM_GEN_TYPES-1) = {"200", "Mod", "220", "Vet", "Mma", "Mjr"}
dim as string unitAbrStr(NUM_UNIT_TYPES-1) = {"R", "M", "S", "E", "C", "B", "L", "X", "K"}
dim As Fl_Check_Button ptr pCheckGen(NUM_GEN_TYPES-1), pCheckUnit(NUM_UNIT_TYPES-1)

for i = 0 to NUM_GEN_TYPES-1
   pCheckGen(i) = Fl_Check_ButtonNew(20, 40 + i * 30, 100, 25, genAbrStr(i))
   Fl_ButtonSetValue(pCheckGen(i), 1)
   Fl_WidgetSetCallbackArg(pCheckGen(i), @CheckCB, pCheckGen(i))
next
for i = 0 to NUM_UNIT_TYPES-1
   pCheckUnit(i) = Fl_Check_ButtonNew(130, 40 + i * 30, 100, 25, unitAbrStr(i))
   Fl_ButtonSetValue(pCheckUnit(i), 1)
   Fl_WidgetSetCallbackArg(pCheckUnit(i), @CheckCB, pCheckUnit(i))
next

'Button
dim As Fl_Button ptr pButGo, pButSimSet, pButCost
pButGo = Fl_ButtonNew(20, 10 + 7 * 30, 80, 80, "Go!")
pButSimSet = Fl_ButtonNew(20, 10 + 10 * 30, 190, 25, "Simulatie settings")
pButSimSet = Fl_ButtonNew(20, 10 + 11 * 30, 190, 25, "Kosten eenheden")

'Drop-down list
const as integer NUM_ENEM_TYPES = 4
dim as Fl_Choice ptr pChoAdv, pChoCamp, pChoEnem(NUM_ENEM_TYPES-1)

pChoAdv = Fl_ChoiceNew(250, 10, 260, 25)
Fl_Menu_Add(pChoAdv, "Kies een avontuur")
Fl_Menu_Add(pChoAdv, "Het dappere kleermakertje")
Fl_Menu_Add(pChoAdv, "De zonen van het kleermakertje")
Fl_ChoiceSetValue(pChoAdv, 0)
Fl_WidgetSetCallbackArg(pChoAdv, @ChoiceCB, pChoAdv)

pChoCamp = Fl_ChoiceNew(250, 10 + 2 * 30, 260, 25)
Fl_Menu_Add(pChoCamp, "Kies een kamp")
Fl_ChoiceSetValue(pChoCamp, 0)
Fl_WidgetSetCallbackArg(pChoCamp, @ChoiceCB, pChoCamp)

for i = 0 to NUM_ENEM_TYPES-1
   pChoEnem(i) = Fl_ChoiceNew(250, 10 + (4 + (i * 2)) * 30, 260, 25)
   Fl_Menu_Add(pChoEnem(i), "-")
   Fl_ChoiceSetValue(pChoEnem(i), 0)
   Fl_WidgetSetCallbackArg(pChoEnem(i), @ChoiceCB, pChoEnem(i))
next

'Images
dim as Fl_Box ptr pBoxAdvImg, pBoxCampImg, pBoxEnemImg(NUM_ENEM_TYPES-1)
pBoxAdvImg = Fl_BoxNew2(BoxType(FL_ENGRAVED_BOX), 520, 10, 25 + 30, 25 + 30, "-")
pBoxCampImg = Fl_BoxNew2(BoxType(FL_ENGRAVED_BOX), 520, 10 + 2 * 30, 25 + 30, 25 + 30, "-")

for i = 0 to NUM_ENEM_TYPES-1
   pBoxEnemImg(i) = Fl_BoxNew2(BoxType(FL_ENGRAVED_BOX), 520, 10 + (4 + (2 * i)) * 30, 25 + 30, 25 + 30, "-")
next

'output
dim as Fl_Multiline_Output ptr pOutResut
pOutResut = Fl_Multiline_OutputNew(10, 390, 570, 200)

Fl_WindowShow(pWin)
Fl_Run
BasicCoder2
Posts: 3571
Joined: Jan 01, 2009 7:03
Location: Australia

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

Postby BasicCoder2 » Jun 07, 2015 0:43

I just downloaded and tried the FLTK for FreeBasic and the source code examples that came with it just worked no messing about with FIDE links etc. unlike the download to the CodeBlocks IDE which as usual responds with "fatal error: FL/fl_utf8.h: No such file or directory". Why are libraries so much easier to implement using FBIDE with FreeBASIC vs. using C++ with CodeBlocks?
D.J.Peters
Posts: 8121
Joined: May 28, 2005 3:28
Contact:

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

Postby D.J.Peters » Jun 07, 2015 0:58

I use CodeBlocks for all my projects on all my boxes windows,Linux,ARM
and for different CPU's and MC's AVR, Cortex, STM ...

A code::blocks project is simply a xml file you can create or edit this file with any text editor.

You can add the search path for include files and library's.

Where are the FLTK include files ?
<Add directory="../../../downloads/windows/programmierung/GUI/FLTK/fltk-1.3.3" />

Where are the FLTK libraries files ?
<Add directory="lib/windows/lib" />

Which libraries must be linked ?
<Add library="fltk-1.3.3" />
<Add library="fltk_images" />
<Add library="fltk_png" />
<Add library="fltk_jpeg" />
<Add library="fltk_zlib" />
<Add library="fltk_forms" />

For example the code::blocks project for the fltk c wrapper.

You can see i added different targets in this file Windows 32/64 Linux x86/x86_64

Joshy

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
   <FileVersion major="1" minor="6" />
   <Project>
      <Option title="fltk-1.3.3-c-wrapper" />
      <Option pch_mode="2" />
      <Option compiler="gcc" />
      <Build>
         <Target title="Windows_X86">
            <Option platforms="Windows;" />
            <Option output="./fltk-c-1.3.3-32.dll" imp_lib="./libfltk-c-1.3.3-32.dll.a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME)" prefix_auto="0" extension_auto="0" />
            <Option object_output="obj/windows/lib" />
            <Option type="3" />
            <Option compiler="gnu_gcc_compiler_i686_w64_492" />
            <Option createStaticLib="1" />
            <Compiler>
               <Add option="-Wall" />
               <Add option="-m32" />
               <Add option="-fexceptions" />
               <Add option="-finline-functions" />
               <Add option="-DBUILD_DLL" />
               <Add option="-DNDEBUG" />
               <Add option="-DWIN32" />
               <Add option="-D_WINDOWS" />
               <Add option="-D_CRT_SECURE_NO_DEPRECATE" />
               <Add option="-D_CRT_NONSTDC_NO_DEPRECATE" />
               <Add option="-DWIN32_LEAN_AND_MEAN" />
               <Add option="-DVC_EXTRA_LEAN" />
               <Add option="-DWIN32_EXTRA_LEAN" />
               <Add directory="../../../downloads/windows/programmierung/GUI/FLTK/fltk-1.3.3" />
               <Add directory="zlib" />
               <Add directory="png" />
               <Add directory="jpeg" />
            </Compiler>
            <Linker>
               <Add option="-s" />
               <Add option="-m32" />
               <Add option="-static" />
               <Add library="fltk-1.3.3" />
               <Add library="fltk_images" />
               <Add library="fltk_png" />
               <Add library="fltk_jpeg" />
               <Add library="fltk_zlib" />
               <Add library="fltk_forms" />
               <Add library="fltk_gl" />
               <Add library="kernel32" />
               <Add library="user32" />
               <Add library="gdi32" />
               <Add library="winspool" />
               <Add library="comdlg32" />
               <Add library="advapi32" />
               <Add library="shell32" />
               <Add library="ole32" />
               <Add library="oleaut32" />
               <Add library="uuid" />
               <Add library="opengl32" />
               <Add library="comctl32" />
               <Add directory="lib/windows/lib" />
            </Linker>
         </Target>
         <Target title="Windows_X86_64">
            <Option platforms="Windows;" />
            <Option output="./fltk-c-1.3.3-64.dll" imp_lib="./libfltk-c-1.3.3-64.dll.a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME)" prefix_auto="0" extension_auto="0" />
            <Option object_output="obj/windows/lib64" />
            <Option type="3" />
            <Option compiler="gnu_gcc_compiler_i686_w64_492" />
            <Option createStaticLib="1" />
            <Compiler>
               <Add option="-Wall" />
               <Add option="-fexceptions" />
               <Add option="-finline-functions" />
               <Add option="-m64" />
               <Add option="-DBUILD_DLL" />
               <Add option="-DNDEBUG" />
               <Add option="-D_WINDOWS" />
               <Add option="-DWIN32" />
               <Add option="-DWIN64" />
               <Add option="-D_CRT_SECURE_NO_DEPRECATE" />
               <Add option="-D_CRT_NONSTDC_NO_DEPRECATE" />
               <Add option="-DWIN32_LEAN_AND_MEAN" />
               <Add option="-DWIN32_EXTRA_LEAN" />
               <Add option="-DVC_EXTRA_LEAN" />
               <Add directory="../../../downloads/windows/programmierung/GUI/FLTK/fltk-1.3.3" />
               <Add directory="zlib" />
               <Add directory="png" />
               <Add directory="jpeg" />
            </Compiler>
            <Linker>
               <Add option="-s" />
               <Add option="-static" />
               <Add option="-m64" />
               <Add library="fltk-1.3.3" />
               <Add library="fltk_images" />
               <Add library="fltk_png" />
               <Add library="fltk_jpeg" />
               <Add library="fltk_zlib" />
               <Add library="fltk_forms" />
               <Add library="fltk_gl" />
               <Add library="pthread" />
               <Add library="kernel32" />
               <Add library="user32" />
               <Add library="gdi32" />
               <Add library="winspool" />
               <Add library="comdlg32" />
               <Add library="advapi32" />
               <Add library="shell32" />
               <Add library="ole32" />
               <Add library="oleaut32" />
               <Add library="uuid" />
               <Add library="opengl32" />
               <Add library="comctl32" />
               <Add directory="lib/windows/lib64" />
            </Linker>
         </Target>
         <Target title="Linux_X86">
            <Option platforms="Unix;" />
            <Option output="./libfltk-c-1.3.3-32.so" prefix_auto="0" extension_auto="0" />
            <Option object_output="obj/linux/lib" />
            <Option type="3" />
            <Option compiler="gcc" />
            <Option createStaticLib="1" />
            <Compiler>
               <Add option="-Wall" />
               <Add option="-fexceptions" />
               <Add option="-finline-functions" />
               <Add option="-DBUILD_DLL" />
               <Add option="-DNDEBUG" />
               <Add directory="../../../downloads/windows/programmierung/GUI/FLTK/fltk-1.3.3" />
            </Compiler>
            <Linker>
               <Add option="-s" />
               <Add library="fltk" />
               <Add library="fltk_gl" />
               <Add library="fltk_forms" />
               <Add library="fltk_images" />
               <Add library="fltk_jpeg" />
               <Add library="fltk_png" />
               <Add library="fltk_z" />
               <Add library="GL" />
               <Add library="X11" />
               <Add library="Xft" />
               <Add library="Xinerama" />
               <Add library="Xcursor" />
               <Add directory="lib/linux/lib" />
            </Linker>
         </Target>
         <Target title="Linux_X86_syslib">
            <Option platforms="Unix;" />
            <Option output="./libfltk-c-1.3.3-32-syslib.so" prefix_auto="0" extension_auto="0" />
            <Option object_output="obj/linux/lib" />
            <Option type="3" />
            <Option compiler="gcc" />
            <Option createStaticLib="1" />
            <Compiler>
               <Add option="-Wall" />
               <Add option="-fexceptions" />
               <Add option="-finline-functions" />
               <Add option="-DBUILD_DLL" />
               <Add option="-DNDEBUG" />
               <Add directory="../../../downloads/windows/programmierung/GUI/FLTK/fltk-1.3.3" />
            </Compiler>
            <Linker>
               <Add option="-s" />
               <Add library="fltk" />
               <Add library="fltk_gl" />
               <Add library="fltk_forms" />
               <Add library="fltk_images" />
               <Add library="GL" />
               <Add library="X11" />
               <Add library="Xft" />
               <Add library="Xinerama" />
               <Add library="Xcursor" />
               <Add directory="lib/linux/lib" />
            </Linker>
         </Target>
         <Target title="Linux_X86_64">
            <Option platforms="Unix;" />
            <Option output="./libfltk-c-1.3.3-64.so" prefix_auto="0" extension_auto="0" />
            <Option object_output="obj/linux/lib64" />
            <Option type="3" />
            <Option compiler="gcc" />
            <Compiler>
               <Add option="-Wall" />
               <Add option="-fexceptions" />
               <Add option="-finline-functions" />
               <Add option="-m64" />
               <Add option="-fPIC" />
               <Add option="-DBUILD_DLL" />
               <Add option="-DNDEBUG" />
               <Add directory="../../../downloads/windows/programmierung/GUI/FLTK/fltk-1.3.3" />
            </Compiler>
            <Linker>
               <Add option="-s" />
               <Add option="-m64" />
               <Add option="-fPIC" />
               <Add library="fltk" />
               <Add library="fltk_gl" />
               <Add library="fltk_forms" />
               <Add library="fltk_images" />
               <Add library="fltk_jpeg" />
               <Add library="fltk_png" />
               <Add library="fltk_z" />
               <Add library="GL" />
               <Add library="X11" />
               <Add library="Xft" />
               <Add library="Xinerama" />
               <Add library="Xcursor" />
               <Add directory="lib/linux/lib64" />
            </Linker>
         </Target>
         <Target title="Linux_X86_64_syslib">
            <Option platforms="Unix;" />
            <Option output="./libfltk-c-1.3.3-64-syslib.so" prefix_auto="0" extension_auto="0" />
            <Option object_output="obj/linux/lib64" />
            <Option type="3" />
            <Option compiler="gcc" />
            <Compiler>
               <Add option="-Wall" />
               <Add option="-fexceptions" />
               <Add option="-finline-functions" />
               <Add option="-m64" />
               <Add option="-fPIC" />
               <Add option="-DBUILD_DLL" />
               <Add option="-DNDEBUG" />
               <Add directory="../../../downloads/windows/programmierung/GUI/FLTK/fltk-1.3.3" />
            </Compiler>
            <Linker>
               <Add option="-s" />
               <Add option="-m64" />
               <Add option="-fPIC" />
               <Add library="fltk" />
               <Add library="fltk_gl" />
               <Add library="fltk_forms" />
               <Add library="fltk_images" />
               <Add library="GL" />
               <Add library="X11" />
               <Add library="Xft" />
               <Add library="Xinerama" />
               <Add library="Xcursor" />
               <Add directory="lib/linux/lib64" />
            </Linker>
         </Target>
      </Build>
      <Unit filename="fltk-c-wrapper-box.cpp" />
      <Unit filename="fltk-c-wrapper-box.h" />
      <Unit filename="fltk-c-wrapper-browsers.cpp" />
      <Unit filename="fltk-c-wrapper-browsers.h" />
      <Unit filename="fltk-c-wrapper-buttons.cpp" />
      <Unit filename="fltk-c-wrapper-buttons.h" />
      <Unit filename="fltk-c-wrapper-canvas.cpp" />
      <Unit filename="fltk-c-wrapper-canvas.h" />
      <Unit filename="fltk-c-wrapper-chart.cpp" />
      <Unit filename="fltk-c-wrapper-chart.h" />
      <Unit filename="fltk-c-wrapper-choice.cpp" />
      <Unit filename="fltk-c-wrapper-choice.h" />
      <Unit filename="fltk-c-wrapper-clock.cpp" />
      <Unit filename="fltk-c-wrapper-clock.h" />
      <Unit filename="fltk-c-wrapper-colorchooser.cpp" />
      <Unit filename="fltk-c-wrapper-colorchooser.h" />
      <Unit filename="fltk-c-wrapper-dialogs.cpp" />
      <Unit filename="fltk-c-wrapper-dialogs.h" />
      <Unit filename="fltk-c-wrapper-drawing.cpp" />
      <Unit filename="fltk-c-wrapper-drawing.h" />
      <Unit filename="fltk-c-wrapper-fl.cpp" />
      <Unit filename="fltk-c-wrapper-fl.h" />
      <Unit filename="fltk-c-wrapper-groups.cpp" />
      <Unit filename="fltk-c-wrapper-groups.h" />
      <Unit filename="fltk-c-wrapper-helpview.cpp" />
      <Unit filename="fltk-c-wrapper-helpview.h" />
      <Unit filename="fltk-c-wrapper-images.cpp" />
      <Unit filename="fltk-c-wrapper-images.h" />
      <Unit filename="fltk-c-wrapper-input.cpp" />
      <Unit filename="fltk-c-wrapper-input.h" />
      <Unit filename="fltk-c-wrapper-menus.cpp" />
      <Unit filename="fltk-c-wrapper-menus.h" />
      <Unit filename="fltk-c-wrapper-nfc.cpp" />
      <Unit filename="fltk-c-wrapper-nfc.h" />
      <Unit filename="fltk-c-wrapper-paged-surface.cpp" />
      <Unit filename="fltk-c-wrapper-paged-surface.h" />
      <Unit filename="fltk-c-wrapper-preferences.cpp" />
      <Unit filename="fltk-c-wrapper-preferences.h" />
      <Unit filename="fltk-c-wrapper-progress.cpp" />
      <Unit filename="fltk-c-wrapper-progress.h" />
      <Unit filename="fltk-c-wrapper-surface.cpp" />
      <Unit filename="fltk-c-wrapper-surface.h" />
      <Unit filename="fltk-c-wrapper-table.cpp" />
      <Unit filename="fltk-c-wrapper-table.h" />
      <Unit filename="fltk-c-wrapper-text.cpp" />
      <Unit filename="fltk-c-wrapper-text.h" />
      <Unit filename="fltk-c-wrapper-tools.cpp" />
      <Unit filename="fltk-c-wrapper-tools.h" />
      <Unit filename="fltk-c-wrapper-tooltip.cpp" />
      <Unit filename="fltk-c-wrapper-tooltip.h" />
      <Unit filename="fltk-c-wrapper-treeview.cpp" />
      <Unit filename="fltk-c-wrapper-treeview.h" />
      <Unit filename="fltk-c-wrapper-uri.cpp" />
      <Unit filename="fltk-c-wrapper-uri.h" />
      <Unit filename="fltk-c-wrapper-utf8.cpp" />
      <Unit filename="fltk-c-wrapper-utf8.h" />
      <Unit filename="fltk-c-wrapper-valuator.cpp" />
      <Unit filename="fltk-c-wrapper-valuator.h" />
      <Unit filename="fltk-c-wrapper-widget.cpp" />
      <Unit filename="fltk-c-wrapper-widget.h" />
      <Unit filename="fltk-c-wrapper-windows.cpp" />
      <Unit filename="fltk-c-wrapper-windows.h" />
      <Unit filename="fltk-c-wrapper.h" />
      <Extensions>
         <code_completion />
         <debugger />
         <envvars />
      </Extensions>
   </Project>
</CodeBlocks_project_file>
badidea
Posts: 2120
Joined: May 24, 2007 22:10
Location: The Netherlands

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

Postby badidea » Jun 07, 2015 9:32

@Ike: Yes know that link, which I mentioned as "... the tutorial on the German website ..."
Lothar Schirm
Posts: 333
Joined: Sep 28, 2013 15:08
Location: Bavaria, Germany

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

Postby Lothar Schirm » Jun 07, 2015 14:46

badidea wrote:Naming and typing all the class names makes it more clear for me to understand what I am doing (I hope). But maybe I should use var now, getting more and more variables.

Basic GUI layout done, now to link with actual code...


I see you want to write a GUI for a game or simulation. Do you want to write the simulation itself with a lot of graphics or sprites (moved animations?) with FLTK also, or do you use the FreeBasic graphics window ("Screenres ...")? Up to now, I write my user interface (GUI with menu or listbox, textboxes, buttons etc. ) with my own simple GUI or with FLTK and all graphics and animations on a FreeBasic graphics window.

I would like to know from somebody of our FLTK gurus how simulations and animations can be done with FLTK. For static drawings or diagrams, I have already found the solution. But how can I create moving sprites with FLTK? How can I draw something into an imagebuffer and let it move around in a box until I click on a "Stop" button or press the ESC key? How can I request whether I have clicked on the moving image with a mouseclick? Or should I stay with the FreeBasic graphics window? Seems easier.
D.J.Peters
Posts: 8121
Joined: May 28, 2005 3:28
Contact:

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

Postby D.J.Peters » Jun 07, 2015 16:20

@Lothar FLTK is perfect for video players, animations, simulation, games ...

Fl_Double_Window is the key for flicker free rendering.

My created Fl_Canvas is for any kinds of animations also.
(for example a Fl_Canvas can be 10 times larger then the visible screen)

Level Map based games can be implemented via Fl_Scroll widgets.

Sprites, Bob's are Fl_Image's.

You can use RGBA Pixel Buffers for Fl_RGB_Images.

You can mix FBGFX with FLTK stuff.

You can use bmp, png, jpg, gif ...

You can manage all your game graphics inside of the Fl_Shared_Image collection.

You can use overlay's.

A Fl_Box is a visible rectangulare area .
You can draw any shapes in it.
You can assign a image to a Fl_Box.
You can draw images (scaled) in a Fl_Box.
You can move Fl_Boxes around.

If you assign a pixel buffer to any widget
any changes inside the pixel buffer will be visible in all widgets immediately.

You can use OpenGL 2D,3D drawing with FLTK.
You can include "fltk-glut.bi"
...

see also:
Draggable_BoxesXX.bas
DrawingFastPixels
Fl_ScrollXX.bas
Fl_ScrollDrawing.bas
...

Joshy
Lothar Schirm
Posts: 333
Joined: Sep 28, 2013 15:08
Location: Bavaria, Germany

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

Postby Lothar Schirm » Jun 07, 2015 17:35

Thank you, a lot of stuff! In FreeBasic, I have done much simpler things. As a start, can you please give me the code for a short example:

Draw a simple face into a buffer (e.g. a circle with two eyes (small circles), a nose (vertical line) and a mouth (horizontal line)) and let it move on a circle within a box until the ESC key is pressed.

I think that would be very helpful for me.
Thank you in adavnce!
Lothar
D.J.Peters
Posts: 8121
Joined: May 28, 2005 3:28
Contact:

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

Postby D.J.Peters » Jun 07, 2015 17:59

Lothar Schirm wrote:Draw a simple face into a buffer (e.g. a circle with two eyes (small circles), a nose (vertical line) and a mouth (horizontal line)) and let it move on a circle within a box until the ESC key is pressed.

Code: Select all

#include once "fltk-tools.bi"

' create or load any image
function CreateSprite as Fl_Image ptr
  #undef RGB
  #undef RGBA
  #define RGBA(r,g,b,a) a shl 24 or b shl 16 or g shl 8 or r
  #define RGB(r,g,b) RGBA(r,g,b,255)
  ScreenRes 1,1,32,,&HFFFFFFFF
  dim as ubyte ptr fb_img=ImageCreate(101,101)
  dim as ubyte ptr fb_pixels
  dim as integer   w,h,bpp,pitch
  ImageInfo fb_img,w,h,bpp,pitch,fb_pixels
  Line fb_img,(0,0)-(100,100),RGBA(0,0,0,0),BF
  Circle fb_img,(50,50),50,RGB(255,255,  0),,,,F
  Circle fb_img,(25,30),12,RGB(255,255,255),,,,F
  Circle fb_img,(75,30),12,RGB(255,255,255),,,,F
  Circle fb_img,(25,30), 7,RGB(  0,  0,  0),,,,F
  Circle fb_img,(75,30), 7,RGB(  0,  0,  0),,,,F
  Circle fb_img,(50,50),28,RGB(  0,  0,  0),3.14,0.0
  Circle fb_img,(50,51),28,RGB(  0,  0,  0),3.14,0.0
  Circle fb_img,(50,52),28,RGB(  0,  0,  0),3.14,0.0
  return Fl_RGB_ImageNew(fb_pixels,w,h,bpp,pitch)
end function

sub AnimateCB cdecl (byval box as any ptr)
  static as single r=0
  var win=Fl_WidgetWindow(box)
  var w=Fl_WidgetGetW(win)\2
  var h=Fl_WidgetGetH(win)\2
  Fl_WidgetPosition box,w+cos(r)*w-50,h+sin(r)*h-50
  Fl_WidgetReDraw win
  Fl_RepeatTimeout 1.0/50, @AnimateCB,box
  r+=0.01
end sub

'
' main
'
var win = Fl_Double_WindowNew(640,480,"Fl_Box")
var box = Fl_BoxNew(0,0,101,101)
var img = CreateSprite()
Fl_WidgetSetImage box,img
Fl_WindowShow     win
Fl_AddTimeout 1.0/50, @AnimateCB, box

Fl_Run
badidea
Posts: 2120
Joined: May 24, 2007 22:10
Location: The Netherlands

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

Postby badidea » Jun 07, 2015 21:11

@ Lothar Schirm, my user interface will be simple, some static images, but nothing fancy. I have the game battle simulation code already, but input is done in the code currently. With FLTK I can make a GUI so that others can use my problem. But going from a script to a program with a GUI is quite some work. Need to structure the data more.
BasicCoder2
Posts: 3571
Joined: Jan 01, 2009 7:03
Location: Australia

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

Postby BasicCoder2 » Jun 08, 2015 0:04

D.J.Peters wrote:A code::blocks project is simply a xml file you can create or edit this file with any text editor.
You can add the search path for include files and library's.


That I didn't know. Of course you would still need to know what you were doing. The mechanics between writing some source code and the resulting .exe file isn't covered in the teach yourself C++ books. They all use console projects. On the internet I find attempts to give the set of actions required to set up a library like SDL via compiler settings but when it fails you are left dangling. With FreeBasic the SDL examples just work as is. It seems with Java and other languages all this fiddling is also not required so I guess it is just automated somehow. Want a GUI with Java? Type import javax.swing*; and it just works.
ike
Posts: 387
Joined: Jan 17, 2011 18:59

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

Postby ike » Jun 08, 2015 1:59

IN
FUNCTION DrawCB1 CDECL(box AS ANY PTR) AS INTEGER

I want to draw a blue rectangle then stop drawing and ask a question eg WHAT COLOR IS NEXT RECTANGLE

then wait for answer

and draw second rectangle in desired color.

How do I stop drawing wait for action and then continue to draw depending on answer?
Lothar Schirm
Posts: 333
Joined: Sep 28, 2013 15:08
Location: Bavaria, Germany

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

Postby Lothar Schirm » Jun 08, 2015 9:25

@D.J. Peters, thank you very much for this nice example. Normally, I use a main window (GUI) to enter some parameters and then I start the simulation by means of a "Start" button (maybe in a separate window). I would like to stop the simulation by means of a mouseclick on a "Stop" button or by pressing the ESC key so that new parameters can be entered in the main window and the simulation can be started with new parameters. How can the simulation be stopped in your example?
jdebord
Posts: 529
Joined: May 27, 2005 6:20
Location: Limoges, France
Contact:

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

Postby jdebord » Jun 12, 2015 8:20

Another graphic question. In the following program a line is plotted when the button is clicked. However the line disappears when the window is minimized or covered by another window. Is it possible to make the plot "permanent" ?

Code: Select all

#include "fltk-c.bi"

dim shared as Fl_Window ptr win
dim shared as Fl_Box ptr box
dim shared as Fl_Button ptr btn

sub graph cdecl (self as Fl_Widget ptr)
 
  dim as integer x = Fl_WidgetGetX(box)
  dim as integer y = Fl_WidgetGetY(box)
  dim as integer w = Fl_WidgetGetW(box)
  dim as integer h = Fl_WidgetGetH(box)
 
  Fl_WindowMakeCurrent win
 
  DrawPushClip x, y, w, h
 
  DrawSetColor FL_RED
 
  DrawLine x + 20, y + 20, x + w - 20, y + h - 20
end sub

win = Fl_WindowNew(300, 260)
box = Fl_BoxNew2(BoxType(FL_BORDER_BOX), 20, 20, 260, 160)
btn = Fl_ButtonNew(20, 200, 260, 25, "Graph")

Fl_WidgetSetColor box, FL_WHITE
Fl_WidgetSetCallback0 btn, @graph

Fl_WindowShow win
Fl_Run

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 3 guests