Skip to content

Commit

Permalink
bkp
Browse files Browse the repository at this point in the history
  • Loading branch information
cancerberoSgx committed Nov 20, 2019
1 parent 6438662 commit a8f9668
Show file tree
Hide file tree
Showing 8 changed files with 356 additions and 23 deletions.
28 changes: 14 additions & 14 deletions apps/node-gtk-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apps/node-gtk-tests/src/inspect.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//@ts-ignore
import { GiInfo as GiInfoNative} from 'node-gtk'
import { Type, Parsed, ParsedBase, Function, Vfunc, Constant, Property, Argument, Field, Struct, Enum, Interface, ParsedObject, Entity, Signal } from "./typeGenerationTypes";
// import * as nodeGtk from './gobjectTypes'
import { array } from 'misc-utils-of-mine-generic'
import { readdirSync } from 'fs';
//@ts-ignore
import * as nodeGtk from 'node-gtk'

interface GiInfo extends GiInfoNative {
Expand Down
13 changes: 8 additions & 5 deletions apps/node-gtk-tests/src/typeGenerationTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TODO } from 'misc-utils-of-mine-generic'
//@ts-ignore
import { GiInfo } from 'node-gtk'

export interface ParsedBase {
Expand All @@ -11,6 +12,7 @@ export interface Parsed extends ParsedBase {
// _info: Info;
// _type: number;
infoType: string;
gtype: number;
_flags: number;
is_gtype_struct: boolean;
is_foreign: boolean;
Expand All @@ -28,18 +30,20 @@ export interface Parent extends ParsedBase {
export interface Entity extends Parsed {
prerequisites: Prerequisite[];
properties: Property[];
gtype: any;
methods: Function[];
type: Type;
fields: Field[];
constructor: TODO;
// constructor: TODO;
interfaces: Interface[];
signals: Signal[];
vfuncs: Vfunc[];
constants: Constant[];
_typeInfo: GiInfo;
transfer: string;
_parent: Parent;

return_tag: any;
return_type: Type;
}
export interface Prerequisite extends Entity {
}
Expand Down Expand Up @@ -75,13 +79,12 @@ export interface Function extends Entity {
canThrow: boolean;
skipReturn: boolean;
mayReturnNull: boolean;
return_tag: any;
return_type: Type;
n_args: 0;
symbol: string;
writable: boolean; //TODO: field.callback
args: Argument[];
// TODO: add as a global function too.!
symbol: string;

isMethod: boolean;
isConstructor: boolean;
isGetter: boolean;
Expand Down
2 changes: 1 addition & 1 deletion apps/node-gtk-tests/test/nativesTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'ava'
const nodegtk = require('node-gtk');

test('node-gtk publics & GObject', async t => {
const Gtk = nodegtk.require('Gtk', '3.0')
const Gtk = nodegtk.require('Gtk')
const GObject = nodegtk.require('GObject')
nodegtk.startLoop();
Gtk.init()
Expand Down
116 changes: 116 additions & 0 deletions apps/node-gtk-tests/test/probes/hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/* hello world for gtk with cairo support, by Øvyind Kolås
*/

#include <gtk/gtk.h>
#include <cairo.h>

#define DEFAULT_WIDTH 400
#define DEFAULT_HEIGHT 200

/* forward definition of actual painting function for our drawing area widget
*/
static void paint (GtkWidget *widget,
GdkEventExpose *eev,
gpointer data);

gint
main (gint argc,
gchar **argv)
{
GtkWidget *window;
GtkWidget *canvas;

gtk_init (&argc, &argv);

/* create a new top level window
*/
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

/* make the gtk terminate the process the close button is pressed
*/
g_signal_connect (G_OBJECT (window), "delete-event",
G_CALLBACK (gtk_main_quit), NULL);

/* create a new drawing area widget
*/
canvas = gtk_drawing_area_new ();

/* set a requested (minimum size) for the canvas
*/
gtk_widget_set_size_request (canvas, DEFAULT_WIDTH, DEFAULT_HEIGHT);

/* connect our drawing method to the "expose" signal
*/
g_signal_connect (G_OBJECT (canvas), "expose-event",
G_CALLBACK (paint),
NULL /*< here we can pass a pointer to a custom data structure */
);

/* pack canvas widget into window
*/
gtk_container_add (GTK_CONTAINER (window), canvas);

/* show window and all it's children (just the canvas widget)
*/
gtk_widget_show_all (window);

/* enter main loop
*/
gtk_main ();
return 0;
}


/* the actual function invoked to paint the canvas
* widget, this is where most cairo painting functions
* will go
*/
static void
paint (GtkWidget *widget,
GdkEventExpose *eev,
gpointer data)
{
gint width, height;
gint i;
cairo_t *cr;

width = widget->allocation.width;
height = widget->allocation.height;

cr = gdk_cairo_create (widget->window);

/* clear background */
cairo_set_source_rgb (cr, 1,1,1);
cairo_paint (cr);


cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_BOLD);

/* enclosing in a save/restore pair since we alter the
* font size
*/
cairo_save (cr);
cairo_set_font_size (cr, 40);
cairo_move_to (cr, 40, 60);
cairo_set_source_rgb (cr, 0,0,0);
cairo_show_text (cr, "Hello World");
cairo_restore (cr);

cairo_set_source_rgb (cr, 1,0,0);
cairo_set_font_size (cr, 20);
cairo_move_to (cr, 50, 100);
cairo_show_text (cr, "greetings from gtk and cairo");

cairo_set_source_rgb (cr, 0,0,1);

cairo_move_to (cr, 0, 150);
for (i=0; i< width/10; i++)
{
cairo_rel_line_to (cr, 5, 10);
cairo_rel_line_to (cr, 5, -10);
}
cairo_stroke (cr);

cairo_destroy (cr);
}
Loading

0 comments on commit a8f9668

Please sign in to comment.