You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
3.5 KiB

14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2011 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 2011 KiCad Developers, see change_log.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <sch_canvas.h>
  25. #include <sch_part.h>
  26. #include <gal/font/newstroke_font.h>
  27. #define SWEET_UNIT 50 ///< world units comprizing a sweet grid cell
  28. namespace SCH {
  29. CANVAS::CANVAS( wxWindow* aParent ) :
  30. OPENGL_GAL( aParent, NULL, this ) // I am my own PaintListener
  31. {
  32. Connect( EVT_GAL_REDRAW, wxCommandEventHandler( CANVAS::onRedraw ) );
  33. // Set the world unit length
  34. SetWorldUnitLength( 0.01 );
  35. SetScreenDPI( 100 );
  36. ComputeWorldScreenMatrix();
  37. // Set the world unit length
  38. // SetLookAtPoint( VECTOR2D( size.x / 2, size.y / 2 ) );
  39. // Load Font
  40. if( !m_font.LoadNewStrokeFont( newstroke_font, newstroke_font_bufsize ) )
  41. {
  42. printf( "Loading of the font failed.\n" );
  43. }
  44. m_font.SetGraphicsAbstractionLayer( this );
  45. }
  46. void CANVAS::onRedraw( wxCommandEvent& event )
  47. {
  48. PaintScene();
  49. }
  50. void CANVAS::PaintScene()
  51. {
  52. BeginDrawing();
  53. SetBackgroundColor( COLOR4D( 0x6c/255.0, 0x53/255.0, 0x53/255.0, 1.0 ) );
  54. ClearScreen();
  55. SetLayerDepth( -10 );
  56. SetGridSize( VECTOR2D( SWEET_UNIT, SWEET_UNIT ) );
  57. DrawGrid();
  58. PaintRectangle();
  59. SetLayerDepth( 0 );
  60. Flush();
  61. EndDrawing();
  62. }
  63. void CANVAS::PaintRectangle()
  64. {
  65. VECTOR2D worldSize = GetSize();
  66. #if 1
  67. SetLineWidth( 1 );
  68. SetIsFill( true );
  69. SetIsStroke( true );
  70. SetFillColor( COLOR4D( 1, 1, 1, 1 ) );
  71. SetStrokeColor( COLOR4D( 0, 0, 0, 1 ) );
  72. DrawRectangle( VECTOR2D( worldSize.x/4, worldSize.y/4 ), VECTOR2D( 3*worldSize.x/4, 3*worldSize.y/4 ) );
  73. #else
  74. D( cout << worldSize << endl; )
  75. int k = 0;
  76. double alpha = 0;
  77. for( double y = 0; y < worldSize.y - worldSize.y / 4; y += worldSize.y / 8 )
  78. {
  79. double index = 1;
  80. double y2 = y;
  81. for( double x = 0; x < worldSize.x - worldSize.x / 4; x += worldSize.x / 8 )
  82. {
  83. SetLineWidth( index + 1 );
  84. SetIsFill( ( k == 1 ) || ( k == 2 ) );
  85. SetIsStroke( ( k == 0 ) || ( k == 2 ) );
  86. SetFillColor( COLOR4D( 1 - alpha, 1, 1, 1 - alpha ) );
  87. SetStrokeColor( COLOR4D( alpha, alpha, 1 - alpha, alpha ) );
  88. DrawRectangle( VECTOR2D( x, y2 ), VECTOR2D( x + index * 10, y2 + index * 10 ) );
  89. x += index * 5;
  90. y2 += index * 5;
  91. index += 1;
  92. }
  93. k = ( k + 1 ) % 3;
  94. alpha += 0.1;
  95. }
  96. #endif
  97. }
  98. } // namespace SCH