PDA

View Full Version : Changes to the current ClanLib development branch



rombust
06-30-2014, 03:56 PM
Removed callbacks from the ClanLib API. We now prefer to use std::functions

The CallbackContainer has been replaced with a SlotContainer

Slots can be connected in the container using the clan::bind_member helper, or via a lambda function "[=](int width, int height){return my_func(width, height, another_variable_in_scope);}

Judas
06-30-2014, 05:43 PM
To be more clear, the Signal/Slot syntax has changed to:


Signal<void(int,int)> signal;

SlotContainer slots;
slots.connect(signal, static_function);
slots.connect(signal, instance, &ClassName::member_function);
slots.connect(signal, [](int a, int b) { });

signal(42, 21);

Note that signal.connect() now again returns a Slot. This is how it used to be, however if any code was ported to the Callback connect syntax they will now find that their slots immediately disconnect. Generally, always use a SlotContainer.

The syntax for Callbacks changes to:



std::function<void(int, int)> callback = static_function;
std::function<void(int, int)> callback = clan::bind_member(instance, &ClassName::member_function);
std::function<void(int, int)> callback = [](int a, int b) { };

if (callback) callback(42, 21);


The rationale behind these changes are:


Callback had the same purpose as the C++11 std::function template. Standardizing on std::function makes callbacks easier to understand for everyone. It also pretty much guarantees solid lambda and other C++11 support
Callbacks had the extra feature that they could connect member functions with a much nicer syntax. The bind_member function adds this feature to all situations where an API uses std::function
Using initializer lists for signals created a rather odd syntax. Now, the mix of std::function and bind_member saves typing {} for the common cases and at the same time allowing lambdas for anything more advanced
Using operator() for invoke, and operator bool for empty/null checking aligns the API with how C++11's std::function behaves
Reintroduced Slot because std::function cannot support the more complex destructor-based disconnects used by the signal/slot system

rombust
07-23-2014, 10:10 AM
The Canvas "modelview" functions have changed as follows:

Renamed "modelview" to "transform"

Removed the modelview "pull() and pop()" functions, because these are not exception friendly and do not belong inside the Canvas class.

Removed the translate and scale functions, because these are not required (bloat the API)

To port this code:



canvas.push_translate(center);
canvas.mult_scale(radius_x/max_radius, radius_y/max_radius);
...
canvas.pop_modelview();

Write as:



const Mat4f original_transform = canvas.get_transform();
canvas.mult_transform(Mat4f::translate(center.x, center.y, 0));
canvas.mult_transform(Mat4f::scale(radius_x / max_radius, radius_y / max_radius, 1.0f));
...
canvas.set_transform(original_transform);

rombust
08-04-2014, 08:15 AM
The Euler angle order convention has changed in Mat4<Type>::rotate() and get_euler() has been repaired.

The order now matches the quaternion euler order.

Tests are in Tests/Core/Math (test_matrix.cpp, test_quaternion.cpp)

If you used these functions, then changing "order_XYZ" to "order_ZYX" will be sufficient.

rombust
08-06-2014, 10:03 AM
Fixed a bug in clan::Mat4<Type> transpose function.

"matrix[15] = original[13]"; should have been "matrix[15] = original[15];"

Also, the get_origin_x, get_origin_y and get_origin_x functions have been replaced by get_translate() returning clan::Vec3<Type>

rombust
10-06-2014, 12:43 PM
DisplayWindowDescription:

set_tool_window() is now set_type(WindowType::tool)
set_dialog_window() is now set_type(WindowType:dialog)