def makeform(self):
     label = ["Red", "Green", "Blue"]
     col = [xfl.FL_RED, xfl.FL_GREEN, xfl.FL_BLUE]
     y = 70
     self.pform = xfl.fl_bgn_form(xfl.FL_UP_BOX, 300, 330)
     pobj = xfl.fl_add_button(xfl.FL_NORMAL_BUTTON, 45, 15, \
             210, 45, "Color Editor")
     xfl.fl_set_object_lsize(pobj, xfl.FL_LARGE_SIZE)
     for i in range (0, 3):
         self.pdials[i] = xfl.fl_add_dial(xfl.FL_NORMAL_DIAL, 30, y, \
                 60, 60, label[i])
         xfl.fl_set_object_boxtype(self.pdials[i], xfl.FL_UP_BOX)
         xfl.fl_set_dial_bounds(self.pdials[i], 0.0, 255.0)
         xfl.fl_set_dial_value(self.pdials[i], 128.0)
         xfl.fl_set_object_color(self.pdials[i], col[i], xfl.FL_DIAL_COL2)
         xfl.fl_set_object_callback(self.pdials[i], self.cb, i)
         xfl.fl_set_object_return(self.pdials[i], xfl.FL_RETURN_CHANGED)
         self.ptexts[i] = xfl.fl_add_box(xfl.FL_DOWN_BOX, 105, y + 17, \
                 50, 25, "128")
         y += 85
     self.presult = xfl.fl_add_box(xfl.FL_DOWN_BOX, 180, 70, 90, 245, "")
     xfl.fl_set_object_color(self.presult, xfl.FL_FREE_COL1, \
             xfl.FL_FREE_COL1)
     xfl.fl_mapcolor(xfl.FL_FREE_COL1, 128, 128, 128)
     xfl.fl_set_object_dblbuffer(self.presult, 1)    # to avoid flicker
     xfl.fl_end_form()
 def __init__(self, lsysargv, sysargv):
     self.dcol = 1
     self.on = 1
     xfl.fl_initialize(lsysargv, sysargv, "FormDemo", None, 0)
     pform = xfl.fl_bgn_form(xfl.FL_UP_BOX, 400, 400)
     pobj1 = xfl.fl_add_button(xfl.FL_NORMAL_BUTTON, 320, 20, 40, 30, \
             "Exit")
     xfl.fl_set_object_callback(pobj1, self.done, 0)
     pobj2 = xfl.fl_add_free(xfl.FL_CONTINUOUS_FREE, 40, 80, 320, 280, \
             "", self.handle_free1)
     xfl.fl_end_form()
     depth  = xfl.fl_get_visual_depth()
     if depth < 4:   # Can't do it if less than 4 bit deep...
         print("This Demo requires a depth of at least 4 bits\n")
         xfl.fl_finish()
         sys.exit(1)
     elif depth > 7:     # ...but too large a depth also won't do
         depth = 7
     self.cole = (1 << depth) - 1
     if self.cole > 64:
         self.cole = 64
     pobj2.contents.u_ldata = col = xfl.FL_FREE_COL1
     self.cole += col
     for i in range(col, self.cole + 1):
         j =  255 * (i - col) / (self.cole - col)
         xfl.fl_mapcolor(i, j, j, j)
     xfl.fl_show_form(pform, xfl.FL_PLACE_CENTER, xfl.FL_NOBORDER, \
             "Free Object")
     xfl.fl_do_forms()
def draw_initialize(ui):
    global cur_fig
    xfl.fl_set_form_minsize(ui.drawfree, 530, 490)
    xfl.fl_set_object_gravity(ui.colgrp, xfl.FL_West, xfl.FL_West)
    xfl.fl_set_object_gravity(ui.sizegrp, xfl.FL_SouthWest, xfl.FL_SouthWest)
    xfl.fl_set_object_gravity(ui.figgrp, xfl.FL_NorthWest, xfl.FL_NorthWest)
    xfl.fl_set_object_gravity(ui.miscgrp, xfl.FL_South, xfl.FL_South)
    xfl.fl_set_object_resize(ui.miscgrp, xfl.FL_RESIZE_NONE)
    cur_fig = saved_figure[0]
    cur_fig.c[0] = cur_fig.c[1] = cur_fig.c[2] = 127
    cur_fig.w = cur_fig.h = 30
    cur_fig.drawit = xfl.fl_oval
    cur_fig.fill = 1
    cur_fig.col = xfl.FL_FREE_COL1 + 1
    xfl.fl_mapcolor(xfl.FL_FREE_COL1, \
            cur_fig.c[0], cur_fig.c[1], cur_fig.c[2])
    xfl.fl_mapcolor(cur_fig.col, \
            cur_fig.c[0], cur_fig.c[1], cur_fig.c[2])
    xfl.fl_set_slider_bounds(ui.wsli, 1, max_w)
    xfl.fl_set_slider_bounds(ui.hsli, 1, max_h)
    xfl.fl_set_slider_precision(ui.wsli, 0)
    xfl.fl_set_slider_precision(ui.hsli, 0)
    xfl.fl_set_slider_value(ui.wsli, cur_fig.w)
    xfl.fl_set_slider_value(ui.hsli, cur_fig.h)
    # color sliders
    xfl.fl_set_slider_bounds(ui.rsli, 1.0, 0)
    xfl.fl_set_slider_bounds(ui.gsli, 1.0, 0)
    xfl.fl_set_slider_bounds(ui.bsli, 1.0, 0)
    # initial drawing function
    xfl.fl_set_button(ui.drobj[0], 1)
 def cb(self, pobj, data):
     self.cols[data] = xfl.fl_get_dial_value(pobj)
     xfl.fl_mapcolor(xfl.FL_FREE_COL1, self.cols[0], self.cols[1], \
             self.cols[2])
     xfl.fl_redraw_object(self.presult)
     strng = "%d" % self.cols[data]
     xfl.fl_set_object_label(self.ptexts[data], strng)
def change_color(pobj, which):
    global cur_fig
    cur_fig.c[which] = xfl.fl_get_slider_value(pobj) * 255.01
    xfl.fl_mapcolor(cur_fig.col, cur_fig.c[0], cur_fig.c[1], cur_fig.c[2])
    xfl.fl_mapcolor(xfl.FL_FREE_COL1, cur_fig.c[0], cur_fig.c[1], \
            cur_fig.c[2])
    xfl.fl_redraw_object(drawui.colorobj)
 def color_callback(self, pobj, pvdata):
     ldata = xfl.fls_convert_ptrvoid_to_ptrlongc(pvdata).contents.value
     self.r = int(255 * xfl.fl_get_slider_value(self.predsl))
     self.g = int(255 * xfl.fl_get_slider_value(self.pgreensl))
     self.b = int(255 * xfl.fl_get_slider_value(self.pbluesl))
     xfl.fl_mapcolor(xfl.FL_FREE_COL1, self.r, self.g, self.b)
     xfl.fl_redraw_object(self.pcolorobj)
 def dial_callback(self, pobj, arg):
     clr = [0, 1, 2]
     for i in range(RED, BLUE + 1):
         clr[i] = xfl.fl_get_dial_value(self.pdial[i])
     strng = "%d" % clr[arg]
     xfl.fl_set_object_label(self.ptext[arg], strng)
     xfl.fl_mapcolor(xfl.FL_FREE_COL1, clr[0], clr[1], clr[2])
     xfl.fl_redraw_object(self.presult)
 def init_colorpart(self):
     self.create_colorform()
     xfl.fl_set_form_callback(self.pcolorform, self.color_callback, 0)
     xfl.fl_set_form_position(self.pcolorform, 20, \
             -300 - self.pcolorform.contents.h)
     xfl.fl_show_form(self.pcolorform, xfl.FL_PLACE_GEOMETRY, \
             xfl.FL_TRANSIENT, "Color")
     xfl.fl_mapcolor(xfl.FL_FREE_COL1, self.r, self.g, self.b)
     xfl.fl_redraw_object(self.pcolorobj)
 def set_entry(self, i):
     #RGBdb *db = rgbdb + i;
     #print("i", i, "rgbdb[i].r", self.rgbdb[i]['r'], "rgbdb[i].g",
     #        self.rgbdb[i]['g'], "rgbdb[i].b",  self.rgbdb[i]['b'])
     xfl.fl_freeze_form(self.pcl)
     xfl.fl_mapcolor(xfl.FL_FREE_COL4 + i, self.rgbdb[i]['r'], \
             self.rgbdb[i]['g'], self.rgbdb[i]['b'])
     xfl.fl_mapcolor(xfl.FL_FREE_COL4, self.rgbdb[i]['r'], \
             self.rgbdb[i]['g'], self.rgbdb[i]['b'])
     xfl.fl_set_slider_value(self.prs, self.rgbdb[i]['r'])
     xfl.fl_set_slider_value(self.pgs, self.rgbdb[i]['g'])
     xfl.fl_set_slider_value(self.pbs, self.rgbdb[i]['b'])
     #xfl.fl_redraw_object(self.prescol)
     xfl.fl_unfreeze_form(self.pcl)
 def search_rgb(self, pobj, q):
     top = xfl.fl_get_browser_topline(self.pcolbr)
     r = int(xfl.fl_get_slider_value(self.prs))
     g = int(xfl.fl_get_slider_value(self.pgs))
     b = int(xfl.fl_get_slider_value(self.pbs))
     xfl.fl_freeze_form(self.pcl)
     xfl.fl_mapcolor(xfl.FL_FREE_COL4, r, g, b)
     #xfl.fl_redraw_object(self.prescol)
     i = self.search_entry(r, g, b)
     # change topline only if necessary
     if i < top or i > (top + 15):
         xfl.fl_set_browser_topline(self.pcolbr, i - 8)
     xfl.fl_select_browser_line(self.pcolbr, i + 1)
     xfl.fl_unfreeze_form(self.pcl)
 def makeform(self):
     txt = ["Red", "Green", "Blue"]
     clr = [xfl.FL_RED, xfl.FL_GREEN, xfl.FL_BLUE]
     self.pform = xfl.fl_bgn_form(xfl.FL_UP_BOX, 300, 330)
     pquit = xfl.fl_add_button(xfl.FL_NORMAL_BUTTON, 45, 15, 210, 45, "A Color Editor")
     xfl.fl_set_object_lsize(pquit, xfl.FL_LARGE_SIZE)
     for i in range(RED, BLUE + 1):
         self.pdial[i] = xfl.fl_add_dial(xfl.FL_LINE_DIAL, 30, 240 - i * 85, 60, 60, txt[i])
         xfl.fl_set_dial_bounds(self.pdial[i], 0.0, 255.0)
         xfl.fl_set_dial_angles(self.pdial[i], 15.0, 345.0)
         xfl.fl_set_dial_value(self.pdial[i], 128.0)
         xfl.fl_set_object_color(self.pdial[i], clr[i], xfl.FL_DIAL_COL2)
         xfl.fl_set_object_return(self.pdial[i], xfl.FL_RETURN_CHANGED)
         xfl.fl_set_object_callback(self.pdial[i], self.dial_callback, i)
         self.ptext[i] = xfl.fl_add_box(xfl.FL_DOWN_BOX, 105, 255 - i * 85, 50, 25, "128")
     self.presult = xfl.fl_add_box(xfl.FL_DOWN_BOX, 180, 70, 90, 245, "")
     xfl.fl_mapcolor(xfl.FL_FREE_COL1, 128, 128, 128)
     xfl.fl_set_object_color(self.presult, xfl.FL_FREE_COL1, xfl.FL_FREE_COL1)
     xfl.fl_set_object_dblbuffer(self.presult, 1)
     xfl.fl_end_form()
 def drawit(self, stobj):
     xfl.fl_winset(self.main_win)
     xfl.fl_mapcolor(xfl.FL_FREE_COL1, stobj.r, \
                 stobj.g, stobj.b)
     if stobj.type == 1:
         xfl.fl_rectf(stobj.x - stobj.size, \
                 stobj.y - stobj.size, 2 * stobj.size, \
                 2 * stobj.size, xfl.FL_FREE_COL1)
     elif stobj.type == 2:
         xfl.fl_circf(stobj.x, stobj.y, stobj.size, \
                 xfl.FL_FREE_COL1)
     elif stobj.type == 3:
         mylistpoint = [ \
                 {'x':int(stobj.x - stobj.size), \
                 'y':int(stobj.y + stobj.size)}, \
                 {'x':int(stobj.x + stobj.size), \
                 'y':int(stobj.y + stobj.size)}, \
                 {'x':int(stobj.x), \
                 'y':int(stobj.y - stobj.size)}]
         pxpoint = xfl.fls_make_ptr_flpoint(mylistpoint)
         xfl.fl_polyf(pxpoint, 3, xfl.FL_FREE_COL1)
def freeobject_handler(pobj, event, mx, my, key, pxev):
    #DrawFigure *dr;
    if event == xfl.FL_DRAW:
        if cur_fig.newfig == 1:
            cur_fig.drawit(cur_fig.fill, cur_fig.x + pobj.contents.x, \
                    cur_fig.y + pobj.contents.y, cur_fig.w, cur_fig.h, \
                    cur_fig.col)
        else:
            xfl.fl_drw_box(pobj.contents.boxtype, pobj.contents.x, \
                    pobj.contents.y, pobj.contents.w, pobj.contents.h, \
                    pobj.contents.col1, pobj.contents.bw)
            #for ( dr = saved_figure; dr < cur_fig; dr++ )
            ndr = 0
            for ndr in range(0, len(saved_figure)):
                if saved_figure[ndr] < cur_fig:
                    saved_figure[ndr].drawit(saved_figure[ndr].fill, \
                            saved_figure[ndr].x + pobj.contents.x, \
                            saved_figure[ndr].y + pobj.contents.y, \
                            saved_figure[ndr].w, saved_figure[ndr].h, \
                            saved_figure[ndr].col)
        cur_fig.newfig = 0
    elif event == xfl.FL_PUSH:
        if key != 2:
            cur_fig.x = mx - cur_fig.w / 2
            cur_fig.y = my - cur_fig.h / 2
            # convert position to relative to the free object
            cur_fig.x -= pobj.contents.x
            cur_fig.y -= pobj.contents.y
            cur_fig.newfig = 1
            xfl.fl_redraw_object(pobj)
            #*(cur_fig+1) = *cur_fig;
            xfl.fl_mapcolor(cur_fig.col + 1, cur_fig.c[0], cur_fig.c[1], \
                    cur_fig.c[2])
            #cur_fig++
            #cur_fig.col++
            #cur_fig.col += 1 ??
    return 0
 def __init__(self, lsysargv, sysargv):
     strng = ""
     xfl.fl_initialize(lsysargv, sysargv, "FormDemo", None, 0)
     self.makeform()
     xfl.fl_show_form(self.pform, xfl.FL_PLACE_MOUSE, \
             xfl.FL_TRANSIENT, "A Form")
     r = xfl.fl_get_dial_value(self.pred) + 0.001
     g = xfl.fl_get_dial_value(self.pgreen) + 0.001
     b = xfl.fl_get_dial_value(self.pblue) + 0.001
     xfl.fl_freeze_form(self.pform)
     xfl.fl_mapcolor(xfl.FL_FREE_COL1, r, g, b)
     strng = "%d" % r
     xfl.fl_set_object_label(self.predtext, strng)
     strng = "%d" % g
     xfl.fl_set_object_label(self.pgreentext, strng)
     strng = "%d" % b
     xfl.fl_set_object_label(self.pbluetext, strng)
     xfl.fl_unfreeze_form(self.pform)
     while True:
         if xfl.fl_is_same_object(xfl.fl_do_forms(), self.pbutton):
             break
         r = xfl.fl_get_dial_value(self.pred) + 0.001
         g = xfl.fl_get_dial_value(self.pgreen) + 0.001
         b = xfl.fl_get_dial_value(self.pblue) + 0.001
         xfl.fl_freeze_form(self.pform)
         xfl.fl_mapcolor(xfl.FL_FREE_COL1, r, g, b)
         strng = "%d" % r
         xfl.fl_set_object_label(self.predtext, strng)
         strng = "%d" % g
         xfl.fl_set_object_label(self.pgreentext, strng)
         strng = "%d" % b
         xfl.fl_set_object_label(self.pbluetext, strng)
         xfl.fl_unfreeze_form(self.pform)
     xfl.fl_hide_form(self.pform)
     xfl.fl_finish()
     sys.exit(0)
 def color_change(self, pobj, data):
     c = [0] * 3
     for i in range(0, 3):
         c[i] = xfl.fl_get_counter_value(self.pco[i])
     xfl.fl_mapcolor(xfl.FL_FREE_COL1, c[0], c[1], c[2])
     xfl.fl_redraw_object(self.presult)