Coder Social home page Coder Social logo

aseprite / laf Goto Github PK

View Code? Open in Web Editor NEW
268.0 15.0 54.0 1.18 MB

A C++ library to create desktop applications

Home Page: https://aseprite.github.io/laf/

License: MIT License

CMake 2.45% C++ 84.36% C 1.66% Objective-C++ 10.55% Objective-C 0.99%
cpp cross-platform ui-library cpp17

laf's Introduction

LAF: The Lost Application Framework

build MIT Licensed

A library to create Windows, macOS, and Linux applications.

This library is under active development so we don't provide API or ABI compatibility at this moment.

Dependencies

laf can be compiled with two back-ends (LAF_BACKEND): skia or none.

When LAF_BACKEND=skia, laf requires a compiled version of the Skia library from branch aseprite-m102. You can check the aseprite/skia fork which includes a release with pre-built versions, or the check the instructions to compile skia from scratch.

When LAF_BACKEND=none, the Pixman library can be used as an alternative implementation of the gfx::Region class (generally if you're using laf-os you will link it with Skia, so there is no need for Pixman at all).

Compile

To compile laf with Skia as backend you have to specify some variables pointing to a valid compiled version of Skia in your disk. In the following example /skiadir is the absolute path to a directory where the Skia source code + compiled version is, or just where you've uncompressed a pre-built package of Skia (note that in this case /skiadir/out/Release-x64 should contain the Skia library files, i.e. skia.lib on Windows or libskia.a on other platforms):

git clone https://github.com/aseprite/laf.git
cd laf
mkdir build
cd build
cmake -G Ninja \
  -DLAF_BACKEND=skia \
  -DSKIA_DIR=/skiadir \
  -DSKIA_LIBRARY_DIR=/skiadir/out/Release-x64 \
  ..
ninja
./examples/helloworld

To compile only the library (without examples and tests) you can disable the LAF_WITH_EXAMPLES/LAF_WITH_TESTS options:

cmake -DLAF_WITH_EXAMPLES=OFF -DLAF_WITH_TESTS=OFF ...

Running Tests

You can use ctest to run all tests:

cd build
ninja
ctest

License

laf is distributed under the terms of the MIT license.

Some functions in laf depends on third party libraries (you should include these license notices when you distribute your software):

  • Tests use the Google Test framework by Google Inc. licensed under a BSD-like license.
  • Color spaces, gfx::Region, and the laf::os library use code from the Skia library by Google Inc. licensed under a BSD-like license and several other third-party libraries/licenses.
  • gfx::Region uses the pixman library if you are not compiling with the Skia backend (e.g. a if you want to create only Command Line utilities that uses the gfx::Region class) on Linux or macOS. On Windows we use an alternative implementation with HRGN. Pixman is distributed under the MIT License.

laf's People

Contributors

aesophor avatar ayuusweetfish avatar clarfonthey avatar dacap avatar delta2force avatar gasparoken avatar gnumaru avatar iamogunyinka avatar joefish avatar martincapello avatar tetektoza avatar winterheart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laf's Issues

UTF-8 on Windows

Just yesterday I was investigating about the possibility to enable UTF-8 support on the console (using SetConsoleOutputCP(CP_UTF8)): ad8cf49

But I'm not sure if this should be done by default. Even more, we could add support to use ANSI version of functions which can support UTF-8 directly (if we embed a special manifest file): https://docs.microsoft.com/en-us/windows/apps/design/globalizing/use-utf8-code-page#set-a-process-code-page-to-utf-8

In this way we could avoid the from_utf8/to_utf8 conversions on each Win32 API call (https://docs.microsoft.com/en-us/windows/apps/design/globalizing/use-utf8-code-page#-a-vs--w-apis).

compile-error without reason

I can't compile laf for some reason. The error-message is just
"collect2: error: ld returned 1 exit status". I am trying to compile laf with skia. I downloaded skia-m102 from here: Skia-m102 and chose the libstdc++-version, since I think g++ is the compiler used in my system. I compiled and installed cmake 3.27 by hand, before.

as you can see in the compiler-output, I extracted skia-m102 to ~/deps/skia and set-up all path correctly. Nevertheless compiling just stops without usefull error-message.

Please see full compiler-output on pastebin

Compilation fails on aarch64 platforms

When attempting to compile Aseprite, compilation fails due to the following error:

FAILED: laf/base/CMakeFiles/laf-base.dir/platform.cpp.o 
/usr/bin/c++ -DCMARK_STATIC_DEFINE -DHAVE_CONFIG_H -DLAF_LINUX -DLAF_SKIA -DNDEBUG -DPNG_NO_MMX_CODE -I/home/lmt/Stuff/aseprite/third_party/zlib -I/home/lmt/Stuff/aseprite/build/third_party/zlib -I/home/lmt/Stuff/aseprite/third_party/libpng -I/home/lmt/Stuff/aseprite/build/third_party/libpng -I/home/lmt/Stuff/aseprite/third_party/libwebp/src -I/home/lmt/Stuff/aseprite/third_party/tinyxml -I/home/lmt/Stuff/aseprite/third_party/pixman/pixman -I/home/lmt/Stuff/aseprite/build -I/home/lmt/Stuff/aseprite/third_party/giflib -I/home/lmt/Stuff/aseprite/third_party/jpeg -I/home/lmt/Stuff/aseprite/third_party/curl/include -I/home/lmt/Stuff/aseprite/third_party/simpleini -I/home/lmt/Stuff/aseprite/laf -I/home/lmt/Stuff/aseprite/build/laf -I/home/lmt/Stuff/aseprite/src -I/home/lmt/Stuff/aseprite/laf/third_party/stringencoders/src -O2 -g -DNDEBUG -std=c++14 -MD -MT laf/base/CMakeFiles/laf-base.dir/platform.cpp.o -MF laf/base/CMakeFiles/laf-base.dir/platform.cpp.o.d -o laf/base/CMakeFiles/laf-base.dir/platform.cpp.o -c /home/lmt/Stuff/aseprite/laf/base/platform.cpp
In file included from /home/lmt/Stuff/aseprite/laf/base/platform.cpp:11:
/home/lmt/Stuff/aseprite/laf/base/platform.h:56:59: error: static assertion failed: Invalid identification of CPU architecture
   56 |   static_assert((arch == Arch::x86 && sizeof(void*) == 4) ||
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
   57 |                 ((arch == Arch::x64 ||
      |                 ~~~~~~~~~~~~~~~~~~~~~~                     
   58 |                   arch == Arch::arm64) && sizeof(void*) == 8),
      |                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[600/1554] Building CXX object laf/base/CMakeFiles/laf-base.dir/program_options.cpp.o
ninja: build stopped: subcommand failed.

If I were to guess, this is due to my system reporting aarch64 instead of arm64.

% uname -m
aarch64

My OS is Arch Linux ARM running on the Pinebook Pro.

Drawing text as functions instead of Surface members

To avoid always depending/linking with harfbuzz/icu libraries, we would prefer os::draw_text() as a global function instead of a os::Surface member function. Also we're going to use two alternatives:

  • os::draw_text(), and
  • os::draw_text_with_shaper()

To reduce binary size of apps that don't require the text shaping engine.

error: implicit instantiation of undefined template 'std::__1::array<base::Ref<os::Cursor>, 19>'

/disk-samsung/freebsd-ports/graphics/aseprite/work/aseprite-1.2.28/laf/os/x11/system.cpp:44:51: error: implicit instantiation of undefined template 'std::__1::array<base::Ref<os::Cursor>, 19>'
std::array<CursorRef, int(NativeCursor::Cursors)> g_nativeCursors;
                                                  ^
/usr/include/c++/v1/__tuple:219:64: note: template is declared here
template <class _Tp, size_t _Size> struct _LIBCPP_TEMPLATE_VIS array;
                                                               ^
/disk-samsung/freebsd-ports/graphics/aseprite/work/aseprite-1.2.28/laf/os/x11/system.cpp:63:11: warning: enumeration value 'Cursors' not handled in switch [-Wswitch]
  switch (cursor) {
          ^

Did you forget to include <array>?

CMake cannot find X11

I've been building Aseprite/laf successfully on my Ubuntu-based Linux distros, but I just tried building the latest version and it fails during the CMake stage in laf/os/CMakeLists.txt on this line:

find_package(X11 REQUIRED)

with the error:

CMake Error at ~/dev/tools/cmake-v3.18.4/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
  Could NOT find X11 (missing: X11_X11_LIB)
Call Stack (most recent call first):
  ~/dev/tools/cmake-v3.18.4/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
  ~/dev/tools/cmake-v3.18.4/share/cmake-3.18/Modules/FindX11.cmake:414 (find_package_handle_standard_args)
  laf/os/CMakeLists.txt:126 (find_package)

this is happening on all of the Ubuntu-based linux distros that I've tried:

  • Ubuntu 20.04
  • Linux Mint 20.04
  • Pop!_OS 20.10

Any idea how to fix it? Note that I have all of the Linux packages installed that are recommended in the Aseprite INSTALL.md file, as well as the recommended CMake command. I have been building Aseprite for a number of years now, have not seen this error before, and have all of the relevant x11 packages installed on my system almost surely.

Prepare API for the first release

Some changes that must be done for a probable first release of the library (some of these items are implemented in an internal beta version that will be published in the near future):

  • update to Skia m81
  • add Surface::drawText() expand the current os::draw_text() function (#12) and remove freetype usage if possible, use Skia directly to draw text, SkShaper module uses harfbuzz+icu
  • rename os::Display::setTitleBar() -> setTitle()
  • os::Surface::bounds() -> Rect(0, 0, width, height)
  • os::Display::invalidate() = os::Display->invalidateRegion(display->surface->bounds)
  • what to do with os::ScopedHandle? add os::DisplayHandle and os::SurfaceHandle aliases? or use move semantic and pimpl idiom?
  • rename os::Display -> os::Window?
  • add API to get main monitor/screen, list of monitors/screen, bounds of each monitor, etc.
  • create an example that can create 4 windows in a 2x2 grid of windows on each monitor
  • add a new kind of coordinate/position for os::Display that is bounds + monitor/screen
  • getEvent() -> replace bool arg with an enum { WaitForEvents, DontWait } we've replaced the parameter with a timeout
  • enable GPU support again and create a simple OpenGL example
  • create an example about complex text layout / new text API
  • merge all os::Surface::drawSurface()/blitTo() in one member function with a os::Paint argument
  • decide if constants should have k prefix (e.g. os::Event::ResizeDisplay vs os::kArrowCursor; or os::Key::Esc instead of os::kKeyEsc) / Check web KeyboardEvent codes as a reference / #50
  • create test about color spaces
  • prepare API documentation / tutorial
  • ...

Faild ninja build: `FAILED: gfx/packing_rects_tests`

I tried following the compile section but I got a error when running ninja:

FAILED: gfx/packing_rects_tests 
: && /usr/bin/c++   gfx/CMakeFiles/packing_rects_tests.dir/packing_rects_tests.cpp.o -o gfx/packing_rects_tests  lib/libgtest.a  gfx/liblaf-gfx.a  -lpthread  base/liblaf-base.a  -lpthread  /usr/lib/x86_64-linux-gnu/libdl.so  /usr/lib/x86_64-linux-gnu/libGL.so  third_party/zlib/lib/libz.a  /usr/lib/x86_64-linux-gnu/libfontconfig.so && :
gfx/liblaf-gfx.a(packing_rects.cpp.o): In function `gfx::Region::createSubtraction(gfx::Region const&, gfx::Region const&)':
packing_rects.cpp:(.text._ZN3gfx6Region17createSubtractionERKS0_S2_[_ZN3gfx6Region17createSubtractionERKS0_S2_]+0x29): undefined reference to `SkRegion::op(SkRegion const&, SkRegion const&, SkRegion::Op)'
gfx/liblaf-gfx.a(packing_rects.cpp.o): In function `gfx::Region::~Region()':
packing_rects.cpp:(.text._ZN3gfx6RegionD2Ev[_ZN3gfx6RegionD5Ev]+0x14): undefined reference to `SkRegion::~SkRegion()'
gfx/liblaf-gfx.a(region_skia.cpp.o): In function `gfx::Region::Region()':
region_skia.cpp:(.text+0x80): undefined reference to `SkRegion::SkRegion()'
gfx/liblaf-gfx.a(region_skia.cpp.o): In function `gfx::Region::Region(gfx::Region const&)':

...

There are more undefined reference error, but I omitted them.

Previously when running cmake I get some warnings:

CMake Warning at cmake/FindSkia.cmake:150 (target_link_libraries):
  Target <TARGET> requests linking to directory
  "/home/yudi/deps/skia/out/Release-x64".  Targets may link only to
  libraries.  CMake is dropping the item.
Call Stack (most recent call first):
  CMakeLists.txt:47 (include)

This warning is printed several times with different values for<TARGET>.

Am I missing something?

Versions:

cmake: 3.25.2
g++: 11.0

macOS event queue won't wakeup under certain circumstances

I've found that when a laf client calls os::queue_event(ev) on macOS there is a chance that the event is not processed until some other OS event "wakes up" the queue. This can be seen when the getEvent() method is called from the main thread without a timeout, because when using a timeout, the timeout wakes up the queue and the issue is not perceived.

The issue can happen when the os::queue_event(ev) call takes place after line 77 and before line 82 in the following fragment of code:

if (!m_events.try_pop(ev)) {
if (timeout == kWithoutTimeout)
EV_TRACE("EV: Waiting for events\n");
// Wait until there is a Cocoa event in queue
m_sleeping = true;
event = [app nextEventMatchingMask:NSEventMaskAny
untilDate:untilDate
inMode:NSDefaultRunLoopMode
dequeue:YES];

Because the m_sleeping flag is still false in that moment, the queueEvent() method won't call the wakeUpQueue() method. Then the event got queued (in m_events queue) but then the queue will go to sleep (call to nextEventMatchingMask with untilDate=distantFuture because we are not using a timeout), waiting for any OS event to wake it up.

I think I've a fix for this which is basically a different approach, I'll try it with Aseprite and then create a PR.

EDIT: I've been trying this for a bit with Aseprite and it seems to work fine. Also I want to clarify why I need this fix:
While developing our laf based UI library I wanted to let the main thread just read all the OS events and if there is no OS events then just wait for the next one, no timeout, just sit and wait. When an OS event is available I just translate it to an app event and then push it to the app event queue. This is because in a background thread I keep reading the app queue to then send app events to the appropriate widgets. Still lots of work to do, but I just wanted to let you know which was the use case made the current implementation fail.

cmake error in linux

Hi there, currently I am having a problem compiling laf at the cmake command

cmake -G Ninja
-DLAF_BACKEND=skia
-DSKIA_DIR=/skiadir
-DSKIA_LIBRARY_DIR=/skiadir/out/Release-x64 \

when I put that on the terminal it throws me a cmake error:

~/laf/build$ cmake -G Ninja -DLAF_BACKEND=skia -DSKIA_DIR=/skiadir -DSKIA_LIBRARY_DIR=skiadir/out/Release-x64 ..
CMake Error at third_party/CMakeLists.txt:10 (add_subdirectory):
The source directory

/home/m/laf/third_party/googletest

does not contain a CMakeLists.txt file.


-- laf backend: skia
-- laf zlib: zlib
-- laf pixman: 
-- laf freetype: FREETYPE_LIBRARY-NOTFOUND
-- laf harfbuzz: HARFBUZZ_LIBRARY-NOTFOUND
-- skia dir: /skiadir
-- skia library: SKIA_LIBRARY-NOTFOUND
-- skia library dir: /home/m/laf/build/skiadir/out/Release-x64
CMake Error at CMakeLists.txt:89 (message):
set SKIA_DIR/SKIA_LIBRARY/SKIA_LIBRARY_DIR to compile w/skia backend

So I dont know exactly what to do after this. I have the skia library m102 and everything else but this is giving me problems and I dont know if it is important to not have problems later when I use the ninja aseprite command.

Im on Linux Mint Vera 21.1.(newbie in linux btw)

Id be very glad If someone could help me to compile it :)

Bug in thread_pool_tests (infinite loop?)

From aseprite actions we can see that thread_pool_tests has an infinite loop/thread-safety issues (action cancelled 1 hour ago in 6h 0m 15s) so there might be a bug in our thread_pool impl:

Run if [[ "macOS" == "Linux" ]] ; then
Test project /Users/runner/work/aseprite/aseprite/build
...
12/52 Test #12: split_string_tests ...............   Passed    0.10 sec
      Start 13: string_tests
13/52 Test #13: string_tests .....................   Passed    0.11 sec
      Start 14: task_tests
14/52 Test #14: task_tests .......................   Passed    0.11 sec
      Start 15: thread_pool_tests
Error: The operation was canceled.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.