Commit 005a8e4b authored by Matthew Dawson's avatar Matthew Dawson
Browse files

Implement a simplistic drawing of a grid.

Its a start.


git-svn-id: https://groke.mcmaster.ca/svn/grad/colin/branches/TableTool_refactor@8679 57e6efec-57d4-0310-aeb1-a6c144bb1a8b
parent bd45b155
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
classdef TableGridDraw < handle
    %TABLEGRIDDRAW Draw a TableGrid into a uipanel
    %   Draws a 2D Grid inside a uipanel (Yay!)
    
    properties
        my_table_grid = []
        controls = []
    end
    
    methods
        function object = TableGridDraw(my_table_grid)
           object.my_table_grid = my_table_grid;
        end
    end
    
end
+31 −0
Original line number Diff line number Diff line
function draw_onto( object, parent_handle )
%DRAW_ONTO Draws the controls onto the parent_handle.  This function needs
%to be called everytime an update happens.
%   This function draws the entire handle onto the handle.  This function
%   needs to be called everytime the back table is updated.  The class will
%   notify when its necessary.

    %Need to invert y, so need total size
    [x, y] = object.get_bounding_box();

    % First delete an extra controls
    assert( ~(size(object.controls, 2) > object.my_table_grid.width), 'Implment delete when necessary.');
    assert( ~(size(object.controls, 1) > object.my_table_grid.height), 'Implment delete when necessary.');

    if size(object.controls, 2) ~= object.my_table_grid.width || size(object.controls, 1) ~= object.my_table_grid.height
        object.controls(object.my_table_grid.height, object.my_table_grid.width) = 0;
    end
    
    for i = 1:object.my_table_grid.width
        for j = 1:object.my_table_grid.width
            if object.controls(j,i) ~= 0 && ishandle(object.controls(j,i))
                assert( false, 'Deal with existing controls' );
            else
                %Standardize this
                uicontrol(parent_handle, 'Style', 'edit', 'Position', [(i-1)*120+(i-1)*5, y-((j)*80+(j-1)*5), 120, 80], 'String', ['' num2str(i) ', ' num2str(j)]);
            end
        end
    end

end
+11 −0
Original line number Diff line number Diff line
function [x, y] = get_bounding_box( object )
%GET_BOUNDING_BOX Gets the size in pixels of the grid.
%Returns the size of the grid (as a box) for layout purposes.
    x = object.my_table_grid.height; %Store number of cells first
    x = 120*x + 5*(x-1); %Then calculate the pixels.
    
    y = object.my_table_grid.height;
    y = 80*y + 5*(y-1); %Same here.

end