Browse Source

Make pressing the preview work again

Benjamin Schaaf 4 years ago
parent
commit
d03d4b99e3
4 changed files with 86 additions and 70 deletions
  1. 2 1
      data/camera.css
  2. 77 66
      data/camera.ui
  3. 3 3
      src/main.c
  4. 4 0
      src/process_pipeline.c

+ 2 - 1
data/camera.css

@@ -4,9 +4,10 @@
 }
 
 .controlbox {
-    background: rgba(0,0,0,0.2);
+    background: rgba(0, 0, 0, 0.2);
 }
 
 .button-overlay {
     opacity: 0.9;
+    background-color: rgba(0, 0, 0, 0.2);
 }

+ 77 - 66
data/camera.ui

@@ -25,19 +25,19 @@
                 <child type="overlay">
                   <object class="GtkBox">
                     <property name="orientation">vertical</property>
-                    <property name="vexpand">1</property>
-                    <property name="hexpand">1</property>
+                    <property name="halign">fill</property>
+                    <property name="valign">start</property>
                     <property name="spacing">5</property>
                     <property name="can-focus">0</property>
-                    <property name="margin-start">5</property>
-                    <property name="margin-end">5</property>
-                    <property name="margin-bottom">5</property>
-                    <property name="margin-top">5</property>
                     <child>
                       <object class="GtkBox">
                         <property name="orientation">horizontal</property>
                         <property name="hexpand">1</property>
                         <property name="valign">start</property>
+                        <property name="margin-start">5</property>
+                        <property name="margin-end">5</property>
+                        <property name="margin-top">5</property>
+                        <property name="margin-bottom">5</property>
                         <property name="can-focus">0</property>
                         <property name="spacing">5</property>
                         <child>
@@ -64,6 +64,10 @@
                       <object class="GtkButton">
                         <property name="visible">0</property>
                         <property name="halign">start</property>
+                        <property name="margin-start">5</property>
+                        <property name="margin-end">5</property>
+                        <property name="margin-top">5</property>
+                        <property name="margin-bottom">5</property>
                         <child>
                           <object class="GtkBox">
                             <property name="orientation">horizontal</property>
@@ -85,87 +89,94 @@
                         </style>
                       </object>
                     </child>
+                    <style>
+                      <class name="button-overlay"/>
+                    </style>
+                  </object>
+                </child>
+                <child type="overlay">
+                  <object class="GtkBox">
+                    <property name="orientation">horizontal</property>
+                    <property name="halign">fill</property>
+                    <property name="valign">end</property>
                     <child>
                       <object class="GtkBox">
                         <property name="orientation">horizontal</property>
                         <property name="hexpand">1</property>
-                        <property name="vexpand">1</property>
                         <property name="valign">end</property>
-                        <property name="can-focus">0</property>
+                        <property name="margin-start">5</property>
+                        <property name="margin-top">5</property>
+                        <property name="margin-bottom">5</property>
+                        <property name="spacing">5</property>
                         <child>
-                          <object class="GtkBox">
-                            <property name="orientation">horizontal</property>
-                            <property name="hexpand">1</property>
-                            <property name="valign">end</property>
-                            <property name="can-focus">0</property>
-                            <property name="spacing">5</property>
-                            <child>
-                              <object class="GtkButton">
-                                <property name="action-name">app.open-settings</property>
-                                <property name="icon-name">settings-symbolic</property>
-                              </object>
-                            </child>
-                            <child>
-                              <object class="GtkButton">
-                                <property name="action-name">app.switch-camera</property>
-                                <property name="icon-name">switch-camera-symbolic</property>
-                              </object>
-                            </child>
+                          <object class="GtkButton">
+                            <property name="action-name">app.open-settings</property>
+                            <property name="icon-name">settings-symbolic</property>
                           </object>
                         </child>
                         <child>
                           <object class="GtkButton">
-                            <property name="action-name">app.capture</property>
-                            <child>
-                              <object class="GtkImage">
-                                <property name="pixel-size">60</property>
-                                <property name="can-focus">0</property>
-                                <property name="icon-name">shutter-button-symbolic</property>
-                              </object>
-                            </child>
-                            <style>
-                              <class name="circular"/>
-                            </style>
+                            <property name="action-name">app.switch-camera</property>
+                            <property name="icon-name">switch-camera-symbolic</property>
                           </object>
                         </child>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkButton">
+                        <property name="margin-top">5</property>
+                        <property name="margin-bottom">5</property>
+                        <property name="action-name">app.capture</property>
                         <child>
-                          <object class="GtkBox">
-                            <property name="orientation">horizontal</property>
-                            <property name="hexpand">1</property>
-                            <property name="halign">end</property>
-                            <property name="valign">end</property>
+                          <object class="GtkImage">
+                            <property name="pixel-size">60</property>
                             <property name="can-focus">0</property>
-                            <property name="spacing">5</property>
+                            <property name="icon-name">shutter-button-symbolic</property>
+                          </object>
+                        </child>
+                        <style>
+                          <class name="circular"/>
+                        </style>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkBox">
+                        <property name="orientation">horizontal</property>
+                        <property name="hexpand">1</property>
+                        <property name="halign">end</property>
+                        <property name="valign">end</property>
+                        <property name="margin-end">5</property>
+                        <property name="margin-top">5</property>
+                        <property name="margin-bottom">5</property>
+                        <property name="spacing">5</property>
+                        <child>
+                          <object class="GtkButton">
+                            <property name="action-name">app.open-last</property>
                             <child>
-                              <object class="GtkButton">
-                                <property name="action-name">app.open-last</property>
+                              <object class="GtkStack" id="open_last_stack">
+                                <property name="can-focus">0</property>
                                 <child>
-                                  <object class="GtkStack" id="open_last_stack">
+                                  <object class="GtkImage" id="thumb_last">
+                                    <property name="width-request">24</property>
+                                    <property name="height-request">24</property>
+                                    <property name="can-focus">0</property>
+                                  </object>
+                                </child>
+                                <child>
+                                  <object class="GtkSpinner" id="process_spinner">
+                                    <property name="width-request">24</property>
+                                    <property name="height-request">24</property>
                                     <property name="can-focus">0</property>
-                                    <child>
-                                      <object class="GtkImage" id="thumb_last">
-                                        <property name="width-request">24</property>
-                                        <property name="height-request">24</property>
-                                        <property name="can-focus">0</property>
-                                      </object>
-                                    </child>
-                                    <child>
-                                      <object class="GtkSpinner" id="process_spinner">
-                                        <property name="width-request">24</property>
-                                        <property name="height-request">24</property>
-                                        <property name="can-focus">0</property>
-                                      </object>
-                                    </child>
                                   </object>
                                 </child>
                               </object>
                             </child>
-                            <child>
-                              <object class="GtkButton">
-                                <property name="action-name">app.open-photos</property>
-                                <property name="icon-name">folder-symbolic</property>
-                              </object>
-                            </child>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkButton">
+                            <property name="action-name">app.open-photos</property>
+                            <property name="icon-name">folder-symbolic</property>
                           </object>
                         </child>
                       </object>

+ 3 - 3
src/main.c

@@ -545,6 +545,7 @@ static void
 preview_pressed(GtkGestureClick *gesture, int n_press, double x, double y)
 {
 	GtkWidget *widget = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));
+	int scale_factor = gtk_widget_get_scale_factor(widget);
 
 	// Tapped zbar result
 	if (zbar_result) {
@@ -552,9 +553,8 @@ preview_pressed(GtkGestureClick *gesture, int n_press, double x, double y)
 		float offset_x, offset_y, size_x, size_y;
 		position_preview(&offset_x, &offset_y, &size_x, &size_y);
 
-		double scale = preview_buffer_height / size_y;
-		int zbar_x = (x - offset_x) * scale;
-		int zbar_y = (y - offset_y) * scale;
+		int zbar_x = (x - offset_x) * scale_factor / size_x * preview_buffer_width;
+		int zbar_y = (y - offset_y) * scale_factor / size_y * preview_buffer_height;
 
 		for (uint8_t i = 0; i < zbar_result->size; ++i) {
 			MPZBarCode *code = &zbar_result->codes[i];

+ 4 - 0
src/process_pipeline.c

@@ -255,7 +255,9 @@ mp_process_pipeline_init_gl(GdkSurface *surface)
 static cairo_surface_t *
 process_image_for_preview(const uint8_t *image)
 {
+#ifdef PROFILE_DEBAYER
 	clock_t t1 = clock();
+#endif
 
 	// Pick an available buffer
 	MPProcessPipelineBuffer *output_buffer = NULL;
@@ -293,8 +295,10 @@ process_image_for_preview(const uint8_t *image)
 
 	glDeleteTextures(1, &input_texture);
 
+#ifdef PROFILE_DEBAYER
 	clock_t t2 = clock();
 	printf("%fms\n", (float)(t2 - t1) / CLOCKS_PER_SEC * 1000);
+#endif
 
 	// {
 	// 	glBindTexture(GL_TEXTURE_2D, textures[1]);