├── .editorconfig ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── analysis_options.yaml ├── bin └── flfn_serve.dart ├── doc └── dds-2016-lightning-talk.pdf ├── example ├── cairo.cpp ├── cairo_image_surface.cpp ├── callback.cpp ├── choice.cpp ├── dnd.cpp ├── draw_x.cpp ├── hello_world.cpp ├── image.cpp ├── image.png ├── inline_image.cpp ├── opengl.cpp ├── opengles.cpp ├── text_highlight.cpp └── xpm.cpp ├── ext ├── classes │ ├── Box.yaml │ ├── Button.yaml │ ├── CairoWindow.yaml │ ├── Choice.yaml │ ├── DoubleWindow.yaml │ ├── GlWindow.yaml │ ├── Group.yaml │ ├── Input.yaml │ ├── Menu.yaml │ ├── TextBuffer.yaml │ ├── TextDisplay.yaml │ ├── TextEditor.yaml │ ├── Widget.yaml │ └── Window.yaml ├── functions │ ├── color.yaml │ ├── core.yaml │ ├── draw.yaml │ └── event.yaml └── src │ ├── classes │ ├── Menu.cpp │ ├── TextDisplay.cpp │ └── Widget.cpp │ ├── common.cpp │ ├── common.hpp │ ├── custom.cpp │ ├── custom.hpp │ ├── main.cpp │ └── wrappers │ ├── Fl_Cairo_Window_Wrapper.cpp │ ├── Fl_Cairo_Window_Wrapper.hpp │ ├── Fl_Text_Buffer_Wrapper.cpp │ ├── Fl_Text_Buffer_Wrapper.hpp │ ├── Fl_Text_Display_Wrapper.cpp │ ├── Fl_Text_Display_Wrapper.hpp │ ├── Fl_Text_Editor_Wrapper.cpp │ └── Fl_Text_Editor_Wrapper.hpp ├── lib ├── enums.dart ├── flfn.dart ├── fltk.dart ├── hvif.dart └── src │ ├── box.dart │ ├── button.dart │ ├── cairo_surface.dart │ ├── cairo_window.dart │ ├── choice.dart │ ├── double_window.dart │ ├── enums │ ├── align.dart │ ├── boxtype.dart │ ├── color.dart │ ├── event.dart │ ├── font.dart │ ├── glmode.dart │ ├── labeltype.dart │ ├── option.dart │ ├── shortcut.dart │ └── when.dart │ ├── fl │ ├── color.dart │ ├── core.dart │ ├── draw.dart │ ├── event.dart │ └── xpm.dart │ ├── flfn │ ├── app.dart │ ├── box.dart │ ├── button.dart │ ├── run.dart │ ├── widget.dart │ ├── window.dart │ └── wm.dart │ ├── gl_window.dart │ ├── group.dart │ ├── hvif │ ├── hvif.dart │ ├── path.dart │ ├── shape.dart │ ├── style.dart │ ├── transformer.dart │ └── utils.dart │ ├── input.dart │ ├── menu.dart │ ├── text_buffer.dart │ ├── text_display.dart │ ├── text_editor.dart │ ├── utils │ └── cairo.dart │ ├── widget.dart │ └── window.dart ├── pubspec.yaml ├── tar └── fltk-1.3.3-source.tar.gz ├── test ├── classic │ ├── cairo.dart │ ├── cairo_surface.dart │ ├── callback.dart │ ├── callback_stream.dart │ ├── choice.dart │ ├── dartpad.dart │ ├── dnd.dart │ ├── draw_x.dart │ ├── fltk.hvif │ ├── hello_world.dart │ ├── hvif.dart │ ├── image.dart │ ├── opengl.dart │ ├── shaders │ │ ├── default.frag │ │ ├── hsv_deform.frag │ │ ├── hsv_linear.frag │ │ ├── mandelbrot.frag │ │ └── path_tracer.frag │ ├── shadertoy.dart │ ├── sketchpad.dart │ ├── text_highlight.dart │ └── xpm.dart └── flfn │ ├── callback.dart │ └── hello_world.dart └── tool ├── codegen ├── generate.dart ├── settings.yaml └── templates │ ├── classes │ ├── header.mustache │ └── source.mustache │ ├── functions │ ├── header.mustache │ └── source.mustache │ └── wrappers │ ├── header.mustache │ └── source.mustache ├── compile-ext.sh └── pre-commit.sh /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf # All files use Unix-style newlines. 5 | insert_final_newline = true # All files have a final newline. 6 | charset = utf-8 # All files use UTF-8 encoding. 7 | indent_style = space # All files use space indentation by default. 8 | indent_size = 2 # With 2 spaces as indentation width 9 | 10 | # reST uses 3 spaces for indentation. 11 | [*.rst] 12 | indent_style = space 13 | indent_size = 3 14 | 15 | # Makefiles use tabs for indentation. 16 | [Makefile] 17 | indent_style = tab 18 | indent_size = 4 19 | 20 | # Go uses tabs for indentation. 21 | [*.go] 22 | indent_style = tab 23 | indent_size = 2 24 | 25 | # Python uses 4 spaces for indentation. 26 | [*.py] 27 | indent_style = space 28 | indent_size = 4 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .atom 2 | compile 3 | libfldart.so 4 | ext/src/gen 5 | 6 | ################# 7 | # Linux.gitignore 8 | ################# 9 | 10 | *~ 11 | 12 | # KDE directory preferences 13 | .directory 14 | 15 | # Linux trash folder which might appear on any partition or disk 16 | .Trash-* 17 | 18 | ############### 19 | # OSX.gitignore 20 | ############### 21 | 22 | .DS_Store 23 | .AppleDouble 24 | .LSOverride 25 | 26 | # Icon must end with two \r 27 | Icon 28 | 29 | 30 | # Thumbnails 31 | ._* 32 | 33 | # Files that might appear in the root of a volume 34 | .DocumentRevisions-V100 35 | .fseventsd 36 | .Spotlight-V100 37 | .TemporaryItems 38 | .Trashes 39 | .VolumeIcon.icns 40 | 41 | # Directories potentially created on remote AFP share 42 | .AppleDB 43 | .AppleDesktop 44 | Network Trash Folder 45 | Temporary Items 46 | .apdisk 47 | 48 | ################ 49 | # Dart.gitignore 50 | ################ 51 | 52 | # See https://www.dartlang.org/tools/private-files.html 53 | 54 | # Files and directories created by pub 55 | .buildlog 56 | .packages 57 | .project 58 | .pub/ 59 | build/ 60 | packages 61 | 62 | # Files created by dart2js 63 | # (Most Dart developers will use pub build to compile Dart, use/modify these 64 | # rules if you intend to use dart2js directly 65 | # Convention is to use extension '.dart.js' for Dart compiled to Javascript to 66 | # differentiate from explicit Javascript files) 67 | *.dart.js 68 | *.part.js 69 | *.js.deps 70 | *.js.map 71 | *.info.json 72 | 73 | # Directory created by dartdoc 74 | doc/api/ 75 | 76 | # Don't commit pubspec lock file 77 | # (Library packages only! Remove pattern if developing an application package) 78 | pubspec.lock 79 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Herman Bergwerf 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the "Software"), 5 | to deal in the Software without restriction, including without limitation 6 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | and/or sell copies of the Software, and to permit persons to whom the 8 | Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | DEALINGS IN THE SOFTWARE. 20 | 21 | If we meet some day, and you think this stuff is worth it, you can buy me a 22 | beer in return. 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | install-hook: 2 | # Create symlink for pre-commit hook. 3 | ln -sf ../../tool/pre-commit.sh .git/hooks/pre-commit 4 | 5 | generate-bindings: 6 | # Don't use a directory regex or ZSH will start asking confirmations. 7 | rm -f ext/src/gen/classes/* ext/src/gen/functions/* ext/src/gen/wrappers/* 8 | mkdir -p ext/src/gen/classes ext/src/gen/functions ext/src/gen/wrappers 9 | dart tool/codegen/generate.dart 10 | 11 | fltk_version = "1.3.3" 12 | compile-fltk: 13 | # 1. untar 14 | mkdir -p compile 15 | rm -rf compile/fltk-${fltk_version} 16 | tar -C ./compile -xvf tar/fltk-${fltk_version}-source.tar.gz 17 | 18 | # 2. Enable ABI version 103030 19 | sed -i 's/\/\/#define FLTK_ABI_VERSION 10303/#define FLTK_ABI_VERSION 10303/g' compile/fltk-1.3.3/FL/Enumerations.H 20 | 21 | # 3. compile 22 | cd compile/fltk-${fltk_version}; ./configure --enable-cairo --enable-shared --enable-debug; make; sudo make install 23 | 24 | # 4. reconfigure dynamic linker run-time bindings 25 | sudo ldconfig 26 | 27 | compile-ext: 28 | ./tool/compile-ext.sh 29 | 30 | # Find C++ and linking flags: 31 | # fltk-config --use-gl --use-cairo --use-images --cxxflags 32 | # fltk-config --use-gl --use-cairo --use-images --ldflags 33 | compile-example: 34 | g++ \ 35 | -std=c++11\ 36 | -I/usr/local/include\ 37 | -I/usr/include/cairo\ 38 | -I/usr/include/glib-2.0\ 39 | -I/usr/include/pixman-1\ 40 | -I/usr/include/freetype2\ 41 | -I/usr/include/libpng12\ 42 | -I/usr/local/include/FL/images\ 43 | -I/usr/include/freetype2\ 44 | -fvisibility-inlines-hidden\ 45 | -D_LARGEFILE_SOURCE\ 46 | -D_LARGEFILE64_SOURCE\ 47 | -D_THREAD_SAFE\ 48 | -D_REENTRANT\ 49 | -o 'binary' "example/${name}.cpp"\ 50 | /usr/local/lib/libfltk_cairo.a\ 51 | -lcairo -lpixman-1\ 52 | /usr/local/lib/libfltk_images.a\ 53 | -lpng -lz\ 54 | /usr/local/lib/libfltk_jpeg.a\ 55 | /usr/local/lib/libfltk_gl.a\ 56 | -lGLU -lGL\ 57 | /usr/local/lib/libfltk.a\ 58 | -lXcursor -lXfixes -lXext -lXft -lfontconfig -lXinerama -lpthread -ldl -lm -lX11 59 | ./binary 60 | rm binary 61 | 62 | # Compiling using FLTK helper binary. 63 | #fltk-config --use-gl --use-cairo --compile example/${name}.cpp 64 | #./${name} 65 | #rm ${name} 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Dart bindings for FLTK! 2 | ======================= 3 | Yes! FLTK in Dart, just like this: 4 | ```dart 5 | import 'package:fltk/fltk.dart' as fl; 6 | 7 | int main() { 8 | fl.scheme('gleam'); 9 | var window = new fl.Window(350, 180, 'FLTK'); 10 | var box = new fl.Box(20, 40, 310, 100, 'Hello, World!'); 11 | window.end(); 12 | window.show(); 13 | return fl.run(); 14 | } 15 | ``` 16 | 17 | Integrations 18 | ------------ 19 | - `image` 20 | - `dartgl` 21 | - `cairodart` 22 | 23 | State of the art 24 | ---------------- 25 | This library is mostly experimental and a way to spend some time. Currently only 26 | a subset of features are supported (the exiting ones like loading images, 27 | displaying OpenGL graphics, and asynchronous event streams). The majority of 28 | widgets is not yet ported to Dart. However a sophisticated code generation 29 | program is already in place and adding simple widgets is pretty easy. If this 30 | library is useful for you and you need more widgets, feel free to open an issue! 31 | 32 | Architecture 33 | ------------ 34 | Most bindings are automatically generated from YAML descriptions of the FLTK 35 | functions and classes. Class bindings do not create the target class directly, 36 | instead they create a wrapper class that takes care of draw and callback 37 | events. 38 | 39 | Considerations 40 | -------------- 41 | Maybe we should use static linking for the FLTK libraries so this extension can 42 | be used without locally compiling FLTK. 43 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | linter: 2 | rules: 3 | 4 | ############## 5 | # Error rules 6 | ############## 7 | 8 | - avoid_empty_else 9 | - avoid_slow_async_io 10 | - cancel_subscriptions 11 | - close_sinks 12 | - comment_references 13 | - control_flow_in_finally 14 | - empty_statements 15 | - hash_and_equals 16 | 17 | # High CPU usage. 18 | #- invariant_booleans 19 | 20 | - iterable_contains_unrelated_type 21 | - list_remove_unrelated_type 22 | - literal_only_boolean_expressions 23 | - no_adjacent_strings_in_list 24 | - no_duplicate_case_values 25 | - test_types_in_equals 26 | - throw_in_finally 27 | - unnecessary_statements 28 | - unrelated_type_equality_checks 29 | - valid_regexps 30 | 31 | ############## 32 | # Style rules 33 | ############## 34 | 35 | - always_declare_return_types 36 | - always_put_control_body_on_new_line 37 | - always_require_non_null_named_parameters 38 | - always_put_required_named_parameters_first 39 | 40 | # Infer types when possible. 41 | #- always_specify_types 42 | 43 | - annotate_overrides 44 | - avoid_annotating_with_dynamic 45 | - avoid_as 46 | - avoid_catches_without_on_clauses 47 | - avoid_catching_errors 48 | - avoid_classes_with_only_static_members 49 | - avoid_function_literals_in_foreach_calls 50 | - avoid_init_to_null 51 | - avoid_null_checks_in_equality_operators 52 | 53 | # Too restricting 54 | #- avoid_positional_boolean_parameters 55 | 56 | - avoid_return_types_on_setters 57 | - avoid_returning_null 58 | - avoid_returning_this 59 | - avoid_setters_without_getters 60 | 61 | # For convenience we might assume a certain type even if it is dynamic. 62 | #- avoid_types_on_closure_parameters 63 | 64 | - await_only_futures 65 | - camel_case_types 66 | 67 | # Cascade on constructor is ugly. 68 | #- cascade_invocations 69 | 70 | - constant_identifier_names 71 | 72 | # I prefer sorting blocks based on visual appearance (short to long) 73 | # (I do sort import types in blocks) 74 | #- directives_ordering 75 | 76 | - empty_catches 77 | - empty_constructor_bodies 78 | - implementation_imports 79 | 80 | # Seems anti-pattern. 81 | #- join_return_with_assignment 82 | 83 | - library_names 84 | - library_prefixes 85 | - non_constant_identifier_names 86 | - omit_local_variable_types 87 | - one_member_abstracts 88 | - only_throw_errors 89 | - overridden_fields 90 | - package_api_docs 91 | - package_prefixed_library_names 92 | - parameter_assignments 93 | - prefer_adjacent_string_concatenation 94 | - prefer_asserts_in_initializer_lists 95 | - prefer_bool_in_asserts 96 | 97 | # I prefer using the class constructor to create empty instances. 98 | #- prefer_collection_literals 99 | 100 | - prefer_conditional_assignment 101 | - prefer_const_constructors 102 | - prefer_const_constructors_in_immutables 103 | - prefer_const_declarations 104 | - prefer_const_literals_to_create_immutables 105 | - prefer_constructors_over_static_methods 106 | - prefer_contains 107 | 108 | # In some cases this simply looks ugly and less readably. 109 | #- prefer_expression_function_bodies 110 | 111 | - prefer_final_fields 112 | - prefer_final_locals 113 | - prefer_foreach 114 | - prefer_function_declarations_over_variables 115 | - prefer_initializing_formals 116 | - prefer_interpolation_to_compose_strings 117 | - prefer_is_empty 118 | - prefer_is_not_empty 119 | - prefer_single_quotes 120 | 121 | # Do not add docs when there is nothing to be documented (e.g. constructors). 122 | #- public_member_api_docs 123 | 124 | - recursive_getters 125 | - slash_for_doc_comments 126 | - sort_constructors_first 127 | - sort_unnamed_constructors_first 128 | - super_goes_last 129 | 130 | # Infer types as much as possible, for example from a base class. 131 | #- type_annotate_public_apis 132 | 133 | - type_init_formals 134 | - unawaited_futures 135 | - unnecessary_brace_in_string_interps 136 | - unnecessary_getters_setters 137 | - unnecessary_lambdas 138 | - unnecessary_null_aware_assignments 139 | - unnecessary_null_in_if_null_operators 140 | - unnecessary_overrides 141 | - unnecessary_this 142 | - use_rethrow_when_possible 143 | - use_setters_to_change_properties 144 | - use_string_buffers 145 | - use_to_and_as_if_applicable 146 | 147 | ############ 148 | # Pub rules 149 | ############ 150 | 151 | - package_names 152 | -------------------------------------------------------------------------------- /bin/flfn_serve.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | import 'dart:io'; 6 | import 'dart:async'; 7 | import 'dart:convert'; 8 | 9 | import 'package:watcher/watcher.dart'; 10 | import 'package:vm_service_lib/vm_service_lib.dart' hide Null; 11 | 12 | const vmServicePort = 8282; 13 | const vmServiceHost = 'localhost'; 14 | 15 | Future main(List args) async { 16 | // Return if there are no args. 17 | if (args.isEmpty) { 18 | print('Please specify the entry Dart file.'); 19 | return; 20 | } 21 | 22 | // Run entry point. 23 | final process = await Process.start( 24 | 'dart', ['--enable-vm-service=$vmServicePort', args.first], 25 | environment: {'FLFN_MODE': 'debug'}); 26 | process.stderr.transform(UTF8.decoder).listen(print); 27 | 28 | // Wait until observatory is launched. 29 | StreamSubscription sub; 30 | sub = process.stdout.transform(UTF8.decoder).listen((str) async { 31 | if (str.startsWith('Observatory listening on http://')) { 32 | sub.onData(print); 33 | setupHotReload(); 34 | } 35 | }); 36 | } 37 | 38 | Future setupHotReload() async { 39 | var isolateId = ''; 40 | final controller = new StreamController(); 41 | 42 | // Connect to WebSocket interface. 43 | final ws = await WebSocket.connect('ws://$vmServiceHost:$vmServicePort/ws'); 44 | ws.listen((json) { 45 | print(json); 46 | 47 | // Add message to the stream to the VM service lib client. 48 | controller.add(json); 49 | 50 | // Decode and check if this is a positive source reload. 51 | final data = JSON.decode(json) as Map; 52 | if (data.containsKey('result') && 53 | (data['result'] as Map).containsKey('type') && 54 | data['result']['type'] == 'ReloadReport' && 55 | (data['result'] as Map).containsKey('success') && 56 | data['result']['success']) { 57 | // Send `ext.fltk.flfn.rebuild` to Dart VM to trigger GUI reconfiguration. 58 | ws.add(JSON.encode({ 59 | 'jsonrpc': '2.0', 60 | 'method': 'ext.fltk.flfn.rebuild', 61 | 'params': {'isolateId': '$isolateId'} 62 | })); 63 | } 64 | }); 65 | 66 | // Create VM service client from WebSocket. 67 | final serviceClient = new VmService( 68 | controller.stream, (String message) => ws.add(message), 69 | log: null, disposeHandler: () => ws.close()); 70 | 71 | // Figure out main isolate ID. 72 | final vm = await serviceClient.getVM(); 73 | 74 | // This is probably not the best way. Also, maybe we want to support hot 75 | // reloading secondary isolates? 76 | isolateId = 77 | vm.isolates.reduce((a, b) => a.name.endsWith('\$main') ? a : b).id; 78 | 79 | int id = 100; 80 | 81 | // Watch for changes under current directory. 82 | new DirectoryWatcher(Directory.current.path).events.listen((event) { 83 | if (event.type == ChangeType.MODIFY && event.path.endsWith('.dart')) { 84 | // Send `_reloadSources` to Dart VM to triger code reload. 85 | ws.add(JSON.encode({ 86 | 'id': ++id, 87 | 'jsonrpc': '2.0', 88 | 'method': '_reloadSources', 89 | 'params': {'isolateId': '$isolateId'} 90 | })); 91 | } 92 | }); 93 | } 94 | -------------------------------------------------------------------------------- /doc/dds-2016-lightning-talk.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bergwerf/fltk-dart/d98a42a5484344453e6887c2cc3c6ecd8dd548b3/doc/dds-2016-lightning-talk.pdf -------------------------------------------------------------------------------- /example/cairo.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | // Force enable Cairo 6 | #define USE_X11 1 7 | #define FLTK_HAVE_CAIRO 1 8 | 9 | #include 10 | #include 11 | 12 | static void centered_text(cairo_t *cr, double x0, double y0, double w0, double h0, const char *my_text) { 13 | cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_OBLIQUE, CAIRO_FONT_WEIGHT_BOLD); 14 | cairo_set_source_rgba(cr, 0.9, 0.9, 0.4, 0.6); 15 | cairo_text_extents_t extents; 16 | cairo_text_extents(cr, my_text, &extents); 17 | double x = (extents.width / 2 + extents.x_bearing); 18 | double y = (extents.height / 2 + extents.y_bearing); 19 | cairo_move_to(cr, x0+w0/2-x, y0+h0/2 - y); 20 | cairo_text_path(cr,my_text); 21 | cairo_fill_preserve(cr); 22 | cairo_set_source_rgba(cr, 0, 0, 0,1); 23 | cairo_set_line_width(cr, 0.004); 24 | cairo_stroke(cr); 25 | } 26 | 27 | static void round_button(cairo_t* cr, double x0, double y0, 28 | double rect_width, double rect_height, double radius, 29 | double r, double g, double b, const char *message) { 30 | double x1, y1; 31 | x1 = x0 + rect_width; 32 | y1 = y0 + rect_height; 33 | 34 | if (!rect_width || !rect_height) { 35 | return; 36 | } 37 | 38 | // Draw path. 39 | if (rect_width / 2 < radius) { 40 | if (rect_height / 2 < radius) { 41 | cairo_move_to(cr, x0, (y0 + y1)/2); 42 | cairo_curve_to(cr, x0 ,y0, x0, y0, (x0 + x1) / 2, y0); 43 | cairo_curve_to(cr, x1, y0, x1, y0, x1, (y0 + y1) / 2); 44 | cairo_curve_to(cr, x1, y1, x1, y1, (x1 + x0) / 2, y1); 45 | cairo_curve_to(cr, x0, y1, x0, y1, x0, (y0 + y1) / 2); 46 | } else { 47 | cairo_move_to(cr, x0, y0 + radius); 48 | cairo_curve_to(cr, x0 ,y0, x0, y0, (x0 + x1) / 2, y0); 49 | cairo_curve_to(cr, x1, y0, x1, y0, x1, y0 + radius); 50 | cairo_line_to(cr, x1 , y1 - radius); 51 | cairo_curve_to(cr, x1, y1, x1, y1, (x1 + x0) / 2, y1); 52 | cairo_curve_to(cr, x0, y1, x0, y1, x0, y1- radius); 53 | } 54 | } else { 55 | if (rect_height / 2 < radius) { 56 | cairo_move_to(cr, x0, (y0 + y1) / 2); 57 | cairo_curve_to(cr, x0 , y0, x0 , y0, x0 + radius, y0); 58 | cairo_line_to(cr, x1 - radius, y0); 59 | cairo_curve_to(cr, x1, y0, x1, y0, x1, (y0 + y1) / 2); 60 | cairo_curve_to(cr, x1, y1, x1, y1, x1 - radius, y1); 61 | cairo_line_to(cr, x0 + radius, y1); 62 | cairo_curve_to(cr, x0, y1, x0, y1, x0, (y0 + y1) / 2); 63 | } else { 64 | cairo_move_to(cr, x0, y0 + radius); 65 | cairo_curve_to(cr, x0 , y0, x0 , y0, x0 + radius, y0); 66 | cairo_line_to(cr, x1 - radius, y0); 67 | cairo_curve_to(cr, x1, y0, x1, y0, x1, y0 + radius); 68 | cairo_line_to(cr, x1 , y1 - radius); 69 | cairo_curve_to(cr, x1, y1, x1, y1, x1 - radius, y1); 70 | cairo_line_to(cr, x0 + radius, y1); 71 | cairo_curve_to(cr, x0, y1, x0, y1, x0, y1- radius); 72 | } 73 | } 74 | cairo_close_path(cr); 75 | 76 | // Draw gradient. 77 | cairo_pattern_t *pat= cairo_pattern_create_radial(0.25, 0.24, 0.11, 0.24, 0.14, 0.35); 78 | cairo_pattern_set_extend(pat, CAIRO_EXTEND_REFLECT); 79 | cairo_pattern_add_color_stop_rgba(pat, 1.0, r, g, b, 1); 80 | cairo_pattern_add_color_stop_rgba(pat, 0.0, 1, 1, 1, 1); 81 | cairo_set_source(cr, pat); 82 | cairo_fill_preserve(cr); 83 | cairo_pattern_destroy(pat); 84 | 85 | // Stroke path. 86 | cairo_set_source_rgba(cr, 0, 0, 0.5, 0.3); 87 | cairo_set_line_width(cr, 0.03); 88 | cairo_stroke(cr); 89 | 90 | // Draw inner text. 91 | cairo_set_font_size(cr, 0.07); 92 | centered_text(cr,x0,y0,rect_width, rect_height, message); 93 | } 94 | 95 | // The cairo rendering cb called during Fl_Cairo_Window::draw() 96 | static void my_cairo_draw_cb(Fl_Cairo_Window *window, cairo_t *cr) { 97 | int w = window -> w(), h = window -> h(); 98 | 99 | cairo_scale(cr, w, h); 100 | round_button(cr, 0.1, 0.1, 0.8, 0.2, 0.4, 0, 0, 1, "FLTK loves Cairo!"); 101 | round_button(cr, 0.1, 0.4, 0.8, 0.2, 0.4, 1, 0, 0, "Dart loves FLTK!"); 102 | round_button(cr, 0.1, 0.7, 0.8, 0.2, 0.4, 0, 1, 0, "Dart loves Cairo!"); 103 | 104 | return; 105 | } 106 | 107 | int main(int argc, char** argv) { 108 | auto window = new Fl_Cairo_Window(300, 300); 109 | 110 | window -> resizable(window); 111 | window -> color(FL_WHITE); 112 | window -> set_draw_cb(my_cairo_draw_cb); 113 | window -> show(); 114 | 115 | return Fl::run(); 116 | } 117 | -------------------------------------------------------------------------------- /example/cairo_image_surface.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | 8 | typedef signed long long int64_t; 9 | 10 | int main() { 11 | cairo_surface_t *surface; 12 | cairo_t *cr; 13 | 14 | surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 520, 60); 15 | cr = cairo_create(surface); 16 | 17 | cairo_set_source_rgb(cr, 0, 0, 0); 18 | cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL, 19 | CAIRO_FONT_WEIGHT_NORMAL); 20 | cairo_set_font_size(cr, 40.0); 21 | 22 | cairo_move_to(cr, 10.0, 50.0); 23 | cairo_show_text(cr, "FLTK + Dart = Awesome"); 24 | 25 | cairo_surface_flush(surface); 26 | unsigned char *data = cairo_image_surface_get_data(surface); 27 | printf("sizeof(data) = %i\n", (int)sizeof(data)); 28 | 29 | for (int i = 0; i < 520 * 60 * 4; i++) { 30 | printf("%i", (int64_t)data[i]); 31 | } 32 | printf("\n"); 33 | 34 | cairo_destroy(cr); 35 | cairo_surface_destroy(surface); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /example/callback.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | void button_cb(Fl_Widget *obj, void*) { 12 | obj -> label(strcmp("OFF", obj -> label()) ? "OFF" : "ON"); 13 | } 14 | 15 | int main(int argc, char *argv[]) { 16 | Fl::scheme("gleam"); 17 | auto window = new Fl_Window(300, 200, "Click the button..."); 18 | auto button = new Fl_Button(0, 0, window -> w(), window -> h(), "ON"); 19 | button -> callback((Fl_Callback*)button_cb); 20 | window -> end(); 21 | window -> show(); 22 | return Fl::run(); 23 | } 24 | -------------------------------------------------------------------------------- /example/choice.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | struct SpaceAgency { 11 | int usdBudget; 12 | Fl_Color color; 13 | }; 14 | 15 | void callback(Fl_Widget *widget, void *data) { 16 | auto choice = (Fl_Choice*)widget; 17 | auto agency = (SpaceAgency*)data; 18 | choice -> color(agency -> color); 19 | printf("%i USD\n", agency -> usdBudget); 20 | } 21 | 22 | int main(int argc, char* argv[]) { 23 | Fl::scheme("gtk+"); 24 | auto window = new Fl_Double_Window(420, 80, "Annual budget"); 25 | auto choice = new Fl_Choice(150, 20, 250, 40, "Space agency: "); 26 | choice -> add( 27 | "NASA", FL_CTRL + 'n', callback, new SpaceAgency{19300, FL_YELLOW}); 28 | choice -> add( 29 | "Roscosmos", FL_CTRL + 'r', callback, new SpaceAgency{5600, FL_GREEN}); 30 | choice -> add( 31 | "ESA", FL_CTRL + 'e', callback, new SpaceAgency{5510, FL_CYAN}); 32 | window -> show(); 33 | return Fl::run(); 34 | } 35 | -------------------------------------------------------------------------------- /example/dnd.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | // Based on: http://seriss.com/people/erco/fltk/#DragAndDrop 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | class Sender : public Fl_Box { 14 | public: 15 | Sender(int x, int y, int w, int h) : Fl_Box(x, y, w, h) { 16 | box(FL_FLAT_BOX); 17 | color(FL_GREEN); 18 | label("Drag from\nhere"); 19 | } 20 | 21 | int handle(int event) { 22 | int ret = Fl_Box::handle(event); 23 | 24 | switch (event) { 25 | case FL_PUSH: 26 | Fl::copy("message", 7, 0); 27 | Fl::dnd(); 28 | return 1; 29 | } 30 | 31 | return ret; 32 | } 33 | }; 34 | 35 | class Receiver : public Fl_Box { 36 | public: 37 | Receiver(int x,int y,int w,int h) : Fl_Box(x,y,w,h) { 38 | box(FL_FLAT_BOX); 39 | color(FL_RED); 40 | label("to here"); 41 | } 42 | 43 | int handle(int event) { 44 | int ret = Fl_Box::handle(event); 45 | 46 | switch (event) { 47 | case FL_DND_ENTER: 48 | case FL_DND_DRAG: 49 | case FL_DND_RELEASE: 50 | // Return 1 for these events to 'accept' dnd. 51 | return 1; 52 | 53 | case FL_PASTE: 54 | // Handle actual drop (paste) operation. 55 | label(Fl::event_text()); 56 | return 1; 57 | } 58 | 59 | return ret; 60 | } 61 | }; 62 | 63 | int main(int argc, char **argv) { 64 | // Create sender window and widget. 65 | auto win_a = new Fl_Window(0, 0, 200, 100, "Sender"); 66 | auto a = new Sender(0, 0, 100, 100); 67 | win_a -> end(); 68 | win_a -> show(); 69 | 70 | // Create receiver window and widget. 71 | auto win_b = new Fl_Window(400, 0, 200, 100, "Receiver"); 72 | auto b = new Receiver(100, 0, 100, 100); 73 | win_b -> end(); 74 | win_b -> show(); 75 | 76 | return Fl::run(); 77 | } 78 | -------------------------------------------------------------------------------- /example/draw_x.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | // Based on: http://seriss.com/people/erco/fltk/#FltkX 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | /// Widget that draws two diagonal lines 13 | class XWidget : public Fl_Widget { 14 | public: 15 | /// Constuctor 16 | XWidget(int x, int y, int w, int h) : Fl_Widget(x, y, w, h, 0) {} 17 | 18 | /// Draws the lines 19 | void draw() { 20 | fl_color(FL_BLACK); 21 | int x1 = x(), y1 = y(); 22 | int x2 = x() + w() - 1, y2 = y() + h() - 1; 23 | fl_line(x1, y1, x2, y2); 24 | fl_line(x1, y2, x2, y1); 25 | } 26 | }; 27 | 28 | int main() { 29 | auto window = new Fl_Double_Window(200, 200, "X"); 30 | auto x = new XWidget(0, 0, window -> w(), window -> h()); 31 | window -> resizable(x); 32 | window -> show(); 33 | return Fl::run(); 34 | } 35 | -------------------------------------------------------------------------------- /example/hello_world.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main(int argc, char **argv) { 11 | Fl::scheme("gleam"); 12 | auto window = new Fl_Window(350, 180, "FLTK"); 13 | auto box = new Fl_Box(20, 40, 310, 100, "Hello, World!"); 14 | box -> box(FL_UP_BOX); 15 | box -> labelsize(36); 16 | box -> labelfont(FL_BOLD + FL_ITALIC); 17 | box -> labeltype(FL_SHADOW_LABEL); 18 | box -> labelcolor(FL_YELLOW); 19 | box -> color(FL_RED); 20 | window -> end(); 21 | window -> show(argc, argv); 22 | return Fl::run(); 23 | } 24 | -------------------------------------------------------------------------------- /example/image.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main() { 11 | // Using a single buffered window gives issues with image alpha rendering. 12 | auto window = new Fl_Double_Window(64,64); 13 | 14 | // There is a difference between an empty string and a nullptr label. When you 15 | // use an empty string, FLTK will move the image 8 pixels up. 16 | //auto box = new Fl_Box(0, 0, 64, 64, ""); 17 | auto box = new Fl_Box(0, 0, 64, 64, nullptr); 18 | 19 | auto png = new Fl_PNG_Image("example/image.png"); 20 | box -> image(png); 21 | window -> end(); 22 | window -> show(); 23 | return Fl::run(); 24 | } 25 | -------------------------------------------------------------------------------- /example/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bergwerf/fltk-dart/d98a42a5484344453e6887c2cc3c6ecd8dd548b3/example/image.png -------------------------------------------------------------------------------- /example/inline_image.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | // Grayscale image data, width=16, height=10, depth=1 11 | unsigned char gray_data[16 * 10 * 1] = { 12 | 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, // line #1 13 | 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, // line #2 14 | 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, // line #3 15 | 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, // line #4 16 | 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, // line #5 17 | 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, // line #6 18 | 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, // line #7 19 | 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, // line #8 20 | 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, // line #9 21 | 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, // line #10 22 | }; 23 | 24 | int main() { 25 | auto window = new Fl_Window(160, 100); 26 | auto box = new Fl_Box(0, 0, 160, 100); 27 | auto gray = new Fl_RGB_Image(gray_data, 16, 10, 1); 28 | box -> image(gray); 29 | window -> show(); 30 | return Fl::run(); 31 | } 32 | -------------------------------------------------------------------------------- /example/opengl.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class MyGlWindow : public Fl_Gl_Window { 12 | void draw() { 13 | if (!valid()) { 14 | // Set viewport. 15 | glViewport(0, 0, w(), h()); 16 | 17 | // Set view matrix. 18 | glLoadIdentity(); 19 | glOrtho(-w(), w(), -h(), h(), -1, 1); 20 | 21 | // Init nice line drawing. 22 | glEnable(GL_LINE_SMOOTH); 23 | glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); 24 | glEnable(GL_BLEND); 25 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 26 | } 27 | 28 | // Clear screen. 29 | glClear(GL_COLOR_BUFFER_BIT); 30 | 31 | // Draw white 'X' 32 | glLineWidth(0.9); 33 | glColor3f(1.0, 1.0, 1.0); 34 | glBegin(GL_LINE_STRIP); 35 | glVertex2f(w(), h()); 36 | glVertex2f(-w(), -h()); 37 | glEnd(); 38 | glBegin(GL_LINE_STRIP); 39 | glVertex2f(w(), -h()); 40 | glVertex2f(-w(), h()); 41 | glEnd(); 42 | } 43 | 44 | public: 45 | MyGlWindow(int x, int y, int w, int h, const char* l = 0) : Fl_Gl_Window(x, y, w, h, l) {} 46 | }; 47 | 48 | int main() { 49 | auto window = new Fl_Double_Window(200, 200, "OpenGL X"); 50 | auto mygl = new MyGlWindow(0, 0, window -> w(), window -> h()); 51 | window -> end(); 52 | window -> resizable(mygl); 53 | window -> show(); 54 | return Fl::run(); 55 | } 56 | -------------------------------------------------------------------------------- /example/opengles.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | class MyGlWindow : public Fl_Gl_Window { 16 | /// Orthograpic projection matrix 17 | GLfloat matrix[16] = { 18 | 1, 0, 0, 0, 19 | 0, 1, 0, 0, 20 | 0, 0, 1, 0, 21 | 0, 0, 0, 1 22 | }; 23 | 24 | /// Shader attributes/uniforms 25 | GLint aVertexPosition, uPMatrix; 26 | 27 | /// Scene init status 28 | bool init = false; 29 | 30 | /// Vertex buffer 31 | GLuint vertexBuffer; 32 | 33 | void draw() { 34 | if (!valid()) { 35 | // Compile shaders. 36 | if (!init) { 37 | // Print version info once. 38 | printf("OpenGL version: %s\n", glGetString(GL_VERSION)); 39 | 40 | compileShaders(); 41 | createBuffers(); 42 | init = true; 43 | } 44 | 45 | // Set viewport. 46 | glViewport(0, 0, w(), h()); 47 | 48 | // Compute new matrix. 49 | // see: http://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/orthographic-projection-matrix 50 | double far = 10.0; 51 | double near = 0.1; 52 | matrix[0] = 1.0 / w(); 53 | matrix[5] = 1.0 / h(); 54 | matrix[10] = -2.0 / (far - near); 55 | matrix[11] = (far + near) / (far - near); 56 | } 57 | 58 | // Clear screen. 59 | glClear(GL_COLOR_BUFFER_BIT); 60 | 61 | // Set matrix uniform. 62 | glUniformMatrix4fv(uPMatrix, 1, GL_FALSE, matrix); 63 | 64 | // Link vertex buffer. 65 | glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); 66 | glVertexAttribPointer(aVertexPosition, 2, GL_FLOAT, GL_FALSE, 0, 0); 67 | glDrawArrays(GL_TRIANGLES, 0, 3); 68 | } 69 | 70 | static void checkShader(GLuint shader) { 71 | GLint is_compiled = 0; 72 | glGetShaderiv(shader, GL_COMPILE_STATUS, &is_compiled); 73 | if (is_compiled == GL_FALSE) { 74 | GLint info_log_length = 0; 75 | glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_log_length); 76 | GLchar *info_log = new GLchar[info_log_length]; 77 | glGetShaderInfoLog(shader, info_log_length, &info_log_length, &info_log[0]); 78 | 79 | // Print info log to stdout. 80 | printf("%s\n", info_log); 81 | } else { 82 | printf("Shader compilation successful!\n"); 83 | } 84 | } 85 | 86 | static void checkProgram(GLuint program) { 87 | GLint is_linked = 0; 88 | glGetProgramiv(program, GL_LINK_STATUS, &is_linked); 89 | if (is_linked == GL_FALSE) { 90 | GLint info_log_length = 0; 91 | glGetProgramiv(program, GL_INFO_LOG_LENGTH, &info_log_length); 92 | GLchar *info_log = new GLchar[info_log_length]; 93 | glGetProgramInfoLog(program, info_log_length, &info_log_length, &info_log[0]); 94 | 95 | // Print info log to stdout. 96 | printf("%s\n", info_log); 97 | } else { 98 | printf("Program linking successful!\n"); 99 | } 100 | } 101 | 102 | void compileShaders() { 103 | // Vertex shader source. 104 | string vs_src = 105 | "attribute vec2 aVertexPosition;\n" 106 | "uniform mat4 uPMatrix;\n" 107 | "varying vec2 color;\n" 108 | "void main(void) {\n" 109 | " gl_Position = uPMatrix * vec4(aVertexPosition * 150.0, 0.0, 1.0);\n" 110 | " color = aVertexPosition;\n" 111 | "}\n"; 112 | 113 | // Fragment shader source. 114 | string fs_src= 115 | "#version 130\n" 116 | "precision mediump float;\n" 117 | "varying vec2 color;\n" 118 | "void main() {\n" 119 | " gl_FragColor = vec4(color, 0.5, 1.0);\n" 120 | "}\n"; 121 | 122 | // Compile vertex shader. 123 | GLuint vshader = glCreateShader(GL_VERTEX_SHADER); 124 | const char *vs_src_c = vs_src.c_str(); 125 | glShaderSource(vshader, 1, &vs_src_c, NULL); 126 | glCompileShader(vshader); 127 | 128 | // Compile fragment shader. 129 | GLuint fshader = glCreateShader(GL_FRAGMENT_SHADER); 130 | const char *fs_src_c = fs_src.c_str(); 131 | glShaderSource(fshader, 1, &fs_src_c, NULL); 132 | glCompileShader(fshader); 133 | 134 | // Attach shaders to a GLES program. 135 | GLuint program = glCreateProgram(); 136 | glAttachShader(program, vshader); 137 | glAttachShader(program, fshader); 138 | glLinkProgram(program); 139 | glUseProgram(program); 140 | 141 | // Error checking. 142 | checkShader(vshader); 143 | checkShader(fshader); 144 | checkProgram(program); 145 | 146 | // Resolve attributes and uniforms. 147 | aVertexPosition = glGetAttribLocation(program, "aVertexPosition"); 148 | glEnableVertexAttribArray(aVertexPosition); 149 | uPMatrix = glGetUniformLocation(program, "uPMatrix"); 150 | } 151 | 152 | void createBuffers() { 153 | glGenBuffers(1, &vertexBuffer); 154 | glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); 155 | 156 | // vertices 157 | GLfloat data[8] = { 158 | cos(M_PI / 2), sin(M_PI / 2), 159 | cos(M_PI / 6 * 7), sin(M_PI / 6 * 7), 160 | cos(M_PI / 6 * 11), sin(M_PI / 6 * 11) 161 | }; 162 | 163 | glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW); 164 | } 165 | 166 | public: 167 | MyGlWindow(int x, int y, int w, int h, const char* l = 0) : Fl_Gl_Window(x, y, w, h, l) {} 168 | }; 169 | 170 | int main() { 171 | auto window = new Fl_Double_Window(200, 200, "OpenGLES"); 172 | auto glctx = new MyGlWindow(0, 0, window -> w(), window -> h()); 173 | window -> end(); 174 | window -> resizable(glctx); 175 | window -> show(); 176 | return Fl::run(); 177 | } 178 | -------------------------------------------------------------------------------- /example/text_highlight.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main(int argc, char **argv) { 11 | auto window = new Fl_Double_Window(120, 20, ""); 12 | auto editor = new Fl_Text_Editor(0, 0, window -> w(), window -> h()); 13 | editor -> box(FL_FLAT_BOX); 14 | editor -> deactivate(); 15 | 16 | auto buffer = new Fl_Text_Buffer(); 17 | buffer -> text("red, green, blue"); 18 | editor -> buffer(buffer); 19 | 20 | Fl_Text_Display::Style_Table_Entry styletable[] = { // Style table 21 | { FL_BLACK, FL_HELVETICA, FL_NORMAL_SIZE }, // A - Default 22 | { FL_RED, FL_COURIER, FL_NORMAL_SIZE }, // B - Red 23 | { FL_DARK_GREEN, FL_COURIER_ITALIC, FL_NORMAL_SIZE }, // C - Green 24 | { FL_BLUE, FL_COURIER_BOLD, FL_NORMAL_SIZE }, // D - Blue 25 | }; 26 | auto highlightBuffer = new Fl_Text_Buffer(); 27 | highlightBuffer -> text("BBBAACCCCCAADDDD"); 28 | editor -> highlight_data(highlightBuffer, styletable, 4, 0, 0, 0); 29 | 30 | window -> end(); 31 | window -> show(argc, argv); 32 | return Fl::run(); 33 | } 34 | -------------------------------------------------------------------------------- /example/xpm.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | static const char *cat_xpm[] = { 11 | "50 34 4 1", 12 | " c black", 13 | "o c #ff9900", 14 | "@ c #ffffff", 15 | "# c None", 16 | "##################################################", 17 | "### ############################## ####", 18 | "### ooooo ########################### ooooo ####", 19 | "### oo oo ######################### oo oo ####", 20 | "### oo oo ####################### oo oo ####", 21 | "### oo oo ##################### oo oo ####", 22 | "### oo oo ################### oo oo ####", 23 | "### oo oo oo oo ####", 24 | "### oo oo ooooooooooooooo oo oo ####", 25 | "### oo ooooooooooooooooooooo oo ####", 26 | "### oo ooooooooooooooooooooooooooo ooo ####", 27 | "#### oo ooooooo ooooooooooooo ooooooo oo #####", 28 | "#### oo oooooooo ooooooooooooo oooooooo oo #####", 29 | "##### oo oooooooo ooooooooooooo oooooooo oo ######", 30 | "##### o ooooooooooooooooooooooooooooooo o ######", 31 | "###### ooooooooooooooooooooooooooooooooooo #######", 32 | "##### ooooooooo ooooooooo ooooooooo ######", 33 | "##### oooooooo @@@ ooooooo @@@ oooooooo ######", 34 | "##### oooooooo @@@@@ ooooooo @@@@@ oooooooo ######", 35 | "##### oooooooo @@@@@ ooooooo @@@@@ oooooooo ######", 36 | "##### oooooooo @@@ ooooooo @@@ oooooooo ######", 37 | "##### ooooooooo ooooooooo ooooooooo ######", 38 | "###### oooooooooooooo oooooooooooooo #######", 39 | "###### oooooooo@@@@@@@ @@@@@@@oooooooo #######", 40 | "###### ooooooo@@@@@@@@@ @@@@@@@@@ooooooo #######", 41 | "####### ooooo@@@@@@@@@@@ @@@@@@@@@@@ooooo ########", 42 | "######### oo@@@@@@@@@@@@ @@@@@@@@@@@@oo ##########", 43 | "########## o@@@@@@ @@@@@ @@@@@ @@@@@@o ###########", 44 | "########### @@@@@@@ @ @@@@@@@ ############", 45 | "############ @@@@@@@@@@@@@@@@@@@@@ #############", 46 | "############## @@@@@@@@@@@@@@@@@ ###############", 47 | "################ @@@@@@@@@ #################", 48 | "#################### #####################", 49 | "##################################################", 50 | }; 51 | 52 | int main() { 53 | auto window = new Fl_Double_Window(50, 34); 54 | auto box = new Fl_Box(0, 0, 50, 34); 55 | auto pixmap = new Fl_Pixmap(cat_xpm); 56 | box -> image(pixmap); 57 | window -> end(); 58 | window -> show(); 59 | return Fl::run(); 60 | } 61 | -------------------------------------------------------------------------------- /ext/classes/Box.yaml: -------------------------------------------------------------------------------- 1 | cname: Fl_Box 2 | dartname: Box 3 | 4 | constructors: 5 | - void (int x, int y, int w, int h, String l) 6 | 7 | methods: [] 8 | -------------------------------------------------------------------------------- /ext/classes/Button.yaml: -------------------------------------------------------------------------------- 1 | cname: Fl_Button 2 | dartname: Button 3 | 4 | constructors: 5 | - void (int x, int y, int w, int h, String l) 6 | 7 | methods: [] 8 | -------------------------------------------------------------------------------- /ext/classes/CairoWindow.yaml: -------------------------------------------------------------------------------- 1 | cname: Fl_Cairo_Window 2 | dartname: CairoWindow 3 | customWrapper: true 4 | 5 | constructors: 6 | - void (int w, int h, String l) 7 | 8 | methods: [] 9 | -------------------------------------------------------------------------------- /ext/classes/Choice.yaml: -------------------------------------------------------------------------------- 1 | cname: Fl_Choice 2 | dartname: Choice 3 | 4 | constructors: 5 | - void (int x, int y, int w, int h, String l) 6 | 7 | methods: [] 8 | -------------------------------------------------------------------------------- /ext/classes/DoubleWindow.yaml: -------------------------------------------------------------------------------- 1 | cname: Fl_Double_Window 2 | dartname: DoubleWindow 3 | 4 | constructors: 5 | - void Short(int w, int h, String l) 6 | - void (int x, int y, int w, int h, String l) 7 | 8 | methods: [] 9 | -------------------------------------------------------------------------------- /ext/classes/GlWindow.yaml: -------------------------------------------------------------------------------- 1 | cname: Fl_Gl_Window 2 | dartname: GlWindow 3 | 4 | constructors: 5 | - void (int x, int y, int w, int h, String l) 6 | 7 | methods: 8 | - Fl_Mode mode() 9 | - void mode(Fl_Mode mode) 10 | - bool valid() 11 | -------------------------------------------------------------------------------- /ext/classes/Group.yaml: -------------------------------------------------------------------------------- 1 | cname: Fl_Group 2 | dartname: Group 3 | 4 | constructors: 5 | - void (int x, int y, int w, int h, String l) 6 | 7 | methods: 8 | - void end() 9 | - void resizable(Fl_Widget* o) 10 | -------------------------------------------------------------------------------- /ext/classes/Input.yaml: -------------------------------------------------------------------------------- 1 | cname: Fl_Input 2 | dartname: Input 3 | 4 | constructors: 5 | - void (int x, int y, int w, int h, String l) 6 | 7 | methods: [] 8 | -------------------------------------------------------------------------------- /ext/classes/Menu.yaml: -------------------------------------------------------------------------------- 1 | cname: Fl_Menu_ 2 | dartname: Menu 3 | wrapper: false 4 | 5 | constructors: [] 6 | 7 | methods: 8 | - void add([custom]) 9 | -------------------------------------------------------------------------------- /ext/classes/TextBuffer.yaml: -------------------------------------------------------------------------------- 1 | cname: Fl_Text_Buffer 2 | dartname: TextBuffer 3 | customWrapper: true 4 | 5 | constructors: 6 | - void () 7 | 8 | methods: 9 | - String text() 10 | - void text(String text) 11 | -------------------------------------------------------------------------------- /ext/classes/TextDisplay.yaml: -------------------------------------------------------------------------------- 1 | cname: Fl_Text_Display 2 | dartname: TextDisplay 3 | customWrapper: true 4 | 5 | constructors: 6 | - void (int x, int y, int w, int h, String l) 7 | 8 | methods: 9 | - void buffer(Fl_Text_Buffer* buffer) 10 | - void cursor_color(Fl_Color bg) 11 | - Fl_Color cursor_color() 12 | - void cursor_style(int style) 13 | - Fl_Color textcolor() 14 | - void textcolor(Fl_Color color) 15 | - Fl_Font textfont() 16 | - void textfont(Fl_Font s) 17 | - Fl_Fontsize textsize() 18 | - void textsize(Fl_Fontsize s) 19 | 20 | - void linenumber_align(Fl_Align val) 21 | - Fl_Align linenumber_align() 22 | - void linenumber_bgcolor(Fl_Color val) 23 | - Fl_Color linenumber_bgcolor() 24 | - void linenumber_fgcolor(Fl_Color val) 25 | - Fl_Color linenumber_fgcolor() 26 | - void linenumber_font(Fl_Font val) 27 | - Fl_Font linenumber_font() 28 | - void linenumber_format(String val) 29 | - String linenumber_format() 30 | - void linenumber_size(Fl_Fontsize val) 31 | - Fl_Fontsize linenumber_size() 32 | - void linenumber_width(int width) 33 | - int linenumber_width() 34 | 35 | - void scroll(int row, int collumn) 36 | - void highlight_data([custom]) 37 | 38 | - void set_scrollbar_color(Fl_Color color) 39 | - void set_scrollbar_box(Fl_Boxtype boxtype) 40 | -------------------------------------------------------------------------------- /ext/classes/TextEditor.yaml: -------------------------------------------------------------------------------- 1 | cname: Fl_Text_Editor 2 | dartname: TextEditor 3 | customWrapper: true 4 | 5 | constructors: 6 | - void (int x, int y, int w, int h, String l) 7 | 8 | methods: 9 | - void set_scrollbar_color(Fl_Color color) 10 | - void set_scrollbar_box(Fl_Boxtype boxtype) 11 | -------------------------------------------------------------------------------- /ext/classes/Widget.yaml: -------------------------------------------------------------------------------- 1 | cname: Fl_Widget 2 | dartname: Widget 3 | 4 | constructors: 5 | - void (int x, int y, int w, int h, String l) 6 | 7 | methods: 8 | - int x() 9 | - int y() 10 | - int w() 11 | - int h() 12 | 13 | - void activate() 14 | - void deactivate() 15 | - int active() 16 | - int active_r() 17 | - void show() 18 | - void hide() 19 | - void redraw() 20 | - int visible() 21 | - int visible_r() 22 | 23 | - String label() 24 | - void label(String text) 25 | - Fl_Font labelfont() 26 | - void labelfont(Fl_Font f) 27 | - Fl_Fontsize labelsize() 28 | - void labelsize(Fl_Fontsize pixels) 29 | - Fl_Labeltype labeltype() 30 | - void labeltype(Fl_Labeltype type) 31 | - Fl_Color labelcolor() 32 | - void labelcolor(Fl_Color c) 33 | - Fl_Color color() 34 | - void color(Fl_Color bg) 35 | 36 | - Fl_Align align() 37 | - void align(Fl_Align align) 38 | 39 | - void box(Fl_Boxtype type) 40 | - void image([custom]) 41 | 42 | - int when() 43 | - void when(int mode) 44 | -------------------------------------------------------------------------------- /ext/classes/Window.yaml: -------------------------------------------------------------------------------- 1 | cname: Fl_Window 2 | dartname: Window 3 | 4 | constructors: 5 | - void Short(int w, int h, String l) 6 | - void (int x, int y, int w, int h, String l) 7 | 8 | methods: 9 | - void copy_label(String text) 10 | -------------------------------------------------------------------------------- /ext/functions/color.yaml: -------------------------------------------------------------------------------- 1 | name: color 2 | include: 3 | - 4 | 5 | functions: 6 | - name: background 7 | code: void Fl::background 8 | args: int r, int g, int b 9 | - name: background2 10 | code: void Fl::background2 11 | args: int r, int g, int b 12 | - name: foreground 13 | code: void Fl::foreground 14 | args: int r, int g, int b 15 | - name: set_color 16 | code: void Fl::set_color 17 | args: Fl_Color color, int r, int g, int b 18 | -------------------------------------------------------------------------------- /ext/functions/core.yaml: -------------------------------------------------------------------------------- 1 | name: core 2 | include: 3 | - 4 | 5 | functions: 6 | - name: run 7 | code: int Fl::run 8 | - name: wait 9 | code: int Fl::wait 10 | - name: check 11 | code: int Fl::check 12 | - name: scheme 13 | code: void Fl::scheme 14 | args: String scheme 15 | - name: option 16 | code: void Fl::option 17 | args: Fl::Fl_Option option, bool value 18 | -------------------------------------------------------------------------------- /ext/functions/draw.yaml: -------------------------------------------------------------------------------- 1 | name: draw 2 | include: 3 | - 4 | - 5 | 6 | functions: 7 | - name: color 8 | code: void fl_color 9 | args: Fl_Color c 10 | - name: line1 11 | code: void fl_line 12 | args: int x, int y, int x1, int y1 13 | - name: line2 14 | code: void fl_line 15 | args: int x, int y, int x1, int y1, int x2, int y2 16 | - name: draw_image 17 | code: void fl_draw_image 18 | args: Uint8List buffer, int x, int y, int w, int h, int d, int l 19 | -------------------------------------------------------------------------------- /ext/functions/event.yaml: -------------------------------------------------------------------------------- 1 | name: event 2 | include: 3 | - 4 | 5 | functions: 6 | - name: copy 7 | code: void Fl::copy 8 | args: String scheme, int length, int destination, String mime 9 | - name: dnd 10 | code: void Fl::dnd 11 | 12 | - name: event_x 13 | code: int Fl::event_x 14 | - name: event_y 15 | code: int Fl::event_y 16 | - name: event_dx 17 | code: int Fl::event_dx 18 | - name: event_dy 19 | code: int Fl::event_dy 20 | - name: event_key 21 | code: int Fl::event_key 22 | - name: event_text 23 | code: String Fl::event_text 24 | - name: event_state 25 | code: int Fl::event_state 26 | - name: event_button 27 | code: int Fl::event_button 28 | 29 | # compose 30 | # addHandler 31 | # 32 | # pushed 33 | # belowmouse 34 | # selectionOwner 35 | -------------------------------------------------------------------------------- /ext/src/classes/Menu.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include "../gen/classes/Menu.hpp" 6 | 7 | namespace fldart { 8 | void _menu_callback(Fl_Widget*, void *data) { 9 | Dart_PersistentHandle closure = (Dart_PersistentHandle)data; 10 | HandleError(Dart_InvokeClosure(closure, 0, {})); 11 | } 12 | 13 | void Menu::void_add(Dart_NativeArguments arguments) { 14 | // Local variables 15 | Fl_Menu_ *_ref; 16 | const char *label; 17 | int64_t shortcut = 0; 18 | int64_t flags = 0; 19 | 20 | Dart_EnterScope(); 21 | 22 | // Create pointer to FLTK object. 23 | _ref = (Fl_Menu_*)getptr(arguments, 0); 24 | 25 | // Get arguments. 26 | Dart_Handle _label = getarg(arguments, 1); 27 | Dart_Handle _shortcut = getarg(arguments, 2); 28 | Dart_Handle _callback = getarg(arguments, 3); 29 | Dart_Handle _flags = getarg(arguments, 4); 30 | 31 | HandleError(Dart_StringToCString(_label, &label)); 32 | HandleError(Dart_IntegerToInt64(_shortcut, &shortcut)); 33 | HandleError(Dart_IntegerToInt64(_flags, &flags)); 34 | 35 | // Add callback if a callback reference is passed. 36 | if (!Dart_IsNull(_callback)) { 37 | Dart_PersistentHandle handle = Dart_NewPersistentHandle(_callback); 38 | _ref -> add(label, shortcut, _menu_callback, handle, flags); 39 | } else { 40 | _ref -> add(label, shortcut, NULL, NULL, flags); 41 | } 42 | 43 | // Return 44 | Dart_Handle _ret = Dart_Null(); 45 | Dart_SetReturnValue(arguments, _ret); 46 | Dart_ExitScope(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ext/src/classes/TextDisplay.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include 6 | 7 | #include "../gen/classes/Widget.hpp" 8 | 9 | namespace fldart { 10 | typedef Fl_Text_Display::Style_Table_Entry StyleEntry; 11 | 12 | void TextDisplay::void_highlight_data(Dart_NativeArguments arguments) { 13 | // Local variables 14 | intptr_t ptr, bufferPtr; 15 | Fl_Text_Display_Wrapper *_ref; 16 | Fl_Text_Buffer *buffer; 17 | StyleEntry *styletable; 18 | 19 | Dart_EnterScope(); 20 | 21 | // Create pointer to FLTK object. 22 | _ref = (Fl_Text_Display_Wrapper*)getptr(arguments, 0); 23 | 24 | // Get text buffer. 25 | buffer = (Fl_Text_Buffer*)getptr(arguments, 1); 26 | 27 | // Get styletable. 28 | Dart_Handle list = HandleError(Dart_GetNativeArgument(arguments, 2)); 29 | int64_t length; 30 | HandleError(Dart_ListLength(list, &length)); 31 | styletable = (StyleEntry*)malloc(sizeof(StyleEntry) * length); 32 | for (int64_t i = 0; i < length; i++) { 33 | Dart_Handle element = HandleError(Dart_ListGetAt(list, i)); 34 | 35 | int64_t color, font, size; 36 | HandleError(Dart_IntegerToInt64(getfield(element, "color"), &color)); 37 | HandleError(Dart_IntegerToInt64(getfield(element, "font"), &font)); 38 | HandleError(Dart_IntegerToInt64(getfield(element, "size"), &size)); 39 | 40 | styletable[i] = StyleEntry({ 41 | (Fl_Color)color, 42 | (Fl_Font)font, 43 | (Fl_Fontsize)size 44 | }); 45 | } 46 | 47 | _ref -> highlight_data(buffer, styletable, length, 0, 0, 0); 48 | 49 | // Return 50 | Dart_Handle _ret = Dart_Null(); 51 | Dart_SetReturnValue(arguments, _ret); 52 | Dart_ExitScope(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ext/src/classes/Widget.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include 6 | 7 | #include "../gen/classes/Widget.hpp" 8 | 9 | namespace fldart { 10 | void Widget::void_image(Dart_NativeArguments arguments) { 11 | // Local variables 12 | Fl_Widget_Wrapper *_ref; 13 | int64_t width, height, depth; 14 | 15 | Dart_EnterScope(); 16 | 17 | // Create pointer to FLTK object. 18 | _ref = (Fl_Widget_Wrapper*)getptr(arguments, 0); 19 | 20 | // Get image dimensions. 21 | HandleError(Dart_IntegerToInt64(getarg(arguments, 1), &width)); 22 | HandleError(Dart_IntegerToInt64(getarg(arguments, 2), &height)); 23 | HandleError(Dart_IntegerToInt64(getarg(arguments, 3), &depth)); 24 | 25 | // Get image data. 26 | uint8_t *data = getUint8List(arguments, 4); 27 | 28 | // Set image data. 29 | auto image = new Fl_RGB_Image(data, width, height, depth); 30 | _ref -> image(image); 31 | 32 | // Return 33 | Dart_Handle _ret = Dart_Null(); 34 | Dart_SetReturnValue(arguments, _ret); 35 | Dart_ExitScope(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ext/src/common.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include "common.hpp" 6 | 7 | namespace fldart { 8 | Dart_Handle HandleError(Dart_Handle handle) { 9 | if (Dart_IsError(handle)) { 10 | Dart_PropagateError(handle); 11 | } else { 12 | return handle; 13 | } 14 | } 15 | 16 | const char* newstr(const char *src) { 17 | if (strlen(src) > 0) { 18 | return strcpy(new char[strlen(src) + 1], src); 19 | } else { 20 | return nullptr; 21 | } 22 | } 23 | 24 | Dart_Handle getarg(Dart_NativeArguments arguments, int n) { 25 | return HandleError(Dart_GetNativeArgument(arguments, n)); 26 | } 27 | 28 | Dart_Handle getfield(Dart_Handle container, const char *name) { 29 | HandleError(Dart_GetField(container, Dart_NewStringFromCString(name))); 30 | } 31 | 32 | intptr_t getptr(Dart_NativeArguments arguments, int argn) { 33 | intptr_t dst; 34 | HandleError( 35 | Dart_GetNativeInstanceField( 36 | HandleError( 37 | Dart_GetNativeArgument(arguments, argn)), 0, &dst)); 38 | return dst; 39 | } 40 | 41 | uint8_t *getUint8List(Dart_NativeArguments arguments, int argn) { 42 | void *data; 43 | Dart_Handle handle = getarg(arguments, argn); 44 | 45 | int64_t length; 46 | HandleError(Dart_ListLength(handle, &length)); 47 | 48 | // Aquire data. 49 | Dart_TypedData_Type type = Dart_TypedData_kUint8; 50 | HandleError(Dart_TypedDataAcquireData(handle, &type, &data, &length)); 51 | 52 | // Reallocate to create safe memory block. 53 | uint8_t *byteData = (uint8_t*)malloc(length); 54 | memcpy(byteData, data, length); 55 | 56 | // Release data. 57 | HandleError(Dart_TypedDataReleaseData(handle)); 58 | 59 | return byteData; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /ext/src/common.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #ifndef FLDART_COMMON_H 6 | #define FLDART_COMMON_H 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace fldart { 13 | struct FunctionMapping { 14 | const char* name; 15 | Dart_NativeFunction function; 16 | }; 17 | 18 | /// Catch exceptions in a Dart_Handle 19 | Dart_Handle HandleError(Dart_Handle handle); 20 | 21 | /// Create a copy of the given string. 22 | const char* newstr(const char *src); 23 | 24 | /// Dart API helpers. 25 | Dart_Handle getarg(Dart_NativeArguments arguments, int n); 26 | Dart_Handle getfield(Dart_Handle container, const char *name); 27 | intptr_t getptr(Dart_NativeArguments arguments, int argn); 28 | uint8_t *getUint8List(Dart_NativeArguments arguments, int argn); 29 | } 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /ext/src/custom.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include "custom.hpp" 6 | #include 7 | 8 | namespace fldart { 9 | namespace custom { 10 | void rgb_image_draw(Dart_NativeArguments arguments) { 11 | Dart_EnterScope(); 12 | 13 | uint8_t* buffer = getUint8List(arguments, 0); 14 | 15 | int64_t x, y, w, h, d, ld; 16 | HandleError(Dart_IntegerToInt64(getarg(arguments, 1), &x)); 17 | HandleError(Dart_IntegerToInt64(getarg(arguments, 2), &y)); 18 | HandleError(Dart_IntegerToInt64(getarg(arguments, 3), &w)); 19 | HandleError(Dart_IntegerToInt64(getarg(arguments, 4), &h)); 20 | HandleError(Dart_IntegerToInt64(getarg(arguments, 5), &d)); 21 | HandleError(Dart_IntegerToInt64(getarg(arguments, 6), &ld)); 22 | 23 | auto img = new Fl_RGB_Image(buffer, w, h, d, ld); 24 | img -> draw(x, y); 25 | delete img; 26 | 27 | Dart_SetReturnValue(arguments, Dart_Null()); 28 | Dart_ExitScope(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ext/src/custom.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #ifndef FLDART_CUSTOM_H 6 | #define FLDART_CUSTOM_H 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | 16 | #include "common.hpp" 17 | 18 | namespace fldart { 19 | namespace custom { 20 | void rgb_image_draw(Dart_NativeArguments arguments); 21 | 22 | static FunctionMapping functionMapping[] = { 23 | {"fldart::rgb_image_draw", rgb_image_draw}, 24 | {NULL, NULL} 25 | }; 26 | } 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /ext/src/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | // Force enable Cairo 6 | #define USE_X11 1 7 | #define FLTK_HAVE_CAIRO 1 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include "common.hpp" 18 | #include "custom.hpp" 19 | 20 | #include "gen/functions/core.hpp" 21 | #include "gen/functions/draw.hpp" 22 | #include "gen/functions/color.hpp" 23 | #include "gen/functions/event.hpp" 24 | 25 | #include "gen/classes/Widget.hpp" 26 | #include "gen/classes/Group.hpp" 27 | #include "gen/classes/Box.hpp" 28 | #include "gen/classes/Button.hpp" 29 | #include "gen/classes/Input.hpp" 30 | #include "gen/classes/Menu.hpp" 31 | #include "gen/classes/Choice.hpp" 32 | #include "gen/classes/TextBuffer.hpp" 33 | #include "gen/classes/TextDisplay.hpp" 34 | #include "gen/classes/TextEditor.hpp" 35 | #include "gen/classes/Window.hpp" 36 | #include "gen/classes/DoubleWindow.hpp" 37 | #include "gen/classes/GlWindow.hpp" 38 | #include "gen/classes/CairoWindow.hpp" 39 | 40 | Dart_NativeFunction ResolveName( 41 | Dart_Handle name, 42 | int argc, 43 | bool *autoSetupScope); 44 | 45 | DART_EXPORT Dart_Handle fldart_Init(Dart_Handle parentLibrary) { 46 | if (Dart_IsError(parentLibrary)) { 47 | return parentLibrary; 48 | } 49 | 50 | Dart_Handle resultCode = Dart_SetNativeResolver( 51 | parentLibrary, ResolveName, NULL); 52 | if (Dart_IsError(resultCode)) { 53 | return resultCode; 54 | } 55 | 56 | // Initialize label types. 57 | fl_define_FL_SHADOW_LABEL(); 58 | fl_define_FL_ENGRAVED_LABEL(); 59 | fl_define_FL_EMBOSSED_LABEL(); 60 | 61 | // Prevent dithering. 62 | Fl::visual(FL_RGB); 63 | 64 | return Dart_Null(); 65 | } 66 | 67 | // TODO: use hashtable? 68 | std::vector allFunctions = { 69 | fldart::custom::functionMapping, 70 | fldart::core::functionMapping, 71 | fldart::draw::functionMapping, 72 | fldart::color::functionMapping, 73 | fldart::event::functionMapping, 74 | fldart::Widget::functionMapping, 75 | fldart::Group::functionMapping, 76 | fldart::Box::functionMapping, 77 | fldart::Button::functionMapping, 78 | fldart::Input::functionMapping, 79 | fldart::Menu::functionMapping, 80 | fldart::Choice::functionMapping, 81 | fldart::TextBuffer::functionMapping, 82 | fldart::TextDisplay::functionMapping, 83 | fldart::TextEditor::functionMapping, 84 | fldart::Window::functionMapping, 85 | fldart::DoubleWindow::functionMapping, 86 | fldart::GlWindow::functionMapping, 87 | fldart::CairoWindow::functionMapping 88 | }; 89 | 90 | Dart_NativeFunction ResolveName(Dart_Handle name, int argc, bool *autoSetupScope) { 91 | if (!Dart_IsString(name)) { 92 | return NULL; 93 | } 94 | 95 | Dart_NativeFunction result = NULL; 96 | Dart_EnterScope(); 97 | const char *cname; 98 | fldart::HandleError(Dart_StringToCString(name, &cname)); 99 | 100 | for (int ii = 0; ii < allFunctions.size(); ++ii) { 101 | for (int i = 0; allFunctions[ii][i].name != NULL; ++i) { 102 | if (strcmp(allFunctions[ii][i].name, cname) == 0) { 103 | result = allFunctions[ii][i].function; 104 | break; 105 | } 106 | } 107 | } 108 | 109 | Dart_ExitScope(); 110 | return result; 111 | } 112 | -------------------------------------------------------------------------------- /ext/src/wrappers/Fl_Cairo_Window_Wrapper.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include "Fl_Cairo_Window_Wrapper.hpp" 6 | 7 | namespace fldart { 8 | Fl_Cairo_Window_Wrapper::Fl_Cairo_Window_Wrapper(Dart_Handle ref, int w, int h, const char* l) : Fl_Cairo_Window(w, h) { 9 | label(l); 10 | _ref = Dart_NewPersistentHandle(ref); 11 | user_data(&_ref); 12 | set_draw_cb(draw_cb); 13 | } 14 | 15 | void Fl_Cairo_Window_Wrapper::draw_cb(Fl_Cairo_Window *self, cairo_t *ctx) { 16 | Dart_PersistentHandle *ref = (Dart_PersistentHandle*)self -> user_data(); 17 | 18 | // Create instance of CairoContext. 19 | Dart_Handle dartCairoContextType = HandleError(Dart_GetType( 20 | Dart_LookupLibrary( 21 | Dart_NewStringFromCString("package:fltk/fltk.dart")), 22 | Dart_NewStringFromCString("CairoContext"), 0, {})); 23 | Dart_Handle dartCairoContext = Dart_New( 24 | dartCairoContextType, Dart_EmptyString(), 0, {}); 25 | 26 | // Link cairo context to CairoContext. 27 | Dart_SetNativeInstanceField(dartCairoContext, 0, (intptr_t)ctx); 28 | 29 | Dart_Handle args[1] = { dartCairoContext }; 30 | HandleError(Dart_Invoke(*ref, Dart_NewStringFromCString("runDrawCb"), 1, args)); 31 | } 32 | 33 | void Fl_Cairo_Window_Wrapper::resize(int x, int y, int w, int h) { 34 | Fl_Cairo_Window::resize(x, y, w, h); 35 | Dart_Handle args[4] = { 36 | Dart_NewInteger((int64_t)x), 37 | Dart_NewInteger((int64_t)y), 38 | Dart_NewInteger((int64_t)w), 39 | Dart_NewInteger((int64_t)h) 40 | }; 41 | HandleError(Dart_Invoke(_ref, Dart_NewStringFromCString("resize"), 4, args)); 42 | } 43 | 44 | int Fl_Cairo_Window_Wrapper::handle(int event) { 45 | Dart_Handle args[1] = { Dart_NewInteger((int64_t)event) }; 46 | Dart_Handle ret = HandleError(Dart_Invoke(_ref, Dart_NewStringFromCString("doHandle"), 1, args)); 47 | int64_t returnValue; 48 | Dart_IntegerToInt64(ret, &returnValue); 49 | return returnValue; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ext/src/wrappers/Fl_Cairo_Window_Wrapper.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #ifndef FLDART_FL_CAIRO_WINDOW_WRAPPER_H 6 | #define FLDART_FL_CAIRO_WINDOW_WRAPPER_H 7 | 8 | // Force enable Cairo 9 | #define USE_X11 1 10 | #define FLTK_HAVE_CAIRO 1 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include "../common.hpp" 18 | 19 | namespace fldart { 20 | class Fl_Cairo_Window_Wrapper : public Fl_Cairo_Window { 21 | Dart_PersistentHandle _ref; 22 | 23 | public: 24 | Fl_Cairo_Window_Wrapper(Dart_Handle ref, int w, int h, const char* l); 25 | 26 | void resize(int x, int y, int w, int h); 27 | int handle(int event); 28 | 29 | static void draw_cb(Fl_Cairo_Window *self, cairo_t *ctx); 30 | }; 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /ext/src/wrappers/Fl_Text_Buffer_Wrapper.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include "Fl_Text_Buffer_Wrapper.hpp" 6 | 7 | namespace fldart { 8 | Fl_Text_Buffer_Wrapper::Fl_Text_Buffer_Wrapper(Dart_Handle ref) : Fl_Text_Buffer() { 9 | _ref = Dart_NewPersistentHandle(ref); 10 | add_modify_callback(buffer_modified_cb, &_ref); 11 | } 12 | 13 | void Fl_Text_Buffer_Wrapper::buffer_modified_cb( 14 | int pos, int nInserted, int nDeleted, int nRestyled, 15 | const char *deletedText, void *ptr) { 16 | 17 | Dart_PersistentHandle *ref = (Dart_PersistentHandle*)ptr; 18 | Dart_Handle args[5] = { 19 | Dart_NewInteger((int64_t)pos), 20 | Dart_NewInteger((int64_t)nInserted), 21 | Dart_NewInteger((int64_t)nDeleted), 22 | Dart_NewInteger((int64_t)nRestyled), 23 | deletedText == NULL ? Dart_EmptyString() : Dart_NewStringFromCString(deletedText) 24 | }; 25 | HandleError(Dart_Invoke(*ref, Dart_NewStringFromCString("bufferModified"), 5, args)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ext/src/wrappers/Fl_Text_Buffer_Wrapper.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #ifndef FLDART_FL_TEXT_BUFFER_WRAPPER_H 6 | #define FLDART_FL_TEXT_BUFFER_WRAPPER_H 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include "../common.hpp" 14 | 15 | namespace fldart { 16 | class Fl_Text_Buffer_Wrapper : public Fl_Text_Buffer { 17 | Dart_PersistentHandle _ref; 18 | 19 | public: 20 | Fl_Text_Buffer_Wrapper(Dart_Handle ref); 21 | 22 | static void buffer_modified_cb( 23 | int pos, int nInserted, int nDeleted, int nRestyled, 24 | const char *deletedText, void *ptr); 25 | }; 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /ext/src/wrappers/Fl_Text_Display_Wrapper.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include "Fl_Text_Display_Wrapper.hpp" 6 | 7 | namespace fldart { 8 | Fl_Text_Display_Wrapper::Fl_Text_Display_Wrapper(Dart_Handle ref, int x, int y, int w, int h, const char* l) : Fl_Text_Display(x, y, w, h, l) { 9 | _ref = Dart_NewPersistentHandle(ref); 10 | callback(callback_wrapper, &_ref); 11 | } 12 | 13 | void Fl_Text_Display_Wrapper::set_scrollbar_color(Fl_Color color) { 14 | mHScrollBar -> color(color); 15 | mVScrollBar -> color(color); 16 | } 17 | 18 | void Fl_Text_Display_Wrapper::set_scrollbar_box(Fl_Boxtype boxtype) { 19 | mHScrollBar -> slider(boxtype); 20 | mVScrollBar -> slider(boxtype); 21 | } 22 | 23 | void Fl_Text_Display_Wrapper::callback_wrapper(Fl_Widget*, void *ptr) { 24 | Dart_PersistentHandle *ref = (Dart_PersistentHandle*)ptr; 25 | HandleError(Dart_Invoke(*ref, Dart_NewStringFromCString("doCallback"), 0, {})); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ext/src/wrappers/Fl_Text_Display_Wrapper.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #ifndef FLDART_FL_TEXT_EDITOR_WRAPPER_H 6 | #define FLDART_FL_TEXT_EDITOR_WRAPPER_H 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include "../common.hpp" 14 | 15 | namespace fldart { 16 | class Fl_Text_Display_Wrapper : public Fl_Text_Display { 17 | Dart_PersistentHandle _ref; 18 | 19 | public: 20 | Fl_Text_Display_Wrapper(Dart_Handle ref, int x, int y, int w, int h, const char* l); 21 | 22 | // This feature is not exposed in FLTK. 23 | void set_scrollbar_color(Fl_Color color); 24 | void set_scrollbar_box(Fl_Boxtype boxtype); 25 | 26 | static void callback_wrapper(Fl_Widget*, void*); 27 | }; 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /ext/src/wrappers/Fl_Text_Editor_Wrapper.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #include "Fl_Text_Editor_Wrapper.hpp" 6 | 7 | namespace fldart { 8 | Fl_Text_Editor_Wrapper::Fl_Text_Editor_Wrapper(Dart_Handle ref, int x, int y, int w, int h, const char* l) : Fl_Text_Editor(x, y, w, h, l) { 9 | _ref = Dart_NewPersistentHandle(ref); 10 | callback(callback_wrapper, &_ref); 11 | } 12 | 13 | void Fl_Text_Editor_Wrapper::set_scrollbar_color(Fl_Color color) { 14 | mHScrollBar -> color(color); 15 | mVScrollBar -> color(color); 16 | } 17 | 18 | void Fl_Text_Editor_Wrapper::set_scrollbar_box(Fl_Boxtype boxtype) { 19 | mHScrollBar -> slider(boxtype); 20 | mVScrollBar -> slider(boxtype); 21 | } 22 | 23 | void Fl_Text_Editor_Wrapper::callback_wrapper(Fl_Widget*, void *ptr) { 24 | Dart_PersistentHandle *ref = (Dart_PersistentHandle*)ptr; 25 | HandleError(Dart_Invoke(*ref, Dart_NewStringFromCString("doCallback"), 0, {})); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ext/src/wrappers/Fl_Text_Editor_Wrapper.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | #ifndef FLDART_FL_TEXT_EDITOR_WRAPPER_H 6 | #define FLDART_FL_TEXT_EDITOR_WRAPPER_H 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include "../common.hpp" 14 | 15 | namespace fldart { 16 | class Fl_Text_Editor_Wrapper : public Fl_Text_Editor { 17 | Dart_PersistentHandle _ref; 18 | 19 | public: 20 | Fl_Text_Editor_Wrapper(Dart_Handle ref, int x, int y, int w, int h, const char* l); 21 | 22 | // This feature is not exposed in FLTK. 23 | void set_scrollbar_color(Fl_Color color); 24 | void set_scrollbar_box(Fl_Boxtype boxtype); 25 | 26 | static void callback_wrapper(Fl_Widget*, void*); 27 | }; 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /lib/enums.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | library fltk.enums; 6 | 7 | part 'src/enums/labeltype.dart'; 8 | part 'src/enums/shortcut.dart'; 9 | part 'src/enums/boxtype.dart'; 10 | part 'src/enums/option.dart'; 11 | part 'src/enums/color.dart'; 12 | part 'src/enums/align.dart'; 13 | part 'src/enums/font.dart'; 14 | part 'src/enums/event.dart'; 15 | -------------------------------------------------------------------------------- /lib/flfn.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | library fltk.flfn; 6 | 7 | import 'dart:io'; 8 | import 'dart:async'; 9 | import 'dart:convert'; 10 | import 'dart:developer'; 11 | 12 | import 'package:color/color.dart'; 13 | import 'package:fltk/fltk.dart' as fl; 14 | 15 | export 'enums.dart'; 16 | 17 | part 'src/flfn/run.dart'; 18 | part 'src/flfn/app.dart'; 19 | part 'src/flfn/window.dart'; 20 | part 'src/flfn/widget.dart'; 21 | part 'src/flfn/box.dart'; 22 | part 'src/flfn/button.dart'; 23 | -------------------------------------------------------------------------------- /lib/fltk.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | library fltk; 6 | 7 | import 'dart-ext:fldart'; 8 | 9 | import 'dart:nativewrappers'; 10 | import 'dart:typed_data'; 11 | import 'dart:async'; 12 | 13 | import 'package:color/color.dart'; 14 | import 'package:image/image.dart' hide Color; 15 | import 'package:cairodart/cairodart.dart' as cairo; 16 | 17 | import 'src/utils/cairo.dart'; 18 | 19 | import 'enums.dart'; 20 | export 'enums.dart'; 21 | 22 | part 'src/fl/core.dart'; 23 | part 'src/fl/draw.dart'; 24 | part 'src/fl/color.dart'; 25 | part 'src/fl/event.dart'; 26 | part 'src/fl/xpm.dart'; 27 | 28 | part 'src/widget.dart'; 29 | part 'src/group.dart'; 30 | part 'src/box.dart'; 31 | part 'src/button.dart'; 32 | part 'src/input.dart'; 33 | part 'src/menu.dart'; 34 | part 'src/choice.dart'; 35 | part 'src/text_buffer.dart'; 36 | part 'src/text_display.dart'; 37 | part 'src/text_editor.dart'; 38 | part 'src/window.dart'; 39 | part 'src/double_window.dart'; 40 | part 'src/gl_window.dart'; 41 | part 'src/cairo_window.dart'; 42 | part 'src/cairo_surface.dart'; 43 | -------------------------------------------------------------------------------- /lib/hvif.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | library fltk.hvif; 6 | 7 | import 'dart:typed_data'; 8 | 9 | import 'package:image/image.dart' hide Color; 10 | import 'package:cairodart/cairodart.dart' as cairo; 11 | 12 | import 'src/utils/cairo.dart'; 13 | 14 | part 'src/hvif/hvif.dart'; 15 | part 'src/hvif/path.dart'; 16 | part 'src/hvif/utils.dart'; 17 | part 'src/hvif/style.dart'; 18 | part 'src/hvif/shape.dart'; 19 | part 'src/hvif/transformer.dart'; 20 | -------------------------------------------------------------------------------- /lib/src/box.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk; 6 | 7 | /// Fl_Box 8 | class Box extends Widget { 9 | /// Public constuctor 10 | Box(int x, int y, int w, int h, [String l = '']) : super.empty() { 11 | _createBox(x, y, w, h, l); 12 | } 13 | 14 | Box.empty() : super.empty(); 15 | 16 | /// Native constructor 17 | void _createBox(int x, int y, int w, int h, String l) 18 | native 'fldart::Box::constructor_Box'; 19 | } 20 | -------------------------------------------------------------------------------- /lib/src/button.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk; 6 | 7 | /// Fl_Button 8 | class Button extends Widget { 9 | /// Public constuctor 10 | Button(int x, int y, int w, int h, [String l = '']) : super.empty() { 11 | _createButton(x, y, w, h, l); 12 | } 13 | 14 | Button.empty() : super.empty(); 15 | 16 | /// Native constructor 17 | void _createButton(int x, int y, int w, int h, String l) 18 | native 'fldart::Button::constructor_Button'; 19 | } 20 | -------------------------------------------------------------------------------- /lib/src/cairo_surface.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk; 6 | 7 | /// Special implementation of Cairo using an [ImageSurface] from `cairodart` and 8 | /// the `fl_draw_image` function from FLTK. 9 | /// 10 | /// Note: this class is not currenly working because of issues with 11 | /// [ImageSurface.data] in `cairodart`. 12 | class CairoSurface extends Widget { 13 | /// Target [ImageSurface] (drawing canvas) 14 | cairo.ImageSurface _surface; 15 | 16 | /// Redraw event stream 17 | Stream onDraw; 18 | 19 | /// Redraw stream controller 20 | /// 21 | /// Note that this is a synchronous stream because all redraws have to be 22 | /// completed before drawing the surface data to the widget. 23 | final _onDrawController = 24 | new StreamController.broadcast(sync: true); 25 | 26 | CairoSurface(int x, int y, int w, int h) : super(x, y, w, h) { 27 | onDraw = _onDrawController.stream; 28 | 29 | // Initialize drawing surface. 30 | resizeSurface(w, h); 31 | 32 | onResize.listen((data) { 33 | if (data.w != _surface.width || data.h != _surface.height) { 34 | resizeSurface(data.w, data.h); 35 | } 36 | }); 37 | } 38 | 39 | /// Resize [_surface]. 40 | void resizeSurface(int width, int height) { 41 | if (_surface != null) { 42 | _surface.finish(); 43 | } 44 | 45 | _surface = new cairo.ImageSurface(cairo.Format.ARGB32, width, height); 46 | } 47 | 48 | /// Get context for the image surface. 49 | cairo.Context getContext() => new cairo.Context(_surface); 50 | 51 | /// Redraw surface 52 | /// 53 | /// Do not override this method! To draw, you should draw directly to the 54 | /// image surface. 55 | void draw() { 56 | // Trigger surface updates. 57 | final ctx = getContext(); 58 | _onDrawController.add(ctx); // Synchronous processing 59 | _surface.flush(); 60 | 61 | // Draw pixel data. It turns out using drawRgbImage for this task is glitchy 62 | // for large canvasses. So if the OS does not provide alpha blending 63 | // support, no alpha for you! 64 | final pixeldata = _surface.data; 65 | bgraToRgba(pixeldata); 66 | unpremultiply(pixeldata); 67 | drawImage(pixeldata, x(), y(), _surface.width, _surface.height, 4); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /lib/src/cairo_window.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk; 6 | 7 | /// Wrapper around [NativeFieldWrapperClass2] to carry the 8 | class CairoContext extends NativeFieldWrapperClass2 {} 9 | 10 | /// Cairo draw callback 11 | typedef void CairoDrawCb(CairoWindow window, cairo.Context ctx); 12 | 13 | /// Fl_Cairo_Window 14 | class CairoWindow extends DoubleWindow { 15 | /// FLTK style Cairo callback 16 | CairoDrawCb _drawCallback; 17 | 18 | /// Public constuctor 19 | CairoWindow(int w, int h, [String l = '']) : super.empty() { 20 | _createCairoWindow(w, h, l); 21 | } 22 | 23 | CairoWindow.empty() : super.empty(); 24 | 25 | /// Set draw callback. 26 | set drawCallback(CairoDrawCb cb) => _drawCallback = cb; 27 | 28 | /// Internal draw callback 29 | /// Do not override this method! 30 | void runDrawCb(CairoContext nativeWrapper) { 31 | var ctx = new cairo.Context.fromNative(nativeWrapper); 32 | onDraw(ctx); 33 | } 34 | 35 | /// Draw callback. 36 | void onDraw(cairo.Context ctx) { 37 | if (_drawCallback != null) { 38 | _drawCallback(this, ctx); 39 | } 40 | } 41 | 42 | /// Native constructor 43 | void _createCairoWindow(int w, int h, String l) 44 | native 'fldart::CairoWindow::constructor_CairoWindow'; 45 | } 46 | -------------------------------------------------------------------------------- /lib/src/choice.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk; 6 | 7 | /// Fl_Choice 8 | class Choice extends Menu { 9 | /// Public constuctor 10 | Choice(int x, int y, int w, int h, [String l = '']) : super.empty() { 11 | _createChoice(x, y, w, h, l); 12 | } 13 | 14 | Choice.empty() : super.empty(); 15 | 16 | /// Native constructor 17 | void _createChoice(int x, int y, int w, int h, String l) 18 | native 'fldart::Choice::constructor_Choice'; 19 | } 20 | -------------------------------------------------------------------------------- /lib/src/double_window.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk; 6 | 7 | /// Fl_Double_Window 8 | class DoubleWindow extends Window { 9 | /// Create window with the given dimensions 10 | DoubleWindow(int w, int h, [String l = '']) : super.empty() { 11 | _createDoubleWindow(w, h, l); 12 | } 13 | 14 | /// Create window with the given dimensions at the given position. 15 | DoubleWindow.at(int x, int y, int w, int h, [String l = '']) : super.empty() { 16 | _createDoubleWindowAt(x, y, w, h, l); 17 | } 18 | 19 | DoubleWindow.empty() : super.empty(); 20 | 21 | /// Short native constructor 22 | void _createDoubleWindow(int w, int h, String l) 23 | native 'fldart::DoubleWindow::constructor_DoubleWindowShort'; 24 | 25 | /// Native constructor 26 | void _createDoubleWindowAt(int x, int y, int w, int h, String l) 27 | native 'fldart::DoubleWindow::constructor_DoubleWindow'; 28 | } 29 | -------------------------------------------------------------------------------- /lib/src/enums/align.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk.enums; 6 | 7 | // Fl_Align constants 8 | 9 | /// Align the label horizontally in the middle. 10 | const ALIGN_CENTER = 0; 11 | 12 | /// Align the label at the top of the widget. 13 | const ALIGN_TOP = 1; 14 | 15 | /// Align the label at the bottom of the widget. 16 | const ALIGN_BOTTOM = 2; 17 | 18 | /// Align the label at the left of the widget. 19 | const ALIGN_LEFT = 4; 20 | 21 | /// Align the label to the right of the widget. 22 | const ALIGN_RIGHT = 8; 23 | 24 | /// Draw the label inside of the widget. 25 | const ALIGN_INSIDE = 16; 26 | 27 | /// If the label contains an image, draw the text on top of the image. 28 | const ALIGN_TEXT_OVER_IMAGE = 0x0020; 29 | 30 | /// If the label contains an image, draw the text below the image. 31 | const ALIGN_IMAGE_OVER_TEXT = 0x0000; 32 | 33 | /// All parts of the label that are lager than the widget will not be drawn. 34 | const ALIGN_CLIP = 64; 35 | 36 | /// Wrap text that does not fit the width of the widget. 37 | const ALIGN_WRAP = 128; 38 | 39 | /// If the label contains an image, draw the text to the right of the image. 40 | const ALIGN_IMAGE_NEXT_TO_TEXT = 0x0100; 41 | 42 | /// If the label contains an image, draw the text to the left of the image. 43 | const ALIGN_TEXT_NEXT_TO_IMAGE = 0x0120; 44 | 45 | /// If the label contains an image, draw the image or deimage in the background. 46 | const ALIGN_IMAGE_BACKDROP = 0x0200; 47 | 48 | const ALIGN_TOP_LEFT = ALIGN_TOP | ALIGN_LEFT; 49 | const ALIGN_TOP_RIGHT = ALIGN_TOP | ALIGN_RIGHT; 50 | const ALIGN_BOTTOM_LEFT = ALIGN_BOTTOM | ALIGN_LEFT; 51 | const ALIGN_BOTTOM_RIGHT = ALIGN_BOTTOM | ALIGN_RIGHT; 52 | const ALIGN_LEFT_TOP = 0x0007; 53 | const ALIGN_RIGHT_TOP = 0x000b; 54 | const ALIGN_LEFT_BOTTOM = 0x000d; 55 | const ALIGN_RIGHT_BOTTOM = 0x000e; 56 | const ALIGN_NOWRAP = 0; 57 | const ALIGN_POSITION_MASK = 0x000f; 58 | const ALIGN_IMAGE_MASK = 0x0320; 59 | -------------------------------------------------------------------------------- /lib/src/enums/boxtype.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk.enums; 6 | 7 | // Fl_Boxtype 8 | enum Boxtype { 9 | FL_NO_BOX, 10 | FL_FLAT_BOX, 11 | FL_UP_BOX, 12 | FL_DOWN_BOX, 13 | FL_UP_FRAME, 14 | FL_DOWN_FRAME, 15 | FL_THIN_UP_BOX, 16 | FL_THIN_DOWN_BOX, 17 | FL_THIN_UP_FRAME, 18 | FL_THIN_DOWN_FRAME, 19 | FL_ENGRAVED_BOX, 20 | FL_EMBOSSED_BOX, 21 | FL_ENGRAVED_FRAME, 22 | FL_EMBOSSED_FRAME, 23 | FL_BORDER_BOX, 24 | // ignore: UNUSED_FIELD 25 | _FL_SHADOW_BOX, 26 | FL_BORDER_FRAME, 27 | // ignore: UNUSED_FIELD 28 | _FL_SHADOW_FRAME, 29 | // ignore: UNUSED_FIELD 30 | _FL_ROUNDED_BOX, 31 | // ignore: UNUSED_FIELD 32 | _FL_RSHADOW_BOX, 33 | // ignore: UNUSED_FIELD 34 | _FL_ROUNDED_FRAME, 35 | // ignore: UNUSED_FIELD 36 | _FL_RFLAT_BOX, 37 | // ignore: UNUSED_FIELD 38 | _FL_ROUND_UP_BOX, 39 | // ignore: UNUSED_FIELD 40 | _FL_ROUND_DOWN_BOX, 41 | // ignore: UNUSED_FIELD 42 | _FL_DIAMOND_UP_BOX, 43 | // ignore: UNUSED_FIELD 44 | _FL_DIAMOND_DOWN_BOX, 45 | // ignore: UNUSED_FIELD 46 | _FL_OVAL_BOX, 47 | // ignore: UNUSED_FIELD 48 | _FL_OSHADOW_BOX, 49 | // ignore: UNUSED_FIELD 50 | _FL_OVAL_FRAME, 51 | // ignore: UNUSED_FIELD 52 | _FL_OFLAT_BOX, 53 | // ignore: UNUSED_FIELD 54 | _FL_PLASTIC_UP_BOX, 55 | // ignore: UNUSED_FIELD 56 | _FL_PLASTIC_DOWN_BOX, 57 | // ignore: UNUSED_FIELD 58 | _FL_PLASTIC_UP_FRAME, 59 | // ignore: UNUSED_FIELD 60 | _FL_PLASTIC_DOWN_FRAME, 61 | // ignore: UNUSED_FIELD 62 | _FL_PLASTIC_THIN_UP_BOX, 63 | // ignore: UNUSED_FIELD 64 | _FL_PLASTIC_THIN_DOWN_BOX, 65 | // ignore: UNUSED_FIELD 66 | _FL_PLASTIC_ROUND_UP_BOX, 67 | // ignore: UNUSED_FIELD 68 | _FL_PLASTIC_ROUND_DOWN_BOX, 69 | // ignore: UNUSED_FIELD 70 | _FL_GTK_UP_BOX, 71 | // ignore: UNUSED_FIELD 72 | _FL_GTK_DOWN_BOX, 73 | // ignore: UNUSED_FIELD 74 | _FL_GTK_UP_FRAME, 75 | // ignore: UNUSED_FIELD 76 | _FL_GTK_DOWN_FRAME, 77 | // ignore: UNUSED_FIELD 78 | _FL_GTK_THIN_UP_BOX, 79 | // ignore: UNUSED_FIELD 80 | _FL_GTK_THIN_DOWN_BOX, 81 | // ignore: UNUSED_FIELD 82 | _FL_GTK_THIN_UP_FRAME, 83 | // ignore: UNUSED_FIELD 84 | _FL_GTK_THIN_DOWN_FRAME, 85 | // ignore: UNUSED_FIELD 86 | _FL_GTK_ROUND_UP_BOX, 87 | // ignore: UNUSED_FIELD 88 | _FL_GTK_ROUND_DOWN_BOX, 89 | // ignore: UNUSED_FIELD 90 | _FL_GLEAM_UP_BOX, 91 | // ignore: UNUSED_FIELD 92 | _FL_GLEAM_DOWN_BOX, 93 | // ignore: UNUSED_FIELD 94 | _FL_GLEAM_UP_FRAME, 95 | // ignore: UNUSED_FIELD 96 | _FL_GLEAM_DOWN_FRAME, 97 | // ignore: UNUSED_FIELD 98 | _FL_GLEAM_THIN_UP_BOX, 99 | // ignore: UNUSED_FIELD 100 | _FL_GLEAM_THIN_DOWN_BOX, 101 | // ignore: UNUSED_FIELD, 102 | _FL_GLEAM_ROUND_UP_BOX, 103 | // ignore: UNUSED_FIELD 104 | _FL_GLEAM_ROUND_DOWN_BOX, 105 | FL_FREE_BOXTYPE 106 | } 107 | 108 | // Quick access constants 109 | const NO_BOX = Boxtype.FL_NO_BOX; 110 | const FLAT_BOX = Boxtype.FL_FLAT_BOX; 111 | const UP_BOX = Boxtype.FL_UP_BOX; 112 | const DOWN_BOX = Boxtype.FL_DOWN_BOX; 113 | const UP_FRAME = Boxtype.FL_UP_FRAME; 114 | const DOWN_FRAME = Boxtype.FL_DOWN_FRAME; 115 | const THIN_UP_BOX = Boxtype.FL_THIN_UP_BOX; 116 | const THIN_DOWN_BOX = Boxtype.FL_THIN_DOWN_BOX; 117 | const THIN_UP_FRAME = Boxtype.FL_THIN_UP_FRAME; 118 | const THIN_DOWN_FRAME = Boxtype.FL_THIN_DOWN_FRAME; 119 | const ENGRAVED_BOX = Boxtype.FL_ENGRAVED_BOX; 120 | const EMBOSSED_BOX = Boxtype.FL_EMBOSSED_BOX; 121 | const ENGRAVED_FRAME = Boxtype.FL_ENGRAVED_FRAME; 122 | const EMBOSSED_FRAME = Boxtype.FL_EMBOSSED_FRAME; 123 | const BORDER_BOX = Boxtype.FL_BORDER_BOX; 124 | const BORDER_FRAME = Boxtype.FL_BORDER_FRAME; 125 | const FREE_BOXTYPE = Boxtype.FL_FREE_BOXTYPE; 126 | -------------------------------------------------------------------------------- /lib/src/enums/color.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk.enums; 6 | 7 | // Fl_Color constants 8 | 9 | /// The default foreground color for labels and text 10 | const FOREGROUND_COLOR = 0; 11 | 12 | /// The default background color 13 | const BACKGROUND_COLOR = 49; 14 | 15 | /// The default background color for text, list, and valuator widgets 16 | const BACKGROUND2_COLOR = 7; 17 | 18 | /// The inactive foreground color 19 | const INACTIVE_COLOR = 8; 20 | 21 | /// The default selection/highlight color 22 | const SELECTION_COLOR = 15; 23 | 24 | const GRAY0 = 32; 25 | const DARK3 = 39; 26 | const DARK2 = 45; 27 | const DARK1 = 47; 28 | const LIGHT1 = 50; 29 | const LIGHT2 = 52; 30 | const LIGHT3 = 54; 31 | const BLACK = 56; 32 | const RED = 88; 33 | const GREEN = 63; 34 | const YELLOW = 95; 35 | const BLUE = 216; 36 | const MAGENTA = 248; 37 | const CYAN = 223; 38 | const DARK_RED = 72; 39 | const DARK_GREEN = 60; 40 | const DARK_YELLOW = 76; 41 | const DARK_BLUE = 136; 42 | const DARK_MAGENTA = 152; 43 | const DARK_CYAN = 140; 44 | const WHITE = 255; 45 | -------------------------------------------------------------------------------- /lib/src/enums/event.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk.enums; 6 | 7 | /// Event 8 | enum Event { 9 | /// No event 10 | NO_EVENT, 11 | 12 | /// A mouse button has gone down with the mouse pointing at this widget. 13 | /// You can find out what button by calling [eventButton]. You find out the 14 | /// mouse position by calling [eventX] and [eventY]. 15 | /// 16 | /// A widget indicates that it "wants" the mouse click by returning true from 17 | /// its [Widget.handle] method. It will then become the [pushed] widget and 18 | /// will get [DRAG] and the matching [RELEASE] events. If [Widget.handle] 19 | /// returns zero then FLTK will try sending the [PUSH] to another widget. 20 | PUSH, 21 | 22 | /// A mouse button has been released. You can find out what button by calling 23 | /// [eventButton]. In order to receive the [RELEASE] event, the widget must 24 | /// return true when handling [PUSH]. 25 | RELEASE, 26 | 27 | /// The mouse has been moved to point at this widget. This can be used for 28 | /// highlighting feedback. If a widget wants to highlight or otherwise track 29 | /// the mouse, it indicates this by returning true from its [Widget.handle] 30 | /// method. It then becomes the [belowmouse] widget and will receive [MOVE] 31 | /// and [LEAVE] events. 32 | ENTER, 33 | 34 | /// The mouse has moved out of the widget. In order to receive the [LEAVE] 35 | /// event, the widget must return true when handling [ENTER]. 36 | LEAVE, 37 | 38 | /// The mouse has moved with a button held down. The current button state is 39 | /// in [eventState]. The mouse position is in [eventX] and [eventY]. In order 40 | /// to receive [DRAG] events, the widget must return true when handling 41 | /// [PUSH]. 42 | DRAG, 43 | 44 | /// This indicates an attempt to give a widget the keyboard focus. If a widget 45 | /// wants the focus, it should change itself to display the fact that it has 46 | /// the focus, and return true from its [Widget.handle] method. It then 47 | /// becomes the [focus] widget and gets [KEYDOWN], [KEYUP], and [UNFOCUS] 48 | /// events. The focus will change either because the window manager changed 49 | /// which window gets the focus, or because the user tried to navigate using 50 | /// tab, arrows, or other keys. You can check [eventKey] to figure out why it 51 | /// moved. For navigation it will be the key pressed and for interaction with 52 | /// the window manager it will be zero. 53 | FOCUS, 54 | 55 | /// This event is sent to the previous [focus] widget when another widget gets 56 | /// the focus or the window loses focus. 57 | UNFOCUS, 58 | 59 | /// A key was pressed ([KEYDOWN]) or released ([KEYUP]). To receive [KEYDOWN] 60 | /// events you must also respond to the [FOCUS] and [UNFOCUS] events. 61 | /// 62 | /// The key can be found in [eventKey]. The text that the key should insert 63 | /// can be found with [eventText]. If you use the key [Widget.handle] should 64 | /// return true. If you return zero then FLTK assumes you ignored the key and 65 | /// will then attempt to send it to a parent widget. If none of them want it, 66 | /// it will change the event into a [SHORTCUT] event. 67 | /// 68 | /// If you are writing a text-editing widget you may also want to call the 69 | /// [compose] function to translate individual keystrokes into non-ASCII 70 | /// characters. 71 | /// 72 | /// [KEYUP] events are sent to the widget that currently has focus. This is 73 | /// not necessarily the same widget that received the corresponding [KEYDOWN] 74 | /// event because focus may have changed between events. 75 | KEYDOWN, 76 | 77 | /// Not included because it messes up the enumeration values. 78 | ///KEYBOARD, 79 | 80 | /// Key release event. 81 | KEYUP, 82 | 83 | /// The user clicked the close button of a window. This event is used 84 | /// internally only to trigger the callback of Window derived classed. The 85 | /// default callback closes the window calling [Window.hide]. 86 | CLOSE, 87 | 88 | /// The mouse has moved without any mouse buttons held down. This event is 89 | /// sent to the [belowmouse] widget. In order to receive [MOVE] events, the 90 | /// widget must return true when handling [ENTER]. 91 | MOVE, 92 | 93 | /// If the [focus] widget is null or ignores a [KEYBOARD] event then FLTK 94 | /// tries sending this event to every widget it can, until one of them returns 95 | /// true. 96 | /// 97 | /// SHORTCUT is first sent to the [belowmouse] widget, then its parents and 98 | /// siblings, and eventually to every widget in the window, trying to find an 99 | /// object that returns true. FLTK tries really hard to not to ignore any 100 | /// keystrokes! 101 | /// 102 | /// You can also make global shortcuts by using [addHandler]. A global 103 | /// shortcut will work no matter what windows are displayed or which one has 104 | /// the focus. 105 | SHORTCUT, 106 | 107 | /// This widget is no longer active, due to [Widget.deactivate] being called 108 | /// on it or one of its parents. [Widget.active] may still be true after this, 109 | /// the widget is only active if [Widget.active] is true on it and all its 110 | /// parents (use [Widget.activeR] to check this). 111 | DEACTIVATE, 112 | 113 | /// This widget is now active, due to [Widget.activate] being called on it or 114 | /// one of its parents. 115 | ACTIVATE, 116 | 117 | /// This widget is no longer visible, due to [Widget.hide] being called on it 118 | /// or one of its parents, or due to a parent window being minimized. 119 | /// [Widget.visible] may still be true after this, but the widget is visible 120 | /// only if [Widget.visible] is true for it and all its parents (use 121 | /// [Widget.visibleR] to check this). 122 | HIDE, 123 | 124 | /// This widget is visible again, due to [Widget.show] being called on it or 125 | /// one of its parents, or due to a parent window being restored. 126 | /// 127 | /// Child windows respond to this by actually creating the window if not done 128 | /// already, so if you subclass a window, be sure to pass [SHOW] to the base 129 | /// class [Widget.handle] method! 130 | SHOW, 131 | 132 | /// You should get this event some time after you call [paste]. The contents 133 | /// of [eventText] is the text to insert. 134 | PASTE, 135 | 136 | /// The [selectionOwner] will get this event before the selection is moved 137 | /// to another widget. 138 | /// 139 | /// This indicates that some other widget or program has claimed the 140 | /// selection. Motif programs used this to clear the selection indication. 141 | /// Most modern programs ignore this. 142 | SELECTIONCLEAR, 143 | 144 | /// The user has moved the mouse wheel. The [eventDx] and [eventDy] getters 145 | /// can be used to find the amount to scroll horizontally and vertically. 146 | MOUSEWHEEL, 147 | 148 | /// The mouse has been moved to point at this widget. A widget that is 149 | /// interested in receiving Drag And Drop data must return true to receive 150 | /// [DND_DRAG], [DND_LEAVE] and [DND_RELEASE] events. 151 | DND_ENTER, 152 | 153 | /// The mouse has been moved inside a widget while dragging data. A widget 154 | /// that is interested in receiving Drag And Drop data should indicate the 155 | /// possible drop position. 156 | DND_DRAG, 157 | 158 | /// The mouse has moved out of the widget. 159 | DND_LEAVE, 160 | 161 | /// The user has released the mouse button dropping data into the widget. If 162 | /// the widget returns true, it will receive the data in the immediately 163 | /// following [PASTE] event. 164 | DND_RELEASE, 165 | 166 | /// The screen configuration (number, positions) was changed. Use [addHandler] 167 | /// to be notified of this event. 168 | SCREEN_CONFIGURATION_CHANGED, 169 | 170 | /// The fullscreen state of the window has changed. 171 | FULLSCREEN 172 | } 173 | -------------------------------------------------------------------------------- /lib/src/enums/font.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk.enums; 6 | 7 | // Fl_Font constants 8 | 9 | /// Helvetica (or Arial) normal 10 | const HELVETICA = 0; 11 | 12 | /// Helvetica (or Arial) bold 13 | const HELVETICA_BOLD = 1; 14 | 15 | /// Helvetica (or Arial) oblique 16 | const HELVETICA_ITALIC = 2; 17 | 18 | /// Helvetica (or Arial) bold-oblique 19 | const HELVETICA_BOLD_ITALIC = 3; 20 | 21 | /// Courier normal 22 | const COURIER = 4; 23 | 24 | /// Courier bold 25 | const COURIER_BOLD = 5; 26 | 27 | /// Courier italic 28 | const COURIER_ITALIC = 6; 29 | 30 | /// Courier bold-italic 31 | const COURIER_BOLD_ITALIC = 7; 32 | 33 | /// Times roman 34 | const TIMES = 8; 35 | 36 | /// Times roman bold 37 | const TIMES_BOLD = 9; 38 | 39 | /// Times roman italic 40 | const TIMES_ITALIC = 10; 41 | 42 | /// Times roman bold-italic 43 | const TIMES_BOLD_ITALIC = 11; 44 | 45 | /// Standard symbol font 46 | const SYMBOL = 12; 47 | 48 | /// Default monospaced screen font 49 | const SCREEN = 13; 50 | 51 | /// Default monospaced bold screen font 52 | const SCREEN_BOLD = 14; 53 | 54 | /// Zapf-dingbats font 55 | const ZAPF_DINGBATS = 15; 56 | 57 | /// First one to allocate 58 | const FREE_FONT = 16; 59 | 60 | /// Add this to helvetica, courier, or times 61 | const BOLD = 1; 62 | 63 | /// Add this to helvetica, courier, or times 64 | const ITALIC = 2; 65 | 66 | /// Add this to helvetica, courier, or times 67 | const BOLD_ITALIC = 3; 68 | -------------------------------------------------------------------------------- /lib/src/enums/glmode.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk.enums; 6 | 7 | // Fl_Mode constants 8 | 9 | /// RGB color (not indexed) 10 | const FL_RGB = 0; 11 | 12 | /// Indexed mode 13 | const FL_INDEX = 1; 14 | 15 | /// Not double buffered 16 | const FL_SINGLE = 0; 17 | 18 | /// Double buffered 19 | const FL_DOUBLE = 2; 20 | 21 | /// Accumulation buffer 22 | const FL_ACCUM = 4; 23 | 24 | /// Alpha channel in color 25 | const FL_ALPHA = 8; 26 | 27 | /// Depth buffer 28 | const FL_DEPTH = 16; 29 | 30 | /// Stencil buffer 31 | const FL_STENCIL = 32; 32 | 33 | /// RGB color with at least 8 bits of each color 34 | const FL_RGB8 = 64; 35 | 36 | /// Multisample antialiasing 37 | const FL_MULTISAMPLE = 128; 38 | 39 | /// Undocumented in FLTK 40 | const FL_STEREO = 256; 41 | 42 | /// Undocumented in FLTK 43 | const FL_FAKE_SINGLE = 512; 44 | -------------------------------------------------------------------------------- /lib/src/enums/labeltype.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk.enums; 6 | 7 | // Fl_Labeltype 8 | enum Labeltype { 9 | FL_NORMAL_LABEL, 10 | FL_NO_LABEL, 11 | // ignore: UNUSED_FIELD 12 | _FL_SHADOW_LABEL, 13 | // ignore: UNUSED_FIELD 14 | _FL_ENGRAVED_LABEL, 15 | // ignore: UNUSED_FIELD 16 | _FL_EMBOSSED_LABEL, 17 | // ignore: UNUSED_FIELD 18 | _FL_MULTI_LABEL, 19 | // ignore: UNUSED_FIELD 20 | _FL_ICON_LABEL, 21 | // ignore: UNUSED_FIELD 22 | _FL_IMAGE_LABEL, 23 | FL_FREE_LABELTYPE 24 | } 25 | 26 | // Quick access constants 27 | const NORMAL_LABEL = Labeltype.FL_NORMAL_LABEL; 28 | const NO_LABEL = Labeltype.FL_NO_LABEL; 29 | const SHADOW_LABEL = Labeltype._FL_SHADOW_LABEL; 30 | const ENGRAVED_LABEL = Labeltype._FL_ENGRAVED_LABEL; 31 | const EMBOSSED_LABEL = Labeltype._FL_EMBOSSED_LABEL; 32 | -------------------------------------------------------------------------------- /lib/src/enums/option.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk.enums; 6 | 7 | // Fl_Option 8 | enum Option { 9 | /// When switched on, moving the text cursor beyond the start or end of a text 10 | /// in a text widget will change focus to the next text widget. 11 | /// (This is considered 'old' behavior) 12 | /// 13 | /// When switched off (default), the cursor will stop at the end of the text. 14 | /// Pressing Tab or Ctrl-Tab will advance the keyboard focus. 15 | ARROW_FOCUS, 16 | 17 | /// If visible focus is switched on (default), FLTK will draw a dotted 18 | /// rectangle inside the widget that will receive the next keystroke. 19 | /// 20 | /// If switched off, no such indicator will be drawn and keyboard navigation 21 | /// is disabled. 22 | VISIBLE_FOCUS, 23 | 24 | /// If text drag-and-drop is enabled (default), the user can select and drag 25 | /// text from any text widget. 26 | /// 27 | /// If disabled, no dragging is possible, however dropping text from other 28 | /// applications still works. 29 | DND_TEXT, 30 | 31 | /// If tooltips are enabled (default), hovering the mouse over a widget with a 32 | /// tooltip text will open a little tooltip window until the mouse leaves the 33 | /// widget. 34 | /// 35 | /// If disabled, no tooltip is shown. 36 | SHOW_TOOLTIPS, 37 | 38 | /// When switched on (default), Fl_Native_File_Chooser runs GTK file dialogs 39 | /// if the GTK library is available on the platform (linux/unix only). 40 | /// 41 | /// When switched off, GTK file dialogs aren't used even if the GTK library is 42 | /// available. 43 | FNFC_USES_GTK, 44 | 45 | /// For internal use only 46 | LAST 47 | } 48 | -------------------------------------------------------------------------------- /lib/src/enums/shortcut.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk.enums; 6 | 7 | /// Mimick FLTK shortcut interface. 8 | class Shortcut { 9 | final int value; 10 | 11 | const Shortcut(this.value); 12 | 13 | Shortcut operator +(dynamic data) { 14 | if (data is Shortcut) { 15 | return new Shortcut(value + data.value); 16 | } else if (data is String) { 17 | if (data.length == 1) { 18 | return new Shortcut(value + data.codeUnitAt(0)); 19 | } else { 20 | throw new ArgumentError('data.length != 1'); 21 | } 22 | } else { 23 | throw new ArgumentError('Illegal type'); 24 | } 25 | } 26 | } 27 | 28 | /// Event states 29 | const CTRL = const Shortcut(0x00040000); 30 | -------------------------------------------------------------------------------- /lib/src/enums/when.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk.enums; 6 | 7 | /// Fl_When 8 | /// 9 | /// Since Dart does not support custom indices in an enumeration, we use const 10 | /// values. 11 | 12 | /// Never call the callback. 13 | const WHEN_NEVER = 0; 14 | 15 | /// Do the callback only when the widget value changes. 16 | const WHEN_CHANGED = 1; 17 | 18 | /// Do the callback whenever the user interacts with the widget. 19 | const WHEN_NOT_CHANGED = 2; 20 | 21 | /// Do the callback when the button or key is released and the value changes. 22 | const WHEN_RELEASE = 4; 23 | 24 | /// Do the callback when the button or key is released, even if the value 25 | /// doesn't change. 26 | const WHEN_RELEASE_ALWAYS = 6; 27 | 28 | /// Do the callback when the user presses the ENTER key and the value changes. 29 | const WHEN_ENTER_KEY = 8; 30 | 31 | /// Do the callback when the user presses the ENTER key, even if the value 32 | /// doesn't change. 33 | const WHEN_ENTER_KEY_ALWAYS = 10; 34 | 35 | /// Undocumented in FLTK 36 | const WHEN_ENTER_KEY_CHANGED = 11; 37 | -------------------------------------------------------------------------------- /lib/src/fl/color.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk; 6 | 7 | /// Get color value from RGB values. 8 | int rgbColor(int r, [int g = -1, int b = -1]) { 9 | // if g and b are -1, use r as grayscale. 10 | if (g + b == -2) { 11 | return rgbColor(r, r, r); 12 | } else { 13 | return r << 24 & 0xff000000 | g << 16 & 0xff0000 | b << 8 & 0xff00; 14 | } 15 | } 16 | 17 | /// Alias for calling [rgbColor] with only one argument. 18 | int grayscale(int l) => rgbColor(l); 19 | 20 | /// Get color values from Color object. 21 | int toColor(Color color) { 22 | final rgb = color.toRgbColor(); 23 | return rgbColor(rgb.r, rgb.g, rgb.b); 24 | } 25 | 26 | /// Set application-wide background color. 27 | void background(int r, int g, int b) native 'fldart::background'; 28 | 29 | /// Set application-wide alternative background color. 30 | void background2(int r, int g, int b) native 'fldart::background2'; 31 | 32 | /// Set application-wide foreground color. 33 | void foreground(int r, int g, int b) native 'fldart::foreground'; 34 | 35 | /// Set color index color value. 36 | void setColor(int index, int r, int g, int b) native 'fldart::set_color'; 37 | -------------------------------------------------------------------------------- /lib/src/fl/core.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk; 6 | 7 | /// Switch to use synchronous streams everywhere 8 | bool useSyncStreams = false; 9 | 10 | /// (Timer time) => void function 11 | typedef void _PeriodicTimerCallback(Timer timer); 12 | 13 | /// Run FLTK synchronously 14 | /// 15 | /// Calls [wait] in a loop until the return value is 0. 16 | int run() native 'fldart::run'; 17 | 18 | /// Runs FLTK asynchronously (using some black magic) 19 | /// 20 | /// It is important to use [Timer.run] instead of [scheduleMicrotask] so Timer 21 | /// events are not blocked. 22 | Future runAsync([Duration interval = Duration.ZERO]) { 23 | final completer = new Completer(); 24 | _PeriodicTimerCallback cycle; 25 | cycle = (Timer timer) { 26 | final state = check(); 27 | if (state == 0) { 28 | timer.cancel(); 29 | completer.complete(state); 30 | } 31 | }; 32 | 33 | new Timer.periodic(interval, cycle); 34 | return completer.future; 35 | } 36 | 37 | /// Handle pending events and update interface. 38 | /// Same as `Fl::wait(0);` in FLTK. 39 | int check() native 'fldart::check'; 40 | 41 | /// Waits for the next event. Returns 0 if all windows are closed. 42 | int wait() native 'fldart::wait'; 43 | 44 | /// Set the FLTK widget theme. 45 | /// 46 | /// You can choose from: 47 | /// 48 | /// - `none`: This is the default scheme and resembles old Windows 49 | /// (95/98/Me/NT/2000) and old GTK/KDE. 50 | /// - `base`: This is an alias for none. 51 | /// - `gtk+`: This scheme is inspired by the Red Hat Bluecurve theme. 52 | /// - `gleam`: This scheme is inspired by the Clearlooks Glossy scheme. 53 | /// - `plastic`: This scheme is inspired by the Aqua user interface on Mac OS X. 54 | set scheme(String name) native 'fldart::scheme'; 55 | 56 | void _option(int option, bool value) native 'fldart::option'; 57 | 58 | /// Set option value. 59 | void option(Option option, bool value) => _option(option.index, value); 60 | -------------------------------------------------------------------------------- /lib/src/fl/draw.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk; 6 | 7 | /// Bindings for fl_draw.H 8 | 9 | /// Set the drawing color. 10 | set color(int c) native 'fldart::color'; 11 | 12 | /// Draw line from ([x], [y]) to ([x1], [y1]). 13 | void _line1(int x, int y, int x1, int y1) native 'fldart::line1'; 14 | 15 | /// Draw line from ([x], [y]) to ([x1], [y1]) and then to ([x2], [y2]). 16 | void _line2(int x, int y, int x1, int y1, int x2, int y2) 17 | native 'fldart::line2'; 18 | 19 | /// Draw line from ([x], [y]) to ([x1], [y1]) and optionally to ([x2], [y2]). 20 | void line(int x, int y, int x1, int y1, [int x2 = null, int y2 = null]) { 21 | if (x2 != null && y2 != null) { 22 | _line2(x, y, x1, y1, x2, y2); 23 | } else { 24 | _line1(x, y, x1, y1); 25 | } 26 | } 27 | 28 | /// Draw image data using `fl_draw_image`. 29 | void drawImage(Uint8List buffer, int x, int y, int w, int h, 30 | [int d = 3, int l = 0]) native 'fldart::draw_image'; 31 | 32 | /// Draw image data using Fl_RGB_Image and fallback alpha blending driver. 33 | void drawRgbImage(Uint8List buffer, int x, int y, int w, int h, 34 | [int d = 3, int l = 0]) native 'fldart::rgb_image_draw'; 35 | -------------------------------------------------------------------------------- /lib/src/fl/event.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk; 6 | 7 | /// Initiate a Drag And Drop operation. 8 | void dnd() native 'fldart::dnd'; 9 | 10 | /// Destination for [copy]. 11 | enum CopyDestination { selectionBuffer, clipboard } 12 | 13 | void _copy(String data, int length, int destination, String mime) 14 | native 'fldart::copy'; 15 | 16 | /// Copy [data] with the given [mime] type, into the [destination]. 17 | void copy(String data, 18 | {String mime: 'text/plain', 19 | CopyDestination destination: CopyDestination.selectionBuffer}) => 20 | _copy(data, data.length, destination.index, mime); 21 | 22 | /// Get current mouse x position. 23 | int get eventX native 'fldart::event_x'; 24 | 25 | /// Get current mouse y position. 26 | int get eventY native 'fldart::event_y'; 27 | 28 | /// Get horizontal scroll ammount (right is positive). 29 | int get eventDx native 'fldart::event_dx'; 30 | 31 | /// Get vertical scroll ammount (down is positive). 32 | int get eventDy native 'fldart::event_dy'; 33 | 34 | /// Get key code of the key that was last pressed. 35 | int get eventKey native 'fldart::event_key'; 36 | 37 | /// Get the text associated with the current event. 38 | String get eventText native 'fldart::event_text'; 39 | 40 | /// Bitfield to check what special keys or mouse buttons were pressed in the 41 | /// most recent event. 42 | int get eventState native 'fldart::event_state'; 43 | 44 | /// Get which mouse button caused the current event in case of an [Event.PUSH] 45 | /// or [Event.RELEASE]. 46 | int get eventButton native 'fldart::event_button'; 47 | 48 | /// Wrapper class for all event data. 49 | class EventData { 50 | final int x, y, dx, dy, key, state, button; 51 | final String text; 52 | 53 | EventData(this.x, this.y, this.dx, this.dy, this.key, this.state, this.button, 54 | this.text); 55 | 56 | /// Create instance from the current event data. 57 | factory EventData.current() => new EventData(eventX, eventY, eventDx, eventDy, 58 | eventKey, eventState, eventButton, eventText); 59 | } 60 | 61 | /// Get current event data. 62 | EventData get currentEvent => new EventData.current(); 63 | -------------------------------------------------------------------------------- /lib/src/fl/xpm.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk; 6 | 7 | /// Convert color to [Image] compatible Uint32 color. 8 | int _colorToImageColor(Color c) { 9 | final rgb = c.toRgbColor(); 10 | return rgb.r.toInt() | 11 | rgb.g.toInt() << 8 & 0xff00 | 12 | rgb.b.toInt() << 16 & 0xff0000 | 13 | 255 << 24; 14 | } 15 | 16 | /// Read an XPM image and return an [Image] instance from the `image` library. 17 | Image readXpm(List xpm) { 18 | final dimRegex = new RegExp('([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)'); 19 | 20 | if (xpm.isEmpty) { 21 | throw new ArgumentError('xpm cannot be empty'); 22 | } 23 | 24 | var match = dimRegex.firstMatch(xpm[0]); 25 | if (match == null) { 26 | throw new ArgumentError('xpm is not formatted correctly'); 27 | } 28 | 29 | // Parse dimensions. 30 | final width = int.parse(match.group(1)); 31 | final height = int.parse(match.group(2)); 32 | final ncolors = int.parse(match.group(3)); 33 | final charspp = int.parse(match.group(4)); 34 | 35 | // Read colors. 36 | final colRegex = new RegExp('(.{$charspp}).+c (.+)'); 37 | final colors = new Map(); 38 | for (var i = 1; i <= ncolors; i++) { 39 | match = colRegex.firstMatch(xpm[i]); 40 | if (match == null) { 41 | throw new ArgumentError('xpm is not formatted correctly'); 42 | } 43 | 44 | final colorString = match.group(2).toLowerCase(); 45 | int color = 0; 46 | if (colorString != 'none') { 47 | // [RgbColor.namedColors] color keys do not contain spaces. 48 | final colorNoSpaces = colorString.replaceAll(' ', ''); 49 | if (RgbColor.namedColors.containsKey(colorNoSpaces)) { 50 | // Use named color. 51 | color = _colorToImageColor(RgbColor.namedColors[colorNoSpaces]); 52 | } else { 53 | // Parse as full hex color. 54 | color = _colorToImageColor(new HexColor(colorString)); 55 | } 56 | } 57 | 58 | colors[match.group(1)] = color; 59 | } 60 | 61 | // Read pixels. 62 | final bytes = new Uint32List(width * height); 63 | for (var y = 0, p = 0; 1 + ncolors + y < xpm.length && y < height; y++) { 64 | final i = 1 + ncolors + y; 65 | for (var x = 0; x < xpm[i].length && x < width * charspp; x += charspp) { 66 | final colorKey = xpm[i].substring(x, x + charspp); 67 | bytes[p++] = colors[colorKey]; 68 | } 69 | } 70 | 71 | // Create image. 72 | return new Image.fromBytes(width, height, bytes); 73 | } 74 | 75 | /// XPM data for a 32x32 pixels version of the Dart icon! 76 | const List xpmDartIcon = const [ 77 | '32 32 5 2', 78 | '## c #0082c8', 79 | '++ c #00a4e4', 80 | ':: c #00d2b8', 81 | '.. c #55ddcA', 82 | ' c None', 83 | ' :::: ', 84 | ' :::::::::: ', 85 | ' :::::::::::::: ', 86 | ' :::::::::::::::::: ', 87 | ' :::::::::::::::::::: ', 88 | ' :::::::::::::::::::::::::: ', 89 | ' :::::::::::::::::::::::::::: ', 90 | ' ################################ ', 91 | ' ##::##############################++++ ', 92 | ' ####::::##############################++++++ ', 93 | ' ####::::::############################++++++++ ', 94 | ' ######::::::::############################++++++++ ', 95 | ' ########::::::::::##########################++++++++++ ', 96 | ' ##########::::::::::::##########################++++++++++ ', 97 | ' ############::::::::::::::########################++++++++++++', 98 | ' ############::::::::::::::::########################++++++++++', 99 | '##############::::::::::::::::::######################++++++++++', 100 | '##############::::::::::::::::::::######################++++++++', 101 | ' ############::::::::::::::::::::::####################++++++++', 102 | ' ##########::::::::::::::::::::::::####################++++++', 103 | ' ########::::::::::::::::::::::::::##################++++++', 104 | ' ####::::::::::::::::::::::::::::##################++++', 105 | ' ::::::::::::::::::::::::::::::################++++', 106 | ' ..::::::::::::::::::::::::::::############++++++', 107 | ' ......::::::::::::::::::::::::::##########++++++', 108 | ' ........::::::::::::::::::::::::######++++++ ', 109 | ' ............::::::::::::::::::::::####++ ', 110 | ' ..............:::::::::::::::::::: ', 111 | ' ................::::::::::::.... ', 112 | ' ..................::::...... ', 113 | ' .......................... ', 114 | ' ...................... ' 115 | ]; 116 | -------------------------------------------------------------------------------- /lib/src/flfn/app.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk.flfn; 6 | 7 | class App { 8 | final Map windows; 9 | final String scheme; 10 | App({this.windows: const {}, this.scheme: ''}); 11 | 12 | /// Build actual widgets. 13 | void build() { 14 | fl.scheme = scheme; 15 | for (final window in windows.values) { 16 | window.build(this); 17 | } 18 | } 19 | 20 | void merge(App other) { 21 | fl.scheme = other.scheme; 22 | for (final key in other.windows.keys) { 23 | if (windows.containsKey(key)) { 24 | windows[key].merge(other.windows[key], this); 25 | } else { 26 | windows[key] = other.windows[key]; 27 | windows[key].build(this); 28 | } 29 | } 30 | 31 | for (final key in windows.keys) { 32 | if (!other.windows.containsKey(key)) { 33 | //windows[key].destroy(); 34 | windows.remove(key); 35 | } 36 | } 37 | } 38 | 39 | Button getButton(String id) { 40 | final selector = id.split('/'); 41 | if (windows.containsKey(selector.first)) { 42 | return windows[selector.first].getButton(selector.sublist(1)); 43 | } else { 44 | return null; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/src/flfn/box.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk.flfn; 6 | 7 | class Box extends Widget { 8 | Box(int x, int y, int w, int h, 9 | {String label: '', 10 | int labelsize: 16, 11 | int labelfont: 0, 12 | int labelcolor: fl.BLACK, 13 | fl.Boxtype box: fl.NO_BOX, 14 | fl.Labeltype labeltype: fl.NORMAL_LABEL, 15 | Color color: const RgbColor(255, 255, 255)}) 16 | : super({ 17 | 'x': x, 18 | 'y': y, 19 | 'w': w, 20 | 'h': h, 21 | 'label': label, 22 | 'labelsize': labelsize, 23 | 'labelfont': labelfont, 24 | 'labelcolor': labelcolor, 25 | 'labeltype': labeltype, 26 | 'box': box, 27 | 'color': fl.toColor(color) 28 | }); 29 | 30 | fl.Box _createInstance() => new fl.Box( 31 | _props['x'], _props['y'], _props['w'], _props['h'], _props['label']); 32 | } 33 | -------------------------------------------------------------------------------- /lib/src/flfn/button.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016, Herman Bergwerf. All rights reserved. 2 | // Use of this source code is governed by a MIT-style license 3 | // that can be found in the LICENSE file. 4 | 5 | part of fltk.flfn; 6 | 7 | class Button extends Widget { 8 | Button(int x, int y, int w, int h, 9 | {String label: '', 10 | int labelsize: 16, 11 | int labelfont: 0, 12 | int labelcolor: fl.BLACK, 13 | fl.Boxtype box: fl.NO_BOX, 14 | fl.Labeltype labeltype: fl.NORMAL_LABEL, 15 | Color color: const RgbColor(255, 255, 255), 16 | Callback