mirror of
				https://github.com/AquaMorph/Droplets.git
				synced 2025-10-31 00:23:18 +00:00 
			
		
		
		
	Centered text
This commit is contained in:
		| @@ -28,5 +28,17 @@ void NoiseDroplet::Process(float** in, float** out, size_t size) { | ||||
| } | ||||
|  | ||||
| void NoiseDroplet::Draw() { | ||||
|   WriteString(*patch, 0, 30, Font_6x8, "Test"); | ||||
|   DrawName(patch); | ||||
| } | ||||
|  | ||||
|  | ||||
| void NoiseDroplet::DrawName(DaisyPatch* patch) { | ||||
|   int min = 0; | ||||
|   int max = SSD1309_WIDTH; | ||||
|   if (state == DropletState::kLeft) { | ||||
|     max = SSD1309_WIDTH / 2; | ||||
|   } else if (state == DropletState::kRight) { | ||||
|     min = SSD1309_WIDTH / 2; | ||||
|   } | ||||
|   WriteCenteredString(*patch, (min + max) / 2, 0, Font_6x8, "Noise"); | ||||
| } | ||||
|   | ||||
| @@ -14,6 +14,7 @@ class NoiseDroplet: public Droplet { | ||||
|   DaisyPatch* patch; | ||||
|   daisysp::WhiteNoise noise; | ||||
|   daisysp::NlFilt filter; | ||||
|   void DrawName(DaisyPatch*); | ||||
|  public: | ||||
|   NoiseDroplet(DaisyPatch*, float, DropletState); | ||||
|   void Control(); | ||||
|   | ||||
							
								
								
									
										11
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/main.cpp
									
									
									
									
									
								
							| @@ -18,7 +18,9 @@ Droplet* droplet; | ||||
| int main(void) { | ||||
|   patch.Init(); | ||||
|   float samplerate = patch.AudioSampleRate(); | ||||
|   droplet = new NoiseDroplet(&patch, samplerate, DropletState::kFull); | ||||
|   droplet = new NoiseDroplet(&patch, | ||||
| 			     samplerate, | ||||
| 			     DropletState::kFull); | ||||
|   patch.StartAdc(); | ||||
|   patch.StartAudio(AudioThrough); | ||||
|    | ||||
| @@ -39,7 +41,8 @@ void ProcessControls() { | ||||
|     } | ||||
|   } else { | ||||
|     if (patch.encoder.Pressed()) { | ||||
|       if (patch.encoder.TimeHeldMs() > 500 && patch.encoder.TimeHeldMs() < 505) { | ||||
|       if (patch.encoder.TimeHeldMs() > 500 && | ||||
| 	  patch.encoder.TimeHeldMs() < 505) { | ||||
| 	menu.SetInMenu(true); | ||||
|       } | ||||
|     } | ||||
| @@ -59,7 +62,9 @@ void ProcessOled() { | ||||
|   patch.display.Update(); | ||||
| } | ||||
|  | ||||
| static void AudioThrough(float **in, float **out, size_t size) { | ||||
| static void AudioThrough(float **in, | ||||
| 			 float **out, | ||||
| 			 size_t size) { | ||||
|   patch.UpdateAnalogControls(); | ||||
|   droplet->Process(in, out, size); | ||||
| } | ||||
|   | ||||
							
								
								
									
										19
									
								
								src/util.cpp
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								src/util.cpp
									
									
									
									
									
								
							| @@ -28,3 +28,22 @@ void WriteString(DaisyPatch patch, | ||||
| 		 std::string text) { | ||||
|   WriteString(patch, x, y, font, text, true); | ||||
| } | ||||
|  | ||||
| void WriteCenteredString(DaisyPatch patch, | ||||
| 			 int x, | ||||
| 			 int y, | ||||
| 			 FontDef font, | ||||
| 			 std::string text, | ||||
| 			 bool on) { | ||||
|  | ||||
|   int text_width = font.FontWidth * text.size(); | ||||
|   WriteString(patch, x - (text_width / 2), y, font, text, on); | ||||
| } | ||||
|  | ||||
| void WriteCenteredString(DaisyPatch patch, | ||||
| 		 int x, | ||||
| 		 int y, | ||||
| 		 FontDef font, | ||||
| 		 std::string text) { | ||||
|   WriteCenteredString(patch, x, y, font, text, true); | ||||
| } | ||||
|   | ||||
							
								
								
									
										13
									
								
								src/util.h
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/util.h
									
									
									
									
									
								
							| @@ -29,4 +29,17 @@ void WriteString(DaisyPatch, | ||||
| 		 FontDef, | ||||
| 		 std::string); | ||||
|  | ||||
| void WriteCenteredString(DaisyPatch, | ||||
| 			 int, | ||||
| 			 int, | ||||
| 			 FontDef, | ||||
| 			 std::string, | ||||
| 			 bool); | ||||
|  | ||||
| void WriteCenteredString(DaisyPatch, | ||||
| 			 int, | ||||
| 			 int, | ||||
| 			 FontDef, | ||||
| 			 std::string); | ||||
|  | ||||
| #endif // CASCADE_UTIL_H_ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user