forked from enlightenment/efl
Buildsystem support will be enabled in a future commitdevs/netstar/elm_code_alpha
parent
8b1a72e972
commit
41c073b2e6
20 changed files with 1255 additions and 0 deletions
@ -0,0 +1,43 @@ |
||||
using System; |
||||
using System.Runtime.InteropServices; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
class TestMain |
||||
{ |
||||
/* private efl.Loop loop; */ |
||||
|
||||
public TestMain(efl.Loop loop) |
||||
{ |
||||
/* this.loop = loop; */ |
||||
} |
||||
|
||||
static void Main(string[] args) |
||||
{ |
||||
efl.All.Init(); |
||||
|
||||
efl.Loop loop = new efl.LoopConcrete(); |
||||
|
||||
TestMain listener = new TestMain(loop); |
||||
|
||||
loop.CALLBACK_ADD += listener.callback_added_cb; |
||||
|
||||
loop.CALLBACK_ADD += listener.on_idle_enter; |
||||
loop.CALLBACK_ADD -= listener.on_idle_enter; |
||||
|
||||
loop.IDLE += listener.on_idle_enter; // Will trigger CALLBACK_ADD |
||||
|
||||
efl.All.Shutdown(); |
||||
} |
||||
|
||||
public void on_idle_enter(object sender, EventArgs e) |
||||
{ |
||||
Console.WriteLine("I should not be called while the loop is not running..."); |
||||
} |
||||
|
||||
public void callback_added_cb(object sender, EventArgs e) |
||||
{ |
||||
Console.WriteLine("Looks like we added a new callback."); |
||||
} |
||||
} |
||||
|
||||
|
@ -0,0 +1,52 @@ |
||||
using System; |
||||
using System.Runtime.InteropServices; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
class TestMain |
||||
{ |
||||
private efl.Loop loop; |
||||
private int count; |
||||
|
||||
public TestMain(efl.Loop loop) |
||||
{ |
||||
this.loop = loop; |
||||
this.count = 0; |
||||
} |
||||
|
||||
static void Main(string[] args) |
||||
{ |
||||
efl.All.Init(); |
||||
|
||||
efl.Loop loop = new efl.LoopConcrete(); |
||||
efl.loop.Timer timer = new efl.loop.TimerConcrete(loop); |
||||
|
||||
TestMain listener = new TestMain(loop); |
||||
|
||||
Console.WriteLine("Starting MainLoop"); |
||||
|
||||
timer.interval_set(1.0); |
||||
|
||||
timer.TICK += listener.on_tick; |
||||
timer.TICK += listener.another_callback; |
||||
timer.TICK -= listener.another_callback; |
||||
|
||||
loop.begin(); |
||||
|
||||
efl.All.Shutdown(); |
||||
} |
||||
|
||||
public void on_tick(object sender, EventArgs e) |
||||
{ |
||||
Console.WriteLine("on_tick called on listener"); |
||||
|
||||
if (count++ == 5) |
||||
loop.quit(0); |
||||
} |
||||
|
||||
public void another_callback(object sender, EventArgs e) |
||||
{ |
||||
Console.WriteLine("Ooops. Should not have been called..."); |
||||
} |
||||
} |
||||
|
||||
|
@ -0,0 +1 @@ |
||||
/example_numberwrapper.out |
@ -0,0 +1,64 @@ |
||||
using static System.Console; |
||||
|
||||
class PlusTenNumberWrapper : example.NumberwrapperInherit |
||||
{ |
||||
public PlusTenNumberWrapper(efl.Object parent = null) |
||||
: base(parent) |
||||
{} |
||||
|
||||
public bool derivedCalled = false; |
||||
|
||||
override public void SetNumber(int n) |
||||
{ |
||||
// Call native EFL method |
||||
base.SetNumber(n + 10); |
||||
derivedCalled = true; |
||||
} |
||||
} |
||||
|
||||
public class ExampleEoInherit01 |
||||
{ |
||||
public static void Main() |
||||
{ |
||||
eina.Config.Init(); |
||||
efl.eo.Config.Init(); |
||||
|
||||
var inheritObj = new PlusTenNumberWrapper(); |
||||
|
||||
WriteLine("## Using inherit object ##\n"); |
||||
|
||||
int given = 111; |
||||
|
||||
// Call the C# override from the C method |
||||
example.NumberwrapperConcrete.example_numberwrapper_number_set(inheritObj.raw_handle, given); |
||||
|
||||
WriteLine($"Override successfully called? {inheritObj.derivedCalled}!\n"); |
||||
|
||||
// Call C function from C# object |
||||
int stored = inheritObj.GetNumber(); |
||||
|
||||
WriteLine($"Given value: {given}"); |
||||
WriteLine($"Stored value: {stored}\n"); |
||||
|
||||
// Call C# override directly |
||||
given = 333; |
||||
inheritObj.SetNumber(given); |
||||
|
||||
stored = inheritObj.GetNumber(); |
||||
|
||||
WriteLine($"Given value: {given}"); |
||||
WriteLine($"Stored value: {stored}\n"); |
||||
|
||||
WriteLine("## Using original object ##\n"); |
||||
|
||||
// Check original EFL object |
||||
var origObj = new example.NumberwrapperConcrete(); |
||||
given = 111; |
||||
origObj.SetNumber(given); |
||||
stored = origObj.GetNumber(); |
||||
|
||||
WriteLine($"Given value: {given}"); |
||||
WriteLine($"Stored value: {stored}\n"); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,45 @@ |
||||
using static System.Console; |
||||
|
||||
public class ExampleFunctionPointer01 |
||||
{ |
||||
private static bool static_called = false; |
||||
|
||||
private static int twiceCb(int n) |
||||
{ |
||||
static_called = true; |
||||
return n * 2; |
||||
} |
||||
|
||||
public static void Main() |
||||
{ |
||||
eina.Config.Init(); |
||||
efl.eo.Config.Init(); |
||||
|
||||
var obj = new example.NumberwrapperConcrete(); |
||||
|
||||
// Set internal value |
||||
obj.SetNumber(12); |
||||
|
||||
// With static method |
||||
obj.SetNumberCallback(twiceCb); |
||||
|
||||
var ret = obj.CallCallback(); |
||||
|
||||
WriteLine($"Callback called? {static_called}."); |
||||
WriteLine($"Returned value: {ret}.\n"); |
||||
|
||||
// With lambda |
||||
bool lamda_called = false; |
||||
|
||||
obj.SetNumberCallback(n => { |
||||
lamda_called = true; |
||||
return n * 3; |
||||
}); |
||||
|
||||
ret = obj.CallCallback(); |
||||
|
||||
WriteLine($"Lambda called? {lamda_called}."); |
||||
WriteLine($"Returned value: {ret}.\n"); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,123 @@ |
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
if HAVE_CSHARP |
||||
|
||||
include $(top_srcdir)/src/Makefile_Eolian_Helper.am |
||||
include $(top_srcdir)/src/Makefile_Eolian_Mono_Helper.am |
||||
include $(top_srcdir)/src/Makefile_Efl_Mono_MSBuild_Gen_Helper.am |
||||
|
||||
SRCS =
|
||||
EXTRA_FILES =
|
||||
EXTRA_PROGRAMS =
|
||||
GENERATED =
|
||||
CLEANFILES =
|
||||
|
||||
# Simple object used by the examples
|
||||
|
||||
EOLIAN_FLAGS := $(EOLIAN_FLAGS)
|
||||
EOLIAN_FLAGS += \
|
||||
-I$(srcdir) \ |
||||
-I$(top_srcdir)/src/lib/eo \ |
||||
-I$(top_srcdir)/src/lib/efl |
||||
|
||||
COMMON_FLAGS = \
|
||||
@EINA_CFLAGS@ @EINA_LDFLAGS@ \ |
||||
-L$(top_builddir)/src/lib/eina/.libs -leina \ |
||||
@EO_CFLAGS@ @EO_LDFLAGS@ \ |
||||
-L$(top_builddir)/src/lib/eo/.libs -leo \ |
||||
@EFL_CFLAGS@ @EFL_LDFLAGS@ \ |
||||
-L$(top_builddir)/src/lib/efl/.libs -lefl |
||||
|
||||
if HAVE_WIN32 |
||||
COMMON_FLAGS += \
|
||||
@EVIL_CFLAGS@ @EVIL_LDFLAGS@ \ |
||||
@EFL_WINDOWS_VERSION_CFLAGS@ \ |
||||
-L$(top_builddir)/src/lib/evil/.libs -levil |
||||
else |
||||
COMMON_FLAGS += \
|
||||
-fPIC -DPIC |
||||
endif |
||||
|
||||
|
||||
%.eo.c: %.eo |
||||
$(AM_V_EOL)$(EOLIAN_GEN) $(EOLIAN_FLAGS) -gc -o c:$@ $<
|
||||
|
||||
%.eo.h: %.eo |
||||
$(AM_V_EOL)$(EOLIAN_GEN) $(EOLIAN_FLAGS) -gh -o h:$@ $<
|
||||
|
||||
example_numberwrapper.c: example_numberwrapper.eo.h example_numberwrapper.eo.c |
||||
|
||||
numberwrapper_lib_name = example_numberwrapper.out
|
||||
|
||||
$(numberwrapper_lib_name): example_numberwrapper.c |
||||
$(CC) -shared -o $@ $< -DEFL_BETA_API_SUPPORT -I. $(COMMON_FLAGS)
|
||||
|
||||
SRCS += example_numberwrapper.c
|
||||
EXTRA_FILES += example_numberwrapper.eo
|
||||
GENERATED += example_numberwrapper.eo.h example_numberwrapper.eo.c $(numberwrapper_lib_name)
|
||||
|
||||
# CSharp examples
|
||||
|
||||
SRCS += \
|
||||
EoInherit01.cs \ |
||||
FunctionPointer01.cs |
||||
|
||||
EXTRA_PROGRAMS += \
|
||||
EoInherit01.exe \ |
||||
FunctionPointer01.exe |
||||
|
||||
example_numberwrapper.eo.cs: example_numberwrapper.eo |
||||
$(AM_V_EOLMONO) \
|
||||
$(EOLIAN_MONO) $(EOLIAN_FLAGS) $(EOLIAN_MONO_FLAGS) --dllimport $(numberwrapper_lib_name) -o $@ -r $(top_builddir)/src/bindings/mono/efl_mono/efl_libs.csv $<
|
||||
|
||||
EoInherit01_exe_SOURCES = EoInherit01.cs
|
||||
EoInherit01_srcs = $(EoInherit01_exe_SOURCES) example_numberwrapper.eo.cs
|
||||
EoInherit01.exe$(EXEEXT): $(EoInherit01_srcs) $(am_dirstamp) $(top_builddir)/src/lib/efl_mono/libefl_mono.dll$(EXEEXT) $(numberwrapper_lib_name) |
||||
@rm -f $@
|
||||
$(AM_V_MCS) $(MCS) $(MCS_FLAGS) -r:$(abs_top_builddir)/src/lib/efl_mono/libefl_mono.dll$(EXEEXT) -out:$@ $(filter %.cs, $(^))
|
||||
|
||||
$(abs_top_builddir)/EoInherit01.csproj: $(EoInherit01_srcs) $(am_dirstamp) $(numberwrapper_lib_name) |
||||
@rm -f $@
|
||||
$(EFL_MONO_MSBUILD_GEN) $(MSBUILD_GEN_FLAGS) -o $@ -a EoInherit01.exe -r libefl_mono.dll -t exe $(patsubst %.cs,src/examples/efl_mono/%.cs,$(filter %.cs, $(^)))
|
||||
|
||||
|
||||
FunctionPointer01_exe_SOURCES = FunctionPointer01.cs
|
||||
FunctionPointer01_srcs = $(FunctionPointer01_exe_SOURCES) example_numberwrapper.eo.cs
|
||||
FunctionPointer01.exe$(EXEEXT): $(FunctionPointer01_srcs) $(am_dirstamp) $(top_builddir)/src/lib/efl_mono/libefl_mono.dll$(EXEEXT) $(numberwrapper_lib_name) |
||||
@rm -f $@
|
||||
$(AM_V_MCS) $(MCS) $(MCS_FLAGS) -r:$(abs_top_builddir)/src/lib/efl_mono/libefl_mono.dll$(EXEEXT) -out:$@ $(filter %.cs, $(^))
|
||||
|
||||
$(abs_top_builddir)/FunctionPointer01.csproj: $(FunctionPointer01_srcs) $(am_dirstamp) $(numberwrapper_lib_name) |
||||
@rm -f $@
|
||||
$(EFL_MONO_MSBUILD_GEN) $(MSBUILD_GEN_FLAGS) -o $@ -a FunctionPointer01.exe -r libefl_mono.dll -t exe $(patsubst %.cs,src/examples/efl_mono/%.cs,$(filter %.cs, $(^)))
|
||||
|
||||
msbuildcsprojs: $(abs_top_builddir)/EoInherit01.csproj $(abs_top_builddir)/FunctionPointer01.csproj |
||||
|
||||
GENERATED += example_numberwrapper.eo.cs
|
||||
|
||||
|
||||
# Finishing
|
||||
|
||||
EXTRA_DIST = $(EXTRA_FILES)
|
||||
|
||||
CLEANFILES += $(GENERATED)
|
||||
|
||||
examples: $(EXTRA_PROGRAMS) |
||||
|
||||
clean-local: |
||||
rm -f $(EXTRA_PROGRAMS) $(GENERATED)
|
||||
|
||||
install-examples: |
||||
$(MKDIR_P) $(DESTDIR)$(datadir)/efl_mono/examples
|
||||
cd $(srcdir) && $(install_sh_DATA) -c $(SRCS) $(EXTRA_FILES) $(DESTDIR)$(datadir)/efl_mono/examples
|
||||
|
||||
uninstall-local: |
||||
for f in $(SRCS) $(EXTRA_FILES); do \
|
||||
rm -f $(DESTDIR)$(datadir)/efl_mono/examples/$$f ; \
|
||||
done
|
||||
|
||||
if ALWAYS_BUILD_EXAMPLES |
||||
noinst_PROGRAMS = $(EXTRA_PROGRAMS)
|
||||
endif |
||||
|
||||
endif |
@ -0,0 +1,87 @@ |
||||
|
||||
#ifdef HAVE_CONFIG_H |
||||
#include "config.h" |
||||
#endif |
||||
|
||||
#include <Eo.h> |
||||
|
||||
#undef EOAPI |
||||
#undef EAPI |
||||
#define EOAPI EAPI EAPI_WEAK |
||||
|
||||
#ifdef _WIN32 |
||||
# ifdef EFL_EO_BUILD |
||||
# ifdef DLL_EXPORT |
||||
# define EAPI __declspec(dllexport) |
||||
# else |
||||
# define EAPI |
||||
# endif /* ! DLL_EXPORT */ |
||||
# else |
||||
# define EAPI __declspec(dllimport) |
||||
# endif /* ! EFL_EO_BUILD */ |
||||
#else |
||||
# ifdef __GNUC__ |
||||
# if __GNUC__ >= 4 |
||||
# define EAPI __attribute__ ((visibility("default"))) |
||||
# else |
||||
# define EAPI |
||||
# endif |
||||
# else |
||||
# define EAPI |
||||
# endif |
||||
#endif /* ! _WIN32 */ |
||||
|
||||
#include "example_numberwrapper.eo.h" |
||||
|
||||
|
||||
typedef struct Example_Numberwrapper_Data |
||||
{ |
||||
int number; |
||||
NumberCb cb; |
||||
void *cb_data; |
||||
Eina_Free_Cb free_cb; |
||||
} Example_Numberwrapper_Data; |
||||
|
||||
// ##################### //
|
||||
// Example.Numberwrapper //
|
||||
// ##################### //
|
||||
|
||||
|
||||
void _example_numberwrapper_number_set(EINA_UNUSED Eo *obj, Example_Numberwrapper_Data *pd, int n) |
||||
{ |
||||
pd->number = n; |
||||
} |
||||
|
||||
int _example_numberwrapper_number_get(EINA_UNUSED Eo *obj, Example_Numberwrapper_Data *pd) |
||||
{ |
||||
return pd->number; |
||||
} |
||||
|
||||
|
||||
void _example_numberwrapper_number_callback_set(EINA_UNUSED Eo *obj, Example_Numberwrapper_Data *pd, void *cb_data, NumberCb cb, Eina_Free_Cb cb_free_cb) |
||||
{ |
||||
if (pd->free_cb) |
||||
pd->free_cb(pd->cb_data); |
||||
|
||||
pd->cb = cb; |
||||
pd->cb_data = cb_data; |
||||
pd->free_cb = cb_free_cb; |
||||
} |
||||
|
||||
|
||||
int _example_numberwrapper_callback_call(EINA_UNUSED Eo *obj, Example_Numberwrapper_Data *pd) |
||||
{ |
||||
if (!pd->cb) |
||||
{ |
||||
static Eina_Error no_cb_err = 0; |
||||
if (!no_cb_err) |
||||
no_cb_err = eina_error_msg_static_register("Trying to call with no callback set"); |
||||
eina_error_set(no_cb_err); |
||||
return -1; |
||||
} |
||||
|
||||
return pd->cb(pd->cb_data, pd->number); |
||||
} |
||||
|
||||
#include "example_numberwrapper.eo.c" |
||||
|
@ -0,0 +1,30 @@ |
||||
function NumberCb { |
||||
params { |
||||
n: int; |
||||
} |
||||
return: int; |
||||
}; |
||||
|
||||
class Example.Numberwrapper (Efl.Object) { |
||||
methods { |
||||
@property number { |
||||
get { |
||||
} |
||||
set { |
||||
} |
||||
values { |
||||
n: int; |
||||
} |
||||
} |
||||
|
||||
number_callback_set { |
||||
params { |
||||
cb: NumberCb; |
||||
} |
||||
} |
||||
|
||||
callback_call { |
||||
return: int; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,41 @@ |
||||
using static System.Console; |
||||
|
||||
public class ExampleEinaArray01 |
||||
{ |
||||
public static void Main() |
||||
{ |
||||
eina.Config.Init(); |
||||
|
||||
var strings = new string[]{ |
||||
"helo", "hera", "starbuck", "kat", "boomer", |
||||
"hotdog", "longshot", "jammer", "crashdown", "hardball", |
||||
"duck", "racetrack", "apolo", "husker", "freaker", |
||||
"skulls", "bulldog", "flat top", "hammerhead", "gonzo" |
||||
}; |
||||
|
||||
var array = new eina.Array<string>(20U); |
||||
|
||||
// Push new elements |
||||
foreach (string s in strings) |
||||
{ |
||||
WriteLine("push: " + s); |
||||
array.Push(s); |
||||
} |
||||
|
||||
// Check count |
||||
WriteLine("array count: " + array.Count()); |
||||
|
||||
// Iterate over the array |
||||
int idx = 0; |
||||
foreach (string s in array) |
||||
{ |
||||
WriteLine($"at[{idx}]: {s}"); |
||||
++idx; |
||||
} |
||||
|
||||
// Remove one by one |
||||
while (array.Length != 0) |
||||
WriteLine("pop: " + array.Pop()); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,65 @@ |
||||
using static System.Console; |
||||
|
||||
public class ExampleEinaBinbuf01 |
||||
{ |
||||
public static void Main() |
||||
{ |
||||
eina.Config.Init(); |
||||
|
||||
var bytes = new byte[]{0, 1, 2, 3, 4, 5, 6}; |
||||
|
||||
var bb = new eina.Binbuf(); |
||||
|
||||
// Append initial bytes |
||||
bb.Append(bytes); |
||||
|
||||
WriteLine("Printing each byte."); |
||||
|
||||
int idx = 0; |
||||
foreach (byte b in bb.GetBytes()) |
||||
{ |
||||
WriteLine($"byte at[{idx}]: {b}"); |
||||
++idx; |
||||
} |
||||
|
||||
// Append more byte by byte |
||||
bb.Append((byte) 7); |
||||
bb.Append((byte) 8); |
||||
bb.Append((byte) 9); |
||||
bb.Append((byte) 0); |
||||
|
||||
WriteLine("\nPrinting each byte."); |
||||
|
||||
idx = 0; |
||||
foreach (byte b in bb.GetBytes()) |
||||
{ |
||||
WriteLine($"byte at[{idx}]: {b}"); |
||||
++idx; |
||||
} |
||||
|
||||
// Remove some |
||||
bb.Remove(2, 5); |
||||
|
||||
WriteLine("\nPrinting each byte."); |
||||
|
||||
idx = 0; |
||||
foreach (byte b in bb.GetBytes()) |
||||
{ |
||||
WriteLine($"byte at[{idx}]: {b}"); |
||||
++idx; |
||||
} |
||||
|
||||
// Insert new bytes in the middle |
||||
bb.Insert(new byte[]{22, 33, 44}, 2); |
||||
|
||||
WriteLine("\nPrinting each byte."); |
||||
|
||||
idx = 0; |
||||
foreach (byte b in bb.GetBytes()) |
||||
{ |
||||
WriteLine($"byte at[{idx}]: {b}"); |
||||
++idx; |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,75 @@ |
||||
using static System.Console; |
||||
|
||||
public class ExampleEinaError01 |
||||
{ |
||||
private static bool RegisteredErrors = false; |
||||
private static eina.Error MyErrorNegative; |
||||
private static eina.Error MyErrorNull; |
||||
|
||||
private static void testFunc(int n, string s) |
||||
{ |
||||
if (!RegisteredErrors) |
||||
{ |
||||
MyErrorNegative = eina.Error.Register("Negative number"); |
||||
MyErrorNull = eina.Error.Register("NULL pointer"); |
||||
RegisteredErrors = true; |
||||
} |
||||
|
||||
if (n < 0) |
||||
{ |
||||
eina.Error.Set(MyErrorNegative); |
||||
return; |
||||
} |
||||
|
||||
if (s == null) |
||||
{ |
||||
eina.Error.Set(MyErrorNull); |
||||
return; |
||||
} |
||||
} |
||||
|
||||
public static void Main() |
||||
{ |
||||
eina.Config.Init(); |
||||
efl.eo.Config.Init(); |
||||
|
||||
// Handling Eina_Error with exception |
||||
try |
||||
{ |
||||
testFunc(-1, "abc"); |
||||
eina.Error.RaiseIfOccurred(); |
||||
} |
||||
catch(efl.EflException e) |
||||
{ |
||||
WriteLine($"Caught error: {e.Message}"); |
||||
} |
||||
|
||||
// Handling Eina_Error directly |
||||
testFunc(42, null); |
||||
eina.Error err = eina.Error.Get(); |
||||
if (err != 0) |
||||
{ |
||||
WriteLine($"Error set: {err.Message}"); |
||||
} |
||||
eina.Error.Clear(); |
||||
|
||||
// No error set |
||||
try |
||||
{ |
||||
testFunc(42, "abc"); |
||||
|
||||
eina.Error.RaiseIfOccurred(); |
||||
|
||||
err = eina.Error.Get(); |
||||
WriteLine($"Really no error? {err == eina.Error.NO_ERROR}."); |
||||
} |
||||
catch |
||||
{ |
||||
WriteLine("Unspected error!!!"); |
||||
} |
||||
|
||||
WriteLine("No error message is empty string: \"{0}\"", eina.Error.NO_ERROR.Message); |
||||
WriteLine("No error message is empty string: \"{0}\"", eina.Error.MsgGet(0)); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,66 @@ |
||||
using static System.Console; |
||||
|
||||
public class ExampleEinaHash01 |
||||
{ |
||||
public static void Main() |
||||
{ |
||||
eina.Config.Init(); |
||||
|
||||
var phone_book = new eina.Hash<string, string>(); |
||||
|
||||
// Add initial entries to our hash |
||||
phone_book.Add("Wolfgang Amadeus Mozart", "+01 23 456-78910"); |
||||
phone_book.Add("Ludwig van Beethoven", "+12 34 567-89101"); |
||||
phone_book.Add("Richard Georg Strauss", "+23 45 678-91012"); |
||||
phone_book.Add("Heitor Villa-Lobos", "+34 56 789-10123"); |
||||
|
||||
// Look for a specific entry and get its phone number |
||||
var entry_name = "Heitor Villa-Lobos"; |
||||
var phone = phone_book.Find(entry_name); |
||||
|
||||
WriteLine("Printing entry."); |
||||
WriteLine($"Name: {entry_name}"); |
||||
WriteLine($"Number: {phone}\n"); |
||||
|
||||
// Delete this entry |
||||
var r = phone_book.DelByKey(entry_name); |
||||
WriteLine($"Hash entry successfully deleted? {r}!\n"); |
||||
|
||||
// Modify the pointer data of an entry and free the old one |
||||
phone_book.Modify("Richard Georg Strauss", "+23 45 111-11111"); |
||||
|
||||
// Modify or add an entry to the hash |
||||
// Let's first add a new entry |
||||
entry_name = "Raul Seixas"; |
||||
phone_book[entry_name] = "+55 01 234-56789"; |
||||
WriteLine("Printing entry."); |
||||
WriteLine($"Name: {entry_name}"); |
||||
WriteLine($"Number: {phone_book[entry_name]}\n"); |
||||
|
||||
// Now change the phone number |
||||
phone_book["Raul Seixas"] = "+55 02 222-22222"; |
||||
WriteLine("Printing entry."); |
||||
WriteLine($"Name: {entry_name}"); |
||||
WriteLine($"Number: {phone_book[entry_name]}\n"); |
||||
|
||||
// Check how many items are in the phone book |
||||
WriteLine("There are {0} items in the hash.\n", phone_book.Count); |
||||
|
||||
// Change the name (key) on an entry |
||||
phone_book.Move("Raul Seixas", "Alceu Valenca"); |
||||
entry_name = "Alceu Valenca"; |
||||
WriteLine("Printing entry."); |
||||
WriteLine($"Name: {entry_name}"); |
||||
WriteLine($"Number: {phone_book[entry_name]}\n"); |
||||
|
||||
// Empty the phone book, but don't destroy it |
||||
phone_book.FreeBuckets(); |
||||
WriteLine("There are {0} items in the hash.\n", phone_book.Count); |
||||
|
||||
// Phone book could still be used, but we are freeing it since we are |
||||
// done for now |
||||
phone_book.Dispose(); |
||||
} |
||||
} |
||||
|
||||
|
@ -0,0 +1,63 @@ |
||||
using System; |
||||
|
||||
public class Example |
||||
{ |
||||
public static efl.ui.Button CreateButton(efl.Object parent, |
||||
string text, |
||||
int w, int h, |
||||
EventHandler callback) { |
||||
efl.ui.Button button = new efl.ui.ButtonConcrete(parent); |
||||
button.SetText(text); |
||||
button.SetSize(w, h); |
||||
|
||||
button.CLICKED += callback; |
||||
|
||||
return button; |
||||
} |
||||
|
||||
#if WIN32 // Passed to the C# compiler with -define:WIN32 |
||||
// Mono on Windows by default uses multi-thread apartments for COM stuff while |
||||
// OLE - used by ecore win32 DnD requires single threading for COM. |
||||
[STAThreadAttribute()] |
||||
#endif |
||||
public static void Main() { |
||||
efl.All.Init(efl.Components.Ui); |
||||
|
||||
efl.ui.Win win = new efl.ui.WinConcrete(null); |
||||
win.SetText("Hello, C#!!"); |
||||
win.SetAutohide(true); |
||||
|
||||
efl.ui.Box_Flow box = new efl.ui.Box_FlowConcrete(win); |
||||
|
||||
efl.ui.Button button = CreateButton(box, "Click to exit", 120, 30, |
||||
(object sender, EventArgs e) => { |
||||
efl.ui.Config.Exit(); |
||||
}); |
||||
|
||||
box.Pack(button); |
||||
|
||||
efl.ui.Progressbar bar = new efl.ui.ProgressbarConcrete(box); |
||||
bar.SetSize(120, 30); |
||||
|
||||
efl.ui.Slider slider = new efl.ui.SliderConcrete(box); |
||||
slider.SetSize(120, 30); |
||||
|
||||
slider.CHANGED += (object sender, EventArgs e) => { |
||||
bar.SetRangeValue(slider.GetRangeValue()); |
||||
}; |
||||
|
||||
box.Pack(bar); |
||||
box.Pack(slider); |
||||
|
||||
button.SetVisible(true); |
||||
box.SetVisible(true); |
||||
|
||||
win.SetSize(120, 90); |
||||
win.SetVisible(true); |
||||
|
||||
efl.ui.Config.Run(); |
||||
|
||||
efl.All.Shutdown(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,73 @@ |
||||
using System; |
||||
using System.Runtime.InteropServices; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
public class MyBox : evas.BoxInherit |
||||
{ |
||||
public MyBox(efl.Object parent) : base(parent) {} |
||||
|
||||
[DllImport("evas")] static extern void evas_obj_box_layout_vertical(IntPtr obj, IntPtr data, IntPtr privdata); |
||||
[DllImport("evas")] static extern void evas_obj_box_layout_horizontal(IntPtr obj, IntPtr data, IntPtr privdata); |
||||
[DllImport("evas")] static extern void evas_object_box_layout_horizontal(IntPtr obj, IntPtr data, IntPtr privdata); |
||||
[DllImport("evas")] static extern IntPtr evas_object_evas_get(IntPtr obj); |
||||
[DllImport("evas")] static extern void evas_event_freeze(IntPtr obj); |
||||
[DllImport("evas")] static extern void evas_event_thaw(IntPtr obj); |
||||
|
||||
override public void CalculateGroup() |
||||
{ |
||||
IntPtr evas = evas_object_evas_get(raw_handle); |
||||
evas_event_freeze(evas); |
||||
Console.WriteLine("called group_calculate"); |
||||
/* layouting_set(true); */ |
||||
evas_obj_box_layout_vertical(raw_handle, IntPtr.Zero, IntPtr.Zero); |
||||
/* layouting_set(false); */ |
||||
/* children_changed_set(false); */ |
||||
evas_event_thaw(evas); |
||||
} |
||||
} |
||||
|
||||
class TestMain |
||||
{ |
||||
static void Main(string[] args) |
||||
{ |
||||
efl.All.Init(); |
||||
|
||||
efl.Loop loop = new efl.LoopConcrete(); |
||||
|
||||
|
||||
EcoreEvas ecore_evas = new EcoreEvas(); |
||||
|
||||
efl.canvas.Object canvas = ecore_evas.canvas; |
||||
canvas.SetVisible(true); |
||||
|
||||
efl.Object parent = canvas.GetParent(); |
||||
System.Diagnostics.Debug.Assert(parent.raw_handle != IntPtr.Zero); |
||||
|
||||
evas.Box box = new MyBox(canvas); |
||||
eina.Size2D size = new eina.Size2D(); |
||||
|
||||
size.W = 320; |
||||
size.H = 240; |
||||
|
||||
box.SetSize(size); |
||||
box.SetVisible(true); |
||||
|
||||
efl.canvas.Rectangle rect = new efl.canvas.RectangleConcrete(canvas); |
||||
rect.SetColor(0, 0, 255, 255); |
||||
size.W = 320; |
||||
size.H = 120; |
||||
rect.SetSize(size); |
||||
rect.SetVisible(true); |
||||
box.Append(rect); |
||||
|
||||
efl.canvas.Rectangle rect2 = new efl.canvas.RectangleConcrete(canvas); |
||||
rect2.SetColor(0, 255, 0, 255); |
||||
rect2.SetSize(size); |
||||
rect2.SetVisible(true); |
||||
box.Append(rect2); |
||||
|
||||
loop.Begin(); |
||||
|
||||
efl.All.Shutdown(); |
||||
} |
||||
} |
@ -0,0 +1,93 @@ |
||||
using System; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
class TestMain |
||||
{ |
||||
static int WIDTH = 320; |
||||
static int HEIGHT = 240; |
||||
|
||||
evas.Image image; |
||||
|
||||
|
||||
static string ImagePath([CallerFilePath] string folder="") |
||||
{ |
||||
return System.IO.Path.GetDirectoryName(folder); |
||||
} |
||||
|
||||
public TestMain(evas.Image image) |
||||
{ |
||||
this.image = image; |
||||
} |
||||
|
||||
static void Main(string[] args) |
||||
{ |
||||
efl.All.Init(); |
||||
|
||||
efl.Loop loop = new efl.LoopConcrete(); |
||||
|
||||
EcoreEvas ecore_evas = new EcoreEvas(); |
||||
eina.Size2D size = new eina.Size2D(); |
||||
|
||||
efl.canvas.Object canvas = ecore_evas.canvas; |
||||
canvas.SetVisible(true); |
||||
|
||||
efl.Object parent = canvas.GetParent(); |
||||
System.Diagnostics.Debug.Assert(parent.raw_handle != IntPtr.Zero); |
||||
|
||||
efl.canvas.Rectangle bg = new efl.canvas.RectangleConcrete(canvas); |
||||
bg.SetColor(255, 255, 255, 255); |
||||
size.W = WIDTH; |
||||
size.H = HEIGHT; |
||||
bg.SetSize(size); |
||||
bg.SetVisible(true); |
||||
|
||||
string valid_path = args[0]; |
||||
evas.Image image = new evas.ImageConcrete(canvas); |
||||
image.SetFile(valid_path, null); |
||||
|
||||
/* FIXME evas-image uses error handling code from |
||||
* evas_object_image_load_error_get, which seems to be not available |
||||
* efl.image.load.State state = image.load_error_get(); */ |
||||
|
||||
// FIXME missing move |
||||
eina.Rect rect = new eina.Rect(); |
||||
|
||||
rect.X = 0; |
||||
rect.Y = 0; |
||||
rect.W = WIDTH / 2; |
||||
rect.H = HEIGHT / 2; |
||||
image.SetFill(rect); |
||||
|
||||
size.W = WIDTH / 2; |
||||
size.H = HEIGHT / 2; |
||||
image.SetSize(size); |
||||
image.SetVisible(true); |
||||
|
||||
rect = image.GetFill(); |
||||
rect.Y -= 50; |
||||
rect.W += 100; |
||||
image.SetFill(rect); |
||||
|
||||
TestMain listener = new TestMain(image); |
||||
|
||||
// TODO handle key events in order to alter the image like the C |
||||
// example. Meanwhile, just set some w fill |
||||
/* EventListener callback = new EventListener(); */ |
||||
|
||||
/* bg.key_focus_set(true); */ |
||||
/* bg.event_callback_priority_add(evas.Callback_Type.Key_down, */ |
||||
/* efl.Callback_Priority.Default, */ |
||||
/* callback, null); */ |
||||
|
||||
loop.Begin(); |
||||
|
||||
efl.All.Shutdown(); |
||||
} |
||||
|
||||
public void on_key_down(object sender, EventArgs e) |
||||
{ |
||||
Console.WriteLine("on_key_down called"); |
||||
} |
||||
} |
||||
|
||||
|
@ -0,0 +1,83 @@ |
||||
using System; |
||||
using System.Runtime.InteropServices; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
class TestMain |
||||
{ |
||||
static int WIDTH = 320; |
||||
static int HEIGHT = 240; |
||||
|
||||
|
||||
static void Main(string[] args) |
||||
{ |
||||
efl.All.Init(); |
||||
|
||||
efl.Loop loop = new efl.LoopConcrete(); |
||||
|
||||
EcoreEvas ecore_evas = new EcoreEvas(); |
||||
|
||||
eina.Size2D size = new eina.Size2D(); |
||||
eina.Position2D pos = new eina.Position2D(); |
||||
|
||||
efl.canvas.Object canvas = ecore_evas.canvas; |
||||
canvas.SetVisible(true); |
||||
|
||||
efl.canvas.Rectangle bg = new efl.canvas.RectangleConcrete(canvas); |
||||
bg.SetColor(255, 255, 255, 255); |
||||
pos.X = 0; |
||||
pos.Y = 0; |
||||
bg.SetPosition(pos); |
||||
size.W = WIDTH; |
||||
size.H = HEIGHT; |
||||
bg.SetSize(size); |
||||
bg.SetVisible(true); |
||||
|
||||
string path = args[0]; |
||||
evas.Image logo = new evas.ImageConcrete(canvas); |
||||
logo.SetFillAuto(true); |
||||
|
||||
// TODO add preloaded support (depends on events) |
||||
|
||||
logo.SetFile(path, null); |
||||
size.W = WIDTH / 2; |
||||
size.H = HEIGHT / 2; |
||||
logo.SetSize(size); |
||||
|
||||
// TODO add a bunch of key/mouse handlers |
||||
|
||||
logo.SetVisible(true); |
||||
|
||||
int[] pixels = new int[(WIDTH/4) * (HEIGHT / 4)]; |
||||
System.Random generator = new System.Random(); |
||||
for (int i = 0; i < pixels.Length; i++) { |
||||
pixels[i] = generator.Next(); |
||||
} |
||||
|
||||
evas.Image noise_img = new evas.ImageConcrete(canvas); |
||||
size.W = WIDTH / 4; |
||||
size.H = HEIGHT / 4; |
||||
noise_img.SetSize(size); |
||||
// FIXME Add a way to set the pixels. |
||||
// noise_img.data_set(pixels); |
||||
noise_img.SetFillAuto(true); |
||||
pos.X = WIDTH * 5 / 8; |
||||
pos.Y = HEIGHT / 8; |
||||
noise_img.SetPosition(pos); |
||||
noise_img.SetVisible(true); |
||||
Console.WriteLine("Creating noise image with sizez %d, %d", WIDTH/4, HEIGHT/4); |
||||
|
||||
efl.canvas.Proxy proxy_img = new efl.canvas.ProxyConcrete(canvas); |
||||
proxy_img.SetSource(noise_img); |
||||
pos.X = WIDTH / 2; |
||||
pos.Y = HEIGHT / 2; |
||||
proxy_img.SetPosition(pos); |
||||
size.W = WIDTH / 2; |
||||
size.H = HEIGHT / 2; |
||||
proxy_img.SetSize(size); |
||||
proxy_img.SetVisible(true); |
||||
|
||||
loop.Begin(); |
||||
} |
||||
} |
||||
|
||||
|
@ -0,0 +1,47 @@ |
||||
using System; |
||||
|
||||
class TestMain |
||||
{ |
||||
private static int[,] colors = new int[,] { |
||||
{255, 0, 0}, |
||||
{0, 255, 0}, |
||||
{0, 0, 255} |
||||
}; |
||||
|
||||
static void Main(string[] args) |
||||
{ |
||||
int color_index = 0; |
||||
|
||||
efl.All.Init(); |
||||
|
||||
efl.Loop loop = new efl.LoopConcrete(); |
||||
EcoreEvas ecore_evas = new EcoreEvas(); |
||||
efl.canvas.Object canvas = ecore_evas.canvas; |
||||
canvas.SetVisible(true); |
||||
|
||||
efl.Object parent = canvas.GetParent(); |
||||
System.Diagnostics.Debug.Assert(parent.raw_handle != IntPtr.Zero); |
||||
|
||||
efl.canvas.Rectangle rect = new efl.canvas.RectangleConcrete(canvas); |
||||
rect.SetColor(colors[0, 0], colors[0, 1], colors[0, 2], 255); |
||||
eina.Size2D size = new eina.Size2D(); |
||||
size.W = 640; |
||||
size.H = 480; |
||||
rect.SetSize(size); |
||||
rect.SetVisible(true); |
||||
|
||||
canvas.KEY_DOWN += (object sender, efl.input.KEY_DOWN_Args e) => { |
||||
color_index = (color_index + 1) % 3; |
||||
Console.WriteLine("Key Down"); |
||||
Console.WriteLine("Got key obj at {0}", e.arg.raw_handle.ToString("X")); |
||||
Console.WriteLine("Got key_get() == [{0}]", e.arg.GetKey()); |
||||
rect.SetColor(colors[color_index, 0], |
||||
colors[color_index, 1], |
||||
colors[color_index, 2], 255); |
||||
}; |
||||
|
||||
loop.Begin(); |
||||
|
||||
efl.All.Shutdown(); |
||||
} |
||||
} |
@ -0,0 +1,77 @@ |
||||
using System; |
||||
using System.Runtime.InteropServices; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
class TestMain |
||||
{ |
||||
static int WIDTH = 100; |
||||
static int HEIGHT = 150; |
||||
|
||||
static void Main(string[] args) |
||||
{ |
||||
efl.All.Init(); |
||||
|
||||
efl.Loop loop = new efl.LoopConcrete(); |
||||
|
||||
EcoreEvas ecore_evas = new EcoreEvas(); |
||||
|
||||
eina.Size2D size = new eina.Size2D(); |
||||
size.W = WIDTH; |
||||
size.H = HEIGHT; |
||||
|
||||
eina.Size2D hint = new eina.Size2D(); |
||||
|
||||
efl.canvas.Object canvas = ecore_evas.canvas; |
||||
canvas.SetVisible(true); |
||||
|
||||
efl.Object parent = canvas.GetParent(); |
||||
System.Diagnostics.Debug.Assert(parent.raw_handle != IntPtr.Zero); |
||||
|
||||
efl.canvas.Rectangle bg = new efl.canvas.RectangleConcrete(canvas); |
||||
bg.SetColor(255, 255, 255, 255); |
||||
bg.SetSize(size); |
||||
bg.SetVisible(true); |
||||
|
||||
|
||||
evas.Table table = new evas.TableConcrete(canvas); |
||||
table.SetHomogeneous(evas.object_table.Homogeneous_Mode.None); |
||||
table.SetPadding(0, 0); |
||||
table.SetSize(size); |
||||
table.SetVisible(true); |
||||
|
||||
efl.canvas.Rectangle rect = new efl.canvas.RectangleConcrete(canvas); |
||||
rect.SetColor(255, 0, 0, 255); |
||||
hint.W = 100; |
||||
hint.H = 50; |
||||
rect.SetHintMin(hint); |
||||
rect.SetVisible(true); |
||||
table.Pack(rect, 1, 1, 2, 1); |
||||
|
||||
rect = new efl.canvas.RectangleConcrete(canvas); |
||||
rect.SetColor(0, 255, 0, 255); |
||||
hint.W = 50; |
||||
hint.H = 100; |
||||
rect.SetHintMin(hint); |
||||
rect.SetVisible(true); |
||||
table.Pack(rect, 1, 2, 1, 2); |
||||
|
||||
rect = new efl.canvas.RectangleConcrete(canvas); |
||||
rect.SetColor(0, 0, 255, 255); |
||||
hint.W = 50; |
||||
hint.H = 50; |
||||
rect.SetHintMin(hint); |
||||
rect.SetVisible(true); |
||||
table.Pack(rect, 2, 2, 1, 1); |
||||
|
||||
rect = new efl.canvas.RectangleConcrete(canvas); |
||||
rect.SetColor(255, 255, 0, 255); |
||||
rect.SetHintMin(hint); |
||||
rect.SetVisible(true); |
||||
table.Pack(rect, 2, 3, 1, 1); |
||||
|
||||
loop.Begin(); |
||||
|
||||
efl.All.Shutdown(); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,126 @@ |
||||
using System; |
||||
using System.Linq; |
||||
using System.Collections.Generic; |
||||
|
||||
static class Extensions |
||||
{ |
||||
public static IEnumerable<T> Circle<T>(this IEnumerable<T> list, int index=0) |
||||
{ |
||||
var count = list.Count(); |
||||
index = index % count; |
||||
|
||||
while (true) { |
||||
yield return list.ElementAt(index); |
||||
index = (index + 1) % count; |
||||
} |
||||
} |
||||
} |
||||
|
||||
class TestMain |
||||
{ |
||||
static int WIDTH = 320; |
||||
static int HEIGHT = 240; |
||||
|
||||
private EcoreEvas ecore_evas; |
||||
private efl.canvas.Object canvas; |
||||
private efl.canvas.Rectangle bg; |
||||
private evas.Text text; |
||||
private evas.Image border; |
||||
|
||||
public TestMain(String border_file) { |
||||
ecore_evas = new EcoreEvas(); |
||||
eina.Size2D size = new eina.Size2D(); |
||||
eina.Position2D position = new eina.Position2D(); |
||||
canvas = ecore_evas.canvas; |
||||
canvas.SetVisible(true); |
||||
|
||||
bg = new efl.canvas.RectangleConcrete(canvas); |
||||
bg.SetColor(255, 255, 255, 255); |
||||
position.X = 0; |
||||
position.Y = 0; |
||||
bg.SetPosition(position); |
||||
size.W = WIDTH; |
||||
size.H = HEIGHT; |
||||
bg.SetSize(size); |
||||
bg.SetVisible(true); |
||||
bg.SetKeyFocus(true); |
||||
|
||||
bg.KEY_DOWN += On_KeyDown; |
||||
|
||||
text = new evas.TextConcrete(canvas); |
||||
text.SetStyle(evas.Text_Style_Type.OutlineSoftShadow); |
||||
|
||||
text.SetColor(0, 0, 0, 255); |
||||
text.SetGlowColor(255, 0, 0, 255); |
||||
text.SetOutlineColor(0, 0, 255, 255); |
||||
text.SetShadowColor(0, 255,255, 255); |
||||
text.SetFont("Courier", 30); |
||||
|
||||
text.SetText("sample text"); |
||||
size.W = 3*WIDTH / 4; |
||||
size.H = HEIGHT / 4; |
||||
text.SetSize(size); |
||||
position.X = WIDTH / 8; |
||||
position.Y = 3 * HEIGHT / 8; |
||||
text.SetPosition(position); |
||||
text.SetVisible(true); |
||||
|
||||
efl.font.Size font_size = 0; |
||||
String font = String.Empty; |
||||
text.GetFont(out font, out font_size); |
||||
Console.WriteLine("Adding text object with font {0} and size {1}", font, size); |
||||
|
||||
// setup border |
||||
border = new evas.ImageConcrete(canvas); |
||||
border.SetFile(border_file, null); |
||||
border.SetBorder(3, 3, 3, 3); |
||||
border.SetBorderCenterFill(0); |
||||
|
||||
size.W = 3 * WIDTH / 4 + 3; |
||||
size.H = HEIGHT / 4 + 3; |
||||
border.SetSize(size); |
||||
position.X = WIDTH / 8 - 3; |
||||
position.Y = 3 * HEIGHT / 8 - 3; |
||||
border.SetPosition(position); |
||||
border.SetVisible(true); |
||||
|
||||
|
||||
} |
||||
|
||||
private void On_KeyDown(object sender, efl.input.KEY_DOWN_Args e) |
||||
{ |
||||
var key = e.arg.GetKey(); |
||||
|
||||
if (key == "h") { |
||||
Console.WriteLine(commands); |
||||
} else if (key == "t") { |
||||
evas.Text_Style_Type type = text.GetStyle(); |
||||
type = (evas.Text_Style_Type)(((int)type + 1) % 10); // 10 hardcoded from C example |
||||
text.SetStyle(type); |
||||
} |
||||
} |
||||
|
||||
static string commands = @"commands are:
|
||||
t - change text's current style |
||||
h - print help";
|
||||
|
||||
|
||||
static void Main(string[] args) |
||||
{ |
||||
efl.All.Init(); |
||||
|
||||
String border_path = "./src/examples/evas/resources/images/red.png"; |
||||
|
||||
if (args.Length >= 1) |
||||
border_path = args[0]; |
||||
|
||||
efl.Loop loop = new efl.LoopConcrete(); |
||||
TestMain t = new TestMain(border_path); |
||||
|
||||
loop.Begin(); |
||||
|
||||
efl.All.Shutdown(); |
||||
} |
||||
} |
||||
|
||||
|
Loading…
Reference in new issue