Skip to content
Snippets Groups Projects
Select Git revision
  • 7d70f0f9525c09ee5c8e0123721479398a55b112
  • master default protected
  • 47-upgrade-framework-and-dependencies
  • 21-improve-app-metadata
  • Release_0.9.0_40 protected
  • Release_0.8.2_39 protected
  • Release_0.8.1_38 protected
  • Release_0.8.0_37 protected
  • Release_0.7.0_36 protected
  • Release_0.6.0_35 protected
  • Release_0.5.0_34 protected
  • Release_0.4.2_33 protected
  • Release_0.4.1_32 protected
  • Release_0.4.0_31 protected
  • Release_0.3.1_30 protected
  • Release_0.3.0_29 protected
  • Release_0.2.1_28 protected
  • Release_0.2.0_27 protected
  • Release_0.1.2_26 protected
  • Release_0.1.1_25 protected
  • Release_0.1.0_24 protected
  • Release_0.0.23_23 protected
  • Release_0.0.22_22 protected
  • Release_0.0.21_21 protected
24 results

parameter_painter.dart

Blame
  • parameter_painter.dart 1.65 KiB
    import 'dart:math';
    
    import 'package:flutter/material.dart';
    
    import 'package:twister/models/settings/settings_game.dart';
    import 'package:twister/models/settings/settings_global.dart';
    import 'package:twister/utils/tools.dart';
    
    class ParameterPainter extends CustomPainter {
      const ParameterPainter({
        required this.code,
        required this.value,
        required this.gameSettings,
        required this.globalSettings,
      });
    
      final String code;
      final String value;
      final GameSettings gameSettings;
      final GlobalSettings globalSettings;
    
      @override
      void paint(Canvas canvas, Size size) {
        // force square
        final double canvasSize = min(size.width, size.height);
    
        // content
        switch (code) {
          default:
            printlog('Unknown parameter: $code/$value');
            paintUnknownParameterItem(canvas, canvasSize);
        }
      }
    
      @override
      bool shouldRepaint(CustomPainter oldDelegate) {
        return false;
      }
    
      // "unknown" parameter -> simple block with text
      void paintUnknownParameterItem(
        final Canvas canvas,
        final double size,
      ) {
        final paint = Paint();
        paint.strokeJoin = StrokeJoin.round;
        paint.strokeWidth = 3;
    
        final textSpan = TextSpan(
          text: '$code\n$value',
          style: const TextStyle(
            color: Colors.black,
            fontSize: 18,
            fontWeight: FontWeight.bold,
          ),
        );
        final textPainter = TextPainter(
          text: textSpan,
          textDirection: TextDirection.ltr,
          textAlign: TextAlign.center,
        );
        textPainter.layout();
        textPainter.paint(
          canvas,
          Offset(
            (size - textPainter.width) * 0.5,
            (size - textPainter.height) * 0.5,
          ),
        );
      }