Skip to content

Commit

Permalink
More additions by @tomet slightly modified to match the library's style
Browse files Browse the repository at this point in the history
  • Loading branch information
pwiecz committed May 17, 2023
1 parent 3d09a1d commit 93b83da
Show file tree
Hide file tree
Showing 14 changed files with 238 additions and 45 deletions.
10 changes: 8 additions & 2 deletions drawings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ void go_fltk_color(unsigned int color) {
void go_fltk_set_draw_font(int font, int size) {
fl_font((Fl_Font)font, size);
}
int go_fltk_draw_font() {
return fl_font();
}
int go_fltk_draw_font_size() {
return fl_size();
}
void go_fltk_draw(const char* text, int x, int y, int w, int h, unsigned int align) {
fl_draw(text, x, y, w, h, (Fl_Align)align);
}
Expand Down Expand Up @@ -70,7 +76,7 @@ void go_fltk_draw_arrow(int x, int y, int w, int h, int arr, int orient, unsigne
Fl_Rect r{x, y, w, h};
fl_draw_arrow(r, (Fl_Arrow_Type)arr, (Fl_Orientation)orient, color);
}


void go_fltk_rect_with_color(int x, int y, int w, int h, unsigned int c) {
fl_rect(x, y, w, h, c);
}
Expand Down Expand Up @@ -455,4 +461,4 @@ void go_fltk_draw_text2(const char *str, int x, int y, int w, int h, int align)

void go_fltk_draw_check(int x, int y, int w, int h, unsigned int col) {
fl_draw_check(Fl_Rect(x, y, w, h), (Fl_Color)col);
}
}
14 changes: 9 additions & 5 deletions drawings.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func SetDrawFont(font Font, size int) {
C.go_fltk_set_draw_font(C.int(font), C.int(size))
}

func DrawFont() (Font, int) {
return Font(C.go_fltk_draw_font()), int(C.go_fltk_draw_font_size())
}

func PushClip(x, y, w, h int) {
C.go_fltk_push_clip(C.int(x), C.int(y), C.int(w), C.int(h))
}
Expand Down Expand Up @@ -65,11 +69,11 @@ func DrawRectf(x, y, w, h int) {
func DrawRectfWithColor(x, y, w, h int, col Color) {
C.go_fltk_rectf_with_color(C.int(x), C.int(y), C.int(w), C.int(h), C.uint(col))
}

func DrawArrow(x, y, w, h int, arr ArrowType, orient Orientation, col Color) {
C.go_fltk_draw_arrow(C.int(x), C.int(y), C.int(w), C.int(h), C.int(arr), C.int(orient), C.uint(col))
}


func DrawArrow(x, y, w, h int, arr ArrowType, orient Orientation, col Color) {
C.go_fltk_draw_arrow(C.int(x), C.int(y), C.int(w), C.int(h), C.int(arr), C.int(orient), C.uint(col))
}

func DrawLine(x, y, x1, y1 int) {
C.go_fltk_line(C.int(x), C.int(y), C.int(x1), C.int(y1))
}
Expand Down
6 changes: 4 additions & 2 deletions drawings.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ extern "C" {

extern void go_fltk_color(unsigned int color);
extern void go_fltk_set_draw_font(int font, int size);
extern int go_fltk_draw_font();
extern int go_fltk_draw_font_size();
extern void go_fltk_draw(const char* text, int x, int y, int w, int h, unsigned int align);
extern void go_fltk_draw_box(int boxType, int x, int y, int w, int h, unsigned int color);
extern void go_fltk_push_clip(int x, int y, int w, int h);
Expand All @@ -26,8 +28,8 @@ extern "C" {
extern void go_fltk_rectf(int x, int y, int w, int h);
extern void go_fltk_rectf_with_color(int x, int y, int w, int h, unsigned int c);
extern void go_fltk_rectf_with_rgb(int x, int y, int w, int h, unsigned char r, unsigned char g,
unsigned char b);
extern void go_fltk_draw_arrow(int x, int y, int w, int h, int arr, int orient, unsigned int color);
unsigned char b);
extern void go_fltk_draw_arrow(int x, int y, int w, int h, int arr, int orient, unsigned int color);
extern void go_fltk_line(int x, int y, int x1, int y1);
extern void go_fltk_line2(int x, int y, int x1, int y1, int x2, int y2);
extern void go_fltk_loop(int x, int y, int x1, int y1, int x2, int y2);
Expand Down
3 changes: 3 additions & 0 deletions enumerations.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ const int go_FL_F9 = FL_F + 9;
const int go_FL_F10 = FL_F + 10;
const int go_FL_F11 = FL_F + 11;
const int go_FL_F12 = FL_F + 12;
const int go_FL_DELETE = FL_Delete;
const int go_FL_BACKSPACE = FL_BackSpace;
const int go_FL_INSERT = FL_Insert;

const int go_FL_RGB = FL_RGB;
const int go_FL_INDEX = FL_INDEX;
Expand Down
21 changes: 12 additions & 9 deletions enumerations.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ var (
type Orientation int

var (
ORIENT_NONE = Orientation(C.go_FL_ORIENT_NONE)
ORIENT_RIGHT = Orientation(C.go_FL_ORIENT_RIGHT)
ORIENT_NE = Orientation(C.go_FL_ORIENT_NE)
ORIENT_UP = Orientation(C.go_FL_ORIENT_UP)
ORIENT_NW = Orientation(C.go_FL_ORIENT_NW)
ORIENT_LEFT = Orientation(C.go_FL_ORIENT_LEFT)
ORIENT_SW = Orientation(C.go_FL_ORIENT_SW)
ORIENT_DOWN = Orientation(C.go_FL_ORIENT_DOWN)
ORIENT_SE = Orientation(C.go_FL_ORIENT_SE)
ORIENT_NONE = Orientation(C.go_FL_ORIENT_NONE)
ORIENT_RIGHT = Orientation(C.go_FL_ORIENT_RIGHT)
ORIENT_NE = Orientation(C.go_FL_ORIENT_NE)
ORIENT_UP = Orientation(C.go_FL_ORIENT_UP)
ORIENT_NW = Orientation(C.go_FL_ORIENT_NW)
ORIENT_LEFT = Orientation(C.go_FL_ORIENT_LEFT)
ORIENT_SW = Orientation(C.go_FL_ORIENT_SW)
ORIENT_DOWN = Orientation(C.go_FL_ORIENT_DOWN)
ORIENT_SE = Orientation(C.go_FL_ORIENT_SE)
)

type BoxType int
Expand Down Expand Up @@ -387,4 +387,7 @@ var (
F10 = int(C.go_FL_F10)
F11 = int(C.go_FL_F11)
F12 = int(C.go_FL_F12)
DELETE = int(C.go_FL_DELETE)
BACKSPACE = int(C.go_FL_BACKSPACE)
INSERT = int(C.go_FL_INSERT)
)
3 changes: 3 additions & 0 deletions enumerations.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ extern "C" {
extern const int go_FL_F10;
extern const int go_FL_F11;
extern const int go_FL_F12;
extern const int go_FL_DELETE;
extern const int go_FL_BACKSPACE;
extern const int go_FL_INSERT;

extern const int go_FL_RGB;
extern const int go_FL_INDEX;
Expand Down
2 changes: 1 addition & 1 deletion event_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class EventHandler : public BaseWidget, public WidgetWithEventHandler, public Wi
if (m_eventHandlerId >= 0) {
const int ret = _go_eventHandler(m_eventHandlerId, event);
if (ret != 0) {
return ret;
return ret;
}
}
return BaseWidget::handle(event);
Expand Down
18 changes: 18 additions & 0 deletions image.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,24 @@ func NewRgbImageFromSvg(img *SvgImage) (*RgbImage) {
return rgbImage
}

func NewRgbImageFromPng(img *PngImage) (*RgbImage) {
rgbImage := &RgbImage{}
rgbImage.image = img.image
return rgbImage
}

func NewRgbImageFromBmp(img *BmpImage) (*RgbImage) {
rgbImage := &RgbImage{}
rgbImage.image = img.image
return rgbImage
}

func NewRgbImageFromJpeg(img *JpegImage) (*RgbImage) {
rgbImage := &RgbImage{}
rgbImage.image = img.image
return rgbImage
}

func NewRgbImageFromImage(image goimage.Image) (*RgbImage, error) {
rgbImage := &RgbImage{}
var w, h, stride, depth int
Expand Down
55 changes: 52 additions & 3 deletions text.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
#include <FL/Fl_Text_Buffer.H>

#include "event_handler.h"
#include "_cgo_export.h"


// --- Text Display ---

class GText_Display : public EventHandler<Fl_Text_Display> {
public:
GText_Display(int x, int y, int w, int h, const char* label)
: EventHandler<Fl_Text_Display>(x, y, w, h, label) {}
GText_Display(int x, int y, int w, int h, const char *label)
: EventHandler<Fl_Text_Display>(x, y, w, h, label) {}

// make xy_to_position() public
int xy_to_position(int x, int y) {
return EventHandler<Fl_Text_Display>::xy_to_position(x, y);
}
};

GText_Display *go_fltk_new_TextDisplay(int x, int y, int w, int h, const char *text) {
Expand All @@ -27,6 +35,14 @@ void go_fltk_TextDisplay_set_wrap_mode(Fl_Text_Display *d, int wrap, int wrapMar
d->wrap_mode(wrap, wrapMargin);
}

int go_fltk_TextDisplay_xy_to_position(Fl_Text_Display *d, int x, int y) {
return ((GText_Display*) d)->xy_to_position(x, y);
}

int go_fltk_TextDisplay_position_to_xy(Fl_Text_Display *d, int pos, int *x, int *y) {
return d->position_to_xy(pos, x, y);
}

int go_fltk_TextDisplay_move_right(Fl_Text_Display *d) {
return d->move_right();
}
Expand All @@ -47,6 +63,10 @@ void go_fltk_TextDisplay_show_insert_position(Fl_Text_Display *d) {
d->show_insert_position();
}

void go_fltk_TextDisplay_hide_cursor(Fl_Text_Display *d) {
d->hide_cursor();
}

unsigned int go_fltk_TextDisplay_text_color(Fl_Text_Display *d) {
return d->textcolor();
}
Expand Down Expand Up @@ -83,6 +103,8 @@ void go_fltk_TextDisplay_overstrike(Fl_Text_Display *d, const char* text) {
d->overstrike(text);
}

// --- Text Editor ---

class GText_Editor : public EventHandler<Fl_Text_Editor> {
public:
GText_Editor(int x, int y, int w, int h, const char* label)
Expand Down Expand Up @@ -117,6 +139,13 @@ void go_fltk_TextEditor_select_all(Fl_Text_Editor *e) {
Fl_Text_Editor::kf_select_all(0, e);
}

// --- Text Buffer ---

void modify_callback_handler(int pos, int nInserted, int nDeleted, int nRestyled, const char *deletedText, void *cbArg) {
uintptr_t id = (uintptr_t)cbArg;
_go_modifyCallbackHandler(id, pos, nInserted, nDeleted, nRestyled, (char*)deletedText);
}

Fl_Text_Buffer *go_fltk_new_TextBuffer(void) {
return new Fl_Text_Buffer;
}
Expand All @@ -125,6 +154,10 @@ void go_fltk_TextBuffer_delete(Fl_Text_Buffer* b) {
delete b;
}

void go_fltk_TextBuffer_add_modify_callback(Fl_Text_Buffer *b, uintptr_t handlerId) {
b->add_modify_callback(modify_callback_handler, (void*)handlerId);
}

void go_fltk_TextBuffer_set_text(Fl_Text_Buffer *b, const char *txt) {
b->text(txt);
}
Expand All @@ -133,6 +166,22 @@ void go_fltk_TextBuffer_append(Fl_Text_Buffer *b, const char *txt) {
b->append(txt);
}

unsigned int go_fltk_TextBuffer_char_at(Fl_Text_Buffer *b, int pos) {
return b->char_at(pos);
}

int go_fltk_TextBuffer_next_char(Fl_Text_Buffer *b, int ix) {
return b->next_char(ix);
}

int go_fltk_TextBuffer_prev_char(Fl_Text_Buffer *b, int ix) {
return b->prev_char(ix);
}

int go_fltk_TextBuffer_length(Fl_Text_Buffer *b) {
return b->length();
}

const char *go_fltk_TextBuffer_text(Fl_Text_Buffer *b) {
return b->text();
}
Expand Down Expand Up @@ -202,4 +251,4 @@ void go_fltk_TextDisplay_set_highlight_data(Fl_Text_Display *self, Fl_Text_Buffe
stable[i] = (Fl_Text_Display::Style_Table_Entry){color[i], font[i], fontsz[i], attr[i], bgcolor[i]};
}
self->highlight_data(sbuff, stable, sz, 'A', 0, 0);
}
}

0 comments on commit 93b83da

Please sign in to comment.