fortrangoingonforty/fortty / 2740db7

Browse files

fixes

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
2740db732b06065bfa286948a642cadc74a0ba16
Parents
4f77477
Tree
319950d

5 changed files

StatusFile+-
M CMakeLists.txt 6 1
M c_src/pty_helpers.c 7 0
M src/fortty.f90 20 15
M src/text/atlas.f90 7 0
M src/text/renderer.f90 7 6
CMakeLists.txtmodified
@@ -30,7 +30,12 @@ add_library(helpers STATIC
3030
 )
3131
 target_include_directories(helpers PUBLIC ${CMAKE_SOURCE_DIR}/include)
3232
 target_include_directories(helpers PRIVATE ${FREETYPE_INCLUDE_DIRS})
33
-target_link_libraries(helpers PRIVATE glfw ${FREETYPE_LIBRARIES} util)
33
+target_link_libraries(helpers PRIVATE glfw ${FREETYPE_LIBRARIES})
34
+
35
+# Link util library for PTY on Linux (not needed on macOS)
36
+if(UNIX AND NOT APPLE)
37
+    target_link_libraries(helpers PRIVATE util)
38
+endif()
3439
 
3540
 # Link fontconfig if available
3641
 if(FONTCONFIG_FOUND)
c_src/pty_helpers.cmodified
@@ -4,7 +4,14 @@
44
  */
55
 
66
 #define _XOPEN_SOURCE 600
7
+
8
+/* Platform-specific PTY header */
9
+#if defined(__APPLE__)
10
+#include <util.h>
11
+#else
712
 #include <pty.h>
13
+#endif
14
+
815
 #include <unistd.h>
916
 #include <fcntl.h>
1017
 #include <sys/ioctl.h>
src/fortty.f90modified
@@ -263,7 +263,9 @@ program fortty
263263
     end if
264264
 
265265
     do row = 1, scr%rows
266
-      y = real(row) * cell_height
266
+      ! Cell top-left y coordinate (for rectangles like selection/cursor)
267
+      ! Row 1 starts at y=0, row 2 at y=cell_height, etc.
268
+      y = real(row - 1) * cell_height
267269
 
268270
       ! Determine if this row shows scrollback or screen content
269271
       sb_offset = scroll_offset - row + 1
@@ -279,17 +281,19 @@ program fortty
279281
 
280282
           x = real(col - 1) * cell_width
281283
 
282
-          ! Draw selection background if selected
283
-          if (selection_contains(sel, row, col)) then
284
-            call renderer_draw_rect(ren, x, y, real(cell_width), real(cell_height), &
285
-                                    0.3, 0.3, 0.6, 1.0)
286
-          end if
287
-
284
+          ! Only render cells with actual text content
288285
           if (cell%codepoint /= 32 .and. cell%codepoint /= 0) then
286
+            ! Draw selection background if selected (only for text cells)
287
+            if (selection_contains(sel, row, col)) then
288
+              call renderer_draw_rect(ren, x, y, real(cell_width), real(cell_height), &
289
+                                      0.3, 0.3, 0.6, 1.0)
290
+            end if
291
+
289292
             r = real(cell%fg%r) / 255.0
290293
             g = real(cell%fg%g) / 255.0
291294
             b = real(cell%fg%b) / 255.0
292
-            call renderer_draw_char(ren, x, y, cell%codepoint, r, g, b, 1.0)
295
+            ! Text baseline is at cell bottom; add cell_height to position correctly
296
+            call renderer_draw_char(ren, x, y + real(cell_height), cell%codepoint, r, g, b, 1.0)
293297
           end if
294298
         end do
295299
       else
@@ -304,17 +308,18 @@ program fortty
304308
 
305309
             x = real(col - 1) * cell_width
306310
 
307
-            ! Draw selection background if selected
308
-            if (selection_contains(sel, row, col)) then
309
-              call renderer_draw_rect(ren, x, y, real(cell_width), real(cell_height), &
310
-                                      0.3, 0.3, 0.6, 1.0)
311
-            end if
312
-
311
+            ! Only render cells with actual text content
313312
             if (cell%codepoint /= 32 .and. cell%codepoint /= 0) then
313
+              ! Draw selection background if selected (only for text cells)
314
+              if (selection_contains(sel, row, col)) then
315
+                call renderer_draw_rect(ren, x, y, real(cell_width), real(cell_height), &
316
+                                        0.3, 0.3, 0.6, 1.0)
317
+              end if
314318
               r = real(cell%fg%r) / 255.0
315319
               g = real(cell%fg%g) / 255.0
316320
               b = real(cell%fg%b) / 255.0
317
-              call renderer_draw_char(ren, x, y, cell%codepoint, r, g, b, 1.0)
321
+              ! Text baseline is at cell bottom; add cell_height to position correctly
322
+              call renderer_draw_char(ren, x, y + real(cell_height), cell%codepoint, r, g, b, 1.0)
318323
             end if
319324
           end do
320325
         end if
src/text/atlas.f90modified
@@ -44,6 +44,7 @@ contains
4444
     integer :: cp, i
4545
     type(glyph_t) :: g
4646
     type(c_ptr) :: bitmap_ptr
47
+    integer(c_int8_t), target :: white_pixel(1)
4748
 
4849
     if (.not. font%loaded) then
4950
       print *, "Error: Cannot create atlas from unloaded font"
@@ -72,6 +73,12 @@ contains
7273
                       atlas%width, atlas%height, 0, &
7374
                       GL_RED, GL_UNSIGNED_BYTE, c_null_ptr)
7475
 
76
+    ! Add a solid white pixel at position (0,0) for solid rectangle rendering
77
+    ! This allows renderer_draw_rect to sample a non-transparent pixel
78
+    white_pixel(1) = -1_c_int8_t  ! 255 as signed byte
79
+    call glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, &
80
+                         GL_RED, GL_UNSIGNED_BYTE, c_loc(white_pixel))
81
+
7582
     ! Initialize glyph array
7683
     do cp = 0, 127
7784
       call glyph_init(atlas%glyphs(cp))
src/text/renderer.f90modified
@@ -358,12 +358,13 @@ contains
358358
     x1 = x0 + real(w, c_float)
359359
     y1 = y0 + real(h, c_float)
360360
 
361
-    ! Use UV coords (0,0) which should sample a solid pixel from atlas
362
-    ! Most atlases have a solid white pixel at origin
363
-    u0 = 0.0_c_float
364
-    v0 = 0.0_c_float
365
-    u1 = 0.001_c_float  ! Tiny region to avoid sampling other glyphs
366
-    v1 = 0.001_c_float
361
+    ! Sample from center of white pixel at atlas origin (0.5, 0.5) in pixel coords
362
+    ! Atlas is 1024x1024, so UV center = 0.5/1024 ≈ 0.000488
363
+    ! Use same UV for all vertices to get solid color (no interpolation)
364
+    u0 = 0.0005_c_float
365
+    v0 = 0.0005_c_float
366
+    u1 = 0.0005_c_float
367
+    v1 = 0.0005_c_float
367368
 
368369
     ! Build 6 vertices for 2 triangles
369370
     base = r%vertex_count * FLOATS_PER_VERTEX + 1