Skip to content
Snippets Groups Projects
Select Git revision
  • 2bcfcc332d9a6bc121af102f5a5d5d9eba02b603
  • master default protected
2 results

image.cxx

  • image.cxx 3.94 KiB
    //
    // Fl_Image test program for the Fast Light Tool Kit (FLTK).
    //
    // Notice that Fl_Image is for a static, multiple-reuse image, such
    // as an icon or postage stamp.  Use fl_draw_image to go directly
    // from an buffered image that changes often.
    //
    // Copyright 1998-2021 by Bill Spitzak and others.
    //
    // This library is free software. Distribution and use rights are outlined in
    // the file "COPYING" which should have been included with this file.  If this
    // file is missing or damaged, see the license at:
    //
    //     https://www.fltk.org/COPYING.php
    //
    // Please see the following page on how to report bugs and issues:
    //
    //     https://www.fltk.org/bugs.php
    //
    
    #include <FL/Fl.H>
    #include <FL/Fl_Double_Window.H>
    #include <FL/Fl_Button.H>
    #include <FL/Fl_Image.H>
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int width = 100;
    int height = 100;
    uchar *image;
    
    void make_image() {
      image = new uchar[4*width*height];
      uchar *p = image;
      for (int y = 0; y < height; y++) {
        double Y = double(y)/(height-1);
        for (int x = 0; x < width; x++) {
          double X = double(x)/(width-1);
          *p++ = uchar(255*((1-X)*(1-Y))); // red in upper-left
          *p++ = uchar(255*((1-X)*Y));     // green in lower-left
          *p++ = uchar(255*(X*Y));         // blue in lower-right
          X -= 0.5;
          Y -= 0.5;
          int alpha = (int)(255 * sqrt(X * X + Y * Y));
          if (alpha < 255) *p++ = uchar(alpha);     // alpha transparency
          else *p++ = 255;
          Y += 0.5;
        }
      }
    }
    
    #include <FL/Fl_Toggle_Button.H>
    
    Fl_Toggle_Button *leftb,*rightb,*topb,*bottomb,*insideb,*overb,*inactb;
    Fl_Button *b;
    Fl_Double_Window *w;
    
    void button_cb(Fl_Widget *,void *) {
      int i = 0;
      if (leftb->value()) i |= FL_ALIGN_LEFT;
      if (rightb->value()) i |= FL_ALIGN_RIGHT;
      if (topb->value()) i |= FL_ALIGN_TOP;
      if (bottomb->value()) i |= FL_ALIGN_BOTTOM;
      if (insideb->value()) i |= FL_ALIGN_INSIDE;
      if (overb->value()) i |= FL_ALIGN_TEXT_OVER_IMAGE;
      b->align(i);
      if (inactb->value()) b->deactivate();
      else b->activate();
      w->redraw();