Graphics demos: improve Misc and Colormap
[scilab.git] / scilab / modules / graphics / demos / misc / misc.dem.sce
index 762fbe9..93d3e42 100644 (file)
@@ -1,21 +1,13 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2008 - INRIA - Pierre MARECHAL
+// Copyright (C) 2016 - Scilab Enterprises - Paul Bignier
 //
 // This file is released under the 3-clause BSD license. See COPYING-BSD.
 
-function demo_misc()
-
-    global margin_x;
-    global margin_y;
-
-    global padding_x;
-    global padding_y;
-
-    global frame_w;
-    global frame_h;
+prot = funcprot();
+funcprot(0);
 
-    global plot_w;
-    global plot_h;
+function demo_misc()
 
     // Parameters
     // =========================================================================
@@ -29,12 +21,8 @@ function demo_misc()
     margin_x             = 15;      // Horizontal margin between each elements
     margin_y             = 15;      // Vertical margin between each elements
 
-    padding_x            = 10;      // Horizontal padding between each elements
-    padding_y            = 10;      // Vertical padding between each elements
-
     defaultfont          = "arial"; // Default Font
-    frametitle_font_size = 16;      // Title font size
-    text_font_size       = 13;      // Text font size
+    text_font_size       = 12;      // Text font size
 
     // Figure creation
     // =========================================================================
@@ -42,290 +30,292 @@ function demo_misc()
     axes_w       = 3*margin_x + frame_w + plot_w;    // axes width
     axes_h       = 2*margin_y + max(frame_h,plot_h); // axes height
 
-    demo_plot3d = figure(100001);
-    clf(demo_plot3d,"reset");
-
-    demo_plot3d.background      = -2;
-    demo_plot3d.color_map       = jetcolormap(128);
-    demo_plot3d.axes_size       = [axes_w axes_h];
-    demo_plot3d.figure_name     = gettext("Misc");
+    fig_handle = figure( ...
+    "infobar_visible", "off", ...
+    "toolbar_visible", "off", ...
+    "toolbar", "none", ...
+    "default_axes", "on", ...
+    "layout", "gridbag", ...
+    "visible", "off", ...
+    "background", -2, ...
+    "figure_position", [0 0], ...
+    "axes_size", [axes_w axes_h], ...
+    "figure_name", _("Misc"));
+
+    c = createConstraints("gridbag", [2 1 1 1], [1 1], "vertical", "right");
+    // Create an empty panel on the right to occupy the 3/4 of the screen (figure plot)
+    empty_frame = uicontrol(fig_handle, "style", "frame","constraints", c);
+
+    c = createConstraints("gridbag", [1 1 1 5], [0.05 1], "both", "left", [0 0], [150 0]);
+    u = uicontrol(fig_handle, ...
+    "style", "frame", ...
+    "backgroundcolor", [1 1 1], ...
+    "layout", "border", ...
+    "constraints", c);
+
+    // Add top and bottom empty panels to pad the upcoming colormap panel
+    c = createConstraints("border", "top", [0 80]);
+    top = uicontrol(u, "style", "frame", "backgroundcolor", [1 1 1], "constraints", c);
+    c = createConstraints("border", "bottom", [0 80]);
+    bottom = uicontrol(u, "style", "frame", "backgroundcolor", [1 1 1], "constraints", c);
+
+    // Border for the colormap frame
+    b_f_colormap = createBorderFont("", 18);
+    b_l_colormap = createBorder("line", "navy", 2);
+    b_colormap   = createBorder("titled", b_l_colormap, "Colormap", "center", "top", b_f_colormap, "navy");
+
+    colormap_frame = uicontrol(u, ...
+    "style", "frame", ...
+    "backgroundcolor", [1 1 1], ...
+    "border", b_colormap, ...
+    "layout", "gridbag", ...
+    "tag", "colormap_frame");
 
-    my_frame_pos_x = margin_x;
-    my_frame_pos_y = (axes_h/2-frame_h/2);
+    demo_viewCode("misc.dem.sce");
 
-    // Frames creation [Control Panel]
-    // =========================================================================
+    fig_handle.color_map = jetcolormap(128);
 
-    my_frame = uicontrol( ...
-    "parent"              , demo_plot3d,...
-    "relief"              , "groove",...
-    "style"               , "frame",...
-    "units"               , "pixels",...
-    "position"            , [ my_frame_pos_x my_frame_pos_y frame_w frame_h],...
-    "horizontalalignment" , "center", ...
-    "background"          , [1 1 1], ...
-    "tag"                 , "frame_control" ...
-    );
-
-    // Frame title
-    my_frame_title = uicontrol( ...
-    "parent"              , demo_plot3d,...
-    "style"               , "text",...
-    "string"              , "Colormap",...
-    "units"               , "pixels",...
-    "position"            , [ 30+my_frame_pos_x my_frame_pos_y+frame_h-10 frame_w-60 20 ],...
-    "fontname"            , defaultfont,...
-    "fontunits"           , "points",...
-    "fontsize"            , frametitle_font_size,...
-    "horizontalalignment" , "center", ...
-    "background"          , [1 1 1], ...
-    "tag"                 , "title_frame_control" ...
-    );
-
-    // Colormap frame creation
+    // Radio buttons
     // =========================================================================
 
-    my_cmap_frame_w     = frame_w;
-    my_cmap_frame_h     = frame_h;
+    // Radio buttons : Jet
 
-    // Colormap : Jetcolormap
-
-    jetcolormap_radio = uicontrol( ...
-    "parent"             , demo_plot3d,...
-    "style"              , "radiobutton",...
-    "string"             , gettext("Jet"),...
-    "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-50 my_cmap_frame_w-25 15],...
-    "horizontalalignment", "left",...
-    "fontname"           , defaultfont,...
-    "fontunits"          , "points",...
-    "fontsize"           , text_font_size,...
+    c = createConstraints("gridbag", [1 1 1 1], [1 1], "both", "upper");
+    square_radio = uicontrol( ...
+    "parent"             , colormap_frame, ...
+    "style"              , "radiobutton", ...
+    "string"             , "Jet", ...
+    "fontname"           , defaultfont, ...
+    "fontunits"          , "points", ...
+    "fontsize"           , text_font_size, ...
     "value"              , 1, ...
-    "background"          , [1 1 1], ...
-    "callback"           , "demo_update_misc",...
+    "background"         , [1 1 1], ...
+    "callback"           , "demo_update_misc", ...
+    "constraints"        , c, ...
     "tag"                , "jetcolormap_radio");
 
-     // Colormap : Parulacolormap
-
-    jetcolormap_radio = uicontrol( ...
-    "parent"             , demo_plot3d,...
-    "style"              , "radiobutton",...
-    "string"             , gettext("Parula"),...
-    "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-70 my_cmap_frame_w-25 15],...
-    "horizontalalignment", "left",...
-    "fontname"           , defaultfont,...
-    "fontunits"          , "points",...
-    "fontsize"           , text_font_size,...
+    // Radio buttons : Parula
+
+    c = createConstraints("gridbag", [1 2 1 1], [1 1], "both", "upper");
+    disk_radio = uicontrol( ...
+    "parent"             , colormap_frame, ...
+    "style"              , "radiobutton", ...
+    "string"             , "Parula", ...
+    "fontname"           , defaultfont, ...
+    "fontunits"          , "points", ...
+    "fontsize"           , text_font_size, ...
     "value"              , 0, ...
-    "background"          , [1 1 1], ...
-    "callback"           , "demo_update_misc",...
+    "background"         , [1 1 1], ...
+    "callback"           , "demo_update_misc", ...
+    "constraints"        , c, ...
     "tag"                , "parulacolormap_radio");
 
-    // Colormap : HSVcolormap
-
-    HSVcolormap_radio = uicontrol( ...
-    "parent"             , demo_plot3d,...
-    "style"              , "radiobutton",...
-    "string"             , gettext("HSV"),...
-    "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-90 my_cmap_frame_w-25 15],...
-    "horizontalalignment", "left",...
-    "fontname"           , defaultfont,...
-    "fontunits"          , "points",...
-    "fontsize"           , text_font_size,...
+    // Radio buttons : HSV
+
+    c = createConstraints("gridbag", [1 3 1 1], [1 1], "both", "upper");
+    disk_radio = uicontrol( ...
+    "parent"             , colormap_frame, ...
+    "style"              , "radiobutton", ...
+    "string"             , "HSV", ...
+    "fontname"           , defaultfont, ...
+    "fontunits"          , "points", ...
+    "fontsize"           , text_font_size, ...
     "value"              , 0, ...
-    "background"          , [1 1 1], ...
-    "callback"           , "demo_update_misc",...
+    "background"         , [1 1 1], ...
+    "callback"           , "demo_update_misc", ...
+    "constraints"        , c, ...
     "tag"                , "HSVcolormap_radio");
 
-    // Colormap : Hotcolormap
-
-    hotcolormap_radio = uicontrol( ...
-    "parent"             , demo_plot3d,...
-    "style"              , "radiobutton",...
-    "string"             , gettext("Hot"),...
-    "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-110 my_cmap_frame_w-25 15],...
-    "horizontalalignment", "left",...
-    "fontname"           , defaultfont,...
-    "fontunits"          , "points",...
-    "fontsize"           , text_font_size,...
+    // Radio buttons : Hot
+
+    c = createConstraints("gridbag", [1 4 1 1], [1 1], "both", "upper");
+    disk_radio = uicontrol( ...
+    "parent"             , colormap_frame, ...
+    "style"              , "radiobutton", ...
+    "string"             , "Hot", ...
+    "fontname"           , defaultfont, ...
+    "fontunits"          , "points", ...
+    "fontsize"           , text_font_size, ...
     "value"              , 0, ...
-    "background"          , [1 1 1], ...
-    "callback"           , "demo_update_misc",...
+    "background"         , [1 1 1], ...
+    "callback"           , "demo_update_misc", ...
+    "constraints"        , c, ...
     "tag"                , "hotcolormap_radio");
 
-    // Colormap : Graycolormap
-
-    graycolormap_radio = uicontrol( ...
-    "parent"             , demo_plot3d,...
-    "style"              , "radiobutton",...
-    "string"             , gettext("Gray"),...
-    "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-130 my_cmap_frame_w-25 15],...
-    "horizontalalignment", "left",...
-    "fontname"           , defaultfont,...
-    "fontunits"          , "points",...
-    "fontsize"           , text_font_size,...
+    // Radio buttons : Gray
+
+    c = createConstraints("gridbag", [1 5 1 1], [1 1], "both", "upper");
+    disk_radio = uicontrol( ...
+    "parent"             , colormap_frame, ...
+    "style"              , "radiobutton", ...
+    "string"             , "Gray", ...
+    "fontname"           , defaultfont, ...
+    "fontunits"          , "points", ...
+    "fontsize"           , text_font_size, ...
     "value"              , 0, ...
-    "background"          , [1 1 1], ...
-    "callback"           , "demo_update_misc",...
+    "background"         , [1 1 1], ...
+    "callback"           , "demo_update_misc", ...
+    "constraints"        , c, ...
     "tag"                , "graycolormap_radio");
 
-    // Colormap : Wintercolormap
-
-    wintercolormap_radio = uicontrol( ...
-    "parent"             , demo_plot3d,...
-    "style"              , "radiobutton",...
-    "string"             , gettext("Winter"),...
-    "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-150 my_cmap_frame_w-25 15],...
-    "horizontalalignment", "left",...
-    "fontname"           , defaultfont,...
-    "fontunits"          , "points",...
-    "fontsize"           , text_font_size,...
+    // Radio buttons : Winter
+
+    c = createConstraints("gridbag", [1 6 1 1], [1 1], "both", "upper");
+    disk_radio = uicontrol( ...
+    "parent"             , colormap_frame, ...
+    "style"              , "radiobutton", ...
+    "string"             , "Winter", ...
+    "fontname"           , defaultfont, ...
+    "fontunits"          , "points", ...
+    "fontsize"           , text_font_size, ...
     "value"              , 0, ...
-    "background"          , [1 1 1], ...
-    "callback"           , "demo_update_misc",...
+    "background"         , [1 1 1], ...
+    "callback"           , "demo_update_misc", ...
+    "constraints"        , c, ...
     "tag"                , "wintercolormap_radio");
 
-    // Colormap : Springcolormap
-
-    springcolormap_radio = uicontrol( ...
-    "parent"             , demo_plot3d,...
-    "style"              , "radiobutton",...
-    "string"             , gettext("Spring"),...
-    "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-170 my_cmap_frame_w-25 15],...
-    "horizontalalignment", "left",...
-    "fontname"           , defaultfont,...
-    "fontunits"          , "points",...
-    "fontsize"           , text_font_size,...
+    // Radio buttons : Spring
+
+    c = createConstraints("gridbag", [1 7 1 1], [1 1], "both", "upper");
+    disk_radio = uicontrol( ...
+    "parent"             , colormap_frame, ...
+    "style"              , "radiobutton", ...
+    "string"             , "Spring", ...
+    "fontname"           , defaultfont, ...
+    "fontunits"          , "points", ...
+    "fontsize"           , text_font_size, ...
     "value"              , 0, ...
-    "background"          , [1 1 1], ...
-    "callback"           , "demo_update_misc",...
+    "background"         , [1 1 1], ...
+    "callback"           , "demo_update_misc", ...
+    "constraints"        , c, ...
     "tag"                , "springcolormap_radio");
 
-    // Colormap : Summercolormap
-
-    summercolormap_radio = uicontrol( ...
-    "parent"             , demo_plot3d,...
-    "style"              , "radiobutton",...
-    "string"             , gettext("Summer"),...
-    "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-190 my_cmap_frame_w-25 15],...
-    "horizontalalignment", "left",...
-    "fontname"           , defaultfont,...
-    "fontunits"          , "points",...
-    "fontsize"           , text_font_size,...
+    // Radio buttons : Summer
+
+    c = createConstraints("gridbag", [1 8 1 1], [1 1], "both", "upper");
+    disk_radio = uicontrol( ...
+    "parent"             , colormap_frame, ...
+    "style"              , "radiobutton", ...
+    "string"             , "Summer", ...
+    "fontname"           , defaultfont, ...
+    "fontunits"          , "points", ...
+    "fontsize"           , text_font_size, ...
     "value"              , 0, ...
-    "background"          , [1 1 1], ...
-    "callback"           , "demo_update_misc",...
+    "background"         , [1 1 1], ...
+    "callback"           , "demo_update_misc", ...
+    "constraints"        , c, ...
     "tag"                , "summercolormap_radio");
 
-    // Colormap : Autumncolormap
-
-    autumncolormap_radio = uicontrol( ...
-    "parent"             , demo_plot3d,...
-    "style"              , "radiobutton",...
-    "string"             , gettext("Autumn"),...
-    "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-210 my_cmap_frame_w-25 15],...
-    "horizontalalignment", "left",...
-    "fontname"           , defaultfont,...
-    "fontunits"          , "points",...
-    "fontsize"           , text_font_size,...
+    // Radio buttons : Autumn
+
+    c = createConstraints("gridbag", [1 9 1 1], [1 1], "both", "upper");
+    disk_radio = uicontrol( ...
+    "parent"             , colormap_frame, ...
+    "style"              , "radiobutton", ...
+    "string"             , "Autumn", ...
+    "fontname"           , defaultfont, ...
+    "fontunits"          , "points", ...
+    "fontsize"           , text_font_size, ...
     "value"              , 0, ...
-    "background"          , [1 1 1], ...
-    "callback"           , "demo_update_misc",...
+    "background"         , [1 1 1], ...
+    "callback"           , "demo_update_misc", ...
+    "constraints"        , c, ...
     "tag"                , "autumncolormap_radio");
 
-    // Colormap : Bonecolormap
-
-    bonecolormap_radio = uicontrol( ...
-    "parent"             , demo_plot3d,...
-    "style"              , "radiobutton",...
-    "string"             , gettext("Bone"),...
-    "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-230 my_cmap_frame_w-25 15],...
-    "horizontalalignment", "left",...
-    "fontname"           , defaultfont,...
-    "fontunits"          , "points",...
-    "fontsize"           , text_font_size,...
+    // Radio buttons : Bone
+
+    c = createConstraints("gridbag", [1 10 1 1], [1 1], "both", "upper");
+    disk_radio = uicontrol( ...
+    "parent"             , colormap_frame, ...
+    "style"              , "radiobutton", ...
+    "string"             , "Bone", ...
+    "fontname"           , defaultfont, ...
+    "fontunits"          , "points", ...
+    "fontsize"           , text_font_size, ...
     "value"              , 0, ...
-    "background"          , [1 1 1], ...
-    "callback"           , "demo_update_misc",...
+    "background"         , [1 1 1], ...
+    "callback"           , "demo_update_misc", ...
+    "constraints"        , c, ...
     "tag"                , "bonecolormap_radio");
 
-    // Colormap : Coppercolormap
-
-    coppercolormap_radio = uicontrol( ...
-    "parent"             , demo_plot3d,...
-    "style"              , "radiobutton",...
-    "string"             , gettext("Copper"),...
-    "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-250 my_cmap_frame_w-25 15],...
-    "horizontalalignment", "left",...
-    "fontname"           , defaultfont,...
-    "fontunits"          , "points",...
-    "fontsize"           , text_font_size,...
+    // Radio buttons : Copper
+
+    c = createConstraints("gridbag", [1 11 1 1], [1 1], "both", "upper");
+    disk_radio = uicontrol( ...
+    "parent"             , colormap_frame, ...
+    "style"              , "radiobutton", ...
+    "string"             , "Copper", ...
+    "fontname"           , defaultfont, ...
+    "fontunits"          , "points", ...
+    "fontsize"           , text_font_size, ...
     "value"              , 0, ...
-    "background"          , [1 1 1], ...
-    "callback"           , "demo_update_misc",...
+    "background"         , [1 1 1], ...
+    "callback"           , "demo_update_misc", ...
+    "constraints"        , c, ...
     "tag"                , "coppercolormap_radio");
 
-    // Colormap : Pinkcolormap
-
-    pinkcolormap_radio = uicontrol( ...
-    "parent"             , demo_plot3d,...
-    "style"              , "radiobutton",...
-    "string"             , gettext("Pink"),...
-    "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-270 my_cmap_frame_w-25 15],...
-    "horizontalalignment", "left",...
-    "fontname"           , defaultfont,...
-    "fontunits"          , "points",...
-    "fontsize"           , text_font_size,...
+    // Radio buttons : Pink
+
+    c = createConstraints("gridbag", [1 12 1 1], [1 1], "both", "upper");
+    disk_radio = uicontrol( ...
+    "parent"             , colormap_frame, ...
+    "style"              , "radiobutton", ...
+    "string"             , "Pink", ...
+    "fontname"           , defaultfont, ...
+    "fontunits"          , "points", ...
+    "fontsize"           , text_font_size, ...
     "value"              , 0, ...
-    "background"          , [1 1 1], ...
-    "callback"           , "demo_update_misc",...
+    "background"         , [1 1 1], ...
+    "callback"           , "demo_update_misc", ...
+    "constraints"        , c, ...
     "tag"                , "pinkcolormap_radio");
 
-    // Colormap : Rainbowcolormap
-
-    rainbowcolormap_radio = uicontrol( ...
-    "parent"             , demo_plot3d,...
-    "style"              , "radiobutton",...
-    "string"             , gettext("Rainbow"),...
-    "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-290 my_cmap_frame_w-25 15],...
-    "horizontalalignment", "left",...
-    "fontname"           , defaultfont,...
-    "fontunits"          , "points",...
-    "fontsize"           , text_font_size,...
+    // Radio buttons : Rainbow
+
+    c = createConstraints("gridbag", [1 13 1 1], [1 1], "both", "upper");
+    disk_radio = uicontrol( ...
+    "parent"             , colormap_frame, ...
+    "style"              , "radiobutton", ...
+    "string"             , "Rainbow", ...
+    "fontname"           , defaultfont, ...
+    "fontunits"          , "points", ...
+    "fontsize"           , text_font_size, ...
     "value"              , 0, ...
-    "background"          , [1 1 1], ...
-    "callback"           , "demo_update_misc",...
+    "background"         , [1 1 1], ...
+    "callback"           , "demo_update_misc", ...
+    "constraints"        , c, ...
     "tag"                , "rainbowcolormap_radio");
 
-    // Colormap : Oceancolormap
-
-    oceancolormap_radio = uicontrol( ...
-    "parent"             , demo_plot3d,...
-    "style"              , "radiobutton",...
-    "string"             , gettext("Ocean"),...
-    "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-310 my_cmap_frame_w-25 15],...
-    "horizontalalignment", "left",...
-    "fontname"           , defaultfont,...
-    "fontunits"          , "points",...
-    "fontsize"           , text_font_size,...
+    // Radio buttons : Ocean
+
+    c = createConstraints("gridbag", [1 14 1 1], [1 1], "both", "upper");
+    disk_radio = uicontrol( ...
+    "parent"             , colormap_frame, ...
+    "style"              , "radiobutton", ...
+    "string"             , "Ocean", ...
+    "fontname"           , defaultfont, ...
+    "fontunits"          , "points", ...
+    "fontsize"           , text_font_size, ...
     "value"              , 0, ...
-    "background"          , [1 1 1], ...
-    "callback"           , "demo_update_misc",...
+    "background"         , [1 1 1], ...
+    "callback"           , "demo_update_misc", ...
+    "constraints"        , c, ...
     "tag"                , "oceancolormap_radio");
 
-    // Colormap : Whitecolormap
-
-    whitecolormap_radio = uicontrol( ...
-    "parent"             , demo_plot3d,...
-    "style"              , "radiobutton",...
-    "string"             , gettext("White"),...
-    "position"           , [ my_frame_pos_x+10 my_frame_pos_y+my_cmap_frame_h-330 my_cmap_frame_w-25 15],...
-    "horizontalalignment", "left",...
-    "fontname"           , defaultfont,...
-    "fontunits"          , "points",...
-    "fontsize"           , text_font_size,...
+    // Radio buttons : White
+
+    c = createConstraints("gridbag", [1 15 1 1], [1 1], "both", "upper");
+    disk_radio = uicontrol( ...
+    "parent"             , colormap_frame, ...
+    "style"              , "radiobutton", ...
+    "string"             , "White", ...
+    "fontname"           , defaultfont, ...
+    "fontunits"          , "points", ...
+    "fontsize"           , text_font_size, ...
     "value"              , 0, ...
-    "background"          , [1 1 1], ...
-    "callback"           , "demo_update_misc",...
+    "background"         , [1 1 1], ...
+    "callback"           , "demo_update_misc", ...
+    "constraints"        , c, ...
     "tag"                , "whitecolormap_radio");
 
     // Plots creation
@@ -408,7 +398,7 @@ function demo_misc()
 
     drawnow();
 
-    demo_viewCode("misc.dem.sce");
+    fig_handle.visible = "on";
 
 endfunction
 
@@ -490,6 +480,7 @@ function demo_update_misc()
 
 endfunction
 
+funcprot(prot);
+
 demo_misc();
 clear demo_misc;
-