source: cpp/frams/canvas/canvasutil.cpp @ 147

Last change on this file since 147 was 147, checked in by sz, 6 years ago

This sample code may be useful for people reimplementing the standard framsticks neural network drawing routine (look for NeuroSymbol::paint(), especially the fragment starting at line 283)

  • Property svn:eol-style set to native
File size: 1.1 KB
Line 
1#include "canvasutil.h"
2
3static int std_unknown_symbol[]={12, 1,4, 25,25, 75,25, 75,75, 25,75, 25,25};
4static int std_neuron_symbol[]={12, 1,4, 75,50, 25,0, 25,99, 75,50, 100,50};
5static int std_inputonly_symbol[]={14, 1,5, 25,40, 35,40, 45,50, 35,60, 25,60, 25,40};
6static int std_outputonly_symbol[]={18, 1,7, 75,50, 75,60, 55,60, 65,50, 55,40, 75,40, 75,50, 100,50};
7
8int* drawNeuroSymbol(CanvasDrawing* c,NeuroClass* cl,int x,int y,int w,int h)
9{
10int *data=std_unknown_symbol;
11if (cl)
12        {
13        data=cl->getSymbolGlyph();
14        if (!data)
15                {
16                if (cl->getPreferredInputs()==0)
17                        data=std_outputonly_symbol;
18                else if (cl->getPreferredOutput()==0)
19                        data=std_inputonly_symbol;
20                else data=std_neuron_symbol;
21                }
22        }
23drawVector(c,data,x,y,w,h);
24return data;
25}
26
27void drawVector(CanvasDrawing* c,int data[],int x,int y,int w,int h)
28{
29if (!data) return;
30Pixel p;
31data++;
32for (int NL=*(data++);NL>0;NL--)
33        {
34        int NS=*(data++);
35        p.x=x+(*(data++)*w)/100;
36        p.y=y+(*(data++)*h)/100;
37        c->moveTo(p);
38        for (;NS>0;NS--)
39                {
40                p.x=x+(*(data++)*w)/100;
41                p.y=y+(*(data++)*h)/100;
42                c->lineTo(p);
43                }
44        }
45}
Note: See TracBrowser for help on using the repository browser.