• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Martomate / TriPaint / 9275511596

28 May 2024 07:51PM UTC coverage: 29.682% (+1.8%) from 27.877%
9275511596

push

github

Martomate
Updated to Scala 3.4 and MUnit 1.0

2 of 11 new or added lines in 9 files covered. (18.18%)

430 existing lines in 38 files now uncovered.

401 of 1351 relevant lines covered (29.68%)

0.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/scala/tripaint/control/TriPaintController.scala
1
package tripaint.control
2

3
import tripaint.model.TriPaintModel
4
import tripaint.model.coords.GridCoords
5
import tripaint.model.effects.{
6
  BlurEffect,
7
  CellEffect,
8
  MotionBlurEffect,
9
  RandomNoiseEffect,
10
  ScrambleEffect
11
}
12
import tripaint.model.image.GridCell
13
import tripaint.view.{TriPaintView, TriPaintViewFactory, TriPaintViewListener}
14
import tripaint.view.gui.UIAction
15

16
class TriPaintController(val model: TriPaintModel, viewFactory: TriPaintViewFactory)
17
    extends TriPaintViewListener {
UNCOV
18
  val view: TriPaintView = viewFactory.createView(this, model)
×
19

20
  override def perform(action: UIAction): Unit = action match
×
21
    case UIAction.New =>
×
22
      for {
×
23
        (x, y) <- view.askForWhereToPutImage()
×
UNCOV
24
        backgroundColor = view.backgroundColor
×
25
        coords = GridCoords(x, y)
UNCOV
26
      } do Actions.createNewImage(model.imageGrid, backgroundColor, coords)
×
27

28
    case UIAction.Open =>
×
29
      for {
×
30
        file <- view.askForFileToOpen()
×
31
        fileOpenSettings <- view.askForFileOpenSettings(file, model.imageGrid.imageSize, 1, 1)
×
UNCOV
32
        (x, y) <- view.askForWhereToPutImage()
×
33
        coords = GridCoords(x, y)
×
UNCOV
34
      } do Actions.openImage(model, file, fileOpenSettings, coords)
×
35

36
    case UIAction.OpenHexagon =>
×
37
      for {
×
38
        file <- view.askForFileToOpen()
×
39
        fileOpenSettings <- view.askForFileOpenSettings(file, model.imageGrid.imageSize, 6, 1)
×
UNCOV
40
        (x, y) <- view.askForWhereToPutImage()
×
41
        coords = GridCoords(x, y)
×
UNCOV
42
      } do Actions.openHexagon(model, file, fileOpenSettings, coords)
×
43

UNCOV
44
    case UIAction.Save =>
×
45
      Actions.save(
46
        model.imageGrid,
47
        model.imagePool,
UNCOV
48
        model.imageGrid.selectedImages.filter(_.changed),
×
49
        model.fileSystem
UNCOV
50
      )(view.askForSaveFile, view.askForFileSaveSettings, view)
×
51

52
    case UIAction.SaveAs =>
×
53
      model.imageGrid.selectedImages.foreach(im =>
×
54
        Actions.saveAs(model.imageGrid, model.imagePool, im, model.fileSystem)(
×
55
          view.askForSaveFile,
×
UNCOV
56
          view.askForFileSaveSettings,
×
57
          view
58
        )
59
      )
60

UNCOV
61
    case UIAction.Exit => if do_exit() then view.close()
×
62

UNCOV
63
    case UIAction.Undo => model.imageGrid.undo()
×
64

UNCOV
65
    case UIAction.Redo => model.imageGrid.redo()
×
66

67
    case UIAction.Blur =>
×
68
      for radius <- view.askForBlurRadius()
×
UNCOV
69
      do Actions.applyEffect(model, new BlurEffect(radius))
×
70

71
    case UIAction.MotionBlur =>
×
72
      for radius <- view.askForMotionBlurRadius()
×
UNCOV
73
      do Actions.applyEffect(model, new MotionBlurEffect(radius))
×
74

75
    case UIAction.RandomNoise =>
×
76
      for (lo, hi) <- view.askForRandomNoiseColors()
×
UNCOV
77
      do Actions.applyEffect(model, new RandomNoiseEffect(lo, hi))
×
78

79
    case UIAction.Scramble =>
×
UNCOV
80
      Actions.applyEffect(model, ScrambleEffect)
×
81

82
    case UIAction.Cell =>
×
UNCOV
83
      Actions.applyEffect(model, new CellEffect)
×
84

UNCOV
85
    case _ =>
×
86

UNCOV
87
  override def requestExit(): Boolean = do_exit()
×
88

UNCOV
89
  override def requestImageRemoval(image: GridCell): Unit =
×
90
    var abortRemoval = false
91
    if image.changed then
×
92
      view.askSaveBeforeClosing(Seq(image)) match
×
UNCOV
93
        case Some(shouldSave) =>
×
94
          if (
95
            shouldSave && !Actions.save(
96
              model.imageGrid,
97
              model.imagePool,
UNCOV
98
              Seq(image),
×
99
              model.fileSystem
100
            )(
×
101
              view.askForSaveFile,
×
UNCOV
102
              view.askForFileSaveSettings,
×
103
              view
104
            )
105
          ) abortRemoval = true
×
UNCOV
106
        case None => abortRemoval = true
×
107

UNCOV
108
    if (!abortRemoval) model.imageGrid -= image.coords
×
109

110
  private def do_exit(): Boolean =
×
111
    model.imageGrid.changedImages match
×
112
      case Seq() => true
×
113
      case images =>
×
114
        view.askSaveBeforeClosing(images) match
×
UNCOV
115
          case Some(shouldSave) =>
×
116
            if shouldSave then
117
              Actions.save(model.imageGrid, model.imagePool, images, model.fileSystem)(
×
118
                view.askForSaveFile,
×
UNCOV
119
                view.askForFileSaveSettings,
×
120
                view
121
              )
122
            else true
×
UNCOV
123
          case None => false
×
124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc