B4R Question Call C Function

Discussion in 'B4R Questions' started by Hypnos, May 7, 2018.

  1. Hypnos

    Hypnos Active Member Licensed User

    I have some inline C code in my BR4 project:

    Code:
    void drawRect(B4R::Object* o)
    {
       B4R::B4RAdafruitGFX* bgfx = (B4R::B4RAdafruitGFX*)o->data.PointerField;
       bgfx->gfx->drawRect(b4r_main::_cx, b4r_main::_cy, b4r_main::_cw, b4r_main::_ch, b4r_main::_ccolor);
    }

    my question is: how can I call the drawRect function within the inline C ?

    can I use : drawRect();

    Maybe it's a simple question, but for me, I got headache eveytime when I handle inline C ..... Thanks!
     
  2. Cableguy

    Cableguy Expert Licensed User

  3. tigrot

    tigrot Well-Known Member Licensed User

    Code:
    RunNative("drawRect",null)
    Since you have not to pass parameters use null as second parameters in RunNative.
     
    Hypnos likes this.
  4. Hypnos

    Hypnos Active Member Licensed User

    Thanks tigrot!
    but maybe my question is not clear, I understand the RunNative command, but for some reason I have to call it inside the inline C code, mean that I need the c syntax to call the drawRect function.

    Hope that you understand what I mean. (It’s a bit difficult for me to write in English....)

    Thanks!

    Example:
    Code:
    B4R:
    RunNative (
    "drawAll",Null)

    Inline C Code:
    void drawRect(B4R::Object* o)
    {
       B4R::B4RAdafruitGFX* bgfx = (B4R::B4RAdafruitGFX*)o->data.PointerField;
       bgfx->gfx->drawRect(b4r_main::_cx, b4r_main::_cy, b4r_main::_cw, b4r_main::_ch, b4r_main::_ccolor);
    }

    void drawAll(B4R::Object* o)
    {
    drawRect (null);  ??? <-- I need to correct syntax
    drawCircle(null);  ???
    drawLine(null);  ???
    }
     
    Last edited: May 7, 2018
  5. Erel

    Erel Administrator Staff Member Licensed User

    Try:
    Code:
    b4r_main::_drawRect(o);
    Why do you need it?
     
    Hypnos likes this.
  6. Hypnos

    Hypnos Active Member Licensed User

    Thank you Erel!

    My case:

    - I find a code in C can extract the pixel information from a 12x12 Chinese Font file
    - I have to pass those info to GFX and use the drawPixel / drawRect command to plot the character to the LCD screen

    I think it should have some better / direct method for the solution, but it's more easy for me to use the "Call" function.
    (as I can't read/write C code, it's the most easy way for me...)

    Here is the result:

     
    Last edited: May 8, 2018
    tigrot, Erel and Cableguy like this.
Loading...