Merge remote-tracking branch 'upstream/master'

This commit is contained in:
James Gray
2015-05-25 17:48:10 -05:00
46 changed files with 793 additions and 155 deletions

View File

@@ -48,6 +48,7 @@
<compilerflag value="-I${NATIVE_TOOLKIT_PATH}/cairo/include/configs/mac/" if="mac"/>
<compilerflag value="-DHAVE_CONFIG_H" />
<compilerflag value="-DCAIRO_WIN32_STATIC_BUILD" if="windows" />
<compilerflag value="-DCAIRO_HAS_FT_FONT" />
<file name="src/graphics/cairo/CairoBindings.cpp" />

View File

@@ -18,6 +18,7 @@ namespace lime {
virtual int Exec () = 0;
virtual void Init () = 0;
virtual int Quit () = 0;
virtual void SetFrameRate (double frameRate) = 0;
virtual bool Update () = 0;

View File

@@ -74,6 +74,15 @@ namespace lime {
}
value lime_application_set_frame_rate (value application, value frameRate) {
Application* app = (Application*)(intptr_t)val_float (application);
app->SetFrameRate (val_number (frameRate));
return alloc_null ();
}
value lime_application_update (value application) {
Application* app = (Application*)(intptr_t)val_float (application);
@@ -993,6 +1002,7 @@ namespace lime {
DEFINE_PRIM (lime_application_exec, 1);
DEFINE_PRIM (lime_application_init, 1);
DEFINE_PRIM (lime_application_quit, 1);
DEFINE_PRIM (lime_application_set_frame_rate, 2);
DEFINE_PRIM (lime_application_update, 1);
DEFINE_PRIM (lime_audio_load, 1);
DEFINE_PRIM (lime_font_get_ascender, 1);

View File

@@ -27,6 +27,8 @@ namespace lime {
currentApplication = this;
framePeriod = 1000.0 / 60.0;
#ifdef EMSCRIPTEN
emscripten_cancel_main_loop ();
emscripten_set_main_loop (UpdateFrame, 0, 0);
@@ -203,7 +205,6 @@ namespace lime {
void SDLApplication::Init () {
framePeriod = 1000.0 / 60.0;
active = true;
lastUpdate = SDL_GetTicks ();
nextUpdate = lastUpdate;
@@ -441,6 +442,21 @@ namespace lime {
}
void SDLApplication::SetFrameRate (double frameRate) {
if (frameRate > 0) {
framePeriod = 1000.0 / frameRate;
} else {
framePeriod = 1000.0;
}
}
static SDL_TimerID timerID = 0;
bool timerActive = false;
bool firstTime = true;

View File

@@ -28,6 +28,7 @@ namespace lime {
virtual int Exec ();
virtual void Init ();
virtual int Quit ();
virtual void SetFrameRate (double frameRate);
virtual bool Update ();
void RegisterWindow (SDLWindow *window);

View File

@@ -1,11 +1,14 @@
#include <cairo.h>
#include <cairo-ft.h>
#include <math/Matrix3.h>
#include <math/Vector2.h>
#include <hx/CFFI.h>
#include <text/Font.h>
namespace lime {
void lime_cairo_font_options_destroy (value handle);
value lime_cairo_arc (value *arg, int argCount) {
@@ -119,7 +122,80 @@ namespace lime {
}
value lime_cairo_font_face_destroy (value handle) {
cairo_font_face_t* face = (cairo_font_face_t*)(intptr_t)val_float(handle);
cairo_font_face_destroy( face );
return alloc_null ();
}
value lime_cairo_font_options_create () {
value options = alloc_float( (intptr_t)cairo_font_options_create() );
val_gc( options, lime_cairo_font_options_destroy );
return options;
}
void lime_cairo_font_options_destroy (value handle) {
cairo_font_options_destroy( (cairo_font_options_t*)(intptr_t)val_float (handle) );
}
value lime_cairo_font_options_get_antialias (value handle) {
return alloc_int( cairo_font_options_get_antialias( (cairo_font_options_t*)(intptr_t)val_float (handle) ) );
}
value lime_cairo_font_options_get_subpixel_order (value handle) {
return alloc_int( cairo_font_options_get_subpixel_order( (cairo_font_options_t*)(intptr_t)val_float (handle) ) );
}
value lime_cairo_font_options_get_hint_style (value handle) {
return alloc_int( cairo_font_options_get_hint_style( (cairo_font_options_t*)(intptr_t)val_float (handle) ) );
}
value lime_cairo_font_options_get_hint_metrics (value handle) {
return alloc_int( cairo_font_options_get_hint_metrics( (cairo_font_options_t*)(intptr_t)val_float (handle) ) );
}
value lime_cairo_font_options_set_antialias (value handle, value v) {
cairo_font_options_set_antialias( (cairo_font_options_t*)(intptr_t)val_float (handle), (cairo_antialias_t)val_int( v ) );
return alloc_null();
}
value lime_cairo_font_options_set_subpixel_order (value handle, value v) {
cairo_font_options_set_subpixel_order( (cairo_font_options_t*)(intptr_t)val_float (handle), (cairo_subpixel_order_t)val_int( v ) );
return alloc_null();
}
value lime_cairo_font_options_set_hint_style (value handle, value v) {
cairo_font_options_set_hint_style( (cairo_font_options_t*)(intptr_t)val_float (handle), (cairo_hint_style_t)val_int( v ) );
return alloc_null();
}
value lime_cairo_font_options_set_hint_metrics (value handle, value v) {
cairo_font_options_set_hint_metrics( (cairo_font_options_t*)(intptr_t)val_float (handle), (cairo_hint_metrics_t)val_int( v ) );
return alloc_null();
}
value lime_cairo_get_antialias (value handle) {
return alloc_int (cairo_get_antialias ((cairo_t*)(intptr_t)val_float (handle)));
@@ -172,6 +248,15 @@ namespace lime {
return alloc_int (cairo_get_fill_rule ((cairo_t*)(intptr_t)val_float (handle)));
}
value lime_cairo_get_font_options (value handle) {
cairo_font_options_t* options = (cairo_font_options_t*)(intptr_t)lime_cairo_font_options_create();
cairo_get_font_options ((cairo_t*)(intptr_t)val_float (handle), options);
return alloc_float ((intptr_t)options);
}
value lime_cairo_get_group_target (value handle) {
@@ -616,6 +701,26 @@ namespace lime {
}
value lime_cairo_set_font_face (value handle, value face) {
cairo_set_font_face ((cairo_t*)(intptr_t)val_float (handle), (cairo_font_face_t*)(intptr_t)val_float (face) );
return alloc_null ();
}
value lime_cairo_set_font_size (value handle, value size) {
cairo_set_font_size ((cairo_t*)(intptr_t)val_float (handle), val_number(size) );
return alloc_null ();
}
value lime_cairo_set_font_options (value handle, value options) {
cairo_set_font_options ((cairo_t*)(intptr_t)val_float (handle), (cairo_font_options_t*)(intptr_t)val_float (options) );
return alloc_null ();
}
value lime_cairo_set_fill_rule (value handle, value cap) {
@@ -725,6 +830,13 @@ namespace lime {
}
value lime_cairo_show_text (value handle, value text) {
cairo_show_text( (cairo_t*)(intptr_t)val_float (handle), (char*)val_string(text) );
return alloc_null ();
}
value lime_cairo_status (value handle) {
@@ -790,6 +902,19 @@ namespace lime {
}
value lime_cairo_rotate (value handle, value amount) {
cairo_rotate ((cairo_t*)(intptr_t)val_float (handle), val_number (amount));
return alloc_null ();
}
value lime_cairo_scale (value handle, value x, value y) {
cairo_scale ((cairo_t*)(intptr_t)val_float (handle), val_number (x), val_number (y));
return alloc_null ();
}
value lime_cairo_translate (value handle, value x, value y) {
@@ -812,6 +937,16 @@ namespace lime {
}
#ifdef LIME_FREETYPE
value lime_cairo_ft_font_face_create_for_ft_face( value face, value flags ) {
Font *font = (Font*)(intptr_t)val_float (face);
return alloc_float ((intptr_t)cairo_ft_font_face_create_for_ft_face( (FT_Face)(font->face), val_int( flags ) ));
}
#endif
DEFINE_PRIM_MULT (lime_cairo_arc);
DEFINE_PRIM_MULT (lime_cairo_arc_negative);
@@ -826,11 +961,23 @@ namespace lime {
DEFINE_PRIM (lime_cairo_fill, 1);
DEFINE_PRIM (lime_cairo_fill_extents, 5);
DEFINE_PRIM (lime_cairo_fill_preserve, 1);
DEFINE_PRIM (lime_cairo_ft_font_face_create_for_ft_face, 2);
DEFINE_PRIM (lime_cairo_font_face_destroy, 1);
DEFINE_PRIM (lime_cairo_font_options_create, 0);
DEFINE_PRIM (lime_cairo_font_options_get_antialias, 1);
DEFINE_PRIM (lime_cairo_font_options_get_subpixel_order, 1);
DEFINE_PRIM (lime_cairo_font_options_get_hint_style, 1);
DEFINE_PRIM (lime_cairo_font_options_get_hint_metrics, 1);
DEFINE_PRIM (lime_cairo_font_options_set_antialias, 2);
DEFINE_PRIM (lime_cairo_font_options_set_subpixel_order, 2);
DEFINE_PRIM (lime_cairo_font_options_set_hint_style, 2);
DEFINE_PRIM (lime_cairo_font_options_set_hint_metrics, 2);
DEFINE_PRIM (lime_cairo_get_antialias, 1);
DEFINE_PRIM (lime_cairo_get_current_point, 1);
DEFINE_PRIM (lime_cairo_get_dash, 1);
DEFINE_PRIM (lime_cairo_get_dash_count, 1);
DEFINE_PRIM (lime_cairo_get_fill_rule, 1);
DEFINE_PRIM (lime_cairo_get_font_options, 1);
DEFINE_PRIM (lime_cairo_get_group_target, 1);
DEFINE_PRIM (lime_cairo_get_line_cap, 1);
DEFINE_PRIM (lime_cairo_get_line_join, 1);
@@ -888,6 +1035,9 @@ namespace lime {
DEFINE_PRIM (lime_cairo_set_antialias, 2);
DEFINE_PRIM (lime_cairo_set_dash, 2);
DEFINE_PRIM (lime_cairo_set_fill_rule, 2);
DEFINE_PRIM (lime_cairo_set_font_face, 2);
DEFINE_PRIM (lime_cairo_set_font_size, 2);
DEFINE_PRIM (lime_cairo_set_font_options, 2);
DEFINE_PRIM (lime_cairo_set_line_cap, 2);
DEFINE_PRIM (lime_cairo_set_line_join, 2);
DEFINE_PRIM (lime_cairo_set_line_width, 2);
@@ -900,6 +1050,7 @@ namespace lime {
DEFINE_PRIM (lime_cairo_set_source_surface, 4);
DEFINE_PRIM (lime_cairo_set_tolerance, 2);
DEFINE_PRIM (lime_cairo_show_page, 1);
DEFINE_PRIM (lime_cairo_show_text, 2);
DEFINE_PRIM (lime_cairo_status, 1);
DEFINE_PRIM (lime_cairo_stroke, 1);
DEFINE_PRIM (lime_cairo_stroke_extents, 5);
@@ -907,6 +1058,8 @@ namespace lime {
DEFINE_PRIM (lime_cairo_surface_destroy, 1);
DEFINE_PRIM (lime_cairo_surface_flush, 1);
DEFINE_PRIM (lime_cairo_transform, 2);
DEFINE_PRIM (lime_cairo_rotate, 2);
DEFINE_PRIM (lime_cairo_scale, 3);
DEFINE_PRIM (lime_cairo_translate, 3);
DEFINE_PRIM (lime_cairo_version, 0);
DEFINE_PRIM (lime_cairo_version_string, 0);

View File

@@ -6,7 +6,7 @@
namespace lime {
static int __alpha16[0xFF];
static int __alpha16[0xFF + 1];
static int __clamp[0xFF + 0xFF + 1];
int initValues () {

View File

@@ -135,7 +135,8 @@ namespace {
PT_MOVE = 1,
PT_LINE = 2,
PT_CURVE = 3
PT_CURVE = 3,
PT_CUBIC = 4
};
@@ -241,20 +242,15 @@ namespace {
int outline_cubic_to (FVecPtr ctl1, FVecPtr ctl2, FVecPtr to, void *user) {
// Cubic curves are not supported, we need to approximate to a quadratic
// TODO: divide into multiple curves
glyph *g = static_cast<glyph*> (user);
FT_Vector ctl;
ctl.x = (-0.25 * g->x) + (0.75 * ctl1->x) + (0.75 * ctl2->x) + (-0.25 * to->x);
ctl.y = (-0.25 * g->y) + (0.75 * ctl1->y) + (0.75 * ctl2->y) + (-0.25 * to->y);
g->pts.push_back (PT_CURVE);
g->pts.push_back (ctl.x - g->x);
g->pts.push_back (ctl.y - g->y);
g->pts.push_back (to->x - ctl.x);
g->pts.push_back (to->y - ctl.y);
g->pts.push_back (PT_CUBIC);
g->pts.push_back (ctl1->x - g->x);
g->pts.push_back (ctl1->y - g->y);
g->pts.push_back (ctl2->x - ctl1->x);
g->pts.push_back (ctl2->y - ctl1->y);
g->pts.push_back (to->x - ctl2->x);
g->pts.push_back (to->y - ctl2->y);
g->x = to->x;
g->y = to->y;
@@ -468,7 +464,8 @@ namespace lime {
int result, i, j;
FT_Set_Char_Size ((FT_Face)face, em, em, 72, 72);
FT_Set_Transform ((FT_Face)face, 0, NULL);
std::vector<glyph*> glyphs;
FT_Outline_Funcs ofn =
@@ -869,19 +866,9 @@ namespace lime {
size_t hdpi = 72;
size_t vdpi = 72;
size_t hres = 100;
FT_Matrix matrix = {
(int)((1.0/hres) * 0x10000L),
(int)((0.0) * 0x10000L),
(int)((0.0) * 0x10000L),
(int)((1.0) * 0x10000L)
};
FT_Set_Char_Size ((FT_Face)face, 0, (int)(size*64), (int)(hdpi * hres), vdpi);
FT_Set_Transform ((FT_Face)face, &matrix, NULL);
FT_Set_Char_Size ((FT_Face)face, (int)(size*64), (int)(size*64), hdpi, vdpi);
mSize = size;
}

View File

@@ -52,7 +52,7 @@ namespace lime {
hb_glyph_info_t *glyph_info = hb_buffer_get_glyph_infos ((hb_buffer_t*)mBuffer, &glyph_count);
hb_glyph_position_t *glyph_pos = hb_buffer_get_glyph_positions ((hb_buffer_t*)mBuffer, &glyph_count);
float hres = 100;
//float hres = 100;
int posIndex = 0;
int glyphSize = sizeof(GlyphPosition);
@@ -79,9 +79,9 @@ namespace lime {
data = (GlyphPosition*)(bytesPosition);
data->index = glyph_info[i].codepoint;
data->advanceX = (float)(pos.x_advance / (float)(hres * 64));
data->advanceX = (float)(pos.x_advance / (float)(64));
data->advanceY = (float)(pos.y_advance / (float)64);
data->offsetX = (float)(pos.x_offset / (float)(hres * 64));
data->offsetX = (float)(pos.x_offset / (float)(64));
data->offsetY = (float)(pos.y_offset / (float)64);
bytesPosition += glyphSize;

View File

@@ -145,6 +145,12 @@ namespace lime {
return alloc_null ();
}
value lime_buffer_get_native_pointer (buffer inBuffer) {
return alloc_float ((intptr_t)buffer_data (inBuffer));
}
value lime_byte_array_init (value inFactory, value inLen, value inResize, value inBytes) {
@@ -201,6 +207,8 @@ namespace lime {
DEFINE_PRIM (lime_byte_array_init, 4);
DEFINE_PRIM (lime_byte_array_overwrite_file, 2);
DEFINE_PRIM (lime_byte_array_read_file, 1);
DEFINE_PRIM (lime_buffer_get_native_pointer, 1);
}