<commit_before>//
//  Display.c
//  nanoVGTest3
//
//  Created by <NAME> on 27/04/2017.
//  Copyright © 2017 Unlimited Development. All rights reserved.
//

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>

#include "Display.h"
#include "piGL.h"

static int get_mouse( PiGLState *state, int *outx, int *outy);

int DisplayInit( Display *disp ,int width , int height)
{
     bcm_host_init();
    assert(disp);
    
    if( disp)
    {
        disp->type = DisplayUnknown;


	disp->_handle = malloc(sizeof(PiGLState));
	assert( disp->_handle );
	
	if( disp->_handle == NULL)
	    return 0;

    PiGLState* state = (PiGLState*)disp->_handle ;
    state->screen_width = width;
    state->screen_height = height;
        
	init_ogl(  state );
	disp->type = DisplayDispman;

        return disp->_handle != NULL;
    }
    return 0;
}

int DisplayRelease( Display *disp)
{
    assert(disp);

    if( disp->_handle)
    {
	free(disp->_handle);
    }
    return 1;
}

void DisplayMakeContextCurrent( Display *disp)
{
    assert(disp);
    assert(disp->_handle);
    PiGLState* state = (PiGLState*) disp->_handle;
    // connect the context to the surface
    EGLBoolean result = eglMakeCurrent(state->display, state->surface, state->surface, state->context);
    assert(EGL_FALSE != result);

}

void DisplaySwap( const Display* disp)
{
    assert(disp);
    assert(disp->_handle);
    PiGLState* state = (PiGLState*) disp->_handle;
    eglSwapBuffers( state->display, state->surface);
}

void DisplayGetWindowSize( const Display* disp, int* width, int* height)
{
    assert(disp);
    assert(disp->_handle);
    PiGLState* state = (PiGLState*) disp->_handle;
	
    *width = state->screen_width;
    *height = state->screen_height;
}

void DisplayGetFramebufferSize( const Display* disp, int* width, int* height)
{
    assert(disp);
    assert(disp->_handle);
    
    DisplayGetWindowSize( disp , width , height);
}

int DisplayShouldClose( const Display* disp)
{
    assert(disp);
    assert(disp->_handle);
    return 0;
}

void DisplaySetShouldClose( Display* disp , int value)
{
    assert(disp);
    assert(disp->_handle);
}

void DisplayPollEvents( const Display *disp)
{
    if( disp->eventListener)
    {
        PiGLState* state = (PiGLState*) disp->_handle;
        int x = -1;
        int y = -1;
        
        const int mouseState = get_mouse( state , &x  ,&y);
        printf("Mouse Pos %i %i state %i \n" , x , y , mouseState);
	
	GXEventMouse mouseEv;
        mouseEv.type = GXEventTypeMouse;<commit_msg>Dispman update<commit_after>//
//  Display.c
//  nanoVGTest3
//
//  Created by <NAME> on 27/04/2017.
//  Copyright © 2017 Unlimited Development. All rights reserved.
//

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>

#include "Display.h"
#include "piGL.h"

static int get_mouse( PiGLState *state, int *outx, int *outy);

int DisplayInit( Display *disp ,int width , int height)
{
     bcm_host_init();
    assert(disp);
    
    if( disp)
    {
        disp->type = DisplayUnknown;


	disp->_handle = malloc(sizeof(PiGLState));
	assert( disp->_handle );
	
	if( disp->_handle == NULL)
	    return 0;

    PiGLState* state = (PiGLState*)disp->_handle ;
    state->screen_width = width;
    state->screen_height = height;
        
	init_ogl(  state );
	disp->type = DisplayDispman;

        return disp->_handle != NULL;
    }
    return 0;
}

int DisplayRelease( Display *disp)
{
    assert(disp);

    if( disp->_handle)
    {
	free(disp->_handle);
    }
    return 1;
}

void DisplayMakeContextCurrent( Display *disp)
{
    assert(disp);
    assert(disp->_handle);
    PiGLState* state = (PiGLState*) disp->_handle;
    // connect the context to the surface
    EGLBoolean result = eglMakeCurrent(state->display, state->surface, state->surface, state->context);
    assert(EGL_FALSE != result);

}

void DisplaySwap( const Display* disp)
{
    assert(disp);
    assert(disp->_handle);
    PiGLState* state = (PiGLState*) disp->_handle;
    eglSwapBuffers( state->display, state->surface);
}

void DisplayGetWindowSize( const Display* disp, int* width, int* height)
{
    assert(disp);
    assert(disp->_handle);
    PiGLState* state = (PiGLState*) disp->_handle;
	
    *width = state->screen_width;
    *height = state->screen_height;
}

void DisplayGetFramebufferSize( const Display* disp, int* width, int* height)
{
    assert(disp);
    assert(disp->_handle);
    
    DisplayGetWindowSize( disp , width , height);
}

int DisplayShouldClose( const Display* disp)
{
    assert(disp);
    assert(disp->_handle);
    return 0;
}

void DisplaySetShouldClose( Display* disp , int value)
{
    assert(disp);
    assert(disp->_handle);
}

void DisplayPollEvents( const Display *disp)
{
    if( disp->eventListener)
    {
        PiGLState* state = (PiGLState*) disp->_handle;
        int x = -1;
        int y = -1;
        
        const int mouseState = get_mouse( state , &x  ,&y);
        //printf("Mouse Pos %i %i state %i \n" , x , y , mouseState);
	
        GXEventMouse mouseEv;
        mouseEv.type = GXEventTypeMouse;
{'fraction_non_alphanumeric': 0.13848568065908198, 'fraction_numerical': 0.00745390349156532, 'mean_word_length': 3.043616177636796, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2618321', 'n_tokens_mistral': 1741, 'n_tokens_neox': 1677, 'n_words': 426}